uigraph 1.0.0 → 1.0.2

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 (323) hide show
  1. package/README.md +30 -51
  2. package/dist/bin.mjs +1608 -59037
  3. package/dist/viewer/assets/abnfDiagram-VCTEODGH-D7zWJuPJ.js +1 -0
  4. package/dist/viewer/assets/actor-avatar-Bu-mKKXB.js +1 -0
  5. package/dist/viewer/assets/{api-adapters-CnQpLiWI.js → api-adapters-tfr51BsS.js} +1 -1
  6. package/dist/viewer/assets/{api-endpoints-DCA5GNpC.js → api-endpoints-D-Whnnwd.js} +9 -9
  7. package/dist/viewer/assets/{api-group-endpoints-page-Di42W69y.js → api-group-endpoints-page-B9R1EI4i.js} +9 -9
  8. package/dist/viewer/assets/{arc-Cn8owoDw.js → arc-DauzQXFu.js} +1 -1
  9. package/dist/viewer/assets/architectureDiagram-5GKGNRK7-CXzgHd-c.js +36 -0
  10. package/dist/viewer/assets/{arrow-left-DWcMgM2U.js → arrow-left-DpQqmf17.js} +1 -1
  11. package/dist/viewer/assets/avatar-DAFUyk1i.js +43 -0
  12. package/dist/viewer/assets/badge-hR3QvPWv.js +1 -0
  13. package/dist/viewer/assets/better-delete-confirmation-modal-CGEQ5O4X.js +1 -0
  14. package/dist/viewer/assets/better-dialog-DcIxFWwk.js +1 -0
  15. package/dist/viewer/assets/{blockDiagram-I7D4REHJ-CbYzOsL_.js → blockDiagram-I7D4REHJ-CFHWUw4z.js} +2 -2
  16. package/dist/viewer/assets/{brands-Bd4RklRx.js → brands-DtmA1AhP.js} +1 -1
  17. package/dist/viewer/assets/button-DZj74qS7.js +1 -0
  18. package/dist/viewer/assets/{c4Diagram-7LVT6UL2-CLkVbphC.js → c4Diagram-7LVT6UL2-BHSggPKI.js} +6 -6
  19. package/dist/viewer/assets/{calendar-C0xdI_ag.js → calendar-Bolgc8E5.js} +1 -1
  20. package/dist/viewer/assets/channel-CNRSofFP.js +1 -0
  21. package/dist/viewer/assets/{check-XjanpAFg.js → check-BpmCQNbj.js} +1 -1
  22. package/dist/viewer/assets/checkbox-CFJfXL6R.js +1 -0
  23. package/dist/viewer/assets/{chevron-down-R7pQzyLD.js → chevron-down-DDsUE_xz.js} +1 -1
  24. package/dist/viewer/assets/{chevron-up-CRPypfOs.js → chevron-up-DVznKMGv.js} +1 -1
  25. package/dist/viewer/assets/{chunk-2Q5K7J3B-CcvtugCu.js → chunk-2Q5K7J3B-CNfz5YDQ.js} +1 -1
  26. package/dist/viewer/assets/{chunk-5VM5RSS4-CpZHHr12.js → chunk-5VM5RSS4-CwIhjvMe.js} +1 -1
  27. package/dist/viewer/assets/{chunk-F27PBJKO-DeAl4iOc.js → chunk-F27PBJKO-YFexFJof.js} +1 -1
  28. package/dist/viewer/assets/{chunk-IMKFNOWR-BfrPe7pS.js → chunk-IMKFNOWR-GY2yrvuo.js} +1 -1
  29. package/dist/viewer/assets/{chunk-JWPE2WC7-DDjyvUmZ.js → chunk-JWPE2WC7-xd0JGvne.js} +1 -1
  30. package/dist/viewer/assets/chunk-OB3PAWPO-DJIP1M4r.js +12 -0
  31. package/dist/viewer/assets/{chunk-POPQ4Y6H-DkDb0mzz.js → chunk-POPQ4Y6H-Bh6rizEy.js} +1 -1
  32. package/dist/viewer/assets/{chunk-SVP7TREG-D-K2XIGs.js → chunk-SVP7TREG-DtNrjvpq.js} +1 -1
  33. package/dist/viewer/assets/{chunk-TICWLB2K-DWMQQx6z.js → chunk-TICWLB2K-DrERwtw8.js} +1 -1
  34. package/dist/viewer/assets/{chunk-XXDRQBXY-DfkljAyM.js → chunk-XXDRQBXY-fYo04iwY.js} +1 -1
  35. package/dist/viewer/assets/{circle-alert-pm13M-Ef.js → circle-alert-Bl7DXYD_.js} +1 -1
  36. package/dist/viewer/assets/classDiagram-ZZMXUADV-D7PO-ME9.js +1 -0
  37. package/dist/viewer/assets/classDiagram-v2-VYDZK3BY-D7PO-ME9.js +1 -0
  38. package/dist/viewer/assets/color-input-ClkkG_kZ.js +11 -0
  39. package/dist/viewer/assets/{common-Y7ySZBdh.js → common-DLCsGQ-t.js} +1 -1
  40. package/dist/viewer/assets/{component-icons-D1BDAuEt.js → component-icons-MJ61E9nt.js} +2 -2
  41. package/dist/viewer/assets/{copy-CN4K2f_R.js → copy-DMJJonQF.js} +1 -1
  42. package/dist/viewer/assets/cose-bilkent-JH36ORCC-Dplz8nVT.js +1 -0
  43. package/dist/viewer/assets/cross-button-D5qst1tj.js +1 -0
  44. package/dist/viewer/assets/{cynefin-OW5HDTMX-yz-uw9Kz.js → cynefin-OW5HDTMX-DiBs4CI8.js} +1 -1
  45. package/dist/viewer/assets/cynefinDiagram-5FMLGOSQ-COXS8-dI.js +62 -0
  46. package/dist/viewer/assets/{dagre-GXQ25YYZ-zjZDwXOe.js → dagre-GXQ25YYZ-K8qvfG8D.js} +2 -2
  47. package/dist/viewer/assets/dashboard-diagrams-page-Cb0xNr4W.js +2 -0
  48. package/dist/viewer/assets/dashboard-diagrams-page-inner-CD--zr5q.js +1 -0
  49. package/dist/viewer/assets/dashboard-docs-page-BfWR9Ai9.js +2 -0
  50. package/dist/viewer/assets/dashboard-docs-page-inner-BLbX-YwF.js +67 -0
  51. package/dist/viewer/assets/dashboard-layout-sTeeHNsZ.js +1 -0
  52. package/dist/viewer/assets/dashboard-lens-layout-D-tu_4kn.js +1 -0
  53. package/dist/viewer/assets/dashboard-map-frame-page-7pDmbTSe.js +1 -0
  54. package/dist/viewer/assets/dashboard-plans-page-CfwOZ34A.js +1 -0
  55. package/dist/viewer/assets/dashboard-service-apis-k93fjW51.js +1 -0
  56. package/dist/viewer/assets/{dashboard-service-diagrams-CIjk95Jk.js → dashboard-service-diagrams-BIWUxX-Y.js} +3 -3
  57. package/dist/viewer/assets/dashboard-service-docs-CnniTD6Q.js +1 -0
  58. package/dist/viewer/assets/{dashboard-service-overview-CzePVPjl.js → dashboard-service-overview-CGBu4omY.js} +5 -5
  59. package/dist/viewer/assets/dashboard-services-DEscIO2O.js +1 -0
  60. package/dist/viewer/assets/{db-type-badge-DOgu1Pyc.js → db-type-badge-UbPgpwQf.js} +2 -2
  61. package/dist/viewer/assets/debounce-Cp8eREM4-D7o-Pzb-.js +2 -0
  62. package/dist/viewer/assets/{dependencies-CYdEztHw.js → dependencies-DK2GDlhQ.js} +1 -1
  63. package/dist/viewer/assets/{dependency-graph-DbyfN-rC.js → dependency-graph-xBEnCS0J.js} +3 -3
  64. package/dist/viewer/assets/{diagram-S7CK7UJ4-q-NHkUCx.js → diagram-S7CK7UJ4-D-liadVe.js} +2 -2
  65. package/dist/viewer/assets/diagram-UQ7AKVKN-CnA8mgXp.js +41 -0
  66. package/dist/viewer/assets/{diagram-VSXAHHWV-DZc1kHGx.js → diagram-VSXAHHWV-Ck7dgRFR.js} +2 -2
  67. package/dist/viewer/assets/diagram-VX7I27RA-Cm1LHbu3.js +24 -0
  68. package/dist/viewer/assets/diagram-Z3DM3KII-DV3yBUCB.js +24 -0
  69. package/dist/viewer/assets/diagram-live-preview-DzJ7Nxp1.js +2 -0
  70. package/dist/viewer/assets/{diagram-portal-page-CWxuok9E.js → diagram-portal-page-gguGLULH.js} +24 -24
  71. package/dist/viewer/assets/{diagrams-C1xkRPqT.js → diagrams-BqBSv2eb.js} +4 -4
  72. package/dist/viewer/assets/dialog-D7wzTt0L.js +6 -0
  73. package/dist/viewer/assets/{doc-file-content-B06roi8L.js → doc-file-content-Be0au9Vo.js} +4 -4
  74. package/dist/viewer/assets/{download-CLdCXVsO.js → download-DhyZ3g4F.js} +1 -1
  75. package/dist/viewer/assets/ebnfDiagram-PWID7BFC-BXbHVQvG.js +1 -0
  76. package/dist/viewer/assets/{editor-vqK4qAnB.js → editor-F9o4zoeB.js} +2 -2
  77. package/dist/viewer/assets/{erDiagram-RLTQ6QDP-BWuA-aqV.js → erDiagram-RLTQ6QDP-DMfiWput.js} +2 -2
  78. package/dist/viewer/assets/{file-text-BvszilVL.js → file-text-BFqJQ67P.js} +1 -1
  79. package/dist/viewer/assets/flow-diagram-preview-B83UU1n_.js +1 -0
  80. package/dist/viewer/assets/{flowDiagram-HODETNUW-Db0QtNj4.js → flowDiagram-HODETNUW-BNFS2Mkr.js} +1 -1
  81. package/dist/viewer/assets/ganttDiagram-EL5Y4UJY-DFDsYJNp.js +292 -0
  82. package/dist/viewer/assets/gitGraphDiagram-WWUBYQGX-BVHabPDp.js +106 -0
  83. package/dist/viewer/assets/global-loader-XJO9_e0l.js +1 -0
  84. package/dist/viewer/assets/{globe-Jl6eIZmG.js → globe-CJ35KsQW.js} +1 -1
  85. package/dist/viewer/assets/gql-FFIj8zdp.js +1 -0
  86. package/dist/viewer/assets/{grid-scroll-body-CPqSxU6-.js → grid-scroll-body-DC5pYDPJ.js} +2 -2
  87. package/dist/viewer/assets/iconBase-DtqdW2XR.js +1 -0
  88. package/dist/viewer/assets/index-B6MxYIzs.js +1 -0
  89. package/dist/viewer/assets/index-BC5xdBQU.js +48 -0
  90. package/dist/viewer/assets/index-BIrx3oY4.js +1 -0
  91. package/dist/viewer/assets/{index-jm22RWpY.js → index-BZGsDmUx.js} +5 -5
  92. package/dist/viewer/assets/{index-Poftp9f1.js → index-BZXhpoWr.js} +4 -4
  93. package/dist/viewer/assets/index-Bn2bqqMd.js +1 -0
  94. package/dist/viewer/assets/{index-HU5pz3kj.js → index-BpCVYTvP.js} +36 -36
  95. package/dist/viewer/assets/{index-Bt2YHgxl.js → index-CBOYhBKJ.js} +1 -1
  96. package/dist/viewer/assets/index-CH7cEAxj.js +17 -0
  97. package/dist/viewer/assets/index-CIf0GId3.js +74 -0
  98. package/dist/viewer/assets/{index-D7MEHpJf.js → index-Ck66Ic_p.js} +4 -4
  99. package/dist/viewer/assets/index-Cp9mIQ8F.js +1 -0
  100. package/dist/viewer/assets/{index-c6Bxcoqm.js → index-DDmBuMKI.js} +1 -1
  101. package/dist/viewer/assets/{index-BSyJbFDG.js → index-DY3BFyb6.js} +1 -1
  102. package/dist/viewer/assets/{index-BS94XVnd.js → index-DkzZ-ZvR.js} +1 -1
  103. package/dist/viewer/assets/{index-C_43VC19.js → index-PglMbhys.js} +1 -1
  104. package/dist/viewer/assets/infoDiagram-27XIBGKW-CG-wwxBf.js +2 -0
  105. package/dist/viewer/assets/input--C59pq6j.js +1 -0
  106. package/dist/viewer/assets/{ishikawaDiagram-5VMMS53U-C4PzFnZ4.js → ishikawaDiagram-5VMMS53U-BlgV7ceJ.js} +2 -2
  107. package/dist/viewer/assets/{journeyDiagram-3NMN7TZE-Dpn3bBNo.js → journeyDiagram-3NMN7TZE-Cn03_Xl6.js} +2 -2
  108. package/dist/viewer/assets/{kanban-definition-UXKFOSKX-CJ99H4G6.js → kanban-definition-UXKFOSKX-CJogvDPY.js} +6 -6
  109. package/dist/viewer/assets/{layout-Bfvxt_D5.js → layout-B26eC4yQ.js} +1 -1
  110. package/dist/viewer/assets/{lens-run-page-DZneics-.js → lens-run-page-Ba1ppzJt.js} +3 -3
  111. package/dist/viewer/assets/lens-runs-page-BnUS57LM.js +1 -0
  112. package/dist/viewer/assets/{link-2-C75goIOt.js → link-2-D1e0xznG.js} +1 -1
  113. package/dist/viewer/assets/linked-project-dot-BY1gEES9.js +543 -0
  114. package/dist/viewer/assets/{loader-circle-C5jZoM7X.js → loader-circle-CiqyoJF7.js} +1 -1
  115. package/dist/viewer/assets/{merge-Cy7YkrN7.js → merge-BhOMvhW1.js} +1 -1
  116. package/dist/viewer/assets/mermaid.core-BDgZg3kW.js +312 -0
  117. package/dist/viewer/assets/method-badge-DErZP7y5.js +1 -0
  118. package/dist/viewer/assets/{mindmap-definition-YA3MSWOX-yQCKA-K4.js → mindmap-definition-YA3MSWOX-DFkLu0ac.js} +2 -2
  119. package/dist/viewer/assets/nav-links-DZWMpwMR.js +61 -0
  120. package/dist/viewer/assets/{network-COWNXGMM.js → network-B1apzT1s.js} +1 -1
  121. package/dist/viewer/assets/{nosql-editor-modal-DTiWkc_r.js → nosql-editor-modal-CvH0SWAi.js} +5 -5
  122. package/dist/viewer/assets/not-found-page-C-fn8QeM.js +1 -0
  123. package/dist/viewer/assets/organization-dependency-graph-page-BryP-iJL.js +1 -0
  124. package/dist/viewer/assets/pegDiagram-XKGWAZYB-g1cM14-L.js +1 -0
  125. package/dist/viewer/assets/{pieDiagram-E7YTZNPT-DqnkpCX4.js → pieDiagram-E7YTZNPT-WEnDsMY3.js} +2 -2
  126. package/dist/viewer/assets/{plus-DQakmTjA.js → plus-DbyuOgKB.js} +1 -1
  127. package/dist/viewer/assets/popover-476u3TN0.js +1 -0
  128. package/dist/viewer/assets/preload-helper-BlTxHScW.js +1 -0
  129. package/dist/viewer/assets/{quadrantDiagram-AXDQQJYC-iQjJfars.js → quadrantDiagram-AXDQQJYC-NdfQCpzF.js} +2 -2
  130. package/dist/viewer/assets/query-D9oj6LGx.js +50 -0
  131. package/dist/viewer/assets/{quill-rCHj4fCw.js → quill-Cde5JMRD.js} +1 -1
  132. package/dist/viewer/assets/railroadDiagram-O6MQD6OU-BYhlXlMY.js +1 -0
  133. package/dist/viewer/assets/{react-BNzYaZuG.js → react-Bx48XWN4.js} +1 -1
  134. package/dist/viewer/assets/react-flow-wrapper-BcbvHgxz.js +277 -0
  135. package/dist/viewer/assets/{requirementDiagram-BXWQKSXE-Bv-Vh1dW.js → requirementDiagram-BXWQKSXE-C25Bcm2L.js} +2 -2
  136. package/dist/viewer/assets/{sankeyDiagram-P5KCCOFB-C__uD07f.js → sankeyDiagram-P5KCCOFB-h8LiCsgk.js} +2 -2
  137. package/dist/viewer/assets/scroll-area-RagrStGj.js +6 -0
  138. package/dist/viewer/assets/{search-DW-qhXLk.js → search-vw7ucoOs.js} +1 -1
  139. package/dist/viewer/assets/section-loader-C4hOfhQS.js +1 -0
  140. package/dist/viewer/assets/section-not-found-BnrXiPog.js +1 -0
  141. package/dist/viewer/assets/select-D9fbrr7O.js +1 -0
  142. package/dist/viewer/assets/{sequenceDiagram-WJ2MYXX4-1RbvcHwO.js → sequenceDiagram-WJ2MYXX4-CDRVvD30.js} +2 -2
  143. package/dist/viewer/assets/{service-context-C17u_Fw9.js → service-context-D5nBtU18.js} +1 -1
  144. package/dist/viewer/assets/{service-database-list-page-cYuDHIls.js → service-database-list-page-DBjaDLVy.js} +2 -2
  145. package/dist/viewer/assets/service-database-page-CenNCgwf.js +2 -0
  146. package/dist/viewer/assets/service-database-page-inner-gS51TQTZ.js +85 -0
  147. package/dist/viewer/assets/{service-doc-Dir8g83J.js → service-doc-C-jHqT1U.js} +4 -4
  148. package/dist/viewer/assets/{service-doc-preview-modal-bJ6tJ5YR.js → service-doc-preview-modal-5sX6FOu1.js} +2 -2
  149. package/dist/viewer/assets/service-layout-Bf0vZBCH.js +1 -0
  150. package/dist/viewer/assets/service-pages-CFikvX4t.js +1 -0
  151. package/dist/viewer/assets/{services-Crqkffr5.js → services-Ivav34WC.js} +4 -4
  152. package/dist/viewer/assets/{share-2-BmYmqN4k.js → share-2-CQEaWbfH.js} +1 -1
  153. package/dist/viewer/assets/sizeCapture-INFHLROL-BJ6ndnPM.js +1 -0
  154. package/dist/viewer/assets/stateDiagram-D77RDMKH-B_tNCX3o.js +1 -0
  155. package/dist/viewer/assets/stateDiagram-v2-MP3YSRHH-Dl9wqdli.js +1 -0
  156. package/dist/viewer/assets/{style-DgSU0bQl.js → style-BPesJvJr.js} +8 -8
  157. package/dist/viewer/assets/super-circle-loader-DSkos6uP.js +1 -0
  158. package/dist/viewer/assets/super-logo-loader-Cxlbn6MB.js +1 -0
  159. package/dist/viewer/assets/swimlanes-42K2YHIH-CzURzYwf.js +1 -0
  160. package/dist/viewer/assets/swimlanesDiagram-VR7AAH4N-DrIlwFtk.js +8 -0
  161. package/dist/viewer/assets/table-B4pFND-o.js +1 -0
  162. package/dist/viewer/assets/textarea-Clgdv3Oi.js +1 -0
  163. package/dist/viewer/assets/{timeline-definition-24CTP7MA-C4yuLwUH.js → timeline-definition-24CTP7MA-D0YXQE1U.js} +2 -2
  164. package/dist/viewer/assets/ui-graph-logo-gHowu5gP.js +1 -0
  165. package/dist/viewer/assets/{upload-CRsS43j9.js → upload-CYb3nN_5.js} +1 -1
  166. package/dist/viewer/assets/{uploads-BOQHX9l4.js → uploads-CX2kdXbM.js} +8 -8
  167. package/dist/viewer/assets/{use-debounced-value-Ba-kkCUY.js → use-debounced-value-BpNFJd3C.js} +1 -1
  168. package/dist/viewer/assets/{use-localstorage-DIisTx-J.js → use-localstorage-D233xVb0.js} +1 -1
  169. package/dist/viewer/assets/use-permissions-BvmxJJ5r.js +1 -0
  170. package/dist/viewer/assets/{use-scoped-storage-C4RzED-E.js → use-scoped-storage-DL1XVp1j.js} +1 -1
  171. package/dist/viewer/assets/useMutation-D5ZHwHsx.js +1 -0
  172. package/dist/viewer/assets/useQuery-Dhe6uxrL.js +1 -0
  173. package/dist/viewer/assets/{vennDiagram-4TSXK5OY-BCtqXZqe.js → vennDiagram-4TSXK5OY-SSjHlqCQ.js} +2 -2
  174. package/dist/viewer/assets/{wardleyDiagram-VM6X3IG4-D3OtZJoT.js → wardleyDiagram-VM6X3IG4-CZWNdQxH.js} +2 -2
  175. package/dist/viewer/assets/{xychartDiagram-S5SC5T6Z-DxLL2CHH.js → xychartDiagram-S5SC5T6Z-B2qAGeb0.js} +2 -2
  176. package/dist/viewer/assets/zod-BMU4UTQt.js +1 -0
  177. package/dist/viewer/index.html +10 -1
  178. package/package.json +57 -57
  179. package/dist/abort-signals-B4fc3ahg.mjs +0 -34
  180. package/dist/agents.md +0 -28
  181. package/dist/anthropic-messages-KPxCHqBN.mjs +0 -14327
  182. package/dist/auth-storage-BvNH97p9.mjs +0 -2180
  183. package/dist/azure-openai-config-BbeCSg4y.mjs +0 -55
  184. package/dist/azure-openai-responses-BRzy8RfL.mjs +0 -182
  185. package/dist/classifier-shared-DBUHiTGw.mjs +0 -105
  186. package/dist/cli-2R6QQFp1.mjs +0 -451
  187. package/dist/cloudflare-workers-ai-system-one-BfqwmRQf.mjs +0 -44
  188. package/dist/config-D8DMGzIq.mjs +0 -647
  189. package/dist/cross-spawn-B2jIQPlu.mjs +0 -404
  190. package/dist/diagnostics-xdSgQR8t.mjs +0 -131
  191. package/dist/dist-BRyghrKX.mjs +0 -404
  192. package/dist/dist-D0EzrblG.mjs +0 -12161
  193. package/dist/dist-EKhnHWHG.mjs +0 -140221
  194. package/dist/dist-pQtuusFv.mjs +0 -1243
  195. package/dist/easter-egg-3d-C9_btlWn.mjs +0 -1225
  196. package/dist/env-api-keys-uytNub6O.mjs +0 -122
  197. package/dist/error-body-FhmCtR7m.mjs +0 -101
  198. package/dist/esm-D5isprgl.mjs +0 -1533
  199. package/dist/esm-DnqE4pfM.mjs +0 -104876
  200. package/dist/execute-BoTKl80U.mjs +0 -1715
  201. package/dist/github-copilot-headers-DWcTgoXr.mjs +0 -22
  202. package/dist/google-generative-ai-Brs5YpJo.mjs +0 -332
  203. package/dist/google-shared-2CyYa4VE.mjs +0 -33438
  204. package/dist/google-vertex-DZDUQPKa.mjs +0 -378
  205. package/dist/hash-DN7ukSfd.mjs +0 -16
  206. package/dist/headers-GhQHLk-3.mjs +0 -17
  207. package/dist/jiti-9kWALm4Y.mjs +0 -5439
  208. package/dist/jiti-loader-f21DrY1K.mjs +0 -27
  209. package/dist/jiti-static-loader-BI_w28l7.mjs +0 -41704
  210. package/dist/json-parse-B2mHg7o7.mjs +0 -381
  211. package/dist/keybinding-hints-D0nLU3ZH.mjs +0 -17899
  212. package/dist/lib-Dj1gKQJc.mjs +0 -24379
  213. package/dist/llama-cpp-classify-C73BoMYd.mjs +0 -344
  214. package/dist/mistral-conversations-DXVR7znL.mjs +0 -698
  215. package/dist/models-DBdii9gQ.mjs +0 -1255
  216. package/dist/multipart-parser-DLw9Z0uJ.mjs +0 -298
  217. package/dist/node-B0NU8X55.mjs +0 -2479
  218. package/dist/node-B8gaKm9g.mjs +0 -23
  219. package/dist/openai-I3_AqKDX.mjs +0 -17357
  220. package/dist/openai-codex-responses-PcZHDuBD.mjs +0 -1198
  221. package/dist/openai-completions-a_mH01ii.mjs +0 -994
  222. package/dist/openai-decisions-Du8y4mQG.mjs +0 -142
  223. package/dist/openai-prompt-cache-Bc6qNWt0.mjs +0 -8
  224. package/dist/openai-responses-a9lV_U7O.mjs +0 -270
  225. package/dist/openai-responses-shared-CDs_PBiH.mjs +0 -598
  226. package/dist/openrouter-images-D0Zc8Cjs.mjs +0 -125
  227. package/dist/photon_rs-DCvMOMu0.mjs +0 -4252
  228. package/dist/pi-messages-B5ietIBq.mjs +0 -306
  229. package/dist/plan-prompt.md +0 -56
  230. package/dist/prompt.md +0 -44
  231. package/dist/provider-env-BJhgA66g.mjs +0 -37
  232. package/dist/provider-retry-DXYM7rVE.mjs +0 -79
  233. package/dist/runtime-DTkBxiaM.mjs +0 -2822
  234. package/dist/sanitize-unicode-CqChtoM6.mjs +0 -26
  235. package/dist/shell-836_JFnI.mjs +0 -162
  236. package/dist/source-CKPndhKl.mjs +0 -478
  237. package/dist/src-DNm2QRm3.mjs +0 -5028
  238. package/dist/system-one-shared-DUAFtNa8.mjs +0 -75
  239. package/dist/token-DEUkymby.mjs +0 -56
  240. package/dist/token-util-Cx5S4eKt.mjs +0 -3
  241. package/dist/tool-DHDYqsyG.mjs +0 -6673
  242. package/dist/transform-messages-BClk99Vn.mjs +0 -477
  243. package/dist/typesafe-system-one-D2d8j8hZ.mjs +0 -24
  244. package/dist/typescript-Br-vsRJV.mjs +0 -6737
  245. package/dist/uuid-CNCZqNBb.mjs +0 -49
  246. package/dist/v2-1z8ijsD3.mjs +0 -6120
  247. package/dist/viewer/assets/abnfDiagram-VCTEODGH-j5YaKnl9.js +0 -1
  248. package/dist/viewer/assets/actor-avatar-DqmoY8Xc.js +0 -1
  249. package/dist/viewer/assets/architectureDiagram-5GKGNRK7-D80cJKz_.js +0 -36
  250. package/dist/viewer/assets/avatar-BI7D-Aia.js +0 -43
  251. package/dist/viewer/assets/badge-870-A4Y6.js +0 -1
  252. package/dist/viewer/assets/better-delete-confirmation-modal-Dib31LVb.js +0 -1
  253. package/dist/viewer/assets/better-dialog-D3AAiahr.js +0 -1
  254. package/dist/viewer/assets/button-DadqadpO.js +0 -1
  255. package/dist/viewer/assets/channel-DRkt3LIn.js +0 -1
  256. package/dist/viewer/assets/checkbox-BXpR079x.js +0 -1
  257. package/dist/viewer/assets/classDiagram-ZZMXUADV-G5CebNaC.js +0 -1
  258. package/dist/viewer/assets/classDiagram-v2-VYDZK3BY-G5CebNaC.js +0 -1
  259. package/dist/viewer/assets/color-input-Efm-lxDy.js +0 -11
  260. package/dist/viewer/assets/cose-bilkent-JH36ORCC-CrSHFmnp.js +0 -1
  261. package/dist/viewer/assets/cross-button-5Sr5rWVP.js +0 -1
  262. package/dist/viewer/assets/cynefinDiagram-5FMLGOSQ-Bdl_eBdu.js +0 -62
  263. package/dist/viewer/assets/dashboard-diagrams-page-DMupOe1m.js +0 -2
  264. package/dist/viewer/assets/dashboard-diagrams-page-inner-Dh0yKh2A.js +0 -1
  265. package/dist/viewer/assets/dashboard-docs-page-DWJ1qOQz.js +0 -2
  266. package/dist/viewer/assets/dashboard-docs-page-inner-Fs6G3oGo.js +0 -67
  267. package/dist/viewer/assets/dashboard-layout-D36InAaB.js +0 -1
  268. package/dist/viewer/assets/dashboard-lens-layout-Cv1Xx3hY.js +0 -1
  269. package/dist/viewer/assets/dashboard-map-frame-page-CTn61NUO.js +0 -1
  270. package/dist/viewer/assets/dashboard-plans-page-DxFJkrgK.js +0 -1
  271. package/dist/viewer/assets/dashboard-service-apis-BHtD9s5z.js +0 -1
  272. package/dist/viewer/assets/dashboard-service-docs-Uv_1uxxO.js +0 -1
  273. package/dist/viewer/assets/dashboard-services-CUP-L4Jg.js +0 -1
  274. package/dist/viewer/assets/diagram-UQ7AKVKN-DhFcurW6.js +0 -41
  275. package/dist/viewer/assets/diagram-VX7I27RA-DE1nREE8.js +0 -24
  276. package/dist/viewer/assets/diagram-Z3DM3KII-CSrYcCbc.js +0 -24
  277. package/dist/viewer/assets/diagram-live-preview-i5doxXLH.js +0 -2
  278. package/dist/viewer/assets/dialog-D_HtNS17.js +0 -6
  279. package/dist/viewer/assets/ebnfDiagram-PWID7BFC-BfL8m_sf.js +0 -1
  280. package/dist/viewer/assets/flow-diagram-preview-T0Z4iMVU.js +0 -1
  281. package/dist/viewer/assets/ganttDiagram-EL5Y4UJY-CsITpniw.js +0 -292
  282. package/dist/viewer/assets/gitGraphDiagram-WWUBYQGX-B4eCBGoe.js +0 -106
  283. package/dist/viewer/assets/iconBase-BoDZfJgC.js +0 -1
  284. package/dist/viewer/assets/index-5E1tJ7yK.js +0 -125
  285. package/dist/viewer/assets/index-7XpV2DRw.js +0 -1
  286. package/dist/viewer/assets/index-C0Rs3s9Z.js +0 -1
  287. package/dist/viewer/assets/index-CzHjJWeV.js +0 -1
  288. package/dist/viewer/assets/index-DcEA6SIV.js +0 -74
  289. package/dist/viewer/assets/infoDiagram-27XIBGKW-lTebN5Ix.js +0 -2
  290. package/dist/viewer/assets/input-YvHTVS0E.js +0 -1
  291. package/dist/viewer/assets/lens-runs-page-DoAOObxx.js +0 -1
  292. package/dist/viewer/assets/linked-project-dot-Ds2uEmJ9.js +0 -543
  293. package/dist/viewer/assets/mermaid.core-BCRBv8Us.js +0 -312
  294. package/dist/viewer/assets/method-badge-DMYDKdDZ.js +0 -1
  295. package/dist/viewer/assets/nav-links-8vT2ixiI.js +0 -61
  296. package/dist/viewer/assets/not-found-page-CnfLlhS4.js +0 -1
  297. package/dist/viewer/assets/organization-dependency-graph-page-3xqIxjNx.js +0 -1
  298. package/dist/viewer/assets/pegDiagram-XKGWAZYB-CMXqeAum.js +0 -1
  299. package/dist/viewer/assets/popover-CN9ni1N3.js +0 -1
  300. package/dist/viewer/assets/railroadDiagram-O6MQD6OU-CfqToX3W.js +0 -1
  301. package/dist/viewer/assets/react-flow-wrapper-BPlRstyO.js +0 -276
  302. package/dist/viewer/assets/scroll-area-BodE-n7W.js +0 -6
  303. package/dist/viewer/assets/section-loader-BzpYM_Nx.js +0 -1
  304. package/dist/viewer/assets/select-DDtnmSET.js +0 -1
  305. package/dist/viewer/assets/service-database-page-CMi1wF4h.js +0 -2
  306. package/dist/viewer/assets/service-database-page-inner-CoqAj93L.js +0 -85
  307. package/dist/viewer/assets/service-layout-0NMm_bKG.js +0 -1
  308. package/dist/viewer/assets/service-pages-dfnc91SU.js +0 -1
  309. package/dist/viewer/assets/sizeCapture-INFHLROL-BRJi3gCg.js +0 -1
  310. package/dist/viewer/assets/stateDiagram-D77RDMKH-DdLsfxgy.js +0 -1
  311. package/dist/viewer/assets/stateDiagram-v2-MP3YSRHH-DFwg8Qki.js +0 -1
  312. package/dist/viewer/assets/super-circle-loader-D8MElOMh.js +0 -1
  313. package/dist/viewer/assets/super-logo-loader-DJYiRbCS.js +0 -1
  314. package/dist/viewer/assets/swimlanes-42K2YHIH-AuYjrPqh.js +0 -1
  315. package/dist/viewer/assets/swimlanesDiagram-VR7AAH4N-0nIGA8_4.js +0 -8
  316. package/dist/viewer/assets/table-Bi4Auk9Z.js +0 -1
  317. package/dist/viewer/assets/textarea-MgxZ5x6-.js +0 -1
  318. package/dist/viewer/assets/ui-graph-logo-D4jRhd4z.js +0 -1
  319. package/dist/viewer/assets/use-permissions-6JVET753.js +0 -1
  320. package/dist/viewer/assets/useMutation-CmVaR9zz.js +0 -1
  321. package/dist/viewer/assets/useQuery-B8yYhO0c.js +0 -1
  322. package/dist/viewer/assets/zod-Dc4H6VVJ.js +0 -1
  323. package/dist/virtual-modules-DnCx0Gdx.mjs +0 -340
@@ -1,4 +1,4 @@
1
- import{_ as Qe}from"./index-5E1tJ7yK.js";import{o as re,r as Ue,s as _,a as gt,b as _e,c as tt,n as Le,d as le,e as Ut,f as Hn,h as Un,g as qn,i as qt,j as Wn,k as Kn,l as je,m as zn,p as vn,q as jn,z as Yn,t as Xn,v as Qn,w as Zn,x as Vn,y as Jn,A as eo,B as Re,u as bn,C as mt}from"./index-DcEA6SIV.js";import{a as wn,g as dt,o as to}from"./index-Dj_05fqk.js";import{b7 as no}from"./mermaid.core-BCRBv8Us.js";import{l as $e}from"./last-DXTTfs9a.js";import{M as xe,d as We,P as nt}from"./index-C0Rs3s9Z.js";let L=(function(e){return e.TextInput="Text Input",e.URLInput="URL Input",e.NumberInput="Number Input",e.TextBox="Text Editor",e.DatePicker="Date Picker",e.DropdownSelect="Dropdown",e.MultiSelect="Multi Select",e.BooleanToggle="Boolean Toggle",e.LinkOrFileUpload="Link or File Upload",e.RichTextEditor="Rich Text Editor",e.CodeEditor="Code Editor",e.KeyValueList="Key-Value List",e.TagInput="Tag Input",e.DateRangePicker="Date Range Picker",e.ColorPicker="Color Picker",e.Slider="Slider",e.FileUpload="File Upload",e.SearchSelect="Search Select",e.CheckboxGroup="Checkbox Group",e})({});const xn=re({name:_().optional(),description:_().optional(),nodes:Ue(_(),re({type:_().optional(),name:_().optional(),value:_().optional(),cloud:_().optional(),service:_().optional(),src:_().optional(),animatedIcon:_().optional(),componentId:_().optional(),shape:tt(["rectangle","rounded-rect","ellipse","diamond","triangle","parallelogram","trapezoid","hexagon","document","cylinder","delay","off-page-connector","display","collate","sort","terminator","or","database","multiple-documents","subroutine","manual-input","summing-junction","internal-storage"]).optional(),data:Ue(_(),re({type:tt(Object.values(L)),options:le(_()).optional(),value:gt()})).optional(),style:re({width:Le().optional(),height:Le().optional(),color:_().optional(),fill:_().optional(),stroke:_().optional(),strokeWidth:Le().optional(),borderRadius:Le().optional(),strokeStyle:tt(["solid","dashed","dotted"]).optional(),borderAnimationEnabled:_e().optional()}).optional(),dbConfig:re({serviceName:_(),databaseName:_(),tableName:_()}).optional(),table:re({columns:_().array(),rows:le(le(_()))}).optional(),___internal:Ue(_(),gt()).optional(),___position:re({x:Le(),y:Le()}).optional()})).optional(),edges:Ue(_(),re({type:_().optional(),sourceHandle:_().optional(),targetHandle:_().optional(),label:_().optional(),style:re({stroke:_().optional(),strokeWidth:Le().optional(),strokeStyle:tt(["solid","dashed","dotted"]).optional(),borderAnimationEnabled:_e().optional()}).optional(),markerStart:re({type:_(),color:_().optional()}).optional(),markerEnd:re({type:_(),color:_().optional()}).optional(),___internal:Ue(_(),gt()).optional()})).optional(),groups:Ue(_(),re({name:_().optional(),nodes:_().array().optional()})).optional()}),oo={}.hasOwnProperty;function En(e,t){let n=-1,o;if(t.extensions)for(;++n<t.extensions.length;)En(e,t.extensions[n]);for(o in t)if(oo.call(t,o))switch(o){case"extensions":break;case"unsafe":{Wt(e[o],t[o]);break}case"join":{Wt(e[o],t[o]);break}case"handlers":{io(e[o],t[o]);break}default:e.options[o]=t[o]}return e}function Wt(e,t){t&&e.push(...t)}function io(e,t){t&&Object.assign(e,t)}function Tt(e){if(e.charCodeAt(0)!==60)return;const t=e.charCodeAt(1);if(t===33){const a=e.charCodeAt(2);return a===45?2:a===91?5:Ut(a)?4:void 0}if(t===63)return 3;const n=t===47,o=n?2:1;let r=o,i=e.charCodeAt(r);if(!Ut(i))return;for(;i===45||Hn(i);)i=e.charCodeAt(++r);const s=e.slice(o,r).toLowerCase();return!n&&i!==47&&Un.includes(s)?1:qn.includes(s)?6:7}const ro=[so];function so(e,t,n,o){if(t.type==="code"&&qt(t,o)&&(e.type==="list"||e.type===t.type&&qt(e,o)))return!1;if("spread"in n&&typeof n.spread=="boolean"){if(e.type==="paragraph"&&(e.type===t.type||t.type==="definition"||t.type==="heading"&&Wn(t,o)))return;if(e.type==="html"){const r=Tt(e.value);if(r===void 0||r===6||r===7)return 1}if(e.type==="paragraph"&&t.type==="html"){const r=Tt(t.value);if(r===void 0||r===7)return 1}return n.spread?1:0}}const Pe=["autolink","destinationLiteral","destinationRaw","reference","titleQuote","titleApostrophe"],In=[{character:" ",after:"[\\r\\n]",inConstruct:"phrasing"},{character:" ",before:"[\\r\\n]",inConstruct:"phrasing"},{character:" ",inConstruct:["codeFencedLangGraveAccent","codeFencedLangTilde"]},{character:"\r",inConstruct:["codeFencedLangGraveAccent","codeFencedLangTilde","codeFencedMetaGraveAccent","codeFencedMetaTilde","destinationLiteral","headingAtx"]},{character:`
1
+ import{_ as Qe}from"./preload-helper-BlTxHScW.js";import{o as re,r as Ue,s as _,a as gt,b as _e,c as tt,n as Le,d as le,e as Ut,f as Un,h as qn,g as Wn,i as qt,j as Kn,k as zn,l as je,m as jn,p as bn,q as Yn,z as Xn,t as Qn,v as Zn,w as Vn,x as Jn,y as eo,A as to,B as Re,u as wn,C as mt}from"./index-CIf0GId3.js";import{a as xn,g as dt,o as no}from"./index-Dj_05fqk.js";import{b7 as oo}from"./mermaid.core-BDgZg3kW.js";import{l as $e}from"./last-DXTTfs9a.js";import{M as xe,d as We,P as nt}from"./index-BIrx3oY4.js";let L=(function(e){return e.TextInput="Text Input",e.URLInput="URL Input",e.NumberInput="Number Input",e.TextBox="Text Editor",e.DatePicker="Date Picker",e.DropdownSelect="Dropdown",e.MultiSelect="Multi Select",e.BooleanToggle="Boolean Toggle",e.LinkOrFileUpload="Link or File Upload",e.RichTextEditor="Rich Text Editor",e.CodeEditor="Code Editor",e.KeyValueList="Key-Value List",e.TagInput="Tag Input",e.DateRangePicker="Date Range Picker",e.ColorPicker="Color Picker",e.Slider="Slider",e.FileUpload="File Upload",e.SearchSelect="Search Select",e.CheckboxGroup="Checkbox Group",e})({});const En=re({name:_().optional(),description:_().optional(),nodes:Ue(_(),re({type:_().optional(),name:_().optional(),value:_().optional(),cloud:_().optional(),service:_().optional(),src:_().optional(),animatedIcon:_().optional(),componentId:_().optional(),shape:tt(["rectangle","rounded-rect","ellipse","diamond","triangle","parallelogram","trapezoid","hexagon","document","cylinder","delay","off-page-connector","display","collate","sort","terminator","or","database","multiple-documents","subroutine","manual-input","summing-junction","internal-storage"]).optional(),data:Ue(_(),re({type:tt(Object.values(L)),options:le(_()).optional(),value:gt()})).optional(),style:re({width:Le().optional(),height:Le().optional(),color:_().optional(),fill:_().optional(),stroke:_().optional(),strokeWidth:Le().optional(),borderRadius:Le().optional(),strokeStyle:tt(["solid","dashed","dotted"]).optional(),borderAnimationEnabled:_e().optional()}).optional(),dbConfig:re({serviceName:_(),databaseName:_(),tableName:_()}).optional(),table:re({columns:_().array(),rows:le(le(_()))}).optional(),___internal:Ue(_(),gt()).optional(),___position:re({x:Le(),y:Le()}).optional()})).optional(),edges:Ue(_(),re({type:_().optional(),sourceHandle:_().optional(),targetHandle:_().optional(),label:_().optional(),style:re({stroke:_().optional(),strokeWidth:Le().optional(),strokeStyle:tt(["solid","dashed","dotted"]).optional(),borderAnimationEnabled:_e().optional()}).optional(),markerStart:re({type:_(),color:_().optional()}).optional(),markerEnd:re({type:_(),color:_().optional()}).optional(),___internal:Ue(_(),gt()).optional()})).optional(),groups:Ue(_(),re({name:_().optional(),nodes:_().array().optional()})).optional()}),io={}.hasOwnProperty;function In(e,t){let n=-1,o;if(t.extensions)for(;++n<t.extensions.length;)In(e,t.extensions[n]);for(o in t)if(io.call(t,o))switch(o){case"extensions":break;case"unsafe":{Wt(e[o],t[o]);break}case"join":{Wt(e[o],t[o]);break}case"handlers":{ro(e[o],t[o]);break}default:e.options[o]=t[o]}return e}function Wt(e,t){t&&e.push(...t)}function ro(e,t){t&&Object.assign(e,t)}function Tt(e){if(e.charCodeAt(0)!==60)return;const t=e.charCodeAt(1);if(t===33){const a=e.charCodeAt(2);return a===45?2:a===91?5:Ut(a)?4:void 0}if(t===63)return 3;const n=t===47,o=n?2:1;let r=o,i=e.charCodeAt(r);if(!Ut(i))return;for(;i===45||Un(i);)i=e.charCodeAt(++r);const s=e.slice(o,r).toLowerCase();return!n&&i!==47&&qn.includes(s)?1:Wn.includes(s)?6:7}const so=[ao];function ao(e,t,n,o){if(t.type==="code"&&qt(t,o)&&(e.type==="list"||e.type===t.type&&qt(e,o)))return!1;if("spread"in n&&typeof n.spread=="boolean"){if(e.type==="paragraph"&&(e.type===t.type||t.type==="definition"||t.type==="heading"&&Kn(t,o)))return;if(e.type==="html"){const r=Tt(e.value);if(r===void 0||r===6||r===7)return 1}if(e.type==="paragraph"&&t.type==="html"){const r=Tt(t.value);if(r===void 0||r===7)return 1}return n.spread?1:0}}const Pe=["autolink","destinationLiteral","destinationRaw","reference","titleQuote","titleApostrophe"],Tn=[{character:" ",after:"[\\r\\n]",inConstruct:"phrasing"},{character:" ",before:"[\\r\\n]",inConstruct:"phrasing"},{character:" ",inConstruct:["codeFencedLangGraveAccent","codeFencedLangTilde"]},{character:"\r",inConstruct:["codeFencedLangGraveAccent","codeFencedLangTilde","codeFencedMetaGraveAccent","codeFencedMetaTilde","destinationLiteral","headingAtx"]},{character:`
2
2
  `,inConstruct:["codeFencedLangGraveAccent","codeFencedLangTilde","codeFencedMetaGraveAccent","codeFencedMetaTilde","destinationLiteral","headingAtx"]},{character:"\r",before:"[\\r\\n]",inConstruct:"phrasing"},{character:"\r",after:"\\r",inConstruct:"phrasing"},{character:`
3
3
  `,before:"\\n",inConstruct:"phrasing"},{character:`
4
4
  `,after:"[\\r\\n]",inConstruct:"phrasing"},{character:" ",after:"[\\r\\n]",inConstruct:"phrasing"},{character:" ",before:"[\\r\\n]",inConstruct:"phrasing"},{character:" ",inConstruct:["codeFencedLangGraveAccent","codeFencedLangTilde"]},{character:"!",after:"\\[",inConstruct:"phrasing",notInConstruct:Pe},{character:'"',inConstruct:"titleQuote"},{atBreak:!0,character:"#"},{character:"#",inConstruct:"headingAtx",after:`(?:[\r
@@ -6,50 +6,50 @@ import{_ as Qe}from"./index-5E1tJ7yK.js";import{o as re,r as Ue,s as _,a as gt,b
6
6
  *])`},{character:"*",inConstruct:"phrasing",notInConstruct:Pe},{atBreak:!0,character:"+",after:`(?:[ \r
7
7
  ])`},{atBreak:!0,character:"-",after:`(?:[ \r
8
8
  -])`},{atBreak:!0,before:"\\d+",character:".",after:`(?:[ \r
9
- ]|$)`},{atBreak:!0,character:"<",after:"[!/?A-Za-z]"},{character:"<",after:"[!/?A-Za-z]",inConstruct:"phrasing",notInConstruct:Pe},{character:"<",inConstruct:"destinationLiteral"},{atBreak:!0,character:"="},{atBreak:!0,character:">"},{character:">",inConstruct:"destinationLiteral"},{atBreak:!0,character:"["},{character:"[",inConstruct:"phrasing",notInConstruct:Pe},{character:"[",inConstruct:["label","reference"]},{character:"\\",after:"[\\r\\n]",inConstruct:"phrasing"},{character:"]",inConstruct:["label","reference"]},{atBreak:!0,character:"_"},{character:"_",inConstruct:"phrasing",notInConstruct:Pe},{atBreak:!0,character:"`"},{character:"`",inConstruct:["codeFencedLangGraveAccent","codeFencedMetaGraveAccent"]},{character:"`",inConstruct:"phrasing",notInConstruct:Pe},{atBreak:!0,character:"~"},{character:"<",inConstruct:"autolink"},{character:">",inConstruct:"autolink"},{character:"",inConstruct:"autolink"}];let Kt=-1;for(;++Kt<33;)In.push({character:String.fromCharCode(Kt),inConstruct:"autolink"});function ao(e){return e.label||!e.identifier?e.label||"":Kn(e.identifier)}function co(e){if(!e._compiled){const t=(e.atBreak?"[\\r\\n][\\t ]*":"")+(e.before?"(?:"+e.before+")":"");e._compiled=new RegExp((t?"("+t+")":"")+(/[$()*+\-.?[\\\]^{|}]/.test(e.character)?"\\":"")+e.character+(e.after?"(?:"+e.after+")":""),"g")}return e._compiled}function ut(e){const t=e.codePointAt(0);return t===void 0?"":String.fromCodePoint(t)}function Ve(e){const t=e.codePointAt(e.length-2);return t!==void 0&&t>65535?e.slice(-2):e.slice(-1)}function zt(e,t,n){const o=je(e),r=je(t);return o===void 0?r===void 0?n==="_"?{inside:!0,outside:!0}:{inside:!1,outside:!1}:r===1?{inside:!0,outside:!0}:{inside:!1,outside:!0}:o===1?r===void 0?{inside:!1,outside:!1}:r===1?{inside:!0,outside:!0}:{inside:!1,outside:!1}:r===void 0?{inside:!1,outside:!1}:r===1?{inside:!0,outside:!1}:{inside:!1,outside:!1}}const lo=new Map([["*",!1],["_",!0]]);function uo(e,t,n){const o=new Set;for(const i of e){const s=n.get(i);if(s&&i.attention&&t.some(a=>a.attention===i.attention))for(const a of s.tokens)o.add(a.attention)}const r=[];for(const i of e)i.attention&&o.delete(i.attention)&&r.push(i.attention);return r.reverse(),r}function Tn(e,t,n){const o=[],r=new Map,i=new Map;let s=0;for(;s<e.length;){if(!e[s].attention){s++;continue}const a=e[s].value.charAt(0),d=lo.get(a);let l=s+1;for(;l<e.length&&e[l].attention&&e[l].value.charAt(0)===a;)l++;const p=s?e[s-1].value:t,f=je(p.charCodeAt(p.length-1)),c=je((l<e.length?e[l].value:n).charCodeAt(0)),u=!c||c===2&&!!f,h=!f||f===2&&!!c,m={tokens:e.slice(s,l),markers:[],start:0,end:0,open:d?u&&(!!f||!h):u,close:d?h&&(!!c||!u):h,split:d!==void 0};for(const g of m.tokens){r.set(g,[...m.tokens]),i.set(g,m);let y=g.value.length;for(;y--;)m.markers.push(g)}m.end=m.markers.length,o.push(m),s=l}for(po(o,r),s=-1;++s<e.length;){const a=r.get(e[s]);if(a)return{attention:uo(e,a,i),index:s}}}function ho(e,t,n){return Nt(Nn(e,t,n),n.before,n.after)}function ot(e,t){const n=e[t?0:e.length-1];if(!n||n.attention)return;const o=t?ut(n.value):Ve(n.value),r=vn(o.codePointAt(0));n.value=t?r+n.value.slice(o.length):n.value.slice(0,n.value.length-o.length)+r}function fo(e,t,n,o,r){for(const i of n.attention){const s=t.get(i)||i.sequences[0];for(const a of i.sequences){if(a===s)continue;const d=new Map(t);d.set(i,a);const l=Lt(e,d,o,r),p=Tn(l,o,r);if(!p||p.index>n.index)return{chosen:d,mistake:p,tokens:l}}}}function po(e,t){let n=0;for(;n<e.length;){const o=e[n],r=o.tokens[0].value.charAt(0),i=o.end-o.start;let s=o.close&&i?n:0;for(;s--;){const a=e[s],d=a.end-a.start;if(a.tokens[0].value.charAt(0)===r&&a.open&&d&&(o.split?!((a.close||o.open)&&i%3)||(d+i)%3:d===a.markers.length&&d===i)){const l=o.split?d>1&&i>1?2:1:i,p=a.markers.slice(a.end-l,a.end),f=o.markers.slice(o.start,o.start+l),c=p[0],u=f[0];if(c===p[l-1]&&c.value.length===l&&u===f[l-1]&&u.value.length===l&&c.attention===u.attention)t.delete(c),t.delete(u);else{const h=[...new Set([...p,...f])];for(const m of h){const g=t.get(m);g&&g.push(...h)}}a.end-=l,o.start+=l;break}}(s===-1||o.start===o.end)&&n++}}function mo(e,t,n){if(t.length===0)throw new Error("Cannot serialize `"+e+"` as attention without markers, expected one or more markers");if(n.length===0)throw new Error("Cannot serialize `"+e+"` as attention without sizes, expected one or more sizes");for(const r of n)if(!Number.isSafeInteger(r)||r<1)throw new Error("Cannot serialize `"+e+"` as attention with `"+r+"` as size, expected positive integer");const o=[];for(const r of t){if(r.length!==1)throw new Error("Cannot serialize `"+e+"` as attention with `"+r+"` as marker, expected a single ascii character");if(!zn(r.charCodeAt(0)))throw new Error("Cannot serialize `"+e+"` as attention with `"+r+"` as marker, expected ascii punctuation");for(const i of n)o.push(r.repeat(i))}return o}function Nn(e,t,n){const o=t.indexStack,r=e.children||[],i=[];let s=-1,a=n.before;o.push(-1);let d=t.createTracker(n);for(;++s<r.length;){const l=r[s];let p;if(o[o.length-1]=s,s+1<r.length){let u=t.handle.handlers[r[s+1].type];u&&u.peek&&(u=u.peek),p=u?ut(u(r[s+1],e,t,{before:"",after:"",...d.current()})):""}else p=n.after;const f=i[i.length-1];typeof f=="string"&&(a==="\r"||a===`
10
- `)&&l.type==="html"&&Tt(l.value)!==7&&(i[i.length-1]=f.replace(/(\r?\n|\r)$/," "),a=" ",d=t.createTracker(n),d.move(Nt(i,n.before,n.after)));const c=t.handle.handlers[l.type];if(c&&c.attention){const{construct:u,markers:h,sizes:m}=c.attention(l,t),g=mo(l.type,h,m),y=g[0],E=t.enter(u);d.move(y);const w=Nn(l,t,{...d.current(),before:y,after:y});d.move(Nt(w,y,y)),d.move(y),E(),i.push({children:w,sequences:g}),a=y.charAt(y.length-1)}else{const u=t.handle(l,e,t,{...d.current(),after:p,before:a});if(!u)continue;d.move(u),i.push(u),a=Ve(u)}}return o.pop(),i}function Lt(e,t,n,o){const r=[];let i,s=Ve(n),a=-1;for(;++a<e.length;){const d=e[a];if(typeof d=="string"){const w={value:d,attention:void 0};i&&i===ut(d)&&ot([w],!0),i=void 0,r.push(w),w.value&&(s=Ve(w.value));continue}const l=t.get(d)||d.sequences[0],p=l.charAt(0),f=e[a+1],c=s,u=ut(f===void 0?o:typeof f=="string"?f:t.get(f)||f.sequences[0]),h=Lt(d.children,t,l,l),m=h.length>0?h[0].value:"",g=zt(c.charCodeAt(c.length-1),m.charCodeAt(0),p);g.inside&&ot(h,!0);const y=h.length>0?Ve(h[h.length-1].value):"",E=zt(u.charCodeAt(0),y.charCodeAt(y.length-1),p);E.inside&&ot(h,!1),g.outside&&c!==`
11
- `&&c!=="\r"&&ot(r,!1),E.outside&&(i=u),r.push({value:l,attention:d},...h,{value:l,attention:d}),s=l.charAt(l.length-1)}return r}function Nt(e,t,n){let o=new Map;const r=Lt(e,o,t,n);let i=r,s=Tn(i,t,n);for(;s;){const d=fo(e,o,s,t,n);if(!d){i=r;break}o=d.chosen,i=d.tokens,s=d.mistake}let a="";for(const d of i)a+=d.value;return a}function go(e,t,n){const o=t.indexStack,r=e.children||[],i=t.createTracker(n),s=[];let a=-1;for(o.push(-1);++a<r.length;){const d=r[a];o[o.length-1]=a,s.push(i.move(t.handle(d,e,t,{before:`
9
+ ]|$)`},{atBreak:!0,character:"<",after:"[!/?A-Za-z]"},{character:"<",after:"[!/?A-Za-z]",inConstruct:"phrasing",notInConstruct:Pe},{character:"<",inConstruct:"destinationLiteral"},{atBreak:!0,character:"="},{atBreak:!0,character:">"},{character:">",inConstruct:"destinationLiteral"},{atBreak:!0,character:"["},{character:"[",inConstruct:"phrasing",notInConstruct:Pe},{character:"[",inConstruct:["label","reference"]},{character:"\\",after:"[\\r\\n]",inConstruct:"phrasing"},{character:"]",inConstruct:["label","reference"]},{atBreak:!0,character:"_"},{character:"_",inConstruct:"phrasing",notInConstruct:Pe},{atBreak:!0,character:"`"},{character:"`",inConstruct:["codeFencedLangGraveAccent","codeFencedMetaGraveAccent"]},{character:"`",inConstruct:"phrasing",notInConstruct:Pe},{atBreak:!0,character:"~"},{character:"<",inConstruct:"autolink"},{character:">",inConstruct:"autolink"},{character:"",inConstruct:"autolink"}];let Kt=-1;for(;++Kt<33;)Tn.push({character:String.fromCharCode(Kt),inConstruct:"autolink"});function co(e){return e.label||!e.identifier?e.label||"":zn(e.identifier)}function lo(e){if(!e._compiled){const t=(e.atBreak?"[\\r\\n][\\t ]*":"")+(e.before?"(?:"+e.before+")":"");e._compiled=new RegExp((e.beforeNode?"^":t?"("+t+")":"")+(/[$()*+.?[\\\]^{|}]/.test(e.character)?"\\":"")+e.character+(e.afterNode?"$":e.after?"(?:"+e.after+")":""),e.unicode?"gu":"g")}return e._compiled}function ut(e){const t=e.codePointAt(0);return t===void 0?"":String.fromCodePoint(t)}function Ve(e){const t=e.codePointAt(e.length-2);return t!==void 0&&t>65535?e.slice(-2):e.slice(-1)}function zt(e,t,n){const o=je(e),r=je(t);return o===void 0?r===void 0?n==="_"?{inside:!0,outside:!0}:{inside:!1,outside:!1}:r===1?{inside:!0,outside:!0}:{inside:!1,outside:!0}:o===1?r===void 0?{inside:!1,outside:!1}:r===1?{inside:!0,outside:!0}:{inside:!1,outside:!1}:r===void 0?{inside:!1,outside:!1}:r===1?{inside:!0,outside:!1}:{inside:!1,outside:!1}}const uo=new Map([["*",!1],["_",!0]]);function ho(e,t,n){const o=new Set;for(const i of e){const s=n.get(i);if(s&&i.attention&&t.some(a=>a.attention===i.attention))for(const a of s.tokens)o.add(a.attention)}const r=[];for(const i of e)i.attention&&o.delete(i.attention)&&r.push(i.attention);return r.reverse(),r}function Nn(e,t,n){const o=[],r=new Map,i=new Map;let s=0;for(;s<e.length;){if(!e[s].attention){s++;continue}const a=e[s].value.charAt(0),d=uo.get(a);let l=s+1;for(;l<e.length&&e[l].attention&&e[l].value.charAt(0)===a;)l++;const p=s?e[s-1].value:t,f=je(p.charCodeAt(p.length-1)),c=je((l<e.length?e[l].value:n).charCodeAt(0)),u=!c||c===2&&!!f,h=!f||f===2&&!!c,m={tokens:e.slice(s,l),markers:[],start:0,end:0,open:d?u&&(!!f||!h):u,close:d?h&&(!!c||!u):h,split:d!==void 0};for(const y of m.tokens){r.set(y,[...m.tokens]),i.set(y,m);let g=y.value.length;for(;g--;)m.markers.push(y)}m.end=m.markers.length,o.push(m),s=l}for(mo(o,r),s=-1;++s<e.length;){const a=r.get(e[s]);if(a)return{attention:ho(e,a,i),index:s}}}function fo(e,t,n){return Nt(Sn(e,t,n),n.before,n.after)}function ot(e,t){const n=e[t?0:e.length-1];if(!n||n.attention)return;const o=t?ut(n.value):Ve(n.value),r=bn(o.codePointAt(0));n.value=t?r+n.value.slice(o.length):n.value.slice(0,n.value.length-o.length)+r}function po(e,t,n,o,r){for(const i of n.attention){const s=t.get(i)||i.sequences[0];for(const a of i.sequences){if(a===s)continue;const d=new Map(t);d.set(i,a);const l=Lt(e,d,o,r),p=Nn(l,o,r);if(!p||p.index>n.index)return{chosen:d,mistake:p,tokens:l}}}}function mo(e,t){let n=0;for(;n<e.length;){const o=e[n],r=o.tokens[0].value.charAt(0),i=o.end-o.start;let s=o.close&&i?n:0;for(;s--;){const a=e[s],d=a.end-a.start;if(a.tokens[0].value.charAt(0)===r&&a.open&&d&&(o.split?!((a.close||o.open)&&i%3)||(d+i)%3:d===a.markers.length&&d===i)){const l=o.split?d>1&&i>1?2:1:i,p=a.markers.slice(a.end-l,a.end),f=o.markers.slice(o.start,o.start+l),c=p[0],u=f[0];if(c===p[l-1]&&c.value.length===l&&u===f[l-1]&&u.value.length===l&&c.attention===u.attention)t.delete(c),t.delete(u);else{const h=[...new Set([...p,...f])];for(const m of h){const y=t.get(m);y&&y.push(...h)}}a.end-=l,o.start+=l;break}}(s===-1||o.start===o.end)&&n++}}function go(e,t,n){if(t.length===0)throw new Error("Cannot serialize `"+e+"` as attention without markers, expected one or more markers");if(n.length===0)throw new Error("Cannot serialize `"+e+"` as attention without sizes, expected one or more sizes");for(const r of n)if(!Number.isSafeInteger(r)||r<1)throw new Error("Cannot serialize `"+e+"` as attention with `"+r+"` as size, expected positive integer");const o=[];for(const r of t){if(r.length!==1)throw new Error("Cannot serialize `"+e+"` as attention with `"+r+"` as marker, expected a single ascii character");if(!jn(r.charCodeAt(0)))throw new Error("Cannot serialize `"+e+"` as attention with `"+r+"` as marker, expected ascii punctuation");for(const i of n)o.push(r.repeat(i))}return o}function Sn(e,t,n){const o=t.indexStack,r=e.children||[],i=[];let s=-1,a=n.before;o.push(-1);let d=t.createTracker(n);for(;++s<r.length;){const l=r[s];let p;if(o[o.length-1]=s,s+1<r.length){let u=t.handle.handlers[r[s+1].type];u&&u.peek&&(u=u.peek),p=u?ut(u(r[s+1],e,t,{before:"",after:"",...d.current()})):""}else p=n.after;const f=i[i.length-1];typeof f=="string"&&(a==="\r"||a===`
10
+ `)&&l.type==="html"&&Tt(l.value)!==7&&(i[i.length-1]=f.replace(/(\r?\n|\r)$/," "),a=" ",d=t.createTracker(n),d.move(Nt(i,n.before,n.after)));const c=t.handle.handlers[l.type];if(c&&c.attention){const{construct:u,markers:h,sizes:m}=c.attention(l,t),y=go(l.type,h,m),g=y[0],E=t.enter(u);d.move(g);const w=Sn(l,t,{...d.current(),before:g,after:g});d.move(Nt(w,g,g)),d.move(g),E(),i.push({children:w,sequences:y}),a=g.charAt(g.length-1)}else{const u=t.handle(l,e,t,{...d.current(),after:p,before:a});if(!u)continue;d.move(u),i.push(u),a=Ve(u)}}return o.pop(),i}function Lt(e,t,n,o){const r=[];let i,s=Ve(n),a=-1;for(;++a<e.length;){const d=e[a];if(typeof d=="string"){const w={value:d,attention:void 0};i&&i===ut(d)&&ot([w],!0),i=void 0,r.push(w),w.value&&(s=Ve(w.value));continue}const l=t.get(d)||d.sequences[0],p=l.charAt(0),f=e[a+1],c=s,u=ut(f===void 0?o:typeof f=="string"?f:t.get(f)||f.sequences[0]),h=Lt(d.children,t,l,l),m=h.length>0?h[0].value:"",y=zt(c.charCodeAt(c.length-1),m.charCodeAt(0),p);y.inside&&ot(h,!0);const g=h.length>0?Ve(h[h.length-1].value):"",E=zt(u.charCodeAt(0),g.charCodeAt(g.length-1),p);E.inside&&ot(h,!1),y.outside&&c!==`
11
+ `&&c!=="\r"&&ot(r,!1),E.outside&&(i=u),r.push({value:l,attention:d},...h,{value:l,attention:d}),s=l.charAt(l.length-1)}return r}function Nt(e,t,n){let o=new Map;const r=Lt(e,o,t,n);let i=r,s=Nn(i,t,n);for(;s;){const d=po(e,o,s,t,n);if(!d){i=r;break}o=d.chosen,i=d.tokens,s=d.mistake}let a="";for(const d of i)a+=d.value;return a}function yo(e,t,n){const o=t.indexStack,r=e.children||[],i=t.createTracker(n),s=[];let a=-1;for(o.push(-1);++a<r.length;){const d=r[a];o[o.length-1]=a,s.push(i.move(t.handle(d,e,t,{before:`
12
12
  `,after:`
13
- `,...i.current()}))),d.type!=="list"&&(t.bulletLastUsed=void 0),a<r.length-1&&s.push(i.move(yo(d,r[a+1],e,t)))}return o.pop(),s.join("")}function yo(e,t,n,o){let r=o.join.length;for(;r--;){const i=o.join[r](e,t,n,o);if(i===!0||i===1)break;if(typeof i=="number")return`
13
+ `,...i.current()}))),d.type!=="list"&&(t.bulletLastUsed=void 0),a<r.length-1&&s.push(i.move(vo(d,r[a+1],e,t)))}return o.pop(),s.join("")}function vo(e,t,n,o){let r=o.join.length;for(;r--;){const i=o.join[r](e,t,n,o);if(i===!0||i===1)break;if(typeof i=="number")return`
14
14
  `.repeat(1+i);if(i===!1)return`
15
15
 
16
16
  <!---->
17
17
 
18
18
  `}return`
19
19
 
20
- `}const vo=/\r?\n|\r/g;function bo(e,t){const n=[];let o=0,r=0,i;for(;i=vo.exec(e);)s(e.slice(o,i.index)),n.push(i[0]),o=i.index+i[0].length,r++;return s(e.slice(o)),n.join("");function s(a){n.push(t(a,r,!a))}}const yt={}.hasOwnProperty;function wo(e,t,n){const o=(n.before||"")+(t||"")+(n.after||""),r=[],i=[],s={},a=e.stack.includes("autolink");let d=-1;for(;++d<e.unsafe.length;){const u=e.unsafe[d];if(!jn(e.stack,u))continue;const h=e.compilePattern(u);let m;for(;m=h.exec(o);){const g="before"in u||!!u.atBreak,y="after"in u,E=m.index+(g?m[1].length:0);yt.call(s,E)?(s[E].before&&!g&&(s[E].before=!1),s[E].after&&!y&&(s[E].after=!1)):(r.push(E),s[E]={before:g,after:y})}}r.sort(xo);const l=n.before?n.before.length:0,p=o.length-(n.after?n.after.length:0);let f=l;for(d=-1;++d<r.length;){const u=r[d];if(!(u<f||u>=p)){if(o.charAt(u)==="_"&&u>0&&je(o.charCodeAt(u-1))===void 0&&!yt.call(s,u-1)&&!(u-1===l&&/[*_]/.test(o.charAt(l-1)))){let h=u+1;for(;h<p&&o.charAt(h)==="_";)h++;const m=h-u-1;if(r[d+m]===h-1&&h<o.length&&je(o.charCodeAt(h))===void 0&&!yt.call(s,h)&&!(h===p-1&&/[*_]/.test(o.charAt(p)))){d+=m;continue}}if(!(u+1<p&&r[d+1]===u+1&&s[u].after&&!s[u+1].before&&!s[u+1].after||r[d-1]===u-1&&s[u].before&&!s[u-1].before&&!s[u-1].after)){if(f!==u){const h=o.slice(f,u);i.push(a?h:jt(h,"\\"))}f=u,a?(i.push("%"+o.charCodeAt(u).toString(16).toUpperCase().padStart(2,"0")),f++):/[!-/:-@[-`{-~]/.test(o.charAt(u))&&(!n.encode||!n.encode.includes(o.charAt(u)))?i.push("\\"):(i.push(vn(o.charCodeAt(u))),f++)}}}const c=o.slice(f,p);return i.push(a?c:jt(c,n.after)),i.join("")}function xo(e,t){return e-t}function jt(e,t){const n=/\\(?=[!-/:-@[-`{-~])/g,o=[],r=[],i=e+t;let s=-1,a=0,d;for(;d=n.exec(i);)o.push(d.index);for(;++s<o.length;)a!==o[s]&&r.push(e.slice(a,o[s])),r.push("\\"),a=o[s];return r.push(e.slice(a)),r.join("")}function Eo(e){const t=e||{},n=t.now||{};let o=t.lineShift||0,r=n.line||1,i=n.column||1;return{move:d,current:s,shift:a};function s(){return{now:{line:r,column:i},lineShift:o}}function a(l){o+=l}function d(l){const p=l||"",f=p.split(/\r?\n|\r/g),c=f[f.length-1];return r+=f.length-1,i=f.length===1?i+c.length:1+c.length+o,p}}function Io(e,t){const n=t||{},o={associationId:ao,bulletCurrent:void 0,bulletLastUsed:void 0,containerPhrasing:Ao,containerFlow:Co,createTracker:Eo,compilePattern:co,enter:i,handlers:{...Xn},handle:void 0,indentLines:bo,indexStack:[],join:[...ro],options:{},safe:ko,stack:[],unsafe:[...In]};En(o,n),o.options.tightDefinitions&&o.join.push(So),o.handle=Yn("type",{invalid:To,unknown:No,handlers:o.handlers});let r=o.handle(Qn(e)?{type:"root",children:[e]}:e,void 0,o,{before:`
20
+ `}const bo=/\r?\n|\r/g;function wo(e,t){const n=[];let o=0,r=0,i;for(;i=bo.exec(e);)s(e.slice(o,i.index)),n.push(i[0]),o=i.index+i[0].length,r++;return s(e.slice(o)),n.join("");function s(a){n.push(t(a,r,!a))}}const yt={}.hasOwnProperty;function xo(e,t,n){const o=(n.before||"")+(t||"")+(n.after||""),r=[],i=[],s={},a=e.stack.includes("autolink"),d=n.before?n.before.length:0,l=o.length-(n.after?n.after.length:0);let p=-1;for(;++p<e.unsafe.length;){const u=e.unsafe[p];if(!Yn(e.stack,u)||!jt(u.beforeNode,n.beforeNode)||!jt(u.afterNode,n.afterNode))continue;const h=e.compilePattern(u),m=u.beforeNode?d:0,y=o.slice(m,u.afterNode?l:void 0);let g;for(;g=h.exec(y);){const E="before"in u||!!u.atBreak,w="after"in u,N=m+g.index+(E?g[1].length:0);yt.call(s,N)?(s[N].before&&!E&&(s[N].before=!1),s[N].after&&!w&&(s[N].after=!1)):(r.push(N),s[N]={before:E,after:w})}}r.sort(Eo);let f=d;for(p=-1;++p<r.length;){const u=r[p];if(!(u<f||u>=l)){if(o.charAt(u)==="_"&&u>0&&je(o.charCodeAt(u-1))===void 0&&!yt.call(s,u-1)&&!(u-1===d&&/[*_]/.test(o.charAt(d-1)))){let h=u+1;for(;h<l&&o.charAt(h)==="_";)h++;const m=h-u-1;if(r[p+m]===h-1&&h<o.length&&je(o.charCodeAt(h))===void 0&&!yt.call(s,h)&&!(h===l-1&&/[*_]/.test(o.charAt(l)))){p+=m;continue}}if(!(u+1<l&&r[p+1]===u+1&&s[u].after&&!s[u+1].before&&!s[u+1].after||r[p-1]===u-1&&s[u].before&&!s[u-1].before&&!s[u-1].after)){if(f!==u){const h=o.slice(f,u);i.push(a?h:Yt(h,"\\"))}f=u,a?(i.push("%"+o.charCodeAt(u).toString(16).toUpperCase().padStart(2,"0")),f++):/[!-/:-@[-`{-~]/.test(o.charAt(u))&&(!n.encode||!n.encode.includes(o.charAt(u)))?i.push("\\"):(i.push(bn(o.charCodeAt(u))),f++)}}}const c=o.slice(f,l);return i.push(a?c:Yt(c,n.after)),i.join("")}function jt(e,t){return e?t?typeof e=="string"?e===t.type:e.includes(t.type):!1:!0}function Eo(e,t){return e-t}function Yt(e,t){const n=/\\(?=[!-/:-@[-`{-~])/g,o=[],r=[],i=e+t;let s=-1,a=0,d;for(;d=n.exec(i);)o.push(d.index);for(;++s<o.length;)a!==o[s]&&r.push(e.slice(a,o[s])),r.push("\\"),a=o[s];return r.push(e.slice(a)),r.join("")}function Io(e){const t=e||{},n=t.now||{};let o=t.lineShift||0,r=n.line||1,i=n.column||1;return{move:d,current:s,shift:a};function s(){return{now:{line:r,column:i},lineShift:o}}function a(l){o+=l}function d(l){const p=l||"",f=p.split(/\r?\n|\r/g),c=f[f.length-1];return r+=f.length-1,i=f.length===1?i+c.length:1+c.length+o,p}}function To(e,t){const n=t||{},o={associationId:co,bulletCurrent:void 0,bulletLastUsed:void 0,containerPhrasing:Co,containerFlow:ko,createTracker:Io,compilePattern:lo,enter:i,handlers:{...Qn},handle:void 0,indentLines:wo,indexStack:[],join:[...so],options:{},safe:Ro,stack:[],unsafe:[...Tn]};In(o,n),o.options.tightDefinitions&&o.join.push(Ao),o.handle=Xn("type",{invalid:No,unknown:So,handlers:o.handlers});let r=o.handle(Zn(e)?{type:"root",children:[e]}:e,void 0,o,{before:`
21
21
  `,after:`
22
22
  `,now:{line:1,column:1},lineShift:0});return r&&r.charCodeAt(r.length-1)!==10&&r.charCodeAt(r.length-1)!==13&&(r+=`
23
- `),r;function i(s){return o.stack.push(s),a;function a(){o.stack.pop()}}}function To(e){throw new Error("Cannot handle value `"+e+"`, expected node")}function No(e){const t=e;throw new Error("Cannot handle unknown node `"+t.type+"`")}function So(e,t){if(e.type==="definition"&&e.type===t.type)return 0}function Ao(e,t){return ho(e,this,t)}function Co(e,t){return go(e,this,t)}function ko(e,t){return wo(this,e,t)}const Ro=(e,t)=>{var n,o;const r=(n=$e(e))===null||n===void 0?void 0:n.children,i=(o=r?.[r.indexOf(t)-1])===null||o===void 0?void 0:o.type;return i??"firstOne"},_o=(e,t)=>{var n,o;const r=(n=$e(e))===null||n===void 0?void 0:n.children,i=(o=r?.[r.indexOf(t)+1])===null||o===void 0?void 0:o.type;return i??"lastOne"},Mo=({node:e,process:t,ancestors:n})=>{if(e.type==="root")return e.children.forEach(o=>t(o,[...n,e])),!0},$o=({node:e,process:t,ancestors:n,ops:o})=>{if(e.type==="paragraph")return e.children.forEach(r=>t(r,[...n,e])),o.push({insert:`
24
- `}),!0},Do=({node:e,ancestors:t,ops:n})=>{if(e.type!=="text")return;const o={};return t.find(r=>r.type==="strong")&&(o.bold=!0),t.find(r=>r.type==="emphasis")&&(o.italic=!0),t.find(r=>r.type==="delete")&&(o.strike=!0),Object.keys(o).length>0?n.push({insert:e.value,attributes:o}):n.push({insert:e.value}),!0},Oo=({node:e,ancestors:t,ops:n,process:o})=>{if(!(e.type!=="strong"&&e.type!=="emphasis"&&e.type!=="delete"))return e.type,e.type,e.type,e.children.forEach(r=>o(r,[...t,e])),!0},Lo=({node:e,ancestors:t,ops:n,process:o})=>{if(e.type==="heading")return e.children.forEach(r=>o(r,[...t,e])),n.push({insert:`
25
- `,attributes:{header:e.depth}}),!0},Po=({node:e,ancestors:t,process:n})=>{if(e.type==="list")return e.children.forEach(o=>n(o,[...t,e])),!0},Fo=({node:e,ancestors:t,ops:n,process:o})=>{var r,i;if(e.type!=="listItem")return;const s=e;s.children.filter(p=>p.type!=="list").forEach(p=>o(p,[...t,e])),((r=$e(n))===null||r===void 0?void 0:r.insert)===`
23
+ `),r;function i(s){return o.stack.push(s),a;function a(){o.stack.pop()}}}function No(e){throw new Error("Cannot handle value `"+e+"`, expected node")}function So(e){const t=e;throw new Error("Cannot handle unknown node `"+t.type+"`")}function Ao(e,t){if(e.type==="definition"&&e.type===t.type)return 0}function Co(e,t){return fo(e,this,t)}function ko(e,t){return yo(e,this,t)}function Ro(e,t){return xo(this,e,t)}const _o=(e,t)=>{var n,o;const r=(n=$e(e))===null||n===void 0?void 0:n.children,i=(o=r?.[r.indexOf(t)-1])===null||o===void 0?void 0:o.type;return i??"firstOne"},Mo=(e,t)=>{var n,o;const r=(n=$e(e))===null||n===void 0?void 0:n.children,i=(o=r?.[r.indexOf(t)+1])===null||o===void 0?void 0:o.type;return i??"lastOne"},$o=({node:e,process:t,ancestors:n})=>{if(e.type==="root")return e.children.forEach(o=>t(o,[...n,e])),!0},Do=({node:e,process:t,ancestors:n,ops:o})=>{if(e.type==="paragraph")return e.children.forEach(r=>t(r,[...n,e])),o.push({insert:`
24
+ `}),!0},Oo=({node:e,ancestors:t,ops:n})=>{if(e.type!=="text")return;const o={};return t.find(r=>r.type==="strong")&&(o.bold=!0),t.find(r=>r.type==="emphasis")&&(o.italic=!0),t.find(r=>r.type==="delete")&&(o.strike=!0),Object.keys(o).length>0?n.push({insert:e.value,attributes:o}):n.push({insert:e.value}),!0},Lo=({node:e,ancestors:t,ops:n,process:o})=>{if(!(e.type!=="strong"&&e.type!=="emphasis"&&e.type!=="delete"))return e.type,e.type,e.type,e.children.forEach(r=>o(r,[...t,e])),!0},Po=({node:e,ancestors:t,ops:n,process:o})=>{if(e.type==="heading")return e.children.forEach(r=>o(r,[...t,e])),n.push({insert:`
25
+ `,attributes:{header:e.depth}}),!0},Fo=({node:e,ancestors:t,process:n})=>{if(e.type==="list")return e.children.forEach(o=>n(o,[...t,e])),!0},Bo=({node:e,ancestors:t,ops:n,process:o})=>{var r,i;if(e.type!=="listItem")return;const s=e;s.children.filter(p=>p.type!=="list").forEach(p=>o(p,[...t,e])),((r=$e(n))===null||r===void 0?void 0:r.insert)===`
26
26
  `&&!(!((i=$e(n))===null||i===void 0)&&i.attributes)&&n.pop();const a=t.filter(p=>p.type==="list"),d=$e(a),l={insert:`
27
- `,attributes:{list:s.checked===null?d?.ordered?"ordered":"bullet":s.checked?"checked":"unchecked"}};return a.length>1&&(l.attributes.indent=a.length-1),n.push(l),s.children.filter(p=>p.type==="list").forEach(p=>o(p,[...t,e])),!0},Bo=({node:e,ancestors:t,ops:n,process:o})=>{var r,i;if(e.type==="blockquote")return e.children.forEach(s=>o(s,[...t,e])),((r=$e(n))===null||r===void 0?void 0:r.insert)===`
27
+ `,attributes:{list:s.checked===null?d?.ordered?"ordered":"bullet":s.checked?"checked":"unchecked"}};return a.length>1&&(l.attributes.indent=a.length-1),n.push(l),s.children.filter(p=>p.type==="list").forEach(p=>o(p,[...t,e])),!0},Go=({node:e,ancestors:t,ops:n,process:o})=>{var r,i;if(e.type==="blockquote")return e.children.forEach(s=>o(s,[...t,e])),((r=$e(n))===null||r===void 0?void 0:r.insert)===`
28
28
  `&&!(!((i=$e(n))===null||i===void 0)&&i.attributes)&&n.pop(),n.push({insert:`
29
- `,attributes:{blockquote:!0}}),!0},Go=({node:e,ancestors:t,ops:n,process:o})=>{if(e.type==="link")return e.children.forEach(r=>{n.push({insert:r.value,attributes:{link:e.url}})}),!0},Ho=({node:e,ancestors:t,ops:n,process:o})=>{if(e.type==="image")return n.push({insert:{image:e.url},attributes:{alt:e.alt}}),!0},Uo=({node:e,ancestors:t,ops:n,process:o})=>{if(e.type==="code")return n.push({insert:e.value},{insert:`
30
- `,attributes:{"code-block":!0}}),!0},qo=({node:e,ancestors:t,ops:n,process:o})=>{if(e.type==="inlineCode")return n.push({insert:e.value,attributes:{code:!0}}),!0},Wo=({node:e,ancestors:t,ops:n})=>(n.push({insert:Io(e,{extensions:[eo()]})}),!0),Ko=({node:e,ancestors:t,ops:n,process:o})=>{if(e.type!=="break")return;const r=Ro(t,e),i=_o(t,e);if(r!=="text"||i!=="text")return n.push({insert:`
29
+ `,attributes:{blockquote:!0}}),!0},Ho=({node:e,ancestors:t,ops:n,process:o})=>{if(e.type==="link")return e.children.forEach(r=>{n.push({insert:r.value,attributes:{link:e.url}})}),!0},Uo=({node:e,ancestors:t,ops:n,process:o})=>{if(e.type==="image")return n.push({insert:{image:e.url},attributes:{alt:e.alt}}),!0},qo=({node:e,ancestors:t,ops:n,process:o})=>{if(e.type==="code")return n.push({insert:e.value},{insert:`
30
+ `,attributes:{"code-block":!0}}),!0},Wo=({node:e,ancestors:t,ops:n,process:o})=>{if(e.type==="inlineCode")return n.push({insert:e.value,attributes:{code:!0}}),!0},Ko=({node:e,ancestors:t,ops:n})=>(n.push({insert:To(e,{extensions:[to()]})}),!0),zo=({node:e,ancestors:t,ops:n,process:o})=>{if(e.type!=="break")return;const r=_o(t,e),i=Mo(t,e);if(r!=="text"||i!=="text")return n.push({insert:`
31
31
  `}),!0;const s=n[n.length-1],a=$e(t).children,d=a[a.indexOf(e)+1];return n[n.length-1]={insert:s.insert+`
32
- `+d.value},a.splice(a.indexOf(d),1),!0};function zo(e,t={}){let n;typeof e=="string"?n=Zn(e,{extensions:[Jn()],mdastExtensions:[Vn()]}):n=e;const o=[];function r(i,s){const a=[Mo,$o,Do,Oo,Lo,Po,Fo,Bo,Go,Ho,Uo,qo,Ko,Wo];t.handle&&a.unshift(t.handle);for(const d of a)if(d({node:i,ancestors:s,ops:o,process:r}))return}return r(n,[]),o}var Yt={};function Xt(e){switch(e){case"S":return"string";case"N":return"number";case"B":return"binary";default:return"string"}}function jo(e){var t;const n=e.primaryKey.partitionKey,o=e.primaryKey.partitionKeyType,r=e.primaryKey.sortKey,i=e.primaryKey.sortKeyType,s=[],a=new Map;(e.attributes||[]).forEach(c=>{const u=c.name.trim();!u||a.has(u)||(a.set(u,c),s.push(c))});const d=((t=e.name)===null||t===void 0?void 0:t.trim())||"dynamodb_table",l=[{type:"column",name:n,dataType:{name:Xt(o||"string")},nullable:!1,comment:void 0}];r&&l.push({type:"column",name:r,dataType:{name:Xt(i||"string")},nullable:!1,comment:void 0});const p=s.map(c=>({type:"column",name:c.name,dataType:{name:c.type},nullable:!c.required,comment:c.notes})),f=e.globalSecondaryIndexes.map(c=>({type:"index",name:c.name||"gsi",columns:[{name:c.partitionKey||n},...c.sortKey?[{name:c.sortKey}]:[]],unique:!1}));return{dialect:"dynamodb",tables:[{type:"table",id:dt(),name:d,columns:[...l,...p],constraints:[{type:"primary_key",columns:r?[n,r]:[n]}],indexes:f,options:{comment:e.description}}],metadata:{createdAt:new Date}}}function Yo(e){return{dialect:"mongodb",tables:e.collections.map(t=>{function n(i,s=""){const a=[],d=s?`${s}.${i.name}`:i.name;if(i.type==="array"){const l=i.itemType||"string";l==="object"&&i.itemFields?i.itemFields.forEach(p=>{a.push(...n(p,`${d}[]`))}):a.push({type:"column",name:d,dataType:{name:`${l}[]`},nullable:!i.required})}else i.type==="object"&&i.fields?i.fields.forEach(l=>{a.push(...n(l,d))}):a.push({type:"column",name:d,dataType:{name:i.type},nullable:!i.required});return a}const o=t.fields.flatMap(i=>n(i)),r=t.indexes.map(i=>({type:"index",name:i.name||`idx_${t.name}`,columns:i.fields.map(s=>({name:s.fieldName})),unique:i.unique}));return{type:"table",id:t.id,name:t.name,columns:o,constraints:[],indexes:r,options:{comment:t.description}}}),metadata:{createdAt:new Date}}}function Xo(e){function t(n,o=""){const r=[],i=o?`${o}.${n.name}`:n.name;if(n.type==="array"){const s=n.itemType||"string";s==="object"&&n.itemFields?n.itemFields.forEach(a=>{r.push(...t(a,`${i}[]`))}):r.push({type:"column",name:i,dataType:{name:`${s}[]`},nullable:!n.required,comment:"notes"in n?n.notes:void 0})}else n.type==="object"&&n.fields?n.fields.forEach(s=>{r.push(...t(s,i))}):r.push({type:"column",name:i,dataType:{name:n.type},nullable:!n.required,comment:"notes"in n?n.notes:void 0});return r}return{dialect:"json",tables:e.collections.map(n=>{const o=n.fields.flatMap(s=>t(s)),r=n.fields.filter(s=>{var a;return(a=s.reference)===null||a===void 0?void 0:a.collectionId}).map(s=>{const a=e.collections.find(l=>{var p;return l.id===((p=s.reference)===null||p===void 0?void 0:p.collectionId)}),d=a?.fields.find(l=>{var p;return l.id===((p=s.reference)===null||p===void 0?void 0:p.fieldId)});return{type:"foreign_key",columns:[s.name],referencedTable:a?.name||"",referencedColumns:d?[d.name]:["id"]}}),i=n.indexes.map(s=>({type:"index",name:s.name||`idx_${n.name}`,columns:s.fields.map(a=>({name:a})),unique:s.unique,where:s.ttl?`ttl:${s.ttl}`:void 0}));return{type:"table",id:n.id,name:n.name,columns:o,constraints:r,indexes:i,options:{comment:n.description}}}),metadata:{createdAt:new Date}}}const Qo=bn([Re("dynamodb"),Re("mongodb"),Re("json")]);Qo.or(Re("nosql"));const Pt=re({name:_(),description:_().optional()}),ht=mt(()=>re({id:_(),name:_(),type:_(),required:_e(),fields:le(ht).optional(),itemType:_().optional(),itemFields:le(ht).optional()})),Zo=mt(()=>re({id:_(),name:_(),type:_(),required:_e(),isArray:_e(),reference:re({collectionId:_(),fieldId:_().optional()}).optional(),notes:_().optional(),fields:le(ht).optional(),itemType:_().optional(),itemFields:le(ht).optional()})),Vo=re({id:_(),name:_(),fields:le(_()),unique:_e(),ttl:_().optional()}),Jo=re({id:_(),name:_(),label:_().optional(),description:_().optional(),tags:_().optional(),fields:le(Zo),indexes:le(Vo),sample:_().optional()}),St=mt(()=>re({id:_(),name:_(),type:_(),required:_e(),fields:le(St).optional(),itemType:_().optional(),itemFields:le(St).optional(),refCollectionId:_().nullable().optional()})),ei=re({id:_(),fieldName:_(),order:bn([Re(1),Re(-1)])}),ti=re({id:_(),name:_(),fields:le(ei),unique:_e()}),ni=re({id:_(),name:_(),tags:_(),description:_(),fields:le(St),indexes:le(ti)}),oi=re({id:_(),name:_(),partitionKey:_(),partitionKeyType:_().optional(),sortKey:_().optional(),sortKeyType:_().optional()}),At=mt(()=>re({id:_(),name:_(),type:_(),required:_e(),notes:_().optional(),fields:le(At).optional(),itemType:_().optional(),itemFields:le(At).optional()})),ii=Pt.extend({dialect:Re("dynamodb"),primaryKey:re({partitionKey:_(),partitionKeyType:_().optional(),sortKey:_().optional(),sortKeyType:_().optional()}),globalSecondaryIndexes:le(oi),attributes:le(At)}),ri=Pt.extend({dialect:Re("mongodb"),collections:le(ni)}),si=Pt.extend({dialect:Re("json"),collections:le(Jo)});function ai(e){const t=ii.safeParse(e);if(t.success)return jo(t.data);const n=ri.safeParse(e);if(n.success)return Yo(n.data);const o=si.safeParse(e);if(o.success)return Xo(o.data);throw new Error("Input does not match any supported NoSQL schema format")}function et(e){"@babel/helpers - typeof";return et=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},et(e)}function ci(e,t){if(et(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var o=n.call(e,t);if(et(o)!="object")return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function li(e){var t=ci(e,"string");return et(t)=="symbol"?t:t+""}function ft(e,t,n){return(t=li(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Qt(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),n.push.apply(n,o)}return n}function R(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?Qt(Object(n),!0).forEach(function(o){ft(e,o,n[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Qt(Object(n)).forEach(function(o){Object.defineProperty(e,o,Object.getOwnPropertyDescriptor(n,o))})}return e}function Zt(e){if(!(!e?.type||e.type==="none"))return e.type===xe.Arrow||e.type===xe.ArrowClosed?R({color:"context-stroke",strokeWidth:1.5},e):e.type}const Vt=350,di=0,ui=100,at=450,Jt=100,hi=100,Sn=600;function fi(e,t,n={}){const{horizontalSpacing:o=at,verticalSpacing:r=Sn,startX:i=ui,startY:s=hi}=n,{acyclicEdges:a,reversedEdges:d}=pi(e,t),l=gi(e),p=mi(e,a,l);yi(p,a,l,4),vi(p,a),bi(e,p,l,a);const f=wi(e,p,o,r,i,s);return xi(f,p),{positions:f,layers:p,reversedEdges:d,ports:Ei(e)}}function pi(e,t){const n=new Set,o=[],r=new Map,i=new Map,s=new Map;e.forEach(c=>{r.set(c.id,new Set),i.set(c.id,new Set)}),t.forEach(c=>{var u,h;const m=`${c.source}->${c.target}`;s.set(m,c),(u=r.get(c.source))===null||u===void 0||u.add(c.target),(h=i.get(c.target))===null||h===void 0||h.add(c.source)});const a=new Set(e.map(c=>c.id)),d=[],l=[];for(;a.size>0;){const c=[...a].filter(g=>![...i.get(g)||new Set].some(y=>a.has(y)));if(c.length>0){c.forEach(g=>{d.push(g),a.delete(g)});continue}const u=[...a].filter(g=>![...r.get(g)||new Set].some(y=>a.has(y)));if(u.length>0){u.forEach(g=>{l.unshift(g),a.delete(g)});continue}let h=-1/0,m=a.values().next().value;a.forEach(g=>{const y=(r.get(g)||new Set).size-(i.get(g)||new Set).size;y>h&&(h=y,m=g)}),m&&(d.push(m),a.delete(m))}const p=[...d,...l],f=new Map(p.map((c,u)=>[c,u]));return t.forEach(c=>{if(f.get(c.source)<f.get(c.target))o.push(c);else{const u=`${c.source}->${c.target}`;n.add(u),o.push(R(R({},c),{},{source:c.target,target:c.source}))}}),{acyclicEdges:o,reversedEdges:n}}function mi(e,t,n){const o=new Map,r=new Map,i=new Map;e.forEach(f=>{r.set(f.id,new Set),i.set(f.id,new Set)}),t.forEach(f=>{var c,u;(c=r.get(f.source))===null||c===void 0||c.add(f.target),(u=i.get(f.target))===null||u===void 0||u.add(f.source)});const s=new Map;e.forEach(f=>{const c=(r.get(f.id)||new Set).size,u=(i.get(f.id)||new Set).size,h=Math.max(-2,Math.min(2,c-u));s.set(f.id,h*.3)});const a=new Set;function d(f,c){(!o.has(f)||o.get(f)<c)&&o.set(f,c),!a.has(f)&&(a.add(f),(r.get(f)||new Set).forEach(u=>{d(u,c+1)}),a.delete(f))}const l=e.filter(f=>(i.get(f.id)||new Set).size===0);l.length===0?[...e].sort((f,c)=>(s.get(c.id)||0)-(s.get(f.id)||0)).slice(0,3).forEach(f=>d(f.id,0)):l.forEach(f=>d(f.id,0)),e.forEach(f=>{o.has(f.id)||o.set(f.id,0)}),e.forEach(f=>{const c=o.get(f.id),u=s.get(f.id)||0,h=Math.max(0,Math.round(c-u));o.set(f.id,h)}),n.forEach(f=>{const c=[...i.get(f)||new Set];if(c.length>=2){const u=c.map(m=>o.get(m)||0),h=Math.max(...u);o.set(f,h+1)}});const p=new Map;return o.forEach((f,c)=>{p.has(f)||p.set(f,[]),p.get(f).push(c)}),p}function gi(e,t){const n=new Set;return e.forEach(o=>{const r=o.columns.filter(s=>s.isForeignKey).length,i=o.columns.filter(s=>!s.isForeignKey).length;r>=2&&i<=2&&n.add(o.id)}),n}function yi(e,t,n,o){const r=Math.max(...e.keys()),i=new Map,s=new Map;t.forEach(a=>{i.has(a.source)||i.set(a.source,[]),i.get(a.source).push({target:a.target,weight:a.weight}),s.has(a.target)||s.set(a.target,[]),s.get(a.target).push({source:a.source,weight:a.weight})});for(let a=0;a<o;a++){for(let d=1;d<=r;d++){const l=e.get(d)||[];if(l.length<=1)continue;const p=e.get(d-1)||[],f=new Map(p.map((u,h)=>[u,h])),c=l.map(u=>{const h=s.get(u)||[];if(h.length===0)return{nodeId:u,barycenter:0,median:0};const m=h.map(E=>f.get(E.source)).filter(E=>E!==void 0).sort((E,w)=>E-w),g=h.reduce((E,w)=>{const A=f.get(w.source);return A!==void 0?E+A*w.weight:E},0),y=h.reduce((E,w)=>E+w.weight,0);return{nodeId:u,barycenter:y>0?g/y:0,median:m.length>0?m[Math.floor(m.length/2)]:0}});c.sort((u,h)=>(n.has(u.nodeId)?u.median:u.barycenter)-(n.has(h.nodeId)?h.median:h.barycenter)),e.set(d,c.map(u=>u.nodeId))}for(let d=r-1;d>=0;d--){const l=e.get(d)||[];if(l.length<=1)continue;const p=e.get(d+1)||[],f=new Map(p.map((u,h)=>[u,h])),c=l.map(u=>{const h=i.get(u)||[];if(h.length===0){const E=e.get(d)||[];return{nodeId:u,barycenter:E.indexOf(u),median:E.indexOf(u)}}const m=h.map(E=>f.get(E.target)).filter(E=>E!==void 0).sort((E,w)=>E-w),g=h.reduce((E,w)=>{const A=f.get(w.target);return A!==void 0?E+A*w.weight:E},0),y=h.reduce((E,w)=>E+w.weight,0);return{nodeId:u,barycenter:y>0?g/y:m[0]||0,median:m.length>0?m[Math.floor(m.length/2)]:0}});c.sort((u,h)=>(n.has(u.nodeId)?u.median:u.barycenter)-(n.has(h.nodeId)?h.median:h.barycenter)),e.set(d,c.map(u=>u.nodeId))}}}function vi(e,t){const n=Math.max(...e.keys());new Set(t.map(r=>`${r.source}->${r.target}`));function o(r,i,s){const a=r[i],d=r[s];let l=0;return t.forEach(p=>{p.source!==a&&p.target!==a||t.forEach(f=>{if(f.source!==d&&f.target!==d)return;const c=r.indexOf(p.source),u=r.indexOf(p.target),h=r.indexOf(f.source),m=r.indexOf(f.target);(c<h&&u>m||c>h&&u<m)&&l++})}),l}for(let r=0;r<=n;r++){const i=e.get(r)||[];if(i.length<=1)continue;let s=!0,a=0;const d=5;for(;s&&a<d;){s=!1,a++;for(let l=0;l<i.length-1;l++){const p=o(i,l,l+1);[i[l],i[l+1]]=[i[l+1],i[l]],o(i,l,l+1)<p?s=!0:[i[l],i[l+1]]=[i[l+1],i[l]]}}e.set(r,i)}}function bi(e,t,n,o){const r=new Map;e.forEach(i=>r.set(i.id,new Set)),o.forEach(i=>{var s;(s=r.get(i.target))===null||s===void 0||s.add(i.source)}),n.forEach(i=>{const s=[...r.get(i)||new Set];if(s.length>=2){let a=-1,d=-1;if(t.forEach((p,f)=>{const c=p.indexOf(i);c!==-1&&(a=f,d=c)}),a===-1)return;const l=[];if(t.forEach((p,f)=>{f<a&&s.forEach(c=>{const u=p.indexOf(c);u!==-1&&l.push(u)})}),l.length>=2){const p=l.reduce((h,m)=>h+m,0)/l.length,f=Math.round(p),c=t.get(a);c.splice(d,1);const u=Math.min(f,c.length);c.splice(u,0,i),t.set(a,c)}}})}function wi(e,t,n,o,r,i){const s={},a=new Map(e.map(d=>[d.id,d]));return t.forEach((d,l)=>{let p=r;d.forEach(f=>{const c=a.get(f),u=c?.width||350;s[f]={x:p,y:i+l*o},p+=u+(n-u)})}),s}function xi(e,t){t.forEach(n=>{if(n.length<=2)return;const o=n.map(i=>e[i].x).sort((i,s)=>i-s),r=o[Math.floor(o.length/2)];n.forEach(i=>{const s=(r-e[i].x)*.1;e[i].x+=s})})}function Ei(e){const t={};return e.forEach(n=>{const o=[],r=[];[...n.columns].sort((i,s)=>i.isPrimaryKey&&!s.isPrimaryKey?-1:!i.isPrimaryKey&&s.isPrimaryKey||i.isForeignKey&&!s.isForeignKey?1:!i.isForeignKey&&s.isForeignKey?-1:0).forEach(i=>{i.isPrimaryKey&&o.push(i.name),i.isForeignKey&&r.push(i.name)}),t[n.id]={left:o,right:r}}),t}function vt(e,t=null){return`${e}-table-${t??Ii()}`}function Ii(){let e=new Date().getTime(),t=typeof performance<"u"&&performance.now?performance.now()*1e3:0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,n=>{let o=Math.random()*16;return e>0?(o=(e+o)%16|0,e=Math.floor(e/16)):(o=(t+o)%16|0,t=Math.floor(t/16)),(n==="x"?o:o&3|8).toString(16)})}var As=class{static updateReactFlow({nodes:e,edges:t,schema:n,sourceName:o,oldDataSources:r}){var i;const s=r.find(T=>T.name===o),a=`${o}-table-`,d=this.calculateSmartLayout(n),l=new Set(n.tables.map(T=>T.name)),p=e.filter(T=>T.id.startsWith(a)),f=new Map;for(const T of p){var c;const x=(c=T.data.localTable)===null||c===void 0?void 0:c.tableName;x&&f.set(x,T)}const u=new Map;for(const T of(i=s?.schemaAst.tables)!==null&&i!==void 0?i:[])u.set(T.name,T);const h=new Set;function m(T,x){var N,b,v,I;const C=R(R(R({},x),T),{},{data:R(R(R({},(N=x.data)!==null&&N!==void 0?N:{}),T.data),{},{style:(b=(v=x.data)===null||v===void 0?void 0:v.style)!==null&&b!==void 0?b:(I=T.data)===null||I===void 0?void 0:I.style})});return x.style&&(C.style=x.style),x.width!==void 0&&(C.width=x.width),x.height!==void 0&&(C.height=x.height),C}const g=n.tables.map((T,x)=>{var N,b,v;let I=f.get(T.name);if(!I||h.has(I.id)){I=void 0;const S=this.tableSignature(T);for(const[k,$]of u){if(l.has(k))continue;const P=f.get(k);if(!(!P||h.has(P.id))&&this.tableSignature($)===S){I=P;break}}}const C=(N=(b=(v=I?.position)!==null&&v!==void 0?v:T.position)!==null&&b!==void 0?b:d[T.name])!==null&&N!==void 0?N:{x:100,y:100+x*210},M=this.tableAstToNode(o,T,C,l);return I?(h.add(I.id),m(M,I)):M}),y=new Set(g.map(T=>T.id)),E=n.tables.flatMap(T=>this.createEdgesFromTable(o,T,n.tables).filter(x=>y.has(x.source)&&y.has(x.target))),w=e.filter(T=>!T.id.startsWith(a)),A=t.filter(T=>!T.id.startsWith(a));return{nodes:[...w,...g],edges:[...A,...E]}}static toReactFlow(e,t){const n=[],o=[],r=new Set(e.tables.map(s=>s.name)),i=this.calculateSmartLayout(e);return e.tables.forEach((s,a)=>{const d=s.position||i[s.name]||{x:100,y:100+a*210},l=this.tableAstToNode(t,s,d,r);n.push(l);const p=this.createEdgesFromTable(t,s,e.tables);o.push(...p)}),{nodes:n,edges:o}}static calculateSmartLayout(e){const t={},n=new Set(e.tables.map(d=>d.name)),o=new Map;e.tables.forEach(d=>{o.has(d.name)||o.set(d.name,new Set),this.extractForeignKeys(d).forEach(l=>{n.has(l.referencedTable)&&(o.get(d.name).add(l.referencedTable),o.has(l.referencedTable)||o.set(l.referencedTable,new Set),o.get(l.referencedTable).add(d.name))})});const r=new Set,i=[];function s(d,l){r.add(d),l.push(d),(o.get(d)||new Set).forEach(p=>{r.has(p)||s(p,l)})}e.tables.forEach(d=>{if(!r.has(d.name)){const l=[];s(d.name,l),i.push(l)}});let a=di;return i.forEach(d=>{if(d.length===1)t[d[0]]={x:a,y:Jt},a+=at;else{const l=this.layoutComponentHierarchical(d,o,a,e);Object.assign(t,l),a=Math.max(...Object.values(l).map(p=>p.x))+Vt+at}}),t}static layoutComponentHierarchical(e,t,n,o){const r=new Map(o.tables.filter(d=>e.includes(d.name)).map(d=>[d.name,d])),i=wn(e.map(d=>{const l=r.get(d);return l?{id:d,width:350,height:Math.max(200,l.columns.length*30+80),columns:l.columns.map(p=>{const f=this.extractPrimaryKeys(l),c=this.extractForeignKeys(l);return{name:p.name,isPrimaryKey:f.includes(p.name),isForeignKey:c.some(u=>u.columns.includes(p.name))}})}:null})),s=[],a=new Set(e);return o.tables.forEach(d=>{a.has(d.name)&&this.extractForeignKeys(d).forEach(l=>{if(a.has(l.referencedTable)&&r.has(l.referencedTable)){const p=this.extractPrimaryKeys(d),f=l.columns.some(c=>p.includes(c));s.push({source:d.name,target:l.referencedTable,sourceColumn:l.columns[0],targetColumn:l.referencedColumns[0],weight:f?2:1})}})}),fi(i,s,{horizontalSpacing:at,verticalSpacing:Sn,startY:Jt,startX:n}).positions}static tableAstToNode(e,t,n,o){return{id:vt(e,t.name),type:"databaseTableSQL",width:Vt,position:n,data:{localTable:{databaseName:e,tableName:t.name}}}}static tableSignature(e){const t=[...e.columns].sort((r,i)=>r.name.localeCompare(i.name)).map(r=>{var i,s;const a=(i=(s=r.dataType.parameters)===null||s===void 0?void 0:s.join(","))!==null&&i!==void 0?i:"";return[r.name,r.dataType.name,a,r.dataType.unsigned?"u":"",r.dataType.timezone?"tz":"",r.nullable?"null":"notnull",r.autoIncrement?"ai":""].join(":")}),n=e.constraints.map(r=>JSON.stringify(r)).sort(),o=[...e.indexes].map(r=>JSON.stringify(r)).sort();return JSON.stringify({columns:t,constraints:n,indexes:o})}static extractPrimaryKeys(e){const t=e.constraints.find(n=>n.type==="primary_key");return t?t.columns:e.columns.filter(n=>n.autoIncrement).map(n=>n.name)}static extractForeignKeys(e){return e.constraints.filter(t=>t.type==="foreign_key")}static formatDataType(e){const{dataType:t}=e;let n=t.name;return t.parameters&&t.parameters.length>0&&(n+=`(${t.parameters.join(", ")})`),t.unsigned&&(n+=" UNSIGNED"),t.timezone&&(n+=" WITH TIME ZONE"),n}static createEdgesFromTable(e,t,n){const o=[];return this.extractForeignKeys(t).forEach((r,i)=>{const s=n.find(y=>y.id===r.referencedTable||y.name===r.referencedTable);if(!s)return;const a=vt(e,t.name),d=vt(e,s.name),l=`${a}-fk-${i}`,p=r.columns,f=p.every(y=>{const E=t.columns.find(w=>w.name===y);return E?E.nullable===!1:!1}),c=t.constraints.some(y=>y.type==="unique"&&y.columns.length===p.length&&p.every(E=>y.columns.includes(E))),u=t.indexes.some(y=>y.unique&&y.columns.length===p.length&&p.every(E=>y.columns.some(w=>w.name===E))),h=c||u,m=f?"erdOnlyOne":"erdZeroOrOne",g=h?"erdZeroOrOne":"erdZeroOrMany";o.push({id:l,source:a,target:d,type:"smoothstep",animated:!1,markerEnd:Zt({type:g}),markerStart:Zt({type:m}),label:`${r.columns.join(", ")} → ${r.referencedColumns.join(", ")}`,style:{stroke:"#3b82f6",strokeWidth:2.5},labelStyle:{fontSize:11,fill:"#475569",fontWeight:500},labelBgStyle:{fill:"#ffffff",fillOpacity:.85}})}),o}},Cs=class{constructor(e="mysql",t=2){ft(this,"dialect",void 0),ft(this,"indentSize",void 0),this.dialect=e,this.indentSize=t}generateNoSQL(e){return JSON.stringify({tables:e.tables},null,this.indentSize)}generateSQL(e){const t=[];return t.push(`-- Generated SQL Schema (${e.dialect.toUpperCase()})`),t.push(`-- Generated at: ${new Date().toISOString()}`),t.push(""),e.tables.forEach(n=>{const o=this.generateCreateTable(n);t.push(o),t.push("")}),t.join(`
32
+ `+d.value},a.splice(a.indexOf(d),1),!0};function jo(e,t={}){let n;typeof e=="string"?n=Vn(e,{extensions:[eo()],mdastExtensions:[Jn()]}):n=e;const o=[];function r(i,s){const a=[$o,Do,Oo,Lo,Po,Fo,Bo,Go,Ho,Uo,qo,Wo,zo,Ko];t.handle&&a.unshift(t.handle);for(const d of a)if(d({node:i,ancestors:s,ops:o,process:r}))return}return r(n,[]),o}var Xt={};function Qt(e){switch(e){case"S":return"string";case"N":return"number";case"B":return"binary";default:return"string"}}function Yo(e){var t;const n=e.primaryKey.partitionKey,o=e.primaryKey.partitionKeyType,r=e.primaryKey.sortKey,i=e.primaryKey.sortKeyType,s=[],a=new Map;(e.attributes||[]).forEach(c=>{const u=c.name.trim();!u||a.has(u)||(a.set(u,c),s.push(c))});const d=((t=e.name)===null||t===void 0?void 0:t.trim())||"dynamodb_table",l=[{type:"column",name:n,dataType:{name:Qt(o||"string")},nullable:!1,comment:void 0}];r&&l.push({type:"column",name:r,dataType:{name:Qt(i||"string")},nullable:!1,comment:void 0});const p=s.map(c=>({type:"column",name:c.name,dataType:{name:c.type},nullable:!c.required,comment:c.notes})),f=e.globalSecondaryIndexes.map(c=>({type:"index",name:c.name||"gsi",columns:[{name:c.partitionKey||n},...c.sortKey?[{name:c.sortKey}]:[]],unique:!1}));return{dialect:"dynamodb",tables:[{type:"table",id:dt(),name:d,columns:[...l,...p],constraints:[{type:"primary_key",columns:r?[n,r]:[n]}],indexes:f,options:{comment:e.description}}],metadata:{createdAt:new Date}}}function Xo(e){return{dialect:"mongodb",tables:e.collections.map(t=>{function n(i,s=""){const a=[],d=s?`${s}.${i.name}`:i.name;if(i.type==="array"){const l=i.itemType||"string";l==="object"&&i.itemFields?i.itemFields.forEach(p=>{a.push(...n(p,`${d}[]`))}):a.push({type:"column",name:d,dataType:{name:`${l}[]`},nullable:!i.required})}else i.type==="object"&&i.fields?i.fields.forEach(l=>{a.push(...n(l,d))}):a.push({type:"column",name:d,dataType:{name:i.type},nullable:!i.required});return a}const o=t.fields.flatMap(i=>n(i)),r=t.indexes.map(i=>({type:"index",name:i.name||`idx_${t.name}`,columns:i.fields.map(s=>({name:s.fieldName})),unique:i.unique}));return{type:"table",id:t.id,name:t.name,columns:o,constraints:[],indexes:r,options:{comment:t.description}}}),metadata:{createdAt:new Date}}}function Qo(e){function t(n,o=""){const r=[],i=o?`${o}.${n.name}`:n.name;if(n.type==="array"){const s=n.itemType||"string";s==="object"&&n.itemFields?n.itemFields.forEach(a=>{r.push(...t(a,`${i}[]`))}):r.push({type:"column",name:i,dataType:{name:`${s}[]`},nullable:!n.required,comment:"notes"in n?n.notes:void 0})}else n.type==="object"&&n.fields?n.fields.forEach(s=>{r.push(...t(s,i))}):r.push({type:"column",name:i,dataType:{name:n.type},nullable:!n.required,comment:"notes"in n?n.notes:void 0});return r}return{dialect:"json",tables:e.collections.map(n=>{const o=n.fields.flatMap(s=>t(s)),r=n.fields.filter(s=>{var a;return(a=s.reference)===null||a===void 0?void 0:a.collectionId}).map(s=>{const a=e.collections.find(l=>{var p;return l.id===((p=s.reference)===null||p===void 0?void 0:p.collectionId)}),d=a?.fields.find(l=>{var p;return l.id===((p=s.reference)===null||p===void 0?void 0:p.fieldId)});return{type:"foreign_key",columns:[s.name],referencedTable:a?.name||"",referencedColumns:d?[d.name]:["id"]}}),i=n.indexes.map(s=>({type:"index",name:s.name||`idx_${n.name}`,columns:s.fields.map(a=>({name:a})),unique:s.unique,where:s.ttl?`ttl:${s.ttl}`:void 0}));return{type:"table",id:n.id,name:n.name,columns:o,constraints:r,indexes:i,options:{comment:n.description}}}),metadata:{createdAt:new Date}}}const Zo=wn([Re("dynamodb"),Re("mongodb"),Re("json")]);Zo.or(Re("nosql"));const Pt=re({name:_(),description:_().optional()}),ht=mt(()=>re({id:_(),name:_(),type:_(),required:_e(),fields:le(ht).optional(),itemType:_().optional(),itemFields:le(ht).optional()})),Vo=mt(()=>re({id:_(),name:_(),type:_(),required:_e(),isArray:_e(),reference:re({collectionId:_(),fieldId:_().optional()}).optional(),notes:_().optional(),fields:le(ht).optional(),itemType:_().optional(),itemFields:le(ht).optional()})),Jo=re({id:_(),name:_(),fields:le(_()),unique:_e(),ttl:_().optional()}),ei=re({id:_(),name:_(),label:_().optional(),description:_().optional(),tags:_().optional(),fields:le(Vo),indexes:le(Jo),sample:_().optional()}),St=mt(()=>re({id:_(),name:_(),type:_(),required:_e(),fields:le(St).optional(),itemType:_().optional(),itemFields:le(St).optional(),refCollectionId:_().nullable().optional()})),ti=re({id:_(),fieldName:_(),order:wn([Re(1),Re(-1)])}),ni=re({id:_(),name:_(),fields:le(ti),unique:_e()}),oi=re({id:_(),name:_(),tags:_(),description:_(),fields:le(St),indexes:le(ni)}),ii=re({id:_(),name:_(),partitionKey:_(),partitionKeyType:_().optional(),sortKey:_().optional(),sortKeyType:_().optional()}),At=mt(()=>re({id:_(),name:_(),type:_(),required:_e(),notes:_().optional(),fields:le(At).optional(),itemType:_().optional(),itemFields:le(At).optional()})),ri=Pt.extend({dialect:Re("dynamodb"),primaryKey:re({partitionKey:_(),partitionKeyType:_().optional(),sortKey:_().optional(),sortKeyType:_().optional()}),globalSecondaryIndexes:le(ii),attributes:le(At)}),si=Pt.extend({dialect:Re("mongodb"),collections:le(oi)}),ai=Pt.extend({dialect:Re("json"),collections:le(ei)});function ci(e){const t=ri.safeParse(e);if(t.success)return Yo(t.data);const n=si.safeParse(e);if(n.success)return Xo(n.data);const o=ai.safeParse(e);if(o.success)return Qo(o.data);throw new Error("Input does not match any supported NoSQL schema format")}function et(e){"@babel/helpers - typeof";return et=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},et(e)}function li(e,t){if(et(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var o=n.call(e,t);if(et(o)!="object")return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function di(e){var t=li(e,"string");return et(t)=="symbol"?t:t+""}function ft(e,t,n){return(t=di(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Zt(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),n.push.apply(n,o)}return n}function R(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?Zt(Object(n),!0).forEach(function(o){ft(e,o,n[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Zt(Object(n)).forEach(function(o){Object.defineProperty(e,o,Object.getOwnPropertyDescriptor(n,o))})}return e}function Vt(e){if(!(!e?.type||e.type==="none"))return e.type===xe.Arrow||e.type===xe.ArrowClosed?R({color:"context-stroke",strokeWidth:1.5},e):e.type}const Jt=350,ui=0,hi=100,at=450,en=100,fi=100,An=600;function pi(e,t,n={}){const{horizontalSpacing:o=at,verticalSpacing:r=An,startX:i=hi,startY:s=fi}=n,{acyclicEdges:a,reversedEdges:d}=mi(e,t),l=yi(e),p=gi(e,a,l);vi(p,a,l,4),bi(p,a),wi(e,p,l,a);const f=xi(e,p,o,r,i,s);return Ei(f,p),{positions:f,layers:p,reversedEdges:d,ports:Ii(e)}}function mi(e,t){const n=new Set,o=[],r=new Map,i=new Map,s=new Map;e.forEach(c=>{r.set(c.id,new Set),i.set(c.id,new Set)}),t.forEach(c=>{var u,h;const m=`${c.source}->${c.target}`;s.set(m,c),(u=r.get(c.source))===null||u===void 0||u.add(c.target),(h=i.get(c.target))===null||h===void 0||h.add(c.source)});const a=new Set(e.map(c=>c.id)),d=[],l=[];for(;a.size>0;){const c=[...a].filter(y=>![...i.get(y)||new Set].some(g=>a.has(g)));if(c.length>0){c.forEach(y=>{d.push(y),a.delete(y)});continue}const u=[...a].filter(y=>![...r.get(y)||new Set].some(g=>a.has(g)));if(u.length>0){u.forEach(y=>{l.unshift(y),a.delete(y)});continue}let h=-1/0,m=a.values().next().value;a.forEach(y=>{const g=(r.get(y)||new Set).size-(i.get(y)||new Set).size;g>h&&(h=g,m=y)}),m&&(d.push(m),a.delete(m))}const p=[...d,...l],f=new Map(p.map((c,u)=>[c,u]));return t.forEach(c=>{if(f.get(c.source)<f.get(c.target))o.push(c);else{const u=`${c.source}->${c.target}`;n.add(u),o.push(R(R({},c),{},{source:c.target,target:c.source}))}}),{acyclicEdges:o,reversedEdges:n}}function gi(e,t,n){const o=new Map,r=new Map,i=new Map;e.forEach(f=>{r.set(f.id,new Set),i.set(f.id,new Set)}),t.forEach(f=>{var c,u;(c=r.get(f.source))===null||c===void 0||c.add(f.target),(u=i.get(f.target))===null||u===void 0||u.add(f.source)});const s=new Map;e.forEach(f=>{const c=(r.get(f.id)||new Set).size,u=(i.get(f.id)||new Set).size,h=Math.max(-2,Math.min(2,c-u));s.set(f.id,h*.3)});const a=new Set;function d(f,c){(!o.has(f)||o.get(f)<c)&&o.set(f,c),!a.has(f)&&(a.add(f),(r.get(f)||new Set).forEach(u=>{d(u,c+1)}),a.delete(f))}const l=e.filter(f=>(i.get(f.id)||new Set).size===0);l.length===0?[...e].sort((f,c)=>(s.get(c.id)||0)-(s.get(f.id)||0)).slice(0,3).forEach(f=>d(f.id,0)):l.forEach(f=>d(f.id,0)),e.forEach(f=>{o.has(f.id)||o.set(f.id,0)}),e.forEach(f=>{const c=o.get(f.id),u=s.get(f.id)||0,h=Math.max(0,Math.round(c-u));o.set(f.id,h)}),n.forEach(f=>{const c=[...i.get(f)||new Set];if(c.length>=2){const u=c.map(m=>o.get(m)||0),h=Math.max(...u);o.set(f,h+1)}});const p=new Map;return o.forEach((f,c)=>{p.has(f)||p.set(f,[]),p.get(f).push(c)}),p}function yi(e,t){const n=new Set;return e.forEach(o=>{const r=o.columns.filter(s=>s.isForeignKey).length,i=o.columns.filter(s=>!s.isForeignKey).length;r>=2&&i<=2&&n.add(o.id)}),n}function vi(e,t,n,o){const r=Math.max(...e.keys()),i=new Map,s=new Map;t.forEach(a=>{i.has(a.source)||i.set(a.source,[]),i.get(a.source).push({target:a.target,weight:a.weight}),s.has(a.target)||s.set(a.target,[]),s.get(a.target).push({source:a.source,weight:a.weight})});for(let a=0;a<o;a++){for(let d=1;d<=r;d++){const l=e.get(d)||[];if(l.length<=1)continue;const p=e.get(d-1)||[],f=new Map(p.map((u,h)=>[u,h])),c=l.map(u=>{const h=s.get(u)||[];if(h.length===0)return{nodeId:u,barycenter:0,median:0};const m=h.map(E=>f.get(E.source)).filter(E=>E!==void 0).sort((E,w)=>E-w),y=h.reduce((E,w)=>{const N=f.get(w.source);return N!==void 0?E+N*w.weight:E},0),g=h.reduce((E,w)=>E+w.weight,0);return{nodeId:u,barycenter:g>0?y/g:0,median:m.length>0?m[Math.floor(m.length/2)]:0}});c.sort((u,h)=>(n.has(u.nodeId)?u.median:u.barycenter)-(n.has(h.nodeId)?h.median:h.barycenter)),e.set(d,c.map(u=>u.nodeId))}for(let d=r-1;d>=0;d--){const l=e.get(d)||[];if(l.length<=1)continue;const p=e.get(d+1)||[],f=new Map(p.map((u,h)=>[u,h])),c=l.map(u=>{const h=i.get(u)||[];if(h.length===0){const E=e.get(d)||[];return{nodeId:u,barycenter:E.indexOf(u),median:E.indexOf(u)}}const m=h.map(E=>f.get(E.target)).filter(E=>E!==void 0).sort((E,w)=>E-w),y=h.reduce((E,w)=>{const N=f.get(w.target);return N!==void 0?E+N*w.weight:E},0),g=h.reduce((E,w)=>E+w.weight,0);return{nodeId:u,barycenter:g>0?y/g:m[0]||0,median:m.length>0?m[Math.floor(m.length/2)]:0}});c.sort((u,h)=>(n.has(u.nodeId)?u.median:u.barycenter)-(n.has(h.nodeId)?h.median:h.barycenter)),e.set(d,c.map(u=>u.nodeId))}}}function bi(e,t){const n=Math.max(...e.keys());new Set(t.map(r=>`${r.source}->${r.target}`));function o(r,i,s){const a=r[i],d=r[s];let l=0;return t.forEach(p=>{p.source!==a&&p.target!==a||t.forEach(f=>{if(f.source!==d&&f.target!==d)return;const c=r.indexOf(p.source),u=r.indexOf(p.target),h=r.indexOf(f.source),m=r.indexOf(f.target);(c<h&&u>m||c>h&&u<m)&&l++})}),l}for(let r=0;r<=n;r++){const i=e.get(r)||[];if(i.length<=1)continue;let s=!0,a=0;const d=5;for(;s&&a<d;){s=!1,a++;for(let l=0;l<i.length-1;l++){const p=o(i,l,l+1);[i[l],i[l+1]]=[i[l+1],i[l]],o(i,l,l+1)<p?s=!0:[i[l],i[l+1]]=[i[l+1],i[l]]}}e.set(r,i)}}function wi(e,t,n,o){const r=new Map;e.forEach(i=>r.set(i.id,new Set)),o.forEach(i=>{var s;(s=r.get(i.target))===null||s===void 0||s.add(i.source)}),n.forEach(i=>{const s=[...r.get(i)||new Set];if(s.length>=2){let a=-1,d=-1;if(t.forEach((p,f)=>{const c=p.indexOf(i);c!==-1&&(a=f,d=c)}),a===-1)return;const l=[];if(t.forEach((p,f)=>{f<a&&s.forEach(c=>{const u=p.indexOf(c);u!==-1&&l.push(u)})}),l.length>=2){const p=l.reduce((h,m)=>h+m,0)/l.length,f=Math.round(p),c=t.get(a);c.splice(d,1);const u=Math.min(f,c.length);c.splice(u,0,i),t.set(a,c)}}})}function xi(e,t,n,o,r,i){const s={},a=new Map(e.map(d=>[d.id,d]));return t.forEach((d,l)=>{let p=r;d.forEach(f=>{const c=a.get(f),u=c?.width||350;s[f]={x:p,y:i+l*o},p+=u+(n-u)})}),s}function Ei(e,t){t.forEach(n=>{if(n.length<=2)return;const o=n.map(i=>e[i].x).sort((i,s)=>i-s),r=o[Math.floor(o.length/2)];n.forEach(i=>{const s=(r-e[i].x)*.1;e[i].x+=s})})}function Ii(e){const t={};return e.forEach(n=>{const o=[],r=[];[...n.columns].sort((i,s)=>i.isPrimaryKey&&!s.isPrimaryKey?-1:!i.isPrimaryKey&&s.isPrimaryKey||i.isForeignKey&&!s.isForeignKey?1:!i.isForeignKey&&s.isForeignKey?-1:0).forEach(i=>{i.isPrimaryKey&&o.push(i.name),i.isForeignKey&&r.push(i.name)}),t[n.id]={left:o,right:r}}),t}function vt(e,t=null){return`${e}-table-${t??Ti()}`}function Ti(){let e=new Date().getTime(),t=typeof performance<"u"&&performance.now?performance.now()*1e3:0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,n=>{let o=Math.random()*16;return e>0?(o=(e+o)%16|0,e=Math.floor(e/16)):(o=(t+o)%16|0,t=Math.floor(t/16)),(n==="x"?o:o&3|8).toString(16)})}var Cs=class{static updateReactFlow({nodes:e,edges:t,schema:n,sourceName:o,oldDataSources:r}){var i;const s=r.find(T=>T.name===o),a=`${o}-table-`,d=this.calculateSmartLayout(n),l=new Set(n.tables.map(T=>T.name)),p=e.filter(T=>T.id.startsWith(a)),f=new Map;for(const T of p){var c;const x=(c=T.data.localTable)===null||c===void 0?void 0:c.tableName;x&&f.set(x,T)}const u=new Map;for(const T of(i=s?.schemaAst.tables)!==null&&i!==void 0?i:[])u.set(T.name,T);const h=new Set;function m(T,x){var S,b,v,I;const C=R(R(R({},x),T),{},{data:R(R(R({},(S=x.data)!==null&&S!==void 0?S:{}),T.data),{},{style:(b=(v=x.data)===null||v===void 0?void 0:v.style)!==null&&b!==void 0?b:(I=T.data)===null||I===void 0?void 0:I.style})});return x.style&&(C.style=x.style),x.width!==void 0&&(C.width=x.width),x.height!==void 0&&(C.height=x.height),C}const y=n.tables.map((T,x)=>{var S,b,v;let I=f.get(T.name);if(!I||h.has(I.id)){I=void 0;const A=this.tableSignature(T);for(const[k,$]of u){if(l.has(k))continue;const P=f.get(k);if(!(!P||h.has(P.id))&&this.tableSignature($)===A){I=P;break}}}const C=(S=(b=(v=I?.position)!==null&&v!==void 0?v:T.position)!==null&&b!==void 0?b:d[T.name])!==null&&S!==void 0?S:{x:100,y:100+x*210},M=this.tableAstToNode(o,T,C,l);return I?(h.add(I.id),m(M,I)):M}),g=new Set(y.map(T=>T.id)),E=n.tables.flatMap(T=>this.createEdgesFromTable(o,T,n.tables).filter(x=>g.has(x.source)&&g.has(x.target))),w=e.filter(T=>!T.id.startsWith(a)),N=t.filter(T=>!T.id.startsWith(a));return{nodes:[...w,...y],edges:[...N,...E]}}static toReactFlow(e,t){const n=[],o=[],r=new Set(e.tables.map(s=>s.name)),i=this.calculateSmartLayout(e);return e.tables.forEach((s,a)=>{const d=s.position||i[s.name]||{x:100,y:100+a*210},l=this.tableAstToNode(t,s,d,r);n.push(l);const p=this.createEdgesFromTable(t,s,e.tables);o.push(...p)}),{nodes:n,edges:o}}static calculateSmartLayout(e){const t={},n=new Set(e.tables.map(d=>d.name)),o=new Map;e.tables.forEach(d=>{o.has(d.name)||o.set(d.name,new Set),this.extractForeignKeys(d).forEach(l=>{n.has(l.referencedTable)&&(o.get(d.name).add(l.referencedTable),o.has(l.referencedTable)||o.set(l.referencedTable,new Set),o.get(l.referencedTable).add(d.name))})});const r=new Set,i=[];function s(d,l){r.add(d),l.push(d),(o.get(d)||new Set).forEach(p=>{r.has(p)||s(p,l)})}e.tables.forEach(d=>{if(!r.has(d.name)){const l=[];s(d.name,l),i.push(l)}});let a=ui;return i.forEach(d=>{if(d.length===1)t[d[0]]={x:a,y:en},a+=at;else{const l=this.layoutComponentHierarchical(d,o,a,e);Object.assign(t,l),a=Math.max(...Object.values(l).map(p=>p.x))+Jt+at}}),t}static layoutComponentHierarchical(e,t,n,o){const r=new Map(o.tables.filter(d=>e.includes(d.name)).map(d=>[d.name,d])),i=xn(e.map(d=>{const l=r.get(d);return l?{id:d,width:350,height:Math.max(200,l.columns.length*30+80),columns:l.columns.map(p=>{const f=this.extractPrimaryKeys(l),c=this.extractForeignKeys(l);return{name:p.name,isPrimaryKey:f.includes(p.name),isForeignKey:c.some(u=>u.columns.includes(p.name))}})}:null})),s=[],a=new Set(e);return o.tables.forEach(d=>{a.has(d.name)&&this.extractForeignKeys(d).forEach(l=>{if(a.has(l.referencedTable)&&r.has(l.referencedTable)){const p=this.extractPrimaryKeys(d),f=l.columns.some(c=>p.includes(c));s.push({source:d.name,target:l.referencedTable,sourceColumn:l.columns[0],targetColumn:l.referencedColumns[0],weight:f?2:1})}})}),pi(i,s,{horizontalSpacing:at,verticalSpacing:An,startY:en,startX:n}).positions}static tableAstToNode(e,t,n,o){return{id:vt(e,t.name),type:"databaseTableSQL",width:Jt,position:n,data:{localTable:{databaseName:e,tableName:t.name}}}}static tableSignature(e){const t=[...e.columns].sort((r,i)=>r.name.localeCompare(i.name)).map(r=>{var i,s;const a=(i=(s=r.dataType.parameters)===null||s===void 0?void 0:s.join(","))!==null&&i!==void 0?i:"";return[r.name,r.dataType.name,a,r.dataType.unsigned?"u":"",r.dataType.timezone?"tz":"",r.nullable?"null":"notnull",r.autoIncrement?"ai":""].join(":")}),n=e.constraints.map(r=>JSON.stringify(r)).sort(),o=[...e.indexes].map(r=>JSON.stringify(r)).sort();return JSON.stringify({columns:t,constraints:n,indexes:o})}static extractPrimaryKeys(e){const t=e.constraints.find(n=>n.type==="primary_key");return t?t.columns:e.columns.filter(n=>n.autoIncrement).map(n=>n.name)}static extractForeignKeys(e){return e.constraints.filter(t=>t.type==="foreign_key")}static formatDataType(e){const{dataType:t}=e;let n=t.name;return t.parameters&&t.parameters.length>0&&(n+=`(${t.parameters.join(", ")})`),t.unsigned&&(n+=" UNSIGNED"),t.timezone&&(n+=" WITH TIME ZONE"),n}static createEdgesFromTable(e,t,n){const o=[];return this.extractForeignKeys(t).forEach((r,i)=>{const s=n.find(g=>g.id===r.referencedTable||g.name===r.referencedTable);if(!s)return;const a=vt(e,t.name),d=vt(e,s.name),l=`${a}-fk-${i}`,p=r.columns,f=p.every(g=>{const E=t.columns.find(w=>w.name===g);return E?E.nullable===!1:!1}),c=t.constraints.some(g=>g.type==="unique"&&g.columns.length===p.length&&p.every(E=>g.columns.includes(E))),u=t.indexes.some(g=>g.unique&&g.columns.length===p.length&&p.every(E=>g.columns.some(w=>w.name===E))),h=c||u,m=f?"erdOnlyOne":"erdZeroOrOne",y=h?"erdZeroOrOne":"erdZeroOrMany";o.push({id:l,source:a,target:d,type:"smoothstep",animated:!1,markerEnd:Vt({type:y}),markerStart:Vt({type:m}),label:`${r.columns.join(", ")} → ${r.referencedColumns.join(", ")}`,style:{stroke:"#3b82f6",strokeWidth:2.5},labelStyle:{fontSize:11,fill:"#475569",fontWeight:500},labelBgStyle:{fill:"#ffffff",fillOpacity:.85}})}),o}},ks=class{constructor(e="mysql",t=2){ft(this,"dialect",void 0),ft(this,"indentSize",void 0),this.dialect=e,this.indentSize=t}generateNoSQL(e){return JSON.stringify({tables:e.tables},null,this.indentSize)}generateSQL(e){const t=[];return t.push(`-- Generated SQL Schema (${e.dialect.toUpperCase()})`),t.push(`-- Generated at: ${new Date().toISOString()}`),t.push(""),e.tables.forEach(n=>{const o=this.generateCreateTable(n);t.push(o),t.push("")}),t.join(`
33
33
  `)}generate(e){switch(this.dialect){case"dynamodb":case"mongodb":case"json":return this.generateNoSQL(e);default:return this.generateSQL(e)}}generateCreateTable(e){const t=[],n=" ".repeat(this.indentSize),o=this.quoteIdentifier(e.name);t.push(`CREATE TABLE IF NOT EXISTS ${o} (`);const r=[];e.columns.forEach(s=>{r.push(this.generateColumn(s))}),e.constraints.forEach(s=>{r.push(this.generateConstraint(s))}),this.dialect==="mysql"&&e.indexes.forEach(s=>{r.push(this.generateIndex(s))}),t.push(r.map(s=>`${n}${s}`).join(`,
34
34
  `)),t.push(")");const i=this.generateTableOptions(e);return i&&(t[t.length-1]+=` ${i}`),t[t.length-1]+=";",this.dialect==="postgresql"&&e.indexes.forEach(s=>{t.push(""),t.push(this.generatePostgresIndex(s,e.name))}),t.join(`
35
- `)}generateColumn(e){const t=[];return t.push(this.quoteIdentifier(e.name)),t.push(this.generateDataType(e.dataType)),t.push(e.nullable?"NULL":"NOT NULL"),e.defaultValue&&t.push(`DEFAULT ${this.generateDefaultValue(e.defaultValue)}`),e.autoIncrement&&(this.dialect==="mysql"?t.push("AUTO_INCREMENT"):this.dialect),e.comment&&this.dialect==="mysql"&&t.push(`COMMENT '${e.comment.replace(/'/g,"''")}'`),t.join(" ")}generateDataType(e){let t=e.name;return e.parameters&&e.parameters.length>0&&(t+=`(${e.parameters.join(", ")})`),e.unsigned&&(t+=" UNSIGNED"),e.timezone&&(t+=" WITH TIME ZONE"),t}generateDefaultValue(e){return e.type==="literal"?e.value===null?"NULL":typeof e.value=="string"?`'${e.value.replace(/'/g,"''")}'`:String(e.value):(e.type==="function"||e.type==="expression")&&e.raw||String(e.value)}generateConstraint(e){switch(e.type){case"primary_key":return this.generatePrimaryKey(e);case"foreign_key":return this.generateForeignKey(e);case"unique":return this.generateUnique(e);case"check":return this.generateCheck(e);default:return""}}generatePrimaryKey(e){const t=e.columns.map(n=>this.quoteIdentifier(n)).join(", ");return e.name?`CONSTRAINT ${this.quoteIdentifier(e.name)} PRIMARY KEY (${t})`:`PRIMARY KEY (${t})`}generateForeignKey(e){const t=[];e.name&&t.push(`CONSTRAINT ${this.quoteIdentifier(e.name)}`);const n=e.columns.map(i=>this.quoteIdentifier(i)).join(", "),o=this.quoteIdentifier(e.referencedTable),r=e.referencedColumns.map(i=>this.quoteIdentifier(i)).join(", ");return t.push(`FOREIGN KEY (${n})`),t.push(`REFERENCES ${o} (${r})`),e.onDelete&&t.push(`ON DELETE ${e.onDelete}`),e.onUpdate&&t.push(`ON UPDATE ${e.onUpdate}`),t.join(" ")}generateUnique(e){const t=e.columns.map(n=>this.quoteIdentifier(n)).join(", ");return e.name?`CONSTRAINT ${this.quoteIdentifier(e.name)} UNIQUE (${t})`:`UNIQUE (${t})`}generateCheck(e){return e.name?`CONSTRAINT ${this.quoteIdentifier(e.name)} CHECK (${e.expression})`:`CHECK (${e.expression})`}generateIndex(e){const t=[];e.unique&&t.push("UNIQUE"),t.push("INDEX"),t.push(this.quoteIdentifier(e.name));const n=e.columns.map(o=>{let r=this.quoteIdentifier(o.name);return o.length&&(r+=`(${o.length})`),o.order&&(r+=` ${o.order}`),r});return t.push(`(${n.join(", ")})`),e.method&&this.dialect==="mysql"&&t.push(`USING ${e.method.toUpperCase()}`),t.join(" ")}generatePostgresIndex(e,t){const n=[];n.push("CREATE"),e.unique&&n.push("UNIQUE"),n.push("INDEX"),n.push(this.quoteIdentifier(e.name)),n.push("ON"),n.push(this.quoteIdentifier(t)),e.method&&n.push(`USING ${e.method.toUpperCase()}`);const o=e.columns.map(r=>{let i=this.quoteIdentifier(r.name);return r.order&&(i+=` ${r.order}`),i});return n.push(`(${o.join(", ")})`),e.where&&n.push(`WHERE ${e.where}`),n.join(" ")+";"}generateTableOptions(e){if(!e.options)return null;const t=[];return this.dialect==="mysql"&&(e.options.engine&&t.push(`ENGINE=${e.options.engine}`),e.options.charset&&t.push(`CHARACTER SET ${e.options.charset}`),e.options.collation&&t.push(`COLLATE ${e.options.collation}`),e.options.autoIncrement&&t.push(`AUTO_INCREMENT=${e.options.autoIncrement}`),e.options.comment&&t.push(`COMMENT='${e.options.comment.replace(/'/g,"''")}'`)),this.dialect==="postgresql"&&e.options.tablespace&&t.push(`TABLESPACE ${e.options.tablespace}`),t.length>0?t.join(" "):null}quoteIdentifier(e){switch(this.dialect){case"mysql":return`\`${e}\``;case"postgresql":return`"${e}"`;case"sqlite":return`"${e}"`;default:return e}}},ks=class{constructor(e="mysql"){ft(this,"dialect",void 0),this.dialect=e}parseSQL(e){const t=this.extractTables(e);return{dialect:this.dialect,tables:t,metadata:{createdAt:new Date}}}parseNoSQL(e){const t=JSON.parse(e||"{}"),n=Array.isArray(t.tables)?t.tables:null;if(n&&n.length>0)return{dialect:this.dialect,tables:n,metadata:{createdAt:new Date}};const o=(Array.isArray(t.collections)?t.collections:[]).map(r=>{if(!r||!r.name)return null;const i=r.fields&&typeof r.fields=="object"?r.fields:{},s=Object.entries(i).map(([a,d])=>({type:"column",name:a,dataType:this.parseNoSqlType(String(d||"string")),nullable:!0}));return{type:"table",id:dt(),name:r.name,columns:s,constraints:[],indexes:[]}}).filter(Boolean);return{dialect:this.dialect,tables:o,metadata:{createdAt:new Date}}}parse(e,t=!1){switch(this.dialect){case"json":case"mongodb":case"dynamodb":return t?ai(JSON.parse(e)):this.parseNoSQL(e);default:return this.parseSQL(e)}}static detectDialect(e){const t=e.toLowerCase();try{return JSON.parse(e),"json"}catch{}return t.includes("serial")||t.includes("bigserial")||t.includes("::")||t.includes("nextval(")||t.includes("create schema")?"postgresql":(t.includes("engine=")||t.includes("auto_increment")||t.includes("unsigned")||t.includes("character set")||t.includes("collate"),"mysql")}extractTables(e){const t=[],n=new Map,o=this.cleanSql(e),r=/CREATE\s+TABLE[\s\S]*?;/gi;let i;for(;(i=r.exec(o))!==null;){const s=i[0],a=this.extractCreateTableComponents(s);if(!a)continue;const{rawIdentifier:d,tableName:l,tableBody:p,tableOptions:f}=a,c=this.normalizeTableKey(d);if(!n.has(c))try{const u=this.parseTableDefinition(l,p,f);t.push(u),n.set(c,u)}catch(u){console.error("Error parsing table:",u)}}return this.applyAlterTableStatements(o,n),t}extractCreateTableComponents(e){const t=e.trim(),n=/^CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?((?:`[^`]+`|"[^"]+"|'[^']+'|\[[^\]]+\]|\w+)(?:\.(?:`[^`]+`|"[^"]+"|'[^']+'|\[[^\]]+\]|\w+))?)\s*\(/i.exec(t);if(!n)return null;const o=n[1],r=n[0].length-1,i=this.findClosingParenthesis(t,r);if(i===-1)return null;const s=t.slice(r+1,i),a=t.slice(i+1,t.length-1).trim();return{rawIdentifier:o,tableName:this.normalizeTableName(o),tableBody:s,tableOptions:a}}findClosingParenthesis(e,t){let n=0,o=!1,r="";for(let i=t;i<e.length;i++){const s=e[i],a=i>0?e[i-1]:"";if((s==='"'||s==="'"||s==="`")&&a!=="\\"&&(o?s===r&&(o=!1,r=""):(o=!0,r=s)),!o){if(s==="(")n++;else if(s===")"&&(n--,n===0))return i}}return-1}applyAlterTableStatements(e,t){const n=/ALTER\s+TABLE\s+(?:IF\s+EXISTS\s+)?(?:ONLY\s+)?((?:`[^`]+`|"[^"]+"|'[^']+'|\[[^\]]+\]|[\w$]+)(?:\.(?:`[^`]+`|"[^"]+"|'[^']+'|\[[^\]]+\]|[\w$]+))?)\s+([\s\S]*?);/gi;let o;for(;(o=n.exec(e))!==null;){const r=o[1],i=o[2]||"";if(!r)continue;const s=t.get(this.normalizeTableKey(r));if(!s)continue;const a=this.splitTableBody(i);for(const d of a){const l=d.trim();if(l&&/^ADD\s+/i.test(l)){const p=l.replace(/^ADD\s+/i,"").trim();if(!p)continue;const f=this.parseConstraint(p);if(f){s.constraints.push(f);continue}const c=this.parseIndex(p);c&&s.indexes.push(c)}}}}cleanSql(e){return e.replace(/--.*$/gm,"").replace(/\/\*[\s\S]*?\*\//g,"").replace(/\r\n/g,`
36
- `).trim()}cleanIdentifier(e){return e.replace(/[`"'\[\]]/g,"").trim()}normalizeTableName(e){const t=this.cleanIdentifier(e);if(!t)return"";const n=t.split(".");return n[n.length-1]}normalizeTableKey(e){return this.cleanIdentifier(e).toLowerCase()}parseNoSqlType(e){const t=e.trim(),n=t.toLowerCase();return n.startsWith("array<")&&n.endsWith(">")?{name:`array<${t.slice(6,-1).trim()||"string"}>`}:{name:t||"string"}}parseTableDefinition(e,t,n){const o=[],r=[],i=[],s=[],a=this.splitTableBody(t);for(const p of a){const f=p.trim();if(f)try{const c=/^(?:CONSTRAINT|PRIMARY\s+KEY|FOREIGN\s+KEY|UNIQUE|CHECK|INDEX|KEY)\b/i;let u=null;if(!c.test(f)&&(u=this.parseColumn(f),u)){s.push({column:u,hasType:!!u.dataType.name}),this.applyInlineColumnConstraints(f,u,r);continue}const h=this.parseConstraint(f);if(h){r.push(h);continue}const m=this.parseIndex(f);if(m){i.push(m);continue}u||(u=this.parseColumn(f)),u&&(s.push({column:u,hasType:!!u.dataType.name}),this.applyInlineColumnConstraints(f,u,r))}catch(c){console.warn("Error parsing line:",f,c)}}const d=s.filter(p=>p.hasType).length;s.forEach((p,f)=>{if(!p.hasType){const c=s.slice(f+1).some(u=>u.hasType);if(!(d<4&&c))return}o.push(p.column)});const l=this.parseTableOptions(n);return{type:"table",id:dt(),name:e,columns:o,constraints:r,indexes:i,options:l}}splitTableBody(e){const t=[];let n="",o=0,r=!1,i="";for(let s=0;s<e.length;s++){const a=e[s],d=s>0?e[s-1]:"";(a==='"'||a==="'"||a==="`")&&d!=="\\"&&(r?a===i&&(r=!1,i=""):(r=!0,i=a)),r||(a==="("?o++:a===")"&&o--),a===","&&o===0&&!r?(t.push(n.trim()),n=""):n+=a}return n.trim()&&t.push(n.trim()),t}parseColumn(e){var t,n,o,r,i,s;const a=e.match(/^(?:`([^`]+)`|"([^"]+)"|'([^']+)'|\[([^\]]+)\]|([a-zA-Z_][\w$]*))\s+([\s\S]+)$/i);if(!a)return null;const d=(t=(n=(o=(r=(i=a[1])!==null&&i!==void 0?i:a[2])!==null&&r!==void 0?r:a[3])!==null&&o!==void 0?o:a[4])!==null&&n!==void 0?n:a[5])!==null&&t!==void 0?t:"";if(!d)return null;const l=(s=a[6])===null||s===void 0?void 0:s.trim().replace(/,+$/,"");if(!l)return null;const{dataTypeStr:p,constraintsStr:f}=this.splitColumnDefinition(l),c=f||"",u=this.parseDataType(p);let h=!/NOT\s+NULL/i.test(c);const m=/AUTO_INCREMENT/i.test(c)||/AUTOINCREMENT/i.test(c)||/(SERIAL|BIGSERIAL)/i.test(p);(m||/\bPRIMARY\s+KEY\b/i.test(c))&&(h=!1);let g;const y=c.match(/DEFAULT\s+((?:'[^']*'|"[^"]*"|\([^)]*\)|[^\s,]+))/i);y&&(g=this.parseDefaultValue(y[1]));let E;const w=c.match(/COMMENT\s+['"]([^'"]+)['"]/i);w&&(E=w[1]);const A={type:"column",name:this.cleanIdentifier(d),dataType:u,nullable:h,defaultValue:g,autoIncrement:m,comment:E},T=c.match(/COLLATE\s+([^\s,]+)/i)||e.match(/COLLATE\s+([^\s,]+)/i);T&&(A.collation=this.cleanIdentifier(T[1]));const x=c.match(/CHARACTER\s+SET\s+([^\s,]+)/i)||c.match(/CHARSET\s*=?\s*([^\s,]+)/i)||e.match(/CHARACTER\s+SET\s+([^\s,]+)/i)||e.match(/CHARSET\s*=?\s*([^\s,]+)/i);return x&&(A.charset=this.cleanIdentifier(x[1])),A}splitColumnDefinition(e){const t=/\b(?:GENERATED|DEFAULT|NOT\s+NULL|NULL|UNIQUE|PRIMARY\s+KEY|CHECK|REFERENCES|COLLATE|COMMENT|AUTO(?:_|\s*)INCREMENT|ON\s+UPDATE|ON\s+DELETE|CONSTRAINT)\b/i.exec(e);return t?{dataTypeStr:e.slice(0,t.index).trim(),constraintsStr:e.slice(t.index).trim()}:{dataTypeStr:e.trim(),constraintsStr:""}}applyInlineColumnConstraints(e,t,n){const o=t.name;if(/\bPRIMARY\s+KEY\b/i.test(e)){const i=e.match(/CONSTRAINT\s+["'`]?([^"'`\s]+)["'`"]?.*PRIMARY\s+KEY/i),s=i?this.cleanIdentifier(i[1]):void 0,a=n.find(d=>d.type==="primary_key");a?a.columns.includes(o)||a.columns.push(o):n.push({type:"primary_key",name:s,columns:[o]})}if(/\bUNIQUE\b/i.test(e)&&!/\bUNIQUE\s+(?:KEY|INDEX)\b/i.test(e)){const i=e.match(/CONSTRAINT\s+["'`]?([^"'`\s]+)["'`"]?.*UNIQUE/i),s=i?this.cleanIdentifier(i[1]):void 0;n.some(a=>a.type==="unique"&&a.columns.length===1&&a.columns[0]===o)||n.push({type:"unique",name:s,columns:[o]})}const r=e.match(/REFERENCES\s+([^\s(]+)\s*\(([^)]+)\)/i);if(r){const i=e.match(/CONSTRAINT\s+["'`]?([^"'`\s]+)["'`"]?.*FOREIGN\s+KEY/i),s=i?this.cleanIdentifier(i[1]):void 0,a=this.normalizeTableName(r[1]),d=r[2].split(",").map(f=>this.cleanIdentifier(f.trim())),l=this.extractReferentialAction(e,"DELETE"),p=this.extractReferentialAction(e,"UPDATE");n.some(f=>f.type==="foreign_key"&&f.columns.length===1&&f.columns[0]===o&&f.referencedTable===a)||n.push({type:"foreign_key",name:s,columns:[o],referencedTable:a,referencedColumns:d,onDelete:l,onUpdate:p})}if(/CHECK\s*\(/i.test(e)){const i=this.parseCheck(e);i&&!n.some(s=>s.type==="check"&&s.expression===i.expression)&&n.push(i)}}parseDataType(e){const t=e.match(/^(\w+)(?:\(([^)]+)\))?(.*)?$/i);if(!t)return{name:e.trim().toUpperCase()};const n=t[1].toUpperCase(),o=t[2],r=t[3]||"",i={name:n};return o&&(i.parameters=o.split(",").map(s=>{const a=s.trim(),d=Number(a);return isNaN(d)?a:d})),i.unsigned=/UNSIGNED/i.test(r),i.timezone=/WITH TIME ZONE/i.test(r),i}parseDefaultValue(e){const t=e.trim();if(/^NULL$/i.test(t))return{type:"literal",value:null,raw:t};if(/\w+\(.*\)/i.test(t))return{type:"function",value:t,raw:t};if(/^['"].*['"]$/.test(t))return{type:"literal",value:t.slice(1,-1),raw:t};const n=Number(t);return isNaN(n)?{type:"expression",value:t,raw:t}:{type:"literal",value:n,raw:t}}parseConstraint(e){return/PRIMARY\s+KEY/i.test(e)?this.parsePrimaryKey(e):/FOREIGN\s+KEY/i.test(e)?this.parseForeignKey(e):/UNIQUE/i.test(e)&&!/INDEX|KEY/i.test(e)?this.parseUnique(e):/CHECK/i.test(e)?this.parseCheck(e):null}parsePrimaryKey(e){const t=e.match(/(?:CONSTRAINT\s+["'`]?([^"'`\s]+)["'`"]?\s+)?PRIMARY\s+KEY\s*\(([^)]+)\)/i);return t?{type:"primary_key",name:t[1]?this.cleanIdentifier(t[1]):void 0,columns:t[2].split(",").map(n=>this.cleanIdentifier(n.trim()))}:null}parseForeignKey(e){const t=e.match(/(?:CONSTRAINT\s+["'`]?([^"'`\s]+)["'`"]?\s+)?FOREIGN\s+KEY\s*\(([^)]+)\)\s*REFERENCES\s+((?:["'`]?[\w$]+["'`"]?|\[[^\]]+\])(?:\.(?:["'`]?[\w$]+["'`"]?|\[[^\]]+\]))?)\s*\(([^)]+)\)/i);return t?{type:"foreign_key",name:t[1]?this.cleanIdentifier(t[1]):void 0,columns:t[2].split(",").map(n=>this.cleanIdentifier(n.trim())),referencedTable:this.normalizeTableName(t[3]),referencedColumns:t[4].split(",").map(n=>this.cleanIdentifier(n.trim())),onDelete:this.extractReferentialAction(e,"DELETE"),onUpdate:this.extractReferentialAction(e,"UPDATE")}:null}extractReferentialAction(e,t){const n=new RegExp(`ON\\s+${t}\\s+([A-Z\\s]+?)(?=\\s+ON\\s+(?:DELETE|UPDATE)\\b|,|\\)|$)`,"i"),o=e.match(n);if(!o)return;const r=o[1].trim().replace(/\s+/g," ").toUpperCase();if(r==="CASCADE"||r==="SET NULL"||r==="SET DEFAULT"||r==="RESTRICT"||r==="NO ACTION")return r}parseUnique(e){const t=e.match(/(?:CONSTRAINT\s+["'`]?([^"'`\s]+)["'`"]?\s+)?UNIQUE\s*\(([^)]+)\)/i);return t?{type:"unique",name:t[1]?this.cleanIdentifier(t[1]):void 0,columns:t[2].split(",").map(n=>this.cleanIdentifier(n.trim()))}:null}parseCheck(e){const t=e.match(/(?:CONSTRAINT\s+["'`]?([^"'`\s]+)["'`"]?\s+)?CHECK\s*\(([\s\S]*?)\)/i);return t?{type:"check",name:t[1]?this.cleanIdentifier(t[1]):void 0,expression:t[2].trim()}:null}parseIndex(e){var t;const n=e.match(/(UNIQUE\s+)?(?:INDEX|KEY)\s+["'`]?([^"'`\s]+)["'`"]?\s*\(([^)]+)\)(?:\s+USING\s+(\w+))?/i);if(!n)return null;const o=!!n[1],r=this.cleanIdentifier(n[2]),i=n[3],s=(t=n[4])===null||t===void 0?void 0:t.toLowerCase();return{type:"index",name:r,columns:i.split(",").map(a=>{var d,l,p,f,c,u;const h=a.trim().match(/^(?:`([^`]+)`|"([^"]+)"|'([^']+)'|\[([^\]]+)\]|([^\s(]+))(?:\((\d+)\))?(?:\s+(ASC|DESC))?$/i);return h?{name:this.cleanIdentifier((d=(l=(p=(f=(c=h[1])!==null&&c!==void 0?c:h[2])!==null&&f!==void 0?f:h[3])!==null&&p!==void 0?p:h[4])!==null&&l!==void 0?l:h[5])!==null&&d!==void 0?d:""),length:h[6]?Number(h[6]):void 0,order:(u=h[7])===null||u===void 0?void 0:u.toUpperCase()}:{name:this.cleanIdentifier(a.trim())}}),unique:o,method:s}}parseTableOptions(e){if(!e.trim())return;const t={},n=e.match(/ENGINE\s*=\s*(\w+)/i);n&&(t.engine=n[1]);const o=e.match(/(?:DEFAULT\s+)?(?:CHARACTER\s+SET|CHARSET)\s*=?\s*([^\s;]+)/i);o&&(t.charset=this.cleanIdentifier(o[1]));const r=e.match(/COLLATE\s*=?\s*([^\s;]+)/i);r&&(t.collation=this.cleanIdentifier(r[1]));const i=e.match(/AUTO_INCREMENT\s*=\s*(\d+)/i);i&&(t.autoIncrement=Number(i[1]));const s=e.match(/COMMENT\s*=\s*['"]([^'"]+)['"]/i);return s&&(t.comment=s[1]),Object.keys(t).length>0?t:void 0}};function en(e,t,n,o,r,i,s){try{var a=e[i](s),d=a.value}catch(l){n(l);return}a.done?t(d):Promise.resolve(d).then(o,r)}function Be(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function s(d){en(i,o,r,s,a,"next",d)}function a(d){en(i,o,r,s,a,"throw",d)}s(void 0)})}}function Rs(e,t){const n={};return e.forEach(o=>{var r;const i=(r=t.find(y=>y?.componentFieldId===o.componentFieldId))===null||r===void 0?void 0:r.data,s=o.componentFieldId;if(s)switch(o.type){case L.TextInput:case L.TextBox:case L.DropdownSelect:case L.SearchSelect:case L.CodeEditor:case L.URLInput:case L.ColorPicker:case L.DatePicker:var a,d;n[s]=String((a=i==null||(d=i[0])===null||d===void 0?void 0:d.value)!==null&&a!==void 0?a:"");break;case L.MultiSelect:case L.CheckboxGroup:case L.TagInput:var l,p;n[s]=(l=i==null||(p=i[0])===null||p===void 0?void 0:p.value)!==null&&l!==void 0?l:[];break;case L.NumberInput:case L.Slider:var f;n[s]=!(i==null||(f=i[0])===null||f===void 0)&&f.value?Number(i[0].value):null;break;case L.FileUpload:case L.LinkOrFileUpload:var c,u;n[s]=(c=i==null||(u=i[0])===null||u===void 0?void 0:u.value)!==null&&c!==void 0?c:null;break;case L.RichTextEditor:var h;n[s]=(h=i?.[0])!==null&&h!==void 0?h:void 0;break;case L.KeyValueList:n[s]=i??[];break;case L.BooleanToggle:var m,g;n[s]=(m=i==null||(g=i[0])===null||g===void 0?void 0:g.value)!==null&&m!==void 0?m:!1;break;case L.DateRangePicker:n[s]=i?.[0];break}}),n}function Ti(e,t){return e.map(n=>{var o,r,i,s,a;let d;const l=t[n.componentFieldId];switch(n.type){case L.TextInput:case L.TextBox:case L.DropdownSelect:case L.SearchSelect:case L.CodeEditor:case L.URLInput:case L.ColorPicker:case L.DatePicker:d=[{value:String(l??"")}];break;case L.MultiSelect:case L.CheckboxGroup:case L.TagInput:d=[{value:l??[]}];break;case L.NumberInput:case L.Slider:d=[{value:l!=null?Number(l):null}];break;case L.FileUpload:case L.LinkOrFileUpload:{const p=l;d=[{value:{fileId:p?.fileId,url:p?.url}}];break}case L.RichTextEditor:d=[l];break;case L.KeyValueList:d=l??[];break;case L.BooleanToggle:d=[{value:l??!1}];break;case L.DateRangePicker:d=[l];break;default:d=l??null;break}return R(R({},n),{},{componentFieldId:n.componentFieldId,type:(o=n.type)!==null&&o!==void 0?o:L.TextInput,required:(r=n.required)!==null&&r!==void 0?r:!1,label:(i=n.label)!==null&&i!==void 0?i:"",order:(s=n.order)!==null&&s!==void 0?s:0,data:(a=d)!==null&&a!==void 0?a:[]})})}function ke(e){var t;const n=(t=e.componentFieldId)!==null&&t!==void 0?t:String(Math.random()),[o]=Ti([R(R({},e),{},{hidden:!0,componentFieldId:n})],{[n]:e.type===L.RichTextEditor&&typeof e.data=="string"?zo(e.data):e.data});return o}function me(e){return ke({componentFieldId:"name",label:"Name",type:L.TextInput,data:e})}function Ni(e,t){return e.find(n=>{var o;return((o=n.label)===null||o===void 0?void 0:o.toLowerCase())===t.toLowerCase()})}const Si={c4ShapeInRow:4,c4BoundaryInRow:2};function Ai(e){const t=e.shape==="db"?"_db":e.shape==="queue"?"_queue":"";return`${e.isExternal?"external_":""}${e.kind}${t}`}const Ci=["C4Context","C4Container","C4Component","C4Dynamic","C4Deployment"],ki={Person:"person",System:"system",Container:"container",Component:"component"},Ri={Boundary:{kind:"generic"},Enterprise_Boundary:{kind:"enterprise",fixedType:"ENTERPRISE"},System_Boundary:{kind:"system",fixedType:"SYSTEM"},Container_Boundary:{kind:"container",fixedType:"CONTAINER"},Deployment_Node:{kind:"node",nodeType:"node"},Node:{kind:"node",nodeType:"node"},Node_L:{kind:"node",nodeType:"nodeL"},Node_R:{kind:"node",nodeType:"nodeR"}},_i={Rel:"default",RelIndex:"default",BiRel:"bi",Rel_Back:"back",Rel_U:"up",Rel_Up:"up",Rel_D:"down",Rel_Down:"down",Rel_L:"left",Rel_Left:"left",Rel_R:"right",Rel_Right:"right",Rel_Neighbor:"default",BiRel_Neighbor:"bi"},Mi=["TB","BT","LR","RL"];function $i(e){let t=e,n=!1;t.endsWith("_Ext")&&(n=!0,t=t.slice(0,-4));let o="default";t.endsWith("Db")?(o="db",t=t.slice(0,-2)):t.endsWith("Queue")&&(o="queue",t=t.slice(0,-5));const r=ki[t];return r?{kind:r,shape:o,isExternal:n}:null}function Di(e){if(!e.trim())return[];const t=[];let n="",o=!1,r=0;for(let i=0;i<e.length;i++){const s=e[i];if(s==='"'&&e[i-1]!=="\\"){o=!o,n+=s;continue}if(!o&&(s==="("||s==="[")&&r++,!o&&(s===")"||s==="]")&&r--,s===","&&!o&&r===0){t.push(n.trim()),n="";continue}n+=s}return t.push(n.trim()),t}function Je(e){const t=e.trim();return t.startsWith('"')&&t.endsWith('"')&&t.length>=2?t.slice(1,-1).replace(/\\"/g,'"').replace(/<br\s*\/?>/gi,`
35
+ `)}generateColumn(e){const t=[];return t.push(this.quoteIdentifier(e.name)),t.push(this.generateDataType(e.dataType)),t.push(e.nullable?"NULL":"NOT NULL"),e.defaultValue&&t.push(`DEFAULT ${this.generateDefaultValue(e.defaultValue)}`),e.autoIncrement&&(this.dialect==="mysql"?t.push("AUTO_INCREMENT"):this.dialect),e.comment&&this.dialect==="mysql"&&t.push(`COMMENT '${e.comment.replace(/'/g,"''")}'`),t.join(" ")}generateDataType(e){let t=e.name;return e.parameters&&e.parameters.length>0&&(t+=`(${e.parameters.join(", ")})`),e.unsigned&&(t+=" UNSIGNED"),e.timezone&&(t+=" WITH TIME ZONE"),t}generateDefaultValue(e){return e.type==="literal"?e.value===null?"NULL":typeof e.value=="string"?`'${e.value.replace(/'/g,"''")}'`:String(e.value):(e.type==="function"||e.type==="expression")&&e.raw||String(e.value)}generateConstraint(e){switch(e.type){case"primary_key":return this.generatePrimaryKey(e);case"foreign_key":return this.generateForeignKey(e);case"unique":return this.generateUnique(e);case"check":return this.generateCheck(e);default:return""}}generatePrimaryKey(e){const t=e.columns.map(n=>this.quoteIdentifier(n)).join(", ");return e.name?`CONSTRAINT ${this.quoteIdentifier(e.name)} PRIMARY KEY (${t})`:`PRIMARY KEY (${t})`}generateForeignKey(e){const t=[];e.name&&t.push(`CONSTRAINT ${this.quoteIdentifier(e.name)}`);const n=e.columns.map(i=>this.quoteIdentifier(i)).join(", "),o=this.quoteIdentifier(e.referencedTable),r=e.referencedColumns.map(i=>this.quoteIdentifier(i)).join(", ");return t.push(`FOREIGN KEY (${n})`),t.push(`REFERENCES ${o} (${r})`),e.onDelete&&t.push(`ON DELETE ${e.onDelete}`),e.onUpdate&&t.push(`ON UPDATE ${e.onUpdate}`),t.join(" ")}generateUnique(e){const t=e.columns.map(n=>this.quoteIdentifier(n)).join(", ");return e.name?`CONSTRAINT ${this.quoteIdentifier(e.name)} UNIQUE (${t})`:`UNIQUE (${t})`}generateCheck(e){return e.name?`CONSTRAINT ${this.quoteIdentifier(e.name)} CHECK (${e.expression})`:`CHECK (${e.expression})`}generateIndex(e){const t=[];e.unique&&t.push("UNIQUE"),t.push("INDEX"),t.push(this.quoteIdentifier(e.name));const n=e.columns.map(o=>{let r=this.quoteIdentifier(o.name);return o.length&&(r+=`(${o.length})`),o.order&&(r+=` ${o.order}`),r});return t.push(`(${n.join(", ")})`),e.method&&this.dialect==="mysql"&&t.push(`USING ${e.method.toUpperCase()}`),t.join(" ")}generatePostgresIndex(e,t){const n=[];n.push("CREATE"),e.unique&&n.push("UNIQUE"),n.push("INDEX"),n.push(this.quoteIdentifier(e.name)),n.push("ON"),n.push(this.quoteIdentifier(t)),e.method&&n.push(`USING ${e.method.toUpperCase()}`);const o=e.columns.map(r=>{let i=this.quoteIdentifier(r.name);return r.order&&(i+=` ${r.order}`),i});return n.push(`(${o.join(", ")})`),e.where&&n.push(`WHERE ${e.where}`),n.join(" ")+";"}generateTableOptions(e){if(!e.options)return null;const t=[];return this.dialect==="mysql"&&(e.options.engine&&t.push(`ENGINE=${e.options.engine}`),e.options.charset&&t.push(`CHARACTER SET ${e.options.charset}`),e.options.collation&&t.push(`COLLATE ${e.options.collation}`),e.options.autoIncrement&&t.push(`AUTO_INCREMENT=${e.options.autoIncrement}`),e.options.comment&&t.push(`COMMENT='${e.options.comment.replace(/'/g,"''")}'`)),this.dialect==="postgresql"&&e.options.tablespace&&t.push(`TABLESPACE ${e.options.tablespace}`),t.length>0?t.join(" "):null}quoteIdentifier(e){switch(this.dialect){case"mysql":return`\`${e}\``;case"postgresql":return`"${e}"`;case"sqlite":return`"${e}"`;default:return e}}},Rs=class{constructor(e="mysql"){ft(this,"dialect",void 0),this.dialect=e}parseSQL(e){const t=this.extractTables(e);return{dialect:this.dialect,tables:t,metadata:{createdAt:new Date}}}parseNoSQL(e){const t=JSON.parse(e||"{}"),n=Array.isArray(t.tables)?t.tables:null;if(n&&n.length>0)return{dialect:this.dialect,tables:n,metadata:{createdAt:new Date}};const o=(Array.isArray(t.collections)?t.collections:[]).map(r=>{if(!r||!r.name)return null;const i=r.fields&&typeof r.fields=="object"?r.fields:{},s=Object.entries(i).map(([a,d])=>({type:"column",name:a,dataType:this.parseNoSqlType(String(d||"string")),nullable:!0}));return{type:"table",id:dt(),name:r.name,columns:s,constraints:[],indexes:[]}}).filter(Boolean);return{dialect:this.dialect,tables:o,metadata:{createdAt:new Date}}}parse(e,t=!1){switch(this.dialect){case"json":case"mongodb":case"dynamodb":return t?ci(JSON.parse(e)):this.parseNoSQL(e);default:return this.parseSQL(e)}}static detectDialect(e){const t=e.toLowerCase();try{return JSON.parse(e),"json"}catch{}return t.includes("serial")||t.includes("bigserial")||t.includes("::")||t.includes("nextval(")||t.includes("create schema")?"postgresql":(t.includes("engine=")||t.includes("auto_increment")||t.includes("unsigned")||t.includes("character set")||t.includes("collate"),"mysql")}extractTables(e){const t=[],n=new Map,o=this.cleanSql(e),r=/CREATE\s+TABLE[\s\S]*?;/gi;let i;for(;(i=r.exec(o))!==null;){const s=i[0],a=this.extractCreateTableComponents(s);if(!a)continue;const{rawIdentifier:d,tableName:l,tableBody:p,tableOptions:f}=a,c=this.normalizeTableKey(d);if(!n.has(c))try{const u=this.parseTableDefinition(l,p,f);t.push(u),n.set(c,u)}catch(u){console.error("Error parsing table:",u)}}return this.applyAlterTableStatements(o,n),t}extractCreateTableComponents(e){const t=e.trim(),n=/^CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?((?:`[^`]+`|"[^"]+"|'[^']+'|\[[^\]]+\]|\w+)(?:\.(?:`[^`]+`|"[^"]+"|'[^']+'|\[[^\]]+\]|\w+))?)\s*\(/i.exec(t);if(!n)return null;const o=n[1],r=n[0].length-1,i=this.findClosingParenthesis(t,r);if(i===-1)return null;const s=t.slice(r+1,i),a=t.slice(i+1,t.length-1).trim();return{rawIdentifier:o,tableName:this.normalizeTableName(o),tableBody:s,tableOptions:a}}findClosingParenthesis(e,t){let n=0,o=!1,r="";for(let i=t;i<e.length;i++){const s=e[i],a=i>0?e[i-1]:"";if((s==='"'||s==="'"||s==="`")&&a!=="\\"&&(o?s===r&&(o=!1,r=""):(o=!0,r=s)),!o){if(s==="(")n++;else if(s===")"&&(n--,n===0))return i}}return-1}applyAlterTableStatements(e,t){const n=/ALTER\s+TABLE\s+(?:IF\s+EXISTS\s+)?(?:ONLY\s+)?((?:`[^`]+`|"[^"]+"|'[^']+'|\[[^\]]+\]|[\w$]+)(?:\.(?:`[^`]+`|"[^"]+"|'[^']+'|\[[^\]]+\]|[\w$]+))?)\s+([\s\S]*?);/gi;let o;for(;(o=n.exec(e))!==null;){const r=o[1],i=o[2]||"";if(!r)continue;const s=t.get(this.normalizeTableKey(r));if(!s)continue;const a=this.splitTableBody(i);for(const d of a){const l=d.trim();if(l&&/^ADD\s+/i.test(l)){const p=l.replace(/^ADD\s+/i,"").trim();if(!p)continue;const f=this.parseConstraint(p);if(f){s.constraints.push(f);continue}const c=this.parseIndex(p);c&&s.indexes.push(c)}}}}cleanSql(e){return e.replace(/--.*$/gm,"").replace(/\/\*[\s\S]*?\*\//g,"").replace(/\r\n/g,`
36
+ `).trim()}cleanIdentifier(e){return e.replace(/[`"'\[\]]/g,"").trim()}normalizeTableName(e){const t=this.cleanIdentifier(e);if(!t)return"";const n=t.split(".");return n[n.length-1]}normalizeTableKey(e){return this.cleanIdentifier(e).toLowerCase()}parseNoSqlType(e){const t=e.trim(),n=t.toLowerCase();return n.startsWith("array<")&&n.endsWith(">")?{name:`array<${t.slice(6,-1).trim()||"string"}>`}:{name:t||"string"}}parseTableDefinition(e,t,n){const o=[],r=[],i=[],s=[],a=this.splitTableBody(t);for(const p of a){const f=p.trim();if(f)try{const c=/^(?:CONSTRAINT|PRIMARY\s+KEY|FOREIGN\s+KEY|UNIQUE|CHECK|INDEX|KEY)\b/i;let u=null;if(!c.test(f)&&(u=this.parseColumn(f),u)){s.push({column:u,hasType:!!u.dataType.name}),this.applyInlineColumnConstraints(f,u,r);continue}const h=this.parseConstraint(f);if(h){r.push(h);continue}const m=this.parseIndex(f);if(m){i.push(m);continue}u||(u=this.parseColumn(f)),u&&(s.push({column:u,hasType:!!u.dataType.name}),this.applyInlineColumnConstraints(f,u,r))}catch(c){console.warn("Error parsing line:",f,c)}}const d=s.filter(p=>p.hasType).length;s.forEach((p,f)=>{if(!p.hasType){const c=s.slice(f+1).some(u=>u.hasType);if(!(d<4&&c))return}o.push(p.column)});const l=this.parseTableOptions(n);return{type:"table",id:dt(),name:e,columns:o,constraints:r,indexes:i,options:l}}splitTableBody(e){const t=[];let n="",o=0,r=!1,i="";for(let s=0;s<e.length;s++){const a=e[s],d=s>0?e[s-1]:"";(a==='"'||a==="'"||a==="`")&&d!=="\\"&&(r?a===i&&(r=!1,i=""):(r=!0,i=a)),r||(a==="("?o++:a===")"&&o--),a===","&&o===0&&!r?(t.push(n.trim()),n=""):n+=a}return n.trim()&&t.push(n.trim()),t}parseColumn(e){var t,n,o,r,i,s;const a=e.match(/^(?:`([^`]+)`|"([^"]+)"|'([^']+)'|\[([^\]]+)\]|([a-zA-Z_][\w$]*))\s+([\s\S]+)$/i);if(!a)return null;const d=(t=(n=(o=(r=(i=a[1])!==null&&i!==void 0?i:a[2])!==null&&r!==void 0?r:a[3])!==null&&o!==void 0?o:a[4])!==null&&n!==void 0?n:a[5])!==null&&t!==void 0?t:"";if(!d)return null;const l=(s=a[6])===null||s===void 0?void 0:s.trim().replace(/,+$/,"");if(!l)return null;const{dataTypeStr:p,constraintsStr:f}=this.splitColumnDefinition(l),c=f||"",u=this.parseDataType(p);let h=!/NOT\s+NULL/i.test(c);const m=/AUTO_INCREMENT/i.test(c)||/AUTOINCREMENT/i.test(c)||/(SERIAL|BIGSERIAL)/i.test(p);(m||/\bPRIMARY\s+KEY\b/i.test(c))&&(h=!1);let y;const g=c.match(/DEFAULT\s+((?:'[^']*'|"[^"]*"|\([^)]*\)|[^\s,]+))/i);g&&(y=this.parseDefaultValue(g[1]));let E;const w=c.match(/COMMENT\s+['"]([^'"]+)['"]/i);w&&(E=w[1]);const N={type:"column",name:this.cleanIdentifier(d),dataType:u,nullable:h,defaultValue:y,autoIncrement:m,comment:E},T=c.match(/COLLATE\s+([^\s,]+)/i)||e.match(/COLLATE\s+([^\s,]+)/i);T&&(N.collation=this.cleanIdentifier(T[1]));const x=c.match(/CHARACTER\s+SET\s+([^\s,]+)/i)||c.match(/CHARSET\s*=?\s*([^\s,]+)/i)||e.match(/CHARACTER\s+SET\s+([^\s,]+)/i)||e.match(/CHARSET\s*=?\s*([^\s,]+)/i);return x&&(N.charset=this.cleanIdentifier(x[1])),N}splitColumnDefinition(e){const t=/\b(?:GENERATED|DEFAULT|NOT\s+NULL|NULL|UNIQUE|PRIMARY\s+KEY|CHECK|REFERENCES|COLLATE|COMMENT|AUTO(?:_|\s*)INCREMENT|ON\s+UPDATE|ON\s+DELETE|CONSTRAINT)\b/i.exec(e);return t?{dataTypeStr:e.slice(0,t.index).trim(),constraintsStr:e.slice(t.index).trim()}:{dataTypeStr:e.trim(),constraintsStr:""}}applyInlineColumnConstraints(e,t,n){const o=t.name;if(/\bPRIMARY\s+KEY\b/i.test(e)){const i=e.match(/CONSTRAINT\s+["'`]?([^"'`\s]+)["'`"]?.*PRIMARY\s+KEY/i),s=i?this.cleanIdentifier(i[1]):void 0,a=n.find(d=>d.type==="primary_key");a?a.columns.includes(o)||a.columns.push(o):n.push({type:"primary_key",name:s,columns:[o]})}if(/\bUNIQUE\b/i.test(e)&&!/\bUNIQUE\s+(?:KEY|INDEX)\b/i.test(e)){const i=e.match(/CONSTRAINT\s+["'`]?([^"'`\s]+)["'`"]?.*UNIQUE/i),s=i?this.cleanIdentifier(i[1]):void 0;n.some(a=>a.type==="unique"&&a.columns.length===1&&a.columns[0]===o)||n.push({type:"unique",name:s,columns:[o]})}const r=e.match(/REFERENCES\s+([^\s(]+)\s*\(([^)]+)\)/i);if(r){const i=e.match(/CONSTRAINT\s+["'`]?([^"'`\s]+)["'`"]?.*FOREIGN\s+KEY/i),s=i?this.cleanIdentifier(i[1]):void 0,a=this.normalizeTableName(r[1]),d=r[2].split(",").map(f=>this.cleanIdentifier(f.trim())),l=this.extractReferentialAction(e,"DELETE"),p=this.extractReferentialAction(e,"UPDATE");n.some(f=>f.type==="foreign_key"&&f.columns.length===1&&f.columns[0]===o&&f.referencedTable===a)||n.push({type:"foreign_key",name:s,columns:[o],referencedTable:a,referencedColumns:d,onDelete:l,onUpdate:p})}if(/CHECK\s*\(/i.test(e)){const i=this.parseCheck(e);i&&!n.some(s=>s.type==="check"&&s.expression===i.expression)&&n.push(i)}}parseDataType(e){const t=e.match(/^(\w+)(?:\(([^)]+)\))?(.*)?$/i);if(!t)return{name:e.trim().toUpperCase()};const n=t[1].toUpperCase(),o=t[2],r=t[3]||"",i={name:n};return o&&(i.parameters=o.split(",").map(s=>{const a=s.trim(),d=Number(a);return isNaN(d)?a:d})),i.unsigned=/UNSIGNED/i.test(r),i.timezone=/WITH TIME ZONE/i.test(r),i}parseDefaultValue(e){const t=e.trim();if(/^NULL$/i.test(t))return{type:"literal",value:null,raw:t};if(/\w+\(.*\)/i.test(t))return{type:"function",value:t,raw:t};if(/^['"].*['"]$/.test(t))return{type:"literal",value:t.slice(1,-1),raw:t};const n=Number(t);return isNaN(n)?{type:"expression",value:t,raw:t}:{type:"literal",value:n,raw:t}}parseConstraint(e){return/PRIMARY\s+KEY/i.test(e)?this.parsePrimaryKey(e):/FOREIGN\s+KEY/i.test(e)?this.parseForeignKey(e):/UNIQUE/i.test(e)&&!/INDEX|KEY/i.test(e)?this.parseUnique(e):/CHECK/i.test(e)?this.parseCheck(e):null}parsePrimaryKey(e){const t=e.match(/(?:CONSTRAINT\s+["'`]?([^"'`\s]+)["'`"]?\s+)?PRIMARY\s+KEY\s*\(([^)]+)\)/i);return t?{type:"primary_key",name:t[1]?this.cleanIdentifier(t[1]):void 0,columns:t[2].split(",").map(n=>this.cleanIdentifier(n.trim()))}:null}parseForeignKey(e){const t=e.match(/(?:CONSTRAINT\s+["'`]?([^"'`\s]+)["'`"]?\s+)?FOREIGN\s+KEY\s*\(([^)]+)\)\s*REFERENCES\s+((?:["'`]?[\w$]+["'`"]?|\[[^\]]+\])(?:\.(?:["'`]?[\w$]+["'`"]?|\[[^\]]+\]))?)\s*\(([^)]+)\)/i);return t?{type:"foreign_key",name:t[1]?this.cleanIdentifier(t[1]):void 0,columns:t[2].split(",").map(n=>this.cleanIdentifier(n.trim())),referencedTable:this.normalizeTableName(t[3]),referencedColumns:t[4].split(",").map(n=>this.cleanIdentifier(n.trim())),onDelete:this.extractReferentialAction(e,"DELETE"),onUpdate:this.extractReferentialAction(e,"UPDATE")}:null}extractReferentialAction(e,t){const n=new RegExp(`ON\\s+${t}\\s+([A-Z\\s]+?)(?=\\s+ON\\s+(?:DELETE|UPDATE)\\b|,|\\)|$)`,"i"),o=e.match(n);if(!o)return;const r=o[1].trim().replace(/\s+/g," ").toUpperCase();if(r==="CASCADE"||r==="SET NULL"||r==="SET DEFAULT"||r==="RESTRICT"||r==="NO ACTION")return r}parseUnique(e){const t=e.match(/(?:CONSTRAINT\s+["'`]?([^"'`\s]+)["'`"]?\s+)?UNIQUE\s*\(([^)]+)\)/i);return t?{type:"unique",name:t[1]?this.cleanIdentifier(t[1]):void 0,columns:t[2].split(",").map(n=>this.cleanIdentifier(n.trim()))}:null}parseCheck(e){const t=e.match(/(?:CONSTRAINT\s+["'`]?([^"'`\s]+)["'`"]?\s+)?CHECK\s*\(([\s\S]*?)\)/i);return t?{type:"check",name:t[1]?this.cleanIdentifier(t[1]):void 0,expression:t[2].trim()}:null}parseIndex(e){var t;const n=e.match(/(UNIQUE\s+)?(?:INDEX|KEY)\s+["'`]?([^"'`\s]+)["'`"]?\s*\(([^)]+)\)(?:\s+USING\s+(\w+))?/i);if(!n)return null;const o=!!n[1],r=this.cleanIdentifier(n[2]),i=n[3],s=(t=n[4])===null||t===void 0?void 0:t.toLowerCase();return{type:"index",name:r,columns:i.split(",").map(a=>{var d,l,p,f,c,u;const h=a.trim().match(/^(?:`([^`]+)`|"([^"]+)"|'([^']+)'|\[([^\]]+)\]|([^\s(]+))(?:\((\d+)\))?(?:\s+(ASC|DESC))?$/i);return h?{name:this.cleanIdentifier((d=(l=(p=(f=(c=h[1])!==null&&c!==void 0?c:h[2])!==null&&f!==void 0?f:h[3])!==null&&p!==void 0?p:h[4])!==null&&l!==void 0?l:h[5])!==null&&d!==void 0?d:""),length:h[6]?Number(h[6]):void 0,order:(u=h[7])===null||u===void 0?void 0:u.toUpperCase()}:{name:this.cleanIdentifier(a.trim())}}),unique:o,method:s}}parseTableOptions(e){if(!e.trim())return;const t={},n=e.match(/ENGINE\s*=\s*(\w+)/i);n&&(t.engine=n[1]);const o=e.match(/(?:DEFAULT\s+)?(?:CHARACTER\s+SET|CHARSET)\s*=?\s*([^\s;]+)/i);o&&(t.charset=this.cleanIdentifier(o[1]));const r=e.match(/COLLATE\s*=?\s*([^\s;]+)/i);r&&(t.collation=this.cleanIdentifier(r[1]));const i=e.match(/AUTO_INCREMENT\s*=\s*(\d+)/i);i&&(t.autoIncrement=Number(i[1]));const s=e.match(/COMMENT\s*=\s*['"]([^'"]+)['"]/i);return s&&(t.comment=s[1]),Object.keys(t).length>0?t:void 0}};function tn(e,t,n,o,r,i,s){try{var a=e[i](s),d=a.value}catch(l){n(l);return}a.done?t(d):Promise.resolve(d).then(o,r)}function Be(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function s(d){tn(i,o,r,s,a,"next",d)}function a(d){tn(i,o,r,s,a,"throw",d)}s(void 0)})}}function _s(e,t){const n={};return e.forEach(o=>{var r;const i=(r=t.find(g=>g?.componentFieldId===o.componentFieldId))===null||r===void 0?void 0:r.data,s=o.componentFieldId;if(s)switch(o.type){case L.TextInput:case L.TextBox:case L.DropdownSelect:case L.SearchSelect:case L.CodeEditor:case L.URLInput:case L.ColorPicker:case L.DatePicker:var a,d;n[s]=String((a=i==null||(d=i[0])===null||d===void 0?void 0:d.value)!==null&&a!==void 0?a:"");break;case L.MultiSelect:case L.CheckboxGroup:case L.TagInput:var l,p;n[s]=(l=i==null||(p=i[0])===null||p===void 0?void 0:p.value)!==null&&l!==void 0?l:[];break;case L.NumberInput:case L.Slider:var f;n[s]=!(i==null||(f=i[0])===null||f===void 0)&&f.value?Number(i[0].value):null;break;case L.FileUpload:case L.LinkOrFileUpload:var c,u;n[s]=(c=i==null||(u=i[0])===null||u===void 0?void 0:u.value)!==null&&c!==void 0?c:null;break;case L.RichTextEditor:var h;n[s]=(h=i?.[0])!==null&&h!==void 0?h:void 0;break;case L.KeyValueList:n[s]=i??[];break;case L.BooleanToggle:var m,y;n[s]=(m=i==null||(y=i[0])===null||y===void 0?void 0:y.value)!==null&&m!==void 0?m:!1;break;case L.DateRangePicker:n[s]=i?.[0];break}}),n}function Ni(e,t){return e.map(n=>{var o,r,i,s,a;let d;const l=t[n.componentFieldId];switch(n.type){case L.TextInput:case L.TextBox:case L.DropdownSelect:case L.SearchSelect:case L.CodeEditor:case L.URLInput:case L.ColorPicker:case L.DatePicker:d=[{value:String(l??"")}];break;case L.MultiSelect:case L.CheckboxGroup:case L.TagInput:d=[{value:l??[]}];break;case L.NumberInput:case L.Slider:d=[{value:l!=null?Number(l):null}];break;case L.FileUpload:case L.LinkOrFileUpload:{const p=l;d=[{value:{fileId:p?.fileId,url:p?.url}}];break}case L.RichTextEditor:d=[l];break;case L.KeyValueList:d=l??[];break;case L.BooleanToggle:d=[{value:l??!1}];break;case L.DateRangePicker:d=[l];break;default:d=l??null;break}return R(R({},n),{},{componentFieldId:n.componentFieldId,type:(o=n.type)!==null&&o!==void 0?o:L.TextInput,required:(r=n.required)!==null&&r!==void 0?r:!1,label:(i=n.label)!==null&&i!==void 0?i:"",order:(s=n.order)!==null&&s!==void 0?s:0,data:(a=d)!==null&&a!==void 0?a:[]})})}function ke(e){var t;const n=(t=e.componentFieldId)!==null&&t!==void 0?t:String(Math.random()),[o]=Ni([R(R({},e),{},{hidden:!0,componentFieldId:n})],{[n]:e.type===L.RichTextEditor&&typeof e.data=="string"?jo(e.data):e.data});return o}function me(e){return ke({componentFieldId:"name",label:"Name",type:L.TextInput,data:e})}function Si(e,t){return e.find(n=>{var o;return((o=n.label)===null||o===void 0?void 0:o.toLowerCase())===t.toLowerCase()})}const Ai={c4ShapeInRow:4,c4BoundaryInRow:2};function Ci(e){const t=e.shape==="db"?"_db":e.shape==="queue"?"_queue":"";return`${e.isExternal?"external_":""}${e.kind}${t}`}const ki=["C4Context","C4Container","C4Component","C4Dynamic","C4Deployment"],Ri={Person:"person",System:"system",Container:"container",Component:"component"},_i={Boundary:{kind:"generic"},Enterprise_Boundary:{kind:"enterprise",fixedType:"ENTERPRISE"},System_Boundary:{kind:"system",fixedType:"SYSTEM"},Container_Boundary:{kind:"container",fixedType:"CONTAINER"},Deployment_Node:{kind:"node",nodeType:"node"},Node:{kind:"node",nodeType:"node"},Node_L:{kind:"node",nodeType:"nodeL"},Node_R:{kind:"node",nodeType:"nodeR"}},Mi={Rel:"default",RelIndex:"default",BiRel:"bi",Rel_Back:"back",Rel_U:"up",Rel_Up:"up",Rel_D:"down",Rel_Down:"down",Rel_L:"left",Rel_Left:"left",Rel_R:"right",Rel_Right:"right",Rel_Neighbor:"default",BiRel_Neighbor:"bi"},$i=["TB","BT","LR","RL"];function Di(e){let t=e,n=!1;t.endsWith("_Ext")&&(n=!0,t=t.slice(0,-4));let o="default";t.endsWith("Db")?(o="db",t=t.slice(0,-2)):t.endsWith("Queue")&&(o="queue",t=t.slice(0,-5));const r=Ri[t];return r?{kind:r,shape:o,isExternal:n}:null}function Oi(e){if(!e.trim())return[];const t=[];let n="",o=!1,r=0;for(let i=0;i<e.length;i++){const s=e[i];if(s==='"'&&e[i-1]!=="\\"){o=!o,n+=s;continue}if(!o&&(s==="("||s==="[")&&r++,!o&&(s===")"||s==="]")&&r--,s===","&&!o&&r===0){t.push(n.trim()),n="";continue}n+=s}return t.push(n.trim()),t}function Je(e){const t=e.trim();return t.startsWith('"')&&t.endsWith('"')&&t.length>=2?t.slice(1,-1).replace(/\\"/g,'"').replace(/<br\s*\/?>/gi,`
37
37
  `).trim():t.replace(/<br\s*\/?>/gi,`
38
- `)}function Oi(e){const t=[],n={};for(const o of e){const r=o.match(/^\$([A-Za-z0-9_]+)\s*=\s*([\s\S]*)$/);if(r){n[r[1]]=Je(r[2]);continue}t.push(Je(o))}return{positional:t,named:n}}function K(e,t){const n=e[t];if(n!==void 0&&n!=="")return n}function Li(e){const t=[];let n="",o=0;for(const r of e.split(`
39
- `)){const i=r.replace(/%%.*$/,"").trim();if(!i)continue;n=n?`${n} ${i}`:i;let s=!1;for(let a=0;a<i.length;a++){const d=i[a];d==='"'&&i[a-1]!=="\\"&&(s=!s),!s&&(d==="("&&o++,d===")"&&o--)}o>0||(o=0,t.push(...tn(n)),n="")}return n&&t.push(...tn(n)),t}function tn(e){const t=[];let n="",o=!1,r=0;function i(){n.trim()&&t.push(n.trim()),n=""}for(let s=0;s<e.length;s++){const a=e[s];if(a==='"'&&e[s-1]!=="\\"&&(o=!o),!o&&a==="("&&r++,!o&&a===")"&&r--,!o&&r===0&&a==="{"){n+=a,i();continue}if(!o&&r===0&&a==="}"){i(),t.push("}");continue}n+=a}return i(),t}function Pi(e){const t=[],n=[],o=[],r={},i={},s={},a=R({},Si);let d="C4Context",l,p,f,c;const u=[];let h=0,m;function g(){return u[u.length-1]}function y(W){const ae=g();if(!ae)return;const Te=n.find(he=>he.id===ae);Te&&(Te.childIds.includes(W)||Te.childIds.push(W))}for(const W of Li(e)){if(m){if(W==="}"){f=m.join(`
40
- `).trim(),m=void 0;continue}m.push(W);continue}const ae=Ci.find(V=>W.toLowerCase().startsWith(V.toLowerCase()));if(ae){d=ae;continue}if(W==="}"){u.pop();continue}const Te=W.match(/^direction\s+(TB|BT|LR|RL)$/i);if(Te){c=Mi.find(V=>V===Te[1].toUpperCase());continue}const he=W.match(/^accTitle\s*:\s*(.*)$/i);if(he){p=Je(he[1]);continue}if(/^accDescr\s*\{$/i.test(W)){m=[];continue}const O=W.match(/^accDescr\s*:\s*(.*)$/i);if(O){f=Je(O[1]);continue}const X=W.match(/^title\s+(.*)$/i);if(X){l=Je(X[1]);continue}const ue=W.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*\(([\s\S]*)\)\s*(\{)?\s*$/);if(!ue)continue;const[,fe,Ye,Bn]=ue,{positional:ee,named:Z}=Oi(Di(Ye));if(fe==="UpdateLayoutConfig"){var E,w;const V=(E=Z.c4ShapeInRow)!==null&&E!==void 0?E:K(ee,0),de=(w=Z.c4BoundaryInRow)!==null&&w!==void 0?w:K(ee,1);V&&(a.c4ShapeInRow=Number(V)||a.c4ShapeInRow),de&&(a.c4BoundaryInRow=Number(de)||a.c4BoundaryInRow);continue}if(fe==="UpdateElementStyle"||fe==="UpdateBoundaryStyle"){var A,T,x,N,b,v,I,C,M;const V=K(ee,0);if(!V)continue;const de=(A=Z.shadowing)!==null&&A!==void 0?A:K(ee,4),pe={bgColor:(T=Z.bgColor)!==null&&T!==void 0?T:K(ee,1),fontColor:(x=Z.fontColor)!==null&&x!==void 0?x:K(ee,2),borderColor:(N=Z.borderColor)!==null&&N!==void 0?N:K(ee,3),shadowing:de===void 0?void 0:de==="true",shape:(b=Z.shape)!==null&&b!==void 0?b:K(ee,5),sprite:(v=Z.sprite)!==null&&v!==void 0?v:K(ee,6),techn:(I=Z.techn)!==null&&I!==void 0?I:K(ee,7),legendText:(C=Z.legendText)!==null&&C!==void 0?C:K(ee,8),legendSprite:(M=Z.legendSprite)!==null&&M!==void 0?M:K(ee,9)};fe==="UpdateBoundaryStyle"?i[V]=pe:r[V]=pe;continue}if(fe==="UpdateRelStyle"){var S,k,$,P;const V=K(ee,0),de=K(ee,1);if(!V||!de)continue;const pe=(S=Z.offsetX)!==null&&S!==void 0?S:K(ee,4),ye=(k=Z.offsetY)!==null&&k!==void 0?k:K(ee,5),Ne=Z.lineWidth;s[`${V}->${de}`]={textColor:($=Z.textColor)!==null&&$!==void 0?$:K(ee,2),lineColor:(P=Z.lineColor)!==null&&P!==void 0?P:K(ee,3),offsetX:pe===void 0?void 0:Number(pe),offsetY:ye===void 0?void 0:Number(ye),lineWidth:Ne===void 0?void 0:Number(Ne),lineStyle:Z.lineStyle};continue}if(/^(SHOW_|HIDE_)/.test(fe))continue;const He=Ri[fe];if(He){var B,U,q,z,Y,G,te,Q;const V=(B=K(ee,0))!==null&&B!==void 0?B:`boundary-${++h}`,de=He.nodeType!==void 0,pe=de?"node":"system",ye=(U=(q=(z=He.fixedType)!==null&&z!==void 0?z:Z.type)!==null&&q!==void 0?q:K(ee,2))!==null&&U!==void 0?U:pe,Ne=He.fixedType?2:de?5:3,Me={id:V,label:(Y=K(ee,1))!==null&&Y!==void 0?Y:V,kind:He.kind,type:ye,description:de?(G=Z.descr)!==null&&G!==void 0?G:K(ee,3):Z.descr,nodeType:He.nodeType,parentId:g(),childIds:[],sprite:(te=Z.sprite)!==null&&te!==void 0?te:de?K(ee,4):void 0,tags:(Q=Z.tags)!==null&&Q!==void 0?Q:K(ee,Ne),link:Z.link};y(V);const Xe=n.findIndex(Gn=>Gn.id===V);Xe===-1?n.push(Me):n[Xe]=R(R({},Me),{},{childIds:n[Xe].childIds}),Bn&&u.push(V);continue}const Ht=_i[fe];if(Ht){var ne,H,J,ie,se;const V=fe==="RelIndex"?ee.slice(1):ee,de=K(V,0),pe=K(V,1);if(!de||!pe)continue;const ye={from:de,to:pe,label:(ne=K(V,2))!==null&&ne!==void 0?ne:"",technology:(H=Z.techn)!==null&&H!==void 0?H:K(V,3),description:(J=Z.descr)!==null&&J!==void 0?J:K(V,4),direction:Ht,index:o.length,sprite:(ie=Z.sprite)!==null&&ie!==void 0?ie:K(V,5),tags:(se=Z.tags)!==null&&se!==void 0?se:K(V,6),link:Z.link},Ne=o.findIndex(Me=>Me.from===de&&Me.to===pe);Ne===-1?o.push(ye):o[Ne]=R(R({},ye),{},{index:o[Ne].index});continue}const Oe=$i(fe);if(Oe){var oe,Ae,Ie,Ce,F;const V=K(ee,0);if(!V)continue;const de=Oe.kind==="container"||Oe.kind==="component",pe=de?3:2,ye=Z.link,Ne={id:V,label:(oe=K(ee,1))!==null&&oe!==void 0?oe:V,technology:(Ae=Z.techn)!==null&&Ae!==void 0?Ae:de?K(ee,2):void 0,description:(Ie=Z.descr)!==null&&Ie!==void 0?Ie:K(ee,pe),kind:Oe.kind,shape:Oe.shape,isExternal:Oe.isExternal,stereotype:Ai(Oe),parentId:g(),sprite:(Ce=Z.sprite)!==null&&Ce!==void 0?Ce:K(ee,pe+1),tags:(F=Z.tags)!==null&&F!==void 0?F:K(ee,pe+2),link:ye,subDiagramId:ye?.startsWith("uig:")?ye.slice(4):void 0};y(V);const Me=t.findIndex(Xe=>Xe.id===V);Me===-1?t.push(Ne):t[Me]=Ne;continue}}return{type:d,title:l,accTitle:p,accDescription:f,direction:c,elements:t,boundaries:n,relationships:o,elementStyles:r,boundaryStyles:i,relStyles:s,layout:a}}const ce={WIDTH:240,MIN_HEIGHT:80,SHAPE_MARGIN:90,ROW_MARGIN:80,SHAPE_PADDING:24,BOUNDARY_HEADER:72,BOUNDARY_PADDING:48,BOUNDARY_MARGIN:120,DIAGRAM_MARGIN_X:60,DIAGRAM_MARGIN_Y:40},nn={person:{fill:"#08427B",stroke:"#052E56"},personExternal:{fill:"#686868",stroke:"#4D4D4D"},system:{fill:"#1168BD",stroke:"#0B4884"},systemExternal:{fill:"#999999",stroke:"#6B6B6B"},container:{fill:"#438DD5",stroke:"#2E6295"},containerExternal:{fill:"#B3B3B3",stroke:"#8A8A8A"},component:{fill:"#85BBF0",stroke:"#5D82A8"},componentExternal:{fill:"#CCCCCC",stroke:"#A6A6A6"},node:{fill:"#1F2937",stroke:"#4B5563"},nodeExternal:{fill:"#374151",stroke:"#6B7280"}},on="#828DA3";function Fi(e){var t;return(t=nn[e.isExternal?`${e.kind}External`:e.kind])!==null&&t!==void 0?t:nn.system}const Bi=22,bt=18,Gi=30,Hi=34,Ui=68;function rn(e,t,n){if(!e)return 0;const o=Math.max(6,Math.floor(t/n));return e.split(`
41
- `).reduce((r,i)=>r+Math.max(1,Math.ceil(i.length/o)),0)}function qi(e){let t=ce.WIDTH-ce.SHAPE_PADDING*2;e.shape==="queue"&&(t-=Ui);let n=ce.SHAPE_PADDING*2;return n+=bt,e.kind==="person"&&(n+=Gi),n+=rn(e.label,t,8.6)*Bi,e.technology&&(n+=bt),n+=rn(e.description,t,5.9)*bt,e.shape==="db"&&(n+=Hi),{width:ce.WIDTH,height:Math.max(ce.MIN_HEIGHT,n)}}function An(e,t,n,o,r){var i;const s=(i=n.get(e))!==null&&i!==void 0?i:[],a=s.filter(w=>o.has(w)),d=s.filter(w=>!o.has(w)),l=e?ce.BOUNDARY_PADDING:ce.DIAGRAM_MARGIN_X,p=e?ce.BOUNDARY_HEADER:ce.DIAGRAM_MARGIN_Y;let f=p,c=l,u=0;const h=Math.max(1,t.layout.c4ShapeInRow);for(let w=0;w<a.length;w+=h){const A=a.slice(w,w+h);let T=0;A.forEach((x,N)=>{const b=qi(o.get(x)),v=l+N*(ce.WIDTH+ce.SHAPE_MARGIN);r.set(x,{x:v,y:f,width:b.width,height:b.height}),T=Math.max(T,b.height),c=Math.max(c,v+b.width)}),f+=T+ce.ROW_MARGIN,u=ce.ROW_MARGIN}const m=new Map;for(const w of d)m.set(w,An(w,t,n,o,r));const g=Math.max(1,t.layout.c4BoundaryInRow);for(let w=0;w<d.length;w+=g){const A=d.slice(w,w+g);let T=0,x=l;for(const N of A){const b=m.get(N);r.set(N,{x,y:f,width:b.width,height:b.height}),x+=b.width+ce.BOUNDARY_MARGIN,T=Math.max(T,b.height),c=Math.max(c,x-ce.BOUNDARY_MARGIN)}f+=T+ce.BOUNDARY_MARGIN,u=ce.BOUNDARY_MARGIN}const y=a.length>0||d.length>0,E=e?ce.BOUNDARY_PADDING:ce.DIAGRAM_MARGIN_Y;return y?{width:c+l,height:f-u+E}:{width:ce.WIDTH+l+E,height:ce.MIN_HEIGHT+p+E}}function Wi(e,t,n){if(e==="up")return{source:"top",target:"bottom"};if(e==="down")return{source:"bottom",target:"top"};if(e==="left")return{source:"left",target:"right"};if(e==="right")return{source:"right",target:"left"};const o=n.x-t.x,r=n.y-t.y;return Math.abs(o)>Math.abs(r)?o>=0?{source:"right",target:"left"}:{source:"left",target:"right"}:r>=0?{source:"bottom",target:"top"}:{source:"top",target:"bottom"}}function Ki(e,t){var n,o;return{fill:(n=t?.bgColor)!==null&&n!==void 0?n:e.fill,stroke:(o=t?.borderColor)!==null&&o!==void 0?o:e.stroke,fontColor:t?.fontColor}}function zi(e){const t=new Map(e.elements.map(c=>[c.id,c])),n=new Map(e.boundaries.map(c=>[c.id,c])),o=new Map;function r(c,u){var h;const m=(h=o.get(u))!==null&&h!==void 0?h:[];m.push(c),o.set(u,m)}for(const c of e.boundaries)r(c.id,c.parentId);for(const c of e.elements)r(c.id,c.parentId);const i=new Map;An(void 0,e,o,t,i);const s=[];for(const c of e.boundaries){var a,d,l;const u=i.get(c.id);if(!u)continue;const h=(a=e.boundaryStyles[c.id])!==null&&a!==void 0?a:e.elementStyles[c.id];s.push({id:c.id,type:"c4Boundary",position:{x:u.x,y:u.y},data:{source:"mermaid",c4DiagramType:e.type,c4BoundaryKind:c.kind,boundaryType:c.type,description:c.description,c4NodeType:c.nodeType,link:c.link,backgroundColor:(d=h?.bgColor)!==null&&d!==void 0?d:"transparent",borderColor:(l=h?.borderColor)!==null&&l!==void 0?l:on,fontColor:h?.fontColor,componentFields:[me(c.label)]},style:{width:u.width,height:u.height},width:u.width,height:u.height,parentId:c.parentId,extent:c.parentId?"parent":void 0,selectable:!0,draggable:!0})}for(const c of e.elements){const u=i.get(c.id);if(!u)continue;const h=Ki(Fi(c),e.elementStyles[c.id]);s.push({id:c.id,type:c.subDiagramId?"subDiagram":"c4",position:{x:u.x,y:u.y},width:u.width,height:u.height,data:{source:"mermaid",diagramId:c.subDiagramId,diagramName:c.label,c4DiagramType:e.type,c4Kind:c.kind,c4Shape:c.shape,isExternal:c.isExternal,technology:c.technology,description:c.description,link:c.link,fill:h.fill,stroke:h.stroke,fontColor:h.fontColor,componentFields:[me(c.label)]},style:{width:u.width,height:u.height},parentId:c.parentId,extent:c.parentId?"parent":void 0})}const p=new Map;for(const c of e.boundaries)p.set(c.id,c.parentId);for(const c of e.elements)p.set(c.id,c.parentId);function f(c){const u=i.get(c);let h=u.x+u.width/2,m=u.y+u.height/2,g=p.get(c);for(;g;){const y=i.get(g);h+=y.x,m+=y.y,g=p.get(g)}return{x:h,y:m}}return{nodes:s,edges:e.relationships.filter(c=>(t.has(c.from)||n.has(c.from))&&(t.has(c.to)||n.has(c.to))).map(c=>{var u,h;const m=c.direction==="back",g=m?c.to:c.from,y=m?c.from:c.to,E=e.relStyles[`${c.from}->${c.to}`],w=(u=E?.lineColor)!==null&&u!==void 0?u:on,A=[c.label,c.technology?`[${c.technology}]`:""].filter(Boolean).join(" "),T=Wi(c.direction,f(g),f(y));return{id:`c4-rel-${c.from}-${c.to}-${c.index}`,source:g,target:y,sourceHandle:`source-${T.source}`,targetHandle:`target-${T.target}`,label:A,type:"smoothstep",style:{stroke:w,strokeWidth:(h=E?.lineWidth)!==null&&h!==void 0?h:1.5},data:{source:"mermaid",c4RelDirection:c.direction,c4RelTechnology:c.technology,c4RelDescription:c.description,labelColor:E?.textColor,labelOffsetX:E?.offsetX,labelOffsetY:E?.offsetY},markerEnd:{type:xe.ArrowClosed,width:14,height:14,color:w},markerStart:c.direction==="bi"?{type:xe.ArrowClosed,width:14,height:14,color:w}:void 0}})}}function ji(e){return zi(Pi(e))}const be={SUBGRAPH_HEADER_HEIGHT:20,SUBGRAPH_PADDING:40,NODE_SEPARATION_HORIZONTAL:120,NODE_SEPARATION_VERTICAL:180,CONTAINER_SEPARATION_HORIZONTAL:180,CONTAINER_SEPARATION_VERTICAL:280,NESTED_SUBGRAPH_SEPARATION_HORIZONTAL:160,NESTED_SUBGRAPH_SEPARATION_VERTICAL:220,META_GRAPH_MARGIN:100,NESTED_CONTENT_MARGIN:40,MIXED_CONTENT_VERTICAL_SPACING:180,MIXED_CONTENT_HORIZONTAL_SPACING:160},De={COLUMN_WIDTH:360,ROW_HEIGHT:60,HEADER_HEIGHT:40,MESSAGE_NODE_WIDTH:140,MESSAGE_NODE_HEIGHT:32,SELF_LOOP_OFFSET:48,PARTICIPANT_NODE_WIDTH:10,MESSAGE_MAX_WIDTH:240,MESSAGE_TARGET_WRAP_LINES:2,MESSAGE_CHAR_WIDTH:7,MESSAGE_LINE_HEIGHT:20,MESSAGE_HORIZONTAL_PADDING:24,MESSAGE_VERTICAL_PADDING:8,ROW_VERTICAL_PADDING:16,NOTE_OFFSET:24,BLOCK_TOP_PADDING:36,BLOCK_BOTTOM_PADDING:16,BLOCK_SIDE_PADDING:44,BLOCK_SECTION_PADDING:22,BLOCK_CONTENT_INSET:12,BLOCK_FRAME_GAP:12,BOX_TOP_INSET:26,BOX_BOTTOM_PADDING:24},Yi=/^\s*type:(\w+)\s*[:|-]\s*/i,Xi=typeof process<"u"&&typeof Yt<"u"&&Yt.DEBUG_MERMAID==="true";function D(...e){Xi&&console.log("[MermaidConverter]",...e)}const sn={builder:"builder",code:"code",text:"text",table:"table",image:"image",cloud:"cloud",comment:"comment",default:"default"};function Qi(e){const t=e.match(Yi);return t?{tag:t[1].toLowerCase(),displayLabel:e.slice(t[0].length).trim()}:{tag:null,displayLabel:e}}function Zi(e,t){return e||t==="image"?"image":t&&sn[t]?sn[t]:"shape"}const Cn={circle:{open:"((",close:"))"},stadium:{open:"([",close:"])"},cylinder:{open:"[(",close:")]"},subroutine:{open:"[[",close:"]]"}};function Vi(e){if(e.includes("{")&&e.includes("}"))return"diamond";for(const[t,{open:n,close:o}]of Object.entries(Cn))if(e.includes(n)&&e.includes(o))return t;return e.includes("[")&&e.includes("]")?"rect":e.includes("(")&&e.includes(")")?"round":"rect"}function Ji(e){const t=[],n=[],o=[],r=new Map,i=new Map,s=new Map;let a="TB",d=e.split(`
38
+ `)}function Li(e){const t=[],n={};for(const o of e){const r=o.match(/^\$([A-Za-z0-9_]+)\s*=\s*([\s\S]*)$/);if(r){n[r[1]]=Je(r[2]);continue}t.push(Je(o))}return{positional:t,named:n}}function K(e,t){const n=e[t];if(n!==void 0&&n!=="")return n}function Pi(e){const t=[];let n="",o=0;for(const r of e.split(`
39
+ `)){const i=r.replace(/%%.*$/,"").trim();if(!i)continue;n=n?`${n} ${i}`:i;let s=!1;for(let a=0;a<i.length;a++){const d=i[a];d==='"'&&i[a-1]!=="\\"&&(s=!s),!s&&(d==="("&&o++,d===")"&&o--)}o>0||(o=0,t.push(...nn(n)),n="")}return n&&t.push(...nn(n)),t}function nn(e){const t=[];let n="",o=!1,r=0;function i(){n.trim()&&t.push(n.trim()),n=""}for(let s=0;s<e.length;s++){const a=e[s];if(a==='"'&&e[s-1]!=="\\"&&(o=!o),!o&&a==="("&&r++,!o&&a===")"&&r--,!o&&r===0&&a==="{"){n+=a,i();continue}if(!o&&r===0&&a==="}"){i(),t.push("}");continue}n+=a}return i(),t}function Fi(e){const t=[],n=[],o=[],r={},i={},s={},a=R({},Ai);let d="C4Context",l,p,f,c;const u=[];let h=0,m;function y(){return u[u.length-1]}function g(W){const ae=y();if(!ae)return;const Te=n.find(he=>he.id===ae);Te&&(Te.childIds.includes(W)||Te.childIds.push(W))}for(const W of Pi(e)){if(m){if(W==="}"){f=m.join(`
40
+ `).trim(),m=void 0;continue}m.push(W);continue}const ae=ki.find(V=>W.toLowerCase().startsWith(V.toLowerCase()));if(ae){d=ae;continue}if(W==="}"){u.pop();continue}const Te=W.match(/^direction\s+(TB|BT|LR|RL)$/i);if(Te){c=$i.find(V=>V===Te[1].toUpperCase());continue}const he=W.match(/^accTitle\s*:\s*(.*)$/i);if(he){p=Je(he[1]);continue}if(/^accDescr\s*\{$/i.test(W)){m=[];continue}const O=W.match(/^accDescr\s*:\s*(.*)$/i);if(O){f=Je(O[1]);continue}const X=W.match(/^title\s+(.*)$/i);if(X){l=Je(X[1]);continue}const ue=W.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*\(([\s\S]*)\)\s*(\{)?\s*$/);if(!ue)continue;const[,fe,Ye,Gn]=ue,{positional:ee,named:Z}=Li(Oi(Ye));if(fe==="UpdateLayoutConfig"){var E,w;const V=(E=Z.c4ShapeInRow)!==null&&E!==void 0?E:K(ee,0),de=(w=Z.c4BoundaryInRow)!==null&&w!==void 0?w:K(ee,1);V&&(a.c4ShapeInRow=Number(V)||a.c4ShapeInRow),de&&(a.c4BoundaryInRow=Number(de)||a.c4BoundaryInRow);continue}if(fe==="UpdateElementStyle"||fe==="UpdateBoundaryStyle"){var N,T,x,S,b,v,I,C,M;const V=K(ee,0);if(!V)continue;const de=(N=Z.shadowing)!==null&&N!==void 0?N:K(ee,4),pe={bgColor:(T=Z.bgColor)!==null&&T!==void 0?T:K(ee,1),fontColor:(x=Z.fontColor)!==null&&x!==void 0?x:K(ee,2),borderColor:(S=Z.borderColor)!==null&&S!==void 0?S:K(ee,3),shadowing:de===void 0?void 0:de==="true",shape:(b=Z.shape)!==null&&b!==void 0?b:K(ee,5),sprite:(v=Z.sprite)!==null&&v!==void 0?v:K(ee,6),techn:(I=Z.techn)!==null&&I!==void 0?I:K(ee,7),legendText:(C=Z.legendText)!==null&&C!==void 0?C:K(ee,8),legendSprite:(M=Z.legendSprite)!==null&&M!==void 0?M:K(ee,9)};fe==="UpdateBoundaryStyle"?i[V]=pe:r[V]=pe;continue}if(fe==="UpdateRelStyle"){var A,k,$,P;const V=K(ee,0),de=K(ee,1);if(!V||!de)continue;const pe=(A=Z.offsetX)!==null&&A!==void 0?A:K(ee,4),ye=(k=Z.offsetY)!==null&&k!==void 0?k:K(ee,5),Ne=Z.lineWidth;s[`${V}->${de}`]={textColor:($=Z.textColor)!==null&&$!==void 0?$:K(ee,2),lineColor:(P=Z.lineColor)!==null&&P!==void 0?P:K(ee,3),offsetX:pe===void 0?void 0:Number(pe),offsetY:ye===void 0?void 0:Number(ye),lineWidth:Ne===void 0?void 0:Number(Ne),lineStyle:Z.lineStyle};continue}if(/^(SHOW_|HIDE_)/.test(fe))continue;const He=_i[fe];if(He){var B,U,q,z,Y,G,te,Q;const V=(B=K(ee,0))!==null&&B!==void 0?B:`boundary-${++h}`,de=He.nodeType!==void 0,pe=de?"node":"system",ye=(U=(q=(z=He.fixedType)!==null&&z!==void 0?z:Z.type)!==null&&q!==void 0?q:K(ee,2))!==null&&U!==void 0?U:pe,Ne=He.fixedType?2:de?5:3,Me={id:V,label:(Y=K(ee,1))!==null&&Y!==void 0?Y:V,kind:He.kind,type:ye,description:de?(G=Z.descr)!==null&&G!==void 0?G:K(ee,3):Z.descr,nodeType:He.nodeType,parentId:y(),childIds:[],sprite:(te=Z.sprite)!==null&&te!==void 0?te:de?K(ee,4):void 0,tags:(Q=Z.tags)!==null&&Q!==void 0?Q:K(ee,Ne),link:Z.link};g(V);const Xe=n.findIndex(Hn=>Hn.id===V);Xe===-1?n.push(Me):n[Xe]=R(R({},Me),{},{childIds:n[Xe].childIds}),Gn&&u.push(V);continue}const Ht=Mi[fe];if(Ht){var ne,H,J,ie,se;const V=fe==="RelIndex"?ee.slice(1):ee,de=K(V,0),pe=K(V,1);if(!de||!pe)continue;const ye={from:de,to:pe,label:(ne=K(V,2))!==null&&ne!==void 0?ne:"",technology:(H=Z.techn)!==null&&H!==void 0?H:K(V,3),description:(J=Z.descr)!==null&&J!==void 0?J:K(V,4),direction:Ht,index:o.length,sprite:(ie=Z.sprite)!==null&&ie!==void 0?ie:K(V,5),tags:(se=Z.tags)!==null&&se!==void 0?se:K(V,6),link:Z.link},Ne=o.findIndex(Me=>Me.from===de&&Me.to===pe);Ne===-1?o.push(ye):o[Ne]=R(R({},ye),{},{index:o[Ne].index});continue}const Oe=Di(fe);if(Oe){var oe,Ae,Ie,Ce,F;const V=K(ee,0);if(!V)continue;const de=Oe.kind==="container"||Oe.kind==="component",pe=de?3:2,ye=Z.link,Ne={id:V,label:(oe=K(ee,1))!==null&&oe!==void 0?oe:V,technology:(Ae=Z.techn)!==null&&Ae!==void 0?Ae:de?K(ee,2):void 0,description:(Ie=Z.descr)!==null&&Ie!==void 0?Ie:K(ee,pe),kind:Oe.kind,shape:Oe.shape,isExternal:Oe.isExternal,stereotype:Ci(Oe),parentId:y(),sprite:(Ce=Z.sprite)!==null&&Ce!==void 0?Ce:K(ee,pe+1),tags:(F=Z.tags)!==null&&F!==void 0?F:K(ee,pe+2),link:ye,subDiagramId:ye?.startsWith("uig:")?ye.slice(4):void 0};g(V);const Me=t.findIndex(Xe=>Xe.id===V);Me===-1?t.push(Ne):t[Me]=Ne;continue}}return{type:d,title:l,accTitle:p,accDescription:f,direction:c,elements:t,boundaries:n,relationships:o,elementStyles:r,boundaryStyles:i,relStyles:s,layout:a}}const ce={WIDTH:240,MIN_HEIGHT:80,SHAPE_MARGIN:90,ROW_MARGIN:80,SHAPE_PADDING:24,BOUNDARY_HEADER:72,BOUNDARY_PADDING:48,BOUNDARY_MARGIN:120,DIAGRAM_MARGIN_X:60,DIAGRAM_MARGIN_Y:40},on={person:{fill:"#08427B",stroke:"#052E56"},personExternal:{fill:"#686868",stroke:"#4D4D4D"},system:{fill:"#1168BD",stroke:"#0B4884"},systemExternal:{fill:"#999999",stroke:"#6B6B6B"},container:{fill:"#438DD5",stroke:"#2E6295"},containerExternal:{fill:"#B3B3B3",stroke:"#8A8A8A"},component:{fill:"#85BBF0",stroke:"#5D82A8"},componentExternal:{fill:"#CCCCCC",stroke:"#A6A6A6"},node:{fill:"#1F2937",stroke:"#4B5563"},nodeExternal:{fill:"#374151",stroke:"#6B7280"}},rn="#828DA3";function Bi(e){var t;return(t=on[e.isExternal?`${e.kind}External`:e.kind])!==null&&t!==void 0?t:on.system}const Gi=22,bt=18,Hi=30,Ui=34,qi=68;function sn(e,t,n){if(!e)return 0;const o=Math.max(6,Math.floor(t/n));return e.split(`
41
+ `).reduce((r,i)=>r+Math.max(1,Math.ceil(i.length/o)),0)}function Wi(e){let t=ce.WIDTH-ce.SHAPE_PADDING*2;e.shape==="queue"&&(t-=qi);let n=ce.SHAPE_PADDING*2;return n+=bt,e.kind==="person"&&(n+=Hi),n+=sn(e.label,t,8.6)*Gi,e.technology&&(n+=bt),n+=sn(e.description,t,5.9)*bt,e.shape==="db"&&(n+=Ui),{width:ce.WIDTH,height:Math.max(ce.MIN_HEIGHT,n)}}function Cn(e,t,n,o,r){var i;const s=(i=n.get(e))!==null&&i!==void 0?i:[],a=s.filter(w=>o.has(w)),d=s.filter(w=>!o.has(w)),l=e?ce.BOUNDARY_PADDING:ce.DIAGRAM_MARGIN_X,p=e?ce.BOUNDARY_HEADER:ce.DIAGRAM_MARGIN_Y;let f=p,c=l,u=0;const h=Math.max(1,t.layout.c4ShapeInRow);for(let w=0;w<a.length;w+=h){const N=a.slice(w,w+h);let T=0;N.forEach((x,S)=>{const b=Wi(o.get(x)),v=l+S*(ce.WIDTH+ce.SHAPE_MARGIN);r.set(x,{x:v,y:f,width:b.width,height:b.height}),T=Math.max(T,b.height),c=Math.max(c,v+b.width)}),f+=T+ce.ROW_MARGIN,u=ce.ROW_MARGIN}const m=new Map;for(const w of d)m.set(w,Cn(w,t,n,o,r));const y=Math.max(1,t.layout.c4BoundaryInRow);for(let w=0;w<d.length;w+=y){const N=d.slice(w,w+y);let T=0,x=l;for(const S of N){const b=m.get(S);r.set(S,{x,y:f,width:b.width,height:b.height}),x+=b.width+ce.BOUNDARY_MARGIN,T=Math.max(T,b.height),c=Math.max(c,x-ce.BOUNDARY_MARGIN)}f+=T+ce.BOUNDARY_MARGIN,u=ce.BOUNDARY_MARGIN}const g=a.length>0||d.length>0,E=e?ce.BOUNDARY_PADDING:ce.DIAGRAM_MARGIN_Y;return g?{width:c+l,height:f-u+E}:{width:ce.WIDTH+l+E,height:ce.MIN_HEIGHT+p+E}}function Ki(e,t,n){if(e==="up")return{source:"top",target:"bottom"};if(e==="down")return{source:"bottom",target:"top"};if(e==="left")return{source:"left",target:"right"};if(e==="right")return{source:"right",target:"left"};const o=n.x-t.x,r=n.y-t.y;return Math.abs(o)>Math.abs(r)?o>=0?{source:"right",target:"left"}:{source:"left",target:"right"}:r>=0?{source:"bottom",target:"top"}:{source:"top",target:"bottom"}}function zi(e,t){var n,o;return{fill:(n=t?.bgColor)!==null&&n!==void 0?n:e.fill,stroke:(o=t?.borderColor)!==null&&o!==void 0?o:e.stroke,fontColor:t?.fontColor}}function ji(e){const t=new Map(e.elements.map(c=>[c.id,c])),n=new Map(e.boundaries.map(c=>[c.id,c])),o=new Map;function r(c,u){var h;const m=(h=o.get(u))!==null&&h!==void 0?h:[];m.push(c),o.set(u,m)}for(const c of e.boundaries)r(c.id,c.parentId);for(const c of e.elements)r(c.id,c.parentId);const i=new Map;Cn(void 0,e,o,t,i);const s=[];for(const c of e.boundaries){var a,d,l;const u=i.get(c.id);if(!u)continue;const h=(a=e.boundaryStyles[c.id])!==null&&a!==void 0?a:e.elementStyles[c.id];s.push({id:c.id,type:"c4Boundary",position:{x:u.x,y:u.y},data:{source:"mermaid",c4DiagramType:e.type,c4BoundaryKind:c.kind,boundaryType:c.type,description:c.description,c4NodeType:c.nodeType,link:c.link,backgroundColor:(d=h?.bgColor)!==null&&d!==void 0?d:"transparent",borderColor:(l=h?.borderColor)!==null&&l!==void 0?l:rn,fontColor:h?.fontColor,componentFields:[me(c.label)]},style:{width:u.width,height:u.height},width:u.width,height:u.height,parentId:c.parentId,extent:c.parentId?"parent":void 0,selectable:!0,draggable:!0})}for(const c of e.elements){const u=i.get(c.id);if(!u)continue;const h=zi(Bi(c),e.elementStyles[c.id]);s.push({id:c.id,type:c.subDiagramId?"subDiagram":"c4",position:{x:u.x,y:u.y},width:u.width,height:u.height,data:{source:"mermaid",diagramId:c.subDiagramId,diagramName:c.label,c4DiagramType:e.type,c4Kind:c.kind,c4Shape:c.shape,isExternal:c.isExternal,technology:c.technology,description:c.description,link:c.link,fill:h.fill,stroke:h.stroke,fontColor:h.fontColor,componentFields:[me(c.label)]},style:{width:u.width,height:u.height},parentId:c.parentId,extent:c.parentId?"parent":void 0})}const p=new Map;for(const c of e.boundaries)p.set(c.id,c.parentId);for(const c of e.elements)p.set(c.id,c.parentId);function f(c){const u=i.get(c);let h=u.x+u.width/2,m=u.y+u.height/2,y=p.get(c);for(;y;){const g=i.get(y);h+=g.x,m+=g.y,y=p.get(y)}return{x:h,y:m}}return{nodes:s,edges:e.relationships.filter(c=>(t.has(c.from)||n.has(c.from))&&(t.has(c.to)||n.has(c.to))).map(c=>{var u,h;const m=c.direction==="back",y=m?c.to:c.from,g=m?c.from:c.to,E=e.relStyles[`${c.from}->${c.to}`],w=(u=E?.lineColor)!==null&&u!==void 0?u:rn,N=[c.label,c.technology?`[${c.technology}]`:""].filter(Boolean).join(" "),T=Ki(c.direction,f(y),f(g));return{id:`c4-rel-${c.from}-${c.to}-${c.index}`,source:y,target:g,sourceHandle:`source-${T.source}`,targetHandle:`target-${T.target}`,label:N,type:"smoothstep",style:{stroke:w,strokeWidth:(h=E?.lineWidth)!==null&&h!==void 0?h:1.5},data:{source:"mermaid",c4RelDirection:c.direction,c4RelTechnology:c.technology,c4RelDescription:c.description,labelColor:E?.textColor,labelOffsetX:E?.offsetX,labelOffsetY:E?.offsetY},markerEnd:{type:xe.ArrowClosed,width:14,height:14,color:w},markerStart:c.direction==="bi"?{type:xe.ArrowClosed,width:14,height:14,color:w}:void 0}})}}function Yi(e){return ji(Fi(e))}const be={SUBGRAPH_HEADER_HEIGHT:20,SUBGRAPH_PADDING:40,NODE_SEPARATION_HORIZONTAL:120,NODE_SEPARATION_VERTICAL:180,CONTAINER_SEPARATION_HORIZONTAL:180,CONTAINER_SEPARATION_VERTICAL:280,NESTED_SUBGRAPH_SEPARATION_HORIZONTAL:160,NESTED_SUBGRAPH_SEPARATION_VERTICAL:220,META_GRAPH_MARGIN:100,NESTED_CONTENT_MARGIN:40,MIXED_CONTENT_VERTICAL_SPACING:180,MIXED_CONTENT_HORIZONTAL_SPACING:160},De={COLUMN_WIDTH:360,ROW_HEIGHT:60,HEADER_HEIGHT:40,MESSAGE_NODE_WIDTH:140,MESSAGE_NODE_HEIGHT:32,SELF_LOOP_OFFSET:48,PARTICIPANT_NODE_WIDTH:10,MESSAGE_MAX_WIDTH:240,MESSAGE_TARGET_WRAP_LINES:2,MESSAGE_CHAR_WIDTH:7,MESSAGE_LINE_HEIGHT:20,MESSAGE_HORIZONTAL_PADDING:24,MESSAGE_VERTICAL_PADDING:8,ROW_VERTICAL_PADDING:16,NOTE_OFFSET:24,BLOCK_TOP_PADDING:36,BLOCK_BOTTOM_PADDING:16,BLOCK_SIDE_PADDING:44,BLOCK_SECTION_PADDING:22,BLOCK_CONTENT_INSET:12,BLOCK_FRAME_GAP:12,BOX_TOP_INSET:26,BOX_BOTTOM_PADDING:24},Xi=/^\s*type:(\w+)\s*[:|-]\s*/i,Qi=typeof process<"u"&&typeof Xt<"u"&&Xt.DEBUG_MERMAID==="true";function D(...e){Qi&&console.log("[MermaidConverter]",...e)}const an={builder:"builder",code:"code",text:"text",table:"table",image:"image",cloud:"cloud",comment:"comment",default:"default"};function Zi(e){const t=e.match(Xi);return t?{tag:t[1].toLowerCase(),displayLabel:e.slice(t[0].length).trim()}:{tag:null,displayLabel:e}}function Vi(e,t){return e||t==="image"?"image":t&&an[t]?an[t]:"shape"}const kn={circle:{open:"((",close:"))"},stadium:{open:"([",close:"])"},cylinder:{open:"[(",close:")]"},subroutine:{open:"[[",close:"]]"}};function Ji(e){if(e.includes("{")&&e.includes("}"))return"diamond";for(const[t,{open:n,close:o}]of Object.entries(kn))if(e.includes(n)&&e.includes(o))return t;return e.includes("[")&&e.includes("]")?"rect":e.includes("(")&&e.includes(")")?"round":"rect"}function er(e){const t=[],n=[],o=[],r=new Map,i=new Map,s=new Map;let a="TB",d=e.split(`
42
42
  `).map(w=>w.trim()).filter(w=>w&&!w.startsWith("%%")).join(`
43
43
  `);const l=[],p=d.split(`
44
- `);let f=0;for(;f<p.length;){const w=p[f].trim(),A=(w.match(/[\[\(\{]/g)||[]).length,T=(w.match(/[\]\)\}]/g)||[]).length;if(A>T&&f<p.length-1){let x=w,N=f+1,b=A,v=T;for(;N<p.length&&b>v;){const I=p[N].trim();x+=" "+I,b+=(I.match(/[\[\(\{]/g)||[]).length,v+=(I.match(/[\]\)\}]/g)||[]).length,N++}l.push(x),f=N}else l.push(w),f++}d=l.join(`
44
+ `);let f=0;for(;f<p.length;){const w=p[f].trim(),N=(w.match(/[\[\(\{]/g)||[]).length,T=(w.match(/[\]\)\}]/g)||[]).length;if(N>T&&f<p.length-1){let x=w,S=f+1,b=N,v=T;for(;S<p.length&&b>v;){const I=p[S].trim();x+=" "+I,b+=(I.match(/[\[\(\{]/g)||[]).length,v+=(I.match(/[\]\)\}]/g)||[]).length,S++}l.push(x),f=S}else l.push(w),f++}d=l.join(`
45
45
  `),D("Clean code:",d);const c=d.match(/(?:flowchart|graph)\s+(TB|TD|BT|RL|LR)/i);c&&(a=c[1].toUpperCase(),a==="TD"&&(a="TB"),D("Detected graph direction:",a));const u=d.split(`
46
- `).flatMap(w=>{const A=[];let T=0,x=!1,N=0;for(let b=0;b<w.length;b++){const v=w[b];if(v==='"'&&(x=!x),x)continue;"[({".includes(v)&&T++,"])}".includes(v)&&T--;const I=/[#&]\w+$/.test(w.slice(N,b));v===";"&&T===0&&!I&&(A.push(w.slice(N,b)),N=b+1)}return A.push(w.slice(N)),A.map(b=>b.trim()).filter(Boolean)}),h=[],m=[["[","]"],["(",")"],["{","}"]];function g(w){let A=w,T=!0;for(;T&&A.length>=2;){T=!1;for(const[x,N]of m)if(A[0]===x&&A[A.length-1]===N){const b=A.slice(1,-1).trim().replace(new RegExp('^"(.*)"$',"s"),"$1").replace(new RegExp("^'(.*)'$","s"),"$1").trim();if(!b)break;A=b,T=!0;break}}return A}function y(w){return g(w.replace(/<br\s*\/?>/gi,`
47
- `).replace(/<[^>]*>/g,"").replace(/\\u([0-9a-fA-F]{4})/g,(A,T)=>{try{return String.fromCharCode(parseInt(T,16))}catch{return D(`Warning: Could not parse unicode character: ${A}`),A}}).replace(/\\n/g,`
46
+ `).flatMap(w=>{const N=[];let T=0,x=!1,S=0;for(let b=0;b<w.length;b++){const v=w[b];if(v==='"'&&(x=!x),x)continue;"[({".includes(v)&&T++,"])}".includes(v)&&T--;const I=/[#&]\w+$/.test(w.slice(S,b));v===";"&&T===0&&!I&&(N.push(w.slice(S,b)),S=b+1)}return N.push(w.slice(S)),N.map(b=>b.trim()).filter(Boolean)}),h=[],m=[["[","]"],["(",")"],["{","}"]];function y(w){let N=w,T=!0;for(;T&&N.length>=2;){T=!1;for(const[x,S]of m)if(N[0]===x&&N[N.length-1]===S){const b=N.slice(1,-1).trim().replace(new RegExp('^"(.*)"$',"s"),"$1").replace(new RegExp("^'(.*)'$","s"),"$1").trim();if(!b)break;N=b,T=!0;break}}return N}function g(w){return y(w.replace(/<br\s*\/?>/gi,`
47
+ `).replace(/<[^>]*>/g,"").replace(/\\u([0-9a-fA-F]{4})/g,(N,T)=>{try{return String.fromCharCode(parseInt(T,16))}catch{return D(`Warning: Could not parse unicode character: ${N}`),N}}).replace(/\\n/g,`
48
48
  `).replace(/\s*\n\s*/g,`
49
- `).trim())}D("Pre-scanning for node definitions..."),u.forEach((w,A)=>{const T=w.trim();if(!T||T.startsWith("subgraph")||T==="end"||T.startsWith("%%"))return;const x=/(^|[\s\-\>]|\|[^|]*\|)([A-Za-z0-9_]+)([\[\(\{])/g;let N;const b=new Set;for(;(N=x.exec(T))!==null;){const v=N[1],I=N[2],C=N[3],M=N.index+v.length;if(b.has(M)||s.has(I))continue;b.add(M);const S=M+I.length,k=C==="["?"]":C==="("?")":"}";let $=-1,P=0;for(let q=S;q<T.length;q++){const z=T[q];if(z===C)P++;else if(z===k&&(P--,P===0)){$=q;break}}let B=I,U="";if($!==-1)B=T.slice(M,$+1),U=T.slice(S,$+1);else{const q=T.slice(M).match(/([A-Za-z0-9_]+)([\[\(\{][^\]\)\}]*[\]\)\}])/);q&&q[1]===I&&(B=q[0],U=q[2])}if(U){const q=Vi(B);let z=I;const Y=Cn[q];if(Y&&U.startsWith(Y.open)&&U.endsWith(Y.close))z=U.slice(Y.open.length,U.length-Y.close.length);else{const te=U.match(new RegExp("^[\\[\\(\\{](.*)[\\]\\)\\}]$","s"));te&&(z=te[1])}z=z.replace(new RegExp('^"(.*)"$',"s"),"$1").replace(new RegExp("^'(.*)'$","s"),"$1");const G=y(z);s.set(I,{label:G,shape:q,fullDef:B}),D(`Pre-scan found node definition: ${I} -> "${G}" (${q}) from line ${A+1}`)}}}),D("First pass: identifying subgraphs...");for(let w=0;w<u.length;w++){const A=u[w].trim();if(A)if(A.startsWith("subgraph")){const T=A.slice(8).trim();let x,N;const b=T.match(/^(["'])(.*?)\1/);if(b)N=b[2],x=N.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||`sg-${w}`;else{const v=T.match(/^([^\s\[]+)(?:\s*\[(.+?)\])?/);if(v&&(x=v[1],v[2]&&(N=v[2])),!N&&T.indexOf(" ")!==-1&&(N=T,x=N.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||`sg-${w}`),!N){const I=T.match(/^[^\s]+\s+(["'])(.*?)\1/);I&&(N=I[2])}}if(x){const v=h.length>0?h[h.length-1]:void 0,I=N?y(N):x;D(`Found subgraph: ${x}, title: "${I}", parent: ${v||"none"}`),h.push(x);const C={id:x,title:I,nodes:[],parentId:v,childrenIds:[]};if(i.set(x,C),v){const M=i.get(v);M&&M.childrenIds.push(x)}o.push(C)}}else if(A.toLowerCase().startsWith("direction ")){const T=A.match(/^direction\s+(TB|TD|BT|RL|LR)$/i);if(T&&h.length>0){const x=h[h.length-1],N=i.get(x);if(N){const b=T[1].toUpperCase();N.direction=b==="TD"?"TB":b}}}else A==="end"&&h.length>0&&h.pop()}h.length=0;function E(w,A){if(r.has(w)){const v=r.get(w);if(A&&!v.subgraph){v.subgraph=A;const I=i.get(A);I&&!I.nodes.includes(w)&&I.nodes.push(w),D(`Updated existing node ${w} to be part of subgraph ${A}`)}return v}const T=s.get(w);let x,N;T?(x=T.label,N=T.shape,D(`Creating node ${w} using pre-scanned definition: "${x}" (${N})`)):(x=w,N="rect",D(`Creating simple fallback node: ${w}`));const b={id:w,label:x,shape:N,subgraph:A,parentSubgraph:h.length>1?h[h.length-2]:void 0};if(t.push(b),r.set(w,b),A){const v=i.get(A);v&&v.nodes.push(w)}return b}D("Second pass: processing nodes and edges...");for(let w=0;w<u.length;w++){let A=function(I,C){const M=I.slice(C).match(/^\s*([A-Za-z0-9_]+)/);if(!M)return null;const S=M[1],k=C+M[0].length,$=I.slice(k),P=$.match(/^[\s]*([\[\(\{])/);if(P){const B=P[1],U=k+$.indexOf(B),q=B==="["?"]":B==="("?")":"}";let z=0,Y=-1;for(let G=U;G<I.length;G++)if(I[G]===B)z++;else if(I[G]===q&&(z--,z===0)){Y=G;break}if(Y!==-1)return{id:S,full:I.slice(C+M[0].search(/\S/),Y+1).trim(),endIndex:Y+1}}return{id:S,full:S,endIndex:k}},T=function(I){try{let C=function($){const P=I.slice($).match(/^\s*:::[A-Za-z0-9_-]+/);return P?$+P[0].length:$};const M=[];let S=0,k=A(I,S);if(!k)return null;for(S=C(k.endIndex);;){for(;S<I.length&&/\s/.test(I[S]);)S++;let $=-1,P="";for(const G of b){const te=I.indexOf(G,S);te!==-1&&($===-1||te<$)&&($=te,P=G)}let B=null,U="";if($!==-1){const G=I.slice(S,$),te=G.match(/\|(.*?)\|/);if(te)U=te[1];else{const Q=G.replace(/^\s*[\-\.=:\~]+\s*/g,"").replace(/\s*[\-\.=:\~]+\s*$/g,"").trim();Q&&(U=Q)}for(B=P,S=$+P.length;S<I.length&&/\s/.test(I[S]);)S++;if(I[S]==="|"){const Q=I.indexOf("|",S+1);Q!==-1&&(U=I.slice(S+1,Q),S=Q+1)}}else if(M.length===0){for(const G of["---","-.-","::",":-:","...","~","==="].sort((te,Q)=>Q.length-te.length))if(I.startsWith(G,S)){B=G,S+=G.length;break}if(!B)return null;for(;S<I.length&&/\s/.test(I[S]);)S++;if(I[S]==="|"){const G=I.indexOf("|",S+1);G!==-1&&(U=I.slice(S+1,G),S=G+1)}}else break;for(;S<I.length&&/\s/.test(I[S]);)S++;const q=A(I,S);if(!q)break;const z=I.slice(q.endIndex).trimStart().match(/^:(?!::)\s*(.+)$/);z&&!U&&(U=z[1].trim());const Y=B==="<-";if(M.push({sourceId:Y?q.id:k.id,sourceFull:Y?q.full:k.full,targetId:Y?k.id:q.id,targetFull:Y?k.full:q.full,edgeType:Y?"->":B,edgeLabel:U}),z)break;k=q,S=C(q.endIndex)}return M.length>0?M:null}catch{return null}};const x=u[w].trim();if(!x)continue;if(x.startsWith("subgraph")){const I=x.slice(8).trim();let C;const M=I.match(/^(?:["'])(.*?)(?:["'])/);if(M)C=M[1].toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||`sg-${w}`;else{const S=I.match(/^([^\s\[]+)(?:\s*\[(.+?)\])?/);if(S){const k=S[1];S[2]?C=k:I.indexOf(" ")!==-1?C=I.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||`sg-${w}`:C=k}}if(C){h.push(C),D(`Entering subgraph: ${C}, stack: [${h.join(", ")}]`);continue}}if(x==="end"){if(h.length>0){const I=h[h.length-1];h.pop(),D(`Exiting subgraph: ${I}, stack: [${h.join(", ")}]`)}else D('Warning: Found "end" without matching subgraph start');continue}if(x.startsWith("direction ")||x.startsWith("flowchart ")||x.startsWith("graph ")||x.startsWith("%%")){D(`Skipping line: ${x}`);continue}const N=h.length>0?h[h.length-1]:void 0;D(`Processing line: "${x}" in subgraph: ${N||"none"}`);const b=["-.->","-->","==>","->>","<->","-<>","<-","->"],v=T(x);if(v||D(`Line "${x}" did not match edge pattern - checking for standalone nodes`),v)for(const{sourceId:I,targetId:C,edgeType:M,edgeLabel:S}of v)try{D(`Found edge: ${I} ${M} ${C} with label: "${S}" in context: ${N||"global"}`);const k=i.has(I),$=i.has(C);if(D(`Source "${I}" is ${k?"a subgraph":"a node"}`),D(`Target "${C}" is ${$?"a subgraph":"a node"}`),!k){const B=r.get(I);B?D(`Source ${I} already exists in subgraph: ${B.subgraph||"none"}`):E(I,N)}if(!$){const B=r.get(C);if(B)D(`Target ${C} already exists in subgraph: ${B.subgraph||"none"}`);else{const U=N;D(`Creating target ${C} with subgraph assignment: ${U||"none"} (current subgraph: ${N||"none"})`),E(C,U)}}const P=S.replace(new RegExp('^"(.*)"$',"s"),"$1").replace(new RegExp("^'(.*)'$","s"),"$1");n.push({source:I,target:C,label:y(P),type:M,isSourceSubgraph:k,isTargetSubgraph:$}),D(`Added edge: ${I} -> ${C} (source subgraph: ${k}, target subgraph: ${$})`)}catch(k){D(`Error parsing edge: ${x}`,k)}else try{const I=[/^([A-Za-z0-9_]+)([\[\(\{][^\]\)\}]*[\]\)\}])/,/^([A-Za-z0-9_]+)$/];let C=!1;for(const M of I){const S=x.match(M);if(S&&!r.has(S[1])){const k=S[1];if(i.has(k)){D(`Skipping node creation for ${k} as it's a subgraph`);break}D(`Found standalone node definition: ${k} in context: ${N||"global"}`),E(k,N),C=!0;break}}C||D(`Line "${x}" did not match any pattern (edge or standalone node)`)}catch(I){D(`Error parsing standalone node: ${x}`,I)}}return D("=== FINAL VERIFICATION ==="),D("Subgraph hierarchy:"),o.forEach(w=>{D(`- ${w.id}: "${w.title}" (parent: ${w.parentId||"none"}, children: ${w.childrenIds.join(", ")||"none"}, nodes: ${w.nodes.length})`)}),D("Final node assignments:"),t.forEach(w=>{D(`- ${w.id}: "${w.label}" in subgraph ${w.subgraph||"none"} (shape: ${w.shape})`)}),D("Final edges:"),n.forEach((w,A)=>{D(`- Edge ${A}: ${w.source} -> ${w.target} (label: "${w.label}", type: "${w.type}")`)}),{nodes:t,edges:n,subgraphs:o,direction:a}}const er={rect:"rectangle",round:"rounded-rect",stadium:"terminator",circle:"ellipse",diamond:"diamond",cylinder:"cylinder",subroutine:"subroutine"},ge=be.SUBGRAPH_PADDING,Ge=be.SUBGRAPH_HEADER_HEIGHT+be.SUBGRAPH_PADDING,kn=be.NODE_SEPARATION_HORIZONTAL,Rn=be.NODE_SEPARATION_VERTICAL,tr=be.CONTAINER_SEPARATION_HORIZONTAL,nr=be.CONTAINER_SEPARATION_VERTICAL,or=be.NESTED_SUBGRAPH_SEPARATION_HORIZONTAL,ir=be.NESTED_SUBGRAPH_SEPARATION_VERTICAL,an=be.META_GRAPH_MARGIN,cn=be.NESTED_CONTENT_MARGIN,Ct=be.MIXED_CONTENT_VERTICAL_SPACING,_n=be.MIXED_CONTENT_HORIZONTAL_SPACING,kt="tight-tree";function Ke(e,t,n=!1){if(n)return{width:80,height:80};const o=e.split(`
50
- `);function r(p){try{if(typeof document<"u"){const f=document.createElement("canvas").getContext("2d");if(f)return f.font='600 13px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',f.measureText(p).width}}catch{}return p.length*8}const i=Math.max(...o.map(p=>Math.ceil(r(p)))),s=i+30,a=o.length*18+20,d=Math.max(80,s+30),l=Math.max(40,a+20);if(t==="diamond")return{width:Math.max(90,Math.ceil(d*1.05)),height:Math.max(90,Math.ceil(l*1.05))};if(t==="circle"){const p=Math.max(d,l)+10;return{width:p,height:p}}if(t==="stadium"){const p=Math.max(12,l/2)*2;return{width:Math.max(d,i+p+20),height:l}}if(t==="cylinder"){const p=Math.max(12,Math.min(l*.18,d*.5)+8)*2;return{width:d,height:Math.max(l,o.length*18+p+10)}}if(t==="subroutine"){const p=Math.max(24,d*.2);return{width:Math.max(d,i+p+20),height:l}}return{width:d,height:l}}function Ft(e){const t=e.match(/https?:\/\/[^\s]+\.(jpg|jpeg|png|gif|svg|webp)(\?[^\s]*)?/i);if(t){const n=t[0];return{imageUrl:n,cleanLabel:e.replace(n,"").trim()}}return{imageUrl:null,cleanLabel:e}}function Bt(e){const t=[],n=new Set;e.forEach(r=>{r.parentId||(t.push(r),n.add(r.id))});let o=0;for(;n.size<e.length&&o!==n.size;)o=n.size,e.forEach(r=>{!n.has(r.id)&&r.parentId&&n.has(r.parentId)&&(t.push(r),n.add(r.id))});return e.forEach(r=>{n.has(r.id)||(D(`Warning: Subgraph ${r.id} has circular reference or missing parent. Adding it anyway.`),t.push(r))}),t}function rr(e,t,n,o){const r=new Map,i=Bt(n);return D(`Laying out ${i.length} subgraphs in hierarchical order`),i.forEach(s=>{const a=e.filter(x=>x.subgraph===s.id),d=t.filter(x=>{const N=e.find(v=>v.id===x.source),b=e.find(v=>v.id===x.target);return N?.subgraph===s.id&&b?.subgraph===s.id});D(`Laying out subgraph: ${s.id} with ${a.length} nodes and ${d.length} edges`);const l=new We.graphlib.Graph;l.setGraph({rankdir:s.direction||o,nodesep:kn,ranksep:Rn,marginx:ge,marginy:Ge,ranker:kt}),l.setDefaultEdgeLabel(()=>({})),a.forEach(x=>{const{imageUrl:N}=Ft(x.label),b=Ke(x.label,x.shape,!!N);l.setNode(x.id,{width:b.width,height:b.height})}),d.forEach(x=>{l.setEdge(x.source,x.target)}),We.layout(l);let p=1/0,f=1/0,c=-1/0,u=-1/0;const h=new Map;a.forEach(x=>{const N=l.node(x.id);if(!N){D(`Warning: No layout information for node ${x.id} in subgraph ${s.id}`);return}const b=Ke(x.label,x.shape);h.set(x.id,{x:N.x,y:N.y,width:b.width,height:b.height}),p=Math.min(p,N.x-b.width/2),c=Math.max(c,N.x+b.width/2),f=Math.min(f,N.y-b.height/2),u=Math.max(u,N.y+b.height/2)}),(a.length===0||p===1/0||f===1/0)&&(p=0,f=0,c=200,u=100,D(`Using default dimensions for subgraph ${s.id}: 200x100`));const m=c-p,g=u-f,y=Ke(s.title,"rect").width,E=Math.max(m,y)+ge*2,w=Ge+g+ge,A=-p+(E-m)/2,T=-f+Ge;h.forEach((x,N)=>{h.set(N,R(R({},x),{},{x:x.x+A,y:x.y+T}))}),dr(h,s.id),r.set(s.id,{id:s.id,title:s.title,nodes:h,width:E,height:w,parentId:s.parentId}),D(`Subgraph ${s.id} sizing: content(${m.toFixed(1)}x${g.toFixed(1)}) = final(${E.toFixed(1)}x${w.toFixed(1)})`)}),sr(r,i,o),r}function sr(e,t,n){for(let o=t.length-1;o>=0;o--){const r=t[o],i=e.get(r.id);if(!i)continue;const s=t.filter(h=>h.parentId===r.id);if(s.length===0)continue;let a=0,d=0;i.nodes.forEach(h=>{const m=h.x+h.width/2,g=h.y+h.height/2;a=Math.max(a,m),d=Math.max(d,g)});const l=n==="LR"||n==="RL";s.forEach(h=>{const m=e.get(h.id);if(m){const g=l?Math.max(ge+m.width/2,a+_n+m.width/2):ge+m.width/2,y=l?Ge+m.height/2:Math.max(Ge+m.height/2,d+Ct+m.height/2),E=g+m.width/2,w=y+m.height/2;a=Math.max(a,E),d=Math.max(d,w)}});const p=a+ge,f=d+ge,c=Math.max(i.width,p),u=Math.max(i.height,f);if(c>i.width||u>i.height){const h=i.width,m=i.height;i.width=c,i.height=u,D(`Pre-sized parent ${r.id}: ${h}x${m} → ${i.width}x${i.height} to contain ${s.length} children + nodes`),s.forEach(g=>{const y=e.get(g.id);y&&D(` Child ${g.id}: ${y.width}x${y.height}`)})}}}function ar(e,t){const n=new Map;return t.forEach(o=>{const r=e.find(p=>p.id===o.source),i=e.find(p=>p.id===o.target);if(!r||!i)return;const s=r.subgraph||r.id,a=i.subgraph||i.id;if(s===a)return;n.has(s)||n.set(s,new Map);const d=n.get(s),l=d.get(a)||0;d.set(a,l+1)}),n}function cr(e,t,n,o){let r=!0,i=0;for(;r&&i<5;)i++,r=!1,n.forEach(s=>{const a=e.get(s.id),d=t.get(s.id);if(!a||!d)return;let l=0,p=Ge;a.nodes.forEach(w=>{const A=w.x+w.width/2,T=w.y+w.height/2;l=Math.max(l,A),p=Math.max(p,T)});let f=0,c=0;n.filter(w=>w.parentId===s.id).forEach(w=>{const A=e.get(w.id),T=t.get(w.id);if(!A||!T)return;const x=T.x-d.x,N=T.y-d.y;f=Math.max(f,x+A.width),c=Math.max(c,N+A.height)});const u=Math.max(l,f),h=Math.max(p,c),m=u+ge,g=h+ge,y=Math.max(a.width,m),E=Math.max(a.height,g);(y>a.width||E>a.height)&&(D(`Post-positioning resize (iter ${i}): ${s.id} ${a.width}x${a.height} → ${y}x${E}`),a.width=y,a.height=E,r=!0)})}function lr(e,t){let n=0;return t.nodes.forEach(o=>{const r=o.y+o.height/2;n=Math.max(n,r)}),D(`Parent ${e} nodes extend to bottom Y=${n}`),n}function dr(e,t){const n=Array.from(e.values());let o=!1;for(let r=0;r<n.length;r++)for(let i=r+1;i<n.length;i++){const s=n[r],a=n[i],d=Math.sqrt(Math.pow(s.x-a.x,2)+Math.pow(s.y-a.y,2)),l=(s.width+a.width)/2+(s.height+a.height)/2+20;d<l&&(o=!0,D(`Warning: Potential node overlap in subgraph ${t} - distance: ${d.toFixed(1)}, required: ${l.toFixed(1)}`))}o||D(`✓ Node spacing validated for subgraph ${t} - no overlaps detected`)}function ur(e,t,n,o){const r=Array.from(n.values()).some(m=>!m.parentId),i=new We.graphlib.Graph;i.setGraph({rankdir:o,nodesep:r?tr:kn,ranksep:r?nr:Rn,marginx:an,marginy:an,ranker:kt}),i.setDefaultEdgeLabel(()=>({})),D("Laying out meta-graph");const s=ar(e,t);n.forEach((m,g)=>{m.parentId||(i.setNode(g,{width:m.width,height:m.height}),D(`Added subgraph ${g} to meta-graph (width=${m.width}, height=${m.height})`))});const a=e.filter(m=>!m.subgraph);a.forEach(m=>{const{imageUrl:g}=Ft(m.label),y=Ke(m.label,m.shape,!!g);i.setNode(m.id,{width:y.width,height:y.height}),D(`Added standalone node ${m.id} to meta-graph`)}),s.forEach((m,g)=>{m.forEach((y,E)=>{const w=n.get(g),A=n.get(E);if(w&&w.parentId===E||A&&A.parentId===g)return;const T=!w||!w.parentId,x=!A||!A.parentId;T&&x&&i.hasNode(g)&&i.hasNode(E)&&(i.hasEdge(g,E)||(i.setEdge(g,E,{weight:y}),D(`Added meta-edge from ${g} to ${E} with weight ${y}`)))})}),We.layout(i);const d=new Map,l=new Map;n.forEach((m,g)=>{if(!m.parentId){const y=i.node(g);y?(d.set(g,{x:y.x-m.width/2,y:y.y-m.height/2}),D(`Positioned subgraph ${g} at (${y.x-m.width/2}, ${y.y-m.height/2})`)):D(`Warning: No position for subgraph ${g} in meta-graph`)}});const p=new Set;function f(m){const g=d.get(m),y=n.get(m);if(!g||!y)return!1;const E=[];if(n.forEach((H,J)=>{H.parentId===m&&E.push(J)}),E.length===0)return!1;let w=0;const A=lr(m,y);A>0&&(w=A,D(`Parent ${m} has nodes extending to Y=${w}, will position child subgraphs below this`));const T=new We.graphlib.Graph,x=o;T.setGraph({rankdir:x,nodesep:or,ranksep:ir,marginx:cn,marginy:cn,ranker:kt}),T.setDefaultEdgeLabel(()=>({})),E.forEach(H=>{const J=n.get(H);T.setNode(H,{width:J.width,height:J.height})});let N=!1;if(E.forEach(H=>{const J=s.get(H);J&&J.forEach((ie,se)=>{E.includes(se)&&!T.hasEdge(H,se)&&(T.setEdge(H,se,{weight:ie}),N=!0)})}),!N&&E.length>1)for(let H=0;H<E.length-1;H++)T.setEdge(E[H],E[H+1],{weight:1});We.layout(T);let b=1/0,v=1/0,I=-1/0,C=-1/0;const M=new Map;E.forEach(H=>{const J=T.node(H),ie=n.get(H),se=J.x-ie.width/2,oe=J.y-ie.height/2,Ae=J.x+ie.width/2,Ie=J.y+ie.height/2;M.set(H,{x:se,y:oe}),b=Math.min(b,se),v=Math.min(v,oe),I=Math.max(I,Ae),C=Math.max(C,Ie)});let S=g.x+ge,k=g.y+Ge;const $=x==="LR"||x==="RL";if($){const H=Array.from(y.nodes.values()).reduce((J,ie)=>Math.max(J,ie.x+ie.width/2),0);if(H>0){const J=g.x+Math.max(ge,H+_n);S=Math.max(S,J),D(`Adjusted child subgraph start position to X=${S} for LR/RL to avoid parent nodes`)}}else if(w>0){const H=w,J=g.y+H+Ct;k=Math.max(k,J),D(`Adjusted child subgraph start position to Y=${k} to avoid parent nodes (added ${Ct}px spacing)`)}const P=S-g.x,B=y.width-P-ge,U=k-g.y,q=y.height-U-ge,z=I-b,Y=C-v,G=$?Math.max(0,(B-z)/2):0,te=$?0:Math.max(0,(q-Y)/2);E.forEach(H=>{const J=M.get(H),ie=S+G+(J.x-b),se=k+te+(J.y-v);d.set(H,{x:ie,y:se}),p.add(H),D(`Positioned nested subgraph "${H}" within parent ${m} at (${ie}, ${se}) with centering`)});const Q=S+G+z-g.x+ge,ne=k+te+Y-g.y+ge;if(Q>y.width||ne>y.height){const H=y.width,J=y.height;y.width=Math.max(y.width,Q),y.height=Math.max(y.height,ne),D(`Expanded parent ${m} from ${H}x${J} to ${y.width}x${y.height} to fit nodes + ${E.length} child subgraphs (overflow-safe)`)}return!0}const c=new Set;let u=!0,h=0;for(;u&&h<100;)h++,u=!1,n.forEach((m,g)=>{d.has(g)&&!c.has(g)&&f(g)&&(u=!0,c.add(g))});return h===100&&D("Warning: nested subgraph layout reached iteration cap; potential cyclic dependency"),a.forEach(m=>{const g=i.node(m.id);if(g){const y=Ke(m.label,m.shape);l.set(m.id,{x:g.x-y.width/2,y:g.y-y.height/2}),D(`Positioned standalone node ${m.id} at (${g.x-y.width/2}, ${g.y-y.height/2})`)}else D(`Warning: No position for standalone node ${m.id} in meta-graph`)}),{subgraphPositions:d,standalonePositions:l}}function hr(e,t,n,o,r,i,s){const a=[];D("Creating React Flow elements");function d(h){const m={rect:["#1C2336","#3D5EA8"],diamond:["#1C2336","#3D5EA8"],circle:["#1C2336","#3D5EA8"],stadium:["#1C2336","#3D5EA8"],round:["#1C2336","#3D5EA8"]}[h]||["#1C2336","#3D5EA8"];return{backgroundColor:m[0],borderColor:m[1]}}function l(h){const m=[{bg:"rgba(100, 181, 246, 0.08)",border:"#64B5F6"},{bg:"rgba(129, 199, 132, 0.08)",border:"#81C784"},{bg:"rgba(186, 104, 200, 0.08)",border:"#BA68C8"},{bg:"rgba(255, 183, 77, 0.08)",border:"#FFB74D"},{bg:"rgba(240, 98, 146, 0.08)",border:"#F06292"}];return m[h%m.length]}const p=Bt(n);p.forEach((h,m)=>{const g=o.get(h.id),y=r.get(h.id);if(g&&y){const E=l(m);let w=y;if(g.parentId){const A=r.get(g.parentId);A&&(w={x:y.x-A.x,y:y.y-A.y})}a.push({id:`subgraph-${h.id}`,type:"group",position:w,data:{backgroundColor:E.bg,borderColor:E.border,childNodes:h.nodes,autoLayout:!0,componentFields:[me(h.title)]},style:{width:g.width,height:g.height,zIndex:0},selectable:!0,draggable:!0,connectable:!0,parentId:g.parentId?`subgraph-${g.parentId}`:void 0,extent:g.parentId?"parent":void 0,zIndex:g.parentId?1:0})}}),e.forEach(h=>{const m=d(h.shape),{imageUrl:g,cleanLabel:y}=Ft(h.label),{tag:E,displayLabel:w}=Qi(y),A=Zi(!!g,E);let T,x;if(h.subgraph){const k=o.get(h.subgraph),$=r.get(h.subgraph),P=k?.nodes.get(h.id);P&&$?(T={x:P.x-P.width/2,y:P.y-P.height/2},x=`subgraph-${h.subgraph}`,D(`Node ${h.id} positioned at (${T.x}, ${T.y}) within subgraph ${h.subgraph}`)):(T={x:0,y:0},D(`Warning: Missing layout data for node ${h.id} in subgraph ${h.subgraph}`))}else T=i.get(h.id)||{x:0,y:0},D(`Standalone node ${h.id} positioned at (${T.x}, ${T.y})`);const N=s==="LR"||s==="RL",b=N?nt.Right:nt.Bottom,v=N?nt.Left:nt.Top;let I=150,C=60;if(h.subgraph){const k=o.get(h.subgraph),$=k?.nodes.get(h.id);$&&(I=Math.max(20,Math.round($.width)),C=Math.max(20,Math.round($.height)))}else{const k=Ke(h.label,h.shape,!!g);I=Math.max(20,Math.round(k.width)),C=Math.max(20,Math.round(k.height))}let M;switch(A.toLowerCase()){case"image":M={src:g??""};break;case"shape":var S;M={shape:(S=er[h.shape])!==null&&S!==void 0?S:"rectangle",componentFields:[me(w)],fill:m.backgroundColor,stroke:m.borderColor,strokeWidth:2};break;case"default":M={name:w,label:w,description:"",componentId:"file-note"};break;case"builder":M={componentName:"file-note",componentFields:[me(w),ke({label:"Label",data:w,type:L.TextInput}),ke({label:"Description",data:"",type:L.TextBox})]};break;case"text":M={componentFields:[ke({componentFieldId:"text",label:"Text",data:w,type:L.TextBox})]};break;case"code":M={componentFields:[me(w),ke({label:"Code",data:"",type:L.CodeEditor})]};break;case"table":M={componentFields:[me(w)],columns:["Task","Owner","Status","Due"],rows:[["Website revamp","Amara","In progress","May 12"],["Marketing sync","Liu","Blocked","May 15"]]};break;case"cloud":M={componentFields:[me(w)]};break;case"comment":M={componentFields:[me(w)]};break;default:M={name:w,label:w,description:"",componentId:"file-note"}}a.push({id:h.id,type:A,position:T,data:M,style:{width:I,height:C},sourcePosition:b,targetPosition:v,parentId:x,extent:x?"parent":void 0,draggable:!0,zIndex:1})});const f=new Map(e.map(h=>[h.id,h.subgraph])),c=t.filter(h=>h.isTargetSubgraph&&f.get(h.source)===h.target?(D(`Dropping edge ${h.source} -> ${h.target}: source already lives inside this subgraph`),!1):h.isSourceSubgraph&&f.get(h.target)===h.source?(D(`Dropping edge ${h.source} -> ${h.target}: target already lives inside this subgraph`),!1):!0),u=new Map;return p.forEach(h=>{const m=r.get(h.id);m&&u.set(`subgraph-${h.id}`,m)}),e.forEach(h=>{if(h.subgraph){const m=o.get(h.subgraph),g=r.get(h.subgraph),y=m?.nodes.get(h.id);y&&g&&u.set(h.id,{x:g.x+y.x,y:g.y+y.y})}else{const m=i.get(h.id);m&&u.set(h.id,m)}}),{nodes:a,edges:c.map((h,m)=>{const g={strokeWidth:2.5},y="smoothstep";switch(h.type){case"-->":case"->":break;case"---":g.strokeDasharray="8,4";break;case"-.-":g.strokeDasharray="4,4";break;case"==>":case"===>":g.strokeWidth=4;break}const E=h.isSourceSubgraph?`subgraph-${h.source}`:h.source,w=h.isTargetSubgraph?`subgraph-${h.target}`:h.target,A=s==="LR"||s==="RL";let T=A?"source-right":"source-bottom",x=A?"target-left":"target-top";const N=u.get(E),b=u.get(w);return N&&b&&(A?b.x<N.x&&(T="source-left",x="target-right"):b.y<N.y&&(T="source-top",x="target-bottom")),{id:`edge-${h.source}-${h.target}-${m}`,source:E,target:w,label:h.label,type:y,style:g,labelStyle:{fontSize:"12px",fontWeight:"500",color:"#E2E8F0",backgroundColor:"#1E293B",padding:"2px 6px"},markerEnd:{type:xe.ArrowClosed,width:20,height:20},sourceHandle:T,targetHandle:x,zIndex:0}})}}function fr(e,t,n,o){D("Starting graph layout with direction:",o),D(`Input: ${e.length} nodes, ${t.length} edges, ${n.length} subgraphs`);const r=rr(e,t,n,o),{subgraphPositions:i,standalonePositions:s}=ur(e,t,r,o);return cr(r,i,Bt(n)),hr(e,t,n,r,i,s,o)}function pr(e){return Rt.apply(this,arguments)}function Rt(){return Rt=Be(function*(e){D("Starting Mermaid to React Flow conversion"),D("Mermaid code:",e);const{nodes:t,edges:n,subgraphs:o,direction:r}=Ji(e);if(t.length===0)return D("No nodes found in Mermaid diagram"),{nodes:[],edges:[]};D(`Parsed ${t.length} nodes, ${n.length} edges, ${o.length} subgraphs`);const i=fr(t,n,o,r);return{nodes:i.nodes.map(s=>R(R({},s),{},{data:R(R({},s.data),{},{source:"mermaid"})})),edges:i.edges.map(s=>R(R({},s),{},{data:R(R({},s.data),{},{source:"mermaid"})}))}}),Rt.apply(this,arguments)}function mr(e,t){let n=1,o=0;for(const r of e){if(r.length>t){o>0&&(n+=1);const s=Math.ceil(r.length/t);n+=s-1,o=r.length-(s-1)*t;continue}const i=o===0?r.length:o+1+r.length;i>t?(n+=1,o=r.length):o=i}return n}function Mn(e){const{MESSAGE_NODE_WIDTH:t,MESSAGE_NODE_HEIGHT:n,MESSAGE_MAX_WIDTH:o,MESSAGE_TARGET_WRAP_LINES:r,MESSAGE_CHAR_WIDTH:i,MESSAGE_LINE_HEIGHT:s,MESSAGE_HORIZONTAL_PADDING:a,MESSAGE_VERTICAL_PADDING:d}=De,l=e.trim();if(!l)return{width:t,height:n};if(l.includes(`
51
- `)){const g=l.split(`
52
- `).map(y=>Mn(y));return{width:Math.max(...g.map(y=>y.width)),height:g.reduce((y,E)=>y+E.height-Number(d),Number(d))}}const p=l.split(/\s+/).filter(Boolean),f=Math.max(1,...p.map(g=>g.length)),c=Math.max(1,Math.ceil(l.length/r)),u=Math.max(c,f),h=Math.min(o,Math.max(t,a+u*i)),m=mr(p,Math.max(1,Math.floor((h-a)/i)));return{width:h,height:Math.max(n,m*s+d)}}const _t=[{token:"<<-->>",lineStyle:"dashed",arrowType:"bidirectional"},{token:"<<->>",lineStyle:"solid",arrowType:"bidirectional"},{token:"--|\\",lineStyle:"dashed",arrowType:"half",half:"top"},{token:"-|\\",lineStyle:"solid",arrowType:"half",half:"top"},{token:"--|/",lineStyle:"dashed",arrowType:"half",half:"bottom"},{token:"-|/",lineStyle:"solid",arrowType:"half",half:"bottom"},{token:"/|--",lineStyle:"dashed",arrowType:"half",half:"top",reversed:!0},{token:"/|-",lineStyle:"solid",arrowType:"half",half:"top",reversed:!0},{token:"\\--",lineStyle:"dashed",arrowType:"half",half:"bottom",reversed:!0},{token:"\\-",lineStyle:"solid",arrowType:"half",half:"bottom",reversed:!0},{token:"//--",lineStyle:"dashed",arrowType:"stick",half:"top",reversed:!0},{token:"//-",lineStyle:"solid",arrowType:"stick",half:"top",reversed:!0},{token:"--//",lineStyle:"dashed",arrowType:"stick",half:"bottom"},{token:"-//",lineStyle:"solid",arrowType:"stick",half:"bottom"},{token:"--\\",lineStyle:"dashed",arrowType:"stick",half:"top"},{token:"-\\",lineStyle:"solid",arrowType:"stick",half:"top"},{token:"-->>",lineStyle:"dashed",arrowType:"filled"},{token:"->>",lineStyle:"solid",arrowType:"filled"},{token:"--x",lineStyle:"dashed",arrowType:"cross"},{token:"-x",lineStyle:"solid",arrowType:"cross"},{token:"--)",lineStyle:"dashed",arrowType:"open"},{token:"-)",lineStyle:"solid",arrowType:"open"},{token:"-->",lineStyle:"dashed",arrowType:"none"},{token:"->",lineStyle:"solid",arrowType:"none"}];function gr(e){const t=_t.find(o=>o.lineStyle===e.lineStyle&&o.arrowType===e.arrowType&&o.half===e.half&&!!o.reversed==!!e.reversed);if(t)return t.token;const n=_t.find(o=>o.lineStyle===e.lineStyle&&o.arrowType===e.arrowType);return n?n.token:e.lineStyle==="dashed"?"-->>":"->>"}const yr=["loop","alt","opt","par","critical","break","rect"],vr=["else","and","option"],br=new Set(`transparent aliceblue antiquewhite aqua aquamarine azure beige bisque black blanchedalmond blue
49
+ `).trim())}D("Pre-scanning for node definitions..."),u.forEach((w,N)=>{const T=w.trim();if(!T||T.startsWith("subgraph")||T==="end"||T.startsWith("%%"))return;const x=/(^|[\s\-\>]|\|[^|]*\|)([A-Za-z0-9_]+)([\[\(\{])/g;let S;const b=new Set;for(;(S=x.exec(T))!==null;){const v=S[1],I=S[2],C=S[3],M=S.index+v.length;if(b.has(M)||s.has(I))continue;b.add(M);const A=M+I.length,k=C==="["?"]":C==="("?")":"}";let $=-1,P=0;for(let q=A;q<T.length;q++){const z=T[q];if(z===C)P++;else if(z===k&&(P--,P===0)){$=q;break}}let B=I,U="";if($!==-1)B=T.slice(M,$+1),U=T.slice(A,$+1);else{const q=T.slice(M).match(/([A-Za-z0-9_]+)([\[\(\{][^\]\)\}]*[\]\)\}])/);q&&q[1]===I&&(B=q[0],U=q[2])}if(U){const q=Ji(B);let z=I;const Y=kn[q];if(Y&&U.startsWith(Y.open)&&U.endsWith(Y.close))z=U.slice(Y.open.length,U.length-Y.close.length);else{const te=U.match(new RegExp("^[\\[\\(\\{](.*)[\\]\\)\\}]$","s"));te&&(z=te[1])}z=z.replace(new RegExp('^"(.*)"$',"s"),"$1").replace(new RegExp("^'(.*)'$","s"),"$1");const G=g(z);s.set(I,{label:G,shape:q,fullDef:B}),D(`Pre-scan found node definition: ${I} -> "${G}" (${q}) from line ${N+1}`)}}}),D("First pass: identifying subgraphs...");for(let w=0;w<u.length;w++){const N=u[w].trim();if(N)if(N.startsWith("subgraph")){const T=N.slice(8).trim();let x,S;const b=T.match(/^(["'])(.*?)\1/);if(b)S=b[2],x=S.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||`sg-${w}`;else{const v=T.match(/^([^\s\[]+)(?:\s*\[(.+?)\])?/);if(v&&(x=v[1],v[2]&&(S=v[2])),!S&&T.indexOf(" ")!==-1&&(S=T,x=S.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||`sg-${w}`),!S){const I=T.match(/^[^\s]+\s+(["'])(.*?)\1/);I&&(S=I[2])}}if(x){const v=h.length>0?h[h.length-1]:void 0,I=S?g(S):x;D(`Found subgraph: ${x}, title: "${I}", parent: ${v||"none"}`),h.push(x);const C={id:x,title:I,nodes:[],parentId:v,childrenIds:[]};if(i.set(x,C),v){const M=i.get(v);M&&M.childrenIds.push(x)}o.push(C)}}else if(N.toLowerCase().startsWith("direction ")){const T=N.match(/^direction\s+(TB|TD|BT|RL|LR)$/i);if(T&&h.length>0){const x=h[h.length-1],S=i.get(x);if(S){const b=T[1].toUpperCase();S.direction=b==="TD"?"TB":b}}}else N==="end"&&h.length>0&&h.pop()}h.length=0;function E(w,N){if(r.has(w)){const v=r.get(w);if(N&&!v.subgraph){v.subgraph=N;const I=i.get(N);I&&!I.nodes.includes(w)&&I.nodes.push(w),D(`Updated existing node ${w} to be part of subgraph ${N}`)}return v}const T=s.get(w);let x,S;T?(x=T.label,S=T.shape,D(`Creating node ${w} using pre-scanned definition: "${x}" (${S})`)):(x=w,S="rect",D(`Creating simple fallback node: ${w}`));const b={id:w,label:x,shape:S,subgraph:N,parentSubgraph:h.length>1?h[h.length-2]:void 0};if(t.push(b),r.set(w,b),N){const v=i.get(N);v&&v.nodes.push(w)}return b}D("Second pass: processing nodes and edges...");for(let w=0;w<u.length;w++){let N=function(I,C){const M=I.slice(C).match(/^\s*([A-Za-z0-9_]+)/);if(!M)return null;const A=M[1],k=C+M[0].length,$=I.slice(k),P=$.match(/^[\s]*([\[\(\{])/);if(P){const B=P[1],U=k+$.indexOf(B),q=B==="["?"]":B==="("?")":"}";let z=0,Y=-1;for(let G=U;G<I.length;G++)if(I[G]===B)z++;else if(I[G]===q&&(z--,z===0)){Y=G;break}if(Y!==-1)return{id:A,full:I.slice(C+M[0].search(/\S/),Y+1).trim(),endIndex:Y+1}}return{id:A,full:A,endIndex:k}},T=function(I){try{let C=function($){const P=I.slice($).match(/^\s*:::[A-Za-z0-9_-]+/);return P?$+P[0].length:$};const M=[];let A=0,k=N(I,A);if(!k)return null;for(A=C(k.endIndex);;){for(;A<I.length&&/\s/.test(I[A]);)A++;let $=-1,P="";for(const G of b){const te=I.indexOf(G,A);te!==-1&&($===-1||te<$)&&($=te,P=G)}let B=null,U="";if($!==-1){const G=I.slice(A,$),te=G.match(/\|(.*?)\|/);if(te)U=te[1];else{const Q=G.replace(/^\s*[\-\.=:\~]+\s*/g,"").replace(/\s*[\-\.=:\~]+\s*$/g,"").trim();Q&&(U=Q)}for(B=P,A=$+P.length;A<I.length&&/\s/.test(I[A]);)A++;if(I[A]==="|"){const Q=I.indexOf("|",A+1);Q!==-1&&(U=I.slice(A+1,Q),A=Q+1)}}else if(M.length===0){for(const G of["---","-.-","::",":-:","...","~","==="].sort((te,Q)=>Q.length-te.length))if(I.startsWith(G,A)){B=G,A+=G.length;break}if(!B)return null;for(;A<I.length&&/\s/.test(I[A]);)A++;if(I[A]==="|"){const G=I.indexOf("|",A+1);G!==-1&&(U=I.slice(A+1,G),A=G+1)}}else break;for(;A<I.length&&/\s/.test(I[A]);)A++;const q=N(I,A);if(!q)break;const z=I.slice(q.endIndex).trimStart().match(/^:(?!::)\s*(.+)$/);z&&!U&&(U=z[1].trim());const Y=B==="<-";if(M.push({sourceId:Y?q.id:k.id,sourceFull:Y?q.full:k.full,targetId:Y?k.id:q.id,targetFull:Y?k.full:q.full,edgeType:Y?"->":B,edgeLabel:U}),z)break;k=q,A=C(q.endIndex)}return M.length>0?M:null}catch{return null}};const x=u[w].trim();if(!x)continue;if(x.startsWith("subgraph")){const I=x.slice(8).trim();let C;const M=I.match(/^(?:["'])(.*?)(?:["'])/);if(M)C=M[1].toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||`sg-${w}`;else{const A=I.match(/^([^\s\[]+)(?:\s*\[(.+?)\])?/);if(A){const k=A[1];A[2]?C=k:I.indexOf(" ")!==-1?C=I.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||`sg-${w}`:C=k}}if(C){h.push(C),D(`Entering subgraph: ${C}, stack: [${h.join(", ")}]`);continue}}if(x==="end"){if(h.length>0){const I=h[h.length-1];h.pop(),D(`Exiting subgraph: ${I}, stack: [${h.join(", ")}]`)}else D('Warning: Found "end" without matching subgraph start');continue}if(x.startsWith("direction ")||x.startsWith("flowchart ")||x.startsWith("graph ")||x.startsWith("%%")){D(`Skipping line: ${x}`);continue}const S=h.length>0?h[h.length-1]:void 0;D(`Processing line: "${x}" in subgraph: ${S||"none"}`);const b=["-.->","-->","==>","->>","<->","-<>","<-","->"],v=T(x);if(v||D(`Line "${x}" did not match edge pattern - checking for standalone nodes`),v)for(const{sourceId:I,targetId:C,edgeType:M,edgeLabel:A}of v)try{D(`Found edge: ${I} ${M} ${C} with label: "${A}" in context: ${S||"global"}`);const k=i.has(I),$=i.has(C);if(D(`Source "${I}" is ${k?"a subgraph":"a node"}`),D(`Target "${C}" is ${$?"a subgraph":"a node"}`),!k){const B=r.get(I);B?D(`Source ${I} already exists in subgraph: ${B.subgraph||"none"}`):E(I,S)}if(!$){const B=r.get(C);if(B)D(`Target ${C} already exists in subgraph: ${B.subgraph||"none"}`);else{const U=S;D(`Creating target ${C} with subgraph assignment: ${U||"none"} (current subgraph: ${S||"none"})`),E(C,U)}}const P=A.replace(new RegExp('^"(.*)"$',"s"),"$1").replace(new RegExp("^'(.*)'$","s"),"$1");n.push({source:I,target:C,label:g(P),type:M,isSourceSubgraph:k,isTargetSubgraph:$}),D(`Added edge: ${I} -> ${C} (source subgraph: ${k}, target subgraph: ${$})`)}catch(k){D(`Error parsing edge: ${x}`,k)}else try{const I=[/^([A-Za-z0-9_]+)([\[\(\{][^\]\)\}]*[\]\)\}])/,/^([A-Za-z0-9_]+)$/];let C=!1;for(const M of I){const A=x.match(M);if(A&&!r.has(A[1])){const k=A[1];if(i.has(k)){D(`Skipping node creation for ${k} as it's a subgraph`);break}D(`Found standalone node definition: ${k} in context: ${S||"global"}`),E(k,S),C=!0;break}}C||D(`Line "${x}" did not match any pattern (edge or standalone node)`)}catch(I){D(`Error parsing standalone node: ${x}`,I)}}return D("=== FINAL VERIFICATION ==="),D("Subgraph hierarchy:"),o.forEach(w=>{D(`- ${w.id}: "${w.title}" (parent: ${w.parentId||"none"}, children: ${w.childrenIds.join(", ")||"none"}, nodes: ${w.nodes.length})`)}),D("Final node assignments:"),t.forEach(w=>{D(`- ${w.id}: "${w.label}" in subgraph ${w.subgraph||"none"} (shape: ${w.shape})`)}),D("Final edges:"),n.forEach((w,N)=>{D(`- Edge ${N}: ${w.source} -> ${w.target} (label: "${w.label}", type: "${w.type}")`)}),{nodes:t,edges:n,subgraphs:o,direction:a}}const tr={rect:"rectangle",round:"rounded-rect",stadium:"terminator",circle:"ellipse",diamond:"diamond",cylinder:"cylinder",subroutine:"subroutine"},ge=be.SUBGRAPH_PADDING,Ge=be.SUBGRAPH_HEADER_HEIGHT+be.SUBGRAPH_PADDING,Rn=be.NODE_SEPARATION_HORIZONTAL,_n=be.NODE_SEPARATION_VERTICAL,nr=be.CONTAINER_SEPARATION_HORIZONTAL,or=be.CONTAINER_SEPARATION_VERTICAL,ir=be.NESTED_SUBGRAPH_SEPARATION_HORIZONTAL,rr=be.NESTED_SUBGRAPH_SEPARATION_VERTICAL,cn=be.META_GRAPH_MARGIN,ln=be.NESTED_CONTENT_MARGIN,Ct=be.MIXED_CONTENT_VERTICAL_SPACING,Mn=be.MIXED_CONTENT_HORIZONTAL_SPACING,kt="tight-tree";function Ke(e,t,n=!1){if(n)return{width:80,height:80};const o=e.split(`
50
+ `);function r(p){try{if(typeof document<"u"){const f=document.createElement("canvas").getContext("2d");if(f)return f.font='600 13px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',f.measureText(p).width}}catch{}return p.length*8}const i=Math.max(...o.map(p=>Math.ceil(r(p)))),s=i+30,a=o.length*18+20,d=Math.max(80,s+30),l=Math.max(40,a+20);if(t==="diamond")return{width:Math.max(90,Math.ceil(d*1.05)),height:Math.max(90,Math.ceil(l*1.05))};if(t==="circle"){const p=Math.max(d,l)+10;return{width:p,height:p}}if(t==="stadium"){const p=Math.max(12,l/2)*2;return{width:Math.max(d,i+p+20),height:l}}if(t==="cylinder"){const p=Math.max(12,Math.min(l*.18,d*.5)+8)*2;return{width:d,height:Math.max(l,o.length*18+p+10)}}if(t==="subroutine"){const p=Math.max(24,d*.2);return{width:Math.max(d,i+p+20),height:l}}return{width:d,height:l}}function Ft(e){const t=e.match(/https?:\/\/[^\s]+\.(jpg|jpeg|png|gif|svg|webp)(\?[^\s]*)?/i);if(t){const n=t[0];return{imageUrl:n,cleanLabel:e.replace(n,"").trim()}}return{imageUrl:null,cleanLabel:e}}function Bt(e){const t=[],n=new Set;e.forEach(r=>{r.parentId||(t.push(r),n.add(r.id))});let o=0;for(;n.size<e.length&&o!==n.size;)o=n.size,e.forEach(r=>{!n.has(r.id)&&r.parentId&&n.has(r.parentId)&&(t.push(r),n.add(r.id))});return e.forEach(r=>{n.has(r.id)||(D(`Warning: Subgraph ${r.id} has circular reference or missing parent. Adding it anyway.`),t.push(r))}),t}function sr(e,t,n,o){const r=new Map,i=Bt(n);return D(`Laying out ${i.length} subgraphs in hierarchical order`),i.forEach(s=>{const a=e.filter(x=>x.subgraph===s.id),d=t.filter(x=>{const S=e.find(v=>v.id===x.source),b=e.find(v=>v.id===x.target);return S?.subgraph===s.id&&b?.subgraph===s.id});D(`Laying out subgraph: ${s.id} with ${a.length} nodes and ${d.length} edges`);const l=new We.graphlib.Graph;l.setGraph({rankdir:s.direction||o,nodesep:Rn,ranksep:_n,marginx:ge,marginy:Ge,ranker:kt}),l.setDefaultEdgeLabel(()=>({})),a.forEach(x=>{const{imageUrl:S}=Ft(x.label),b=Ke(x.label,x.shape,!!S);l.setNode(x.id,{width:b.width,height:b.height})}),d.forEach(x=>{l.setEdge(x.source,x.target)}),We.layout(l);let p=1/0,f=1/0,c=-1/0,u=-1/0;const h=new Map;a.forEach(x=>{const S=l.node(x.id);if(!S){D(`Warning: No layout information for node ${x.id} in subgraph ${s.id}`);return}const b=Ke(x.label,x.shape);h.set(x.id,{x:S.x,y:S.y,width:b.width,height:b.height}),p=Math.min(p,S.x-b.width/2),c=Math.max(c,S.x+b.width/2),f=Math.min(f,S.y-b.height/2),u=Math.max(u,S.y+b.height/2)}),(a.length===0||p===1/0||f===1/0)&&(p=0,f=0,c=200,u=100,D(`Using default dimensions for subgraph ${s.id}: 200x100`));const m=c-p,y=u-f,g=Ke(s.title,"rect").width,E=Math.max(m,g)+ge*2,w=Ge+y+ge,N=-p+(E-m)/2,T=-f+Ge;h.forEach((x,S)=>{h.set(S,R(R({},x),{},{x:x.x+N,y:x.y+T}))}),ur(h,s.id),r.set(s.id,{id:s.id,title:s.title,nodes:h,width:E,height:w,parentId:s.parentId}),D(`Subgraph ${s.id} sizing: content(${m.toFixed(1)}x${y.toFixed(1)}) = final(${E.toFixed(1)}x${w.toFixed(1)})`)}),ar(r,i,o),r}function ar(e,t,n){for(let o=t.length-1;o>=0;o--){const r=t[o],i=e.get(r.id);if(!i)continue;const s=t.filter(h=>h.parentId===r.id);if(s.length===0)continue;let a=0,d=0;i.nodes.forEach(h=>{const m=h.x+h.width/2,y=h.y+h.height/2;a=Math.max(a,m),d=Math.max(d,y)});const l=n==="LR"||n==="RL";s.forEach(h=>{const m=e.get(h.id);if(m){const y=l?Math.max(ge+m.width/2,a+Mn+m.width/2):ge+m.width/2,g=l?Ge+m.height/2:Math.max(Ge+m.height/2,d+Ct+m.height/2),E=y+m.width/2,w=g+m.height/2;a=Math.max(a,E),d=Math.max(d,w)}});const p=a+ge,f=d+ge,c=Math.max(i.width,p),u=Math.max(i.height,f);if(c>i.width||u>i.height){const h=i.width,m=i.height;i.width=c,i.height=u,D(`Pre-sized parent ${r.id}: ${h}x${m} → ${i.width}x${i.height} to contain ${s.length} children + nodes`),s.forEach(y=>{const g=e.get(y.id);g&&D(` Child ${y.id}: ${g.width}x${g.height}`)})}}}function cr(e,t){const n=new Map;return t.forEach(o=>{const r=e.find(p=>p.id===o.source),i=e.find(p=>p.id===o.target);if(!r||!i)return;const s=r.subgraph||r.id,a=i.subgraph||i.id;if(s===a)return;n.has(s)||n.set(s,new Map);const d=n.get(s),l=d.get(a)||0;d.set(a,l+1)}),n}function lr(e,t,n,o){let r=!0,i=0;for(;r&&i<5;)i++,r=!1,n.forEach(s=>{const a=e.get(s.id),d=t.get(s.id);if(!a||!d)return;let l=0,p=Ge;a.nodes.forEach(w=>{const N=w.x+w.width/2,T=w.y+w.height/2;l=Math.max(l,N),p=Math.max(p,T)});let f=0,c=0;n.filter(w=>w.parentId===s.id).forEach(w=>{const N=e.get(w.id),T=t.get(w.id);if(!N||!T)return;const x=T.x-d.x,S=T.y-d.y;f=Math.max(f,x+N.width),c=Math.max(c,S+N.height)});const u=Math.max(l,f),h=Math.max(p,c),m=u+ge,y=h+ge,g=Math.max(a.width,m),E=Math.max(a.height,y);(g>a.width||E>a.height)&&(D(`Post-positioning resize (iter ${i}): ${s.id} ${a.width}x${a.height} → ${g}x${E}`),a.width=g,a.height=E,r=!0)})}function dr(e,t){let n=0;return t.nodes.forEach(o=>{const r=o.y+o.height/2;n=Math.max(n,r)}),D(`Parent ${e} nodes extend to bottom Y=${n}`),n}function ur(e,t){const n=Array.from(e.values());let o=!1;for(let r=0;r<n.length;r++)for(let i=r+1;i<n.length;i++){const s=n[r],a=n[i],d=Math.sqrt(Math.pow(s.x-a.x,2)+Math.pow(s.y-a.y,2)),l=(s.width+a.width)/2+(s.height+a.height)/2+20;d<l&&(o=!0,D(`Warning: Potential node overlap in subgraph ${t} - distance: ${d.toFixed(1)}, required: ${l.toFixed(1)}`))}o||D(`✓ Node spacing validated for subgraph ${t} - no overlaps detected`)}function hr(e,t,n,o){const r=Array.from(n.values()).some(m=>!m.parentId),i=new We.graphlib.Graph;i.setGraph({rankdir:o,nodesep:r?nr:Rn,ranksep:r?or:_n,marginx:cn,marginy:cn,ranker:kt}),i.setDefaultEdgeLabel(()=>({})),D("Laying out meta-graph");const s=cr(e,t);n.forEach((m,y)=>{m.parentId||(i.setNode(y,{width:m.width,height:m.height}),D(`Added subgraph ${y} to meta-graph (width=${m.width}, height=${m.height})`))});const a=e.filter(m=>!m.subgraph);a.forEach(m=>{const{imageUrl:y}=Ft(m.label),g=Ke(m.label,m.shape,!!y);i.setNode(m.id,{width:g.width,height:g.height}),D(`Added standalone node ${m.id} to meta-graph`)}),s.forEach((m,y)=>{m.forEach((g,E)=>{const w=n.get(y),N=n.get(E);if(w&&w.parentId===E||N&&N.parentId===y)return;const T=!w||!w.parentId,x=!N||!N.parentId;T&&x&&i.hasNode(y)&&i.hasNode(E)&&(i.hasEdge(y,E)||(i.setEdge(y,E,{weight:g}),D(`Added meta-edge from ${y} to ${E} with weight ${g}`)))})}),We.layout(i);const d=new Map,l=new Map;n.forEach((m,y)=>{if(!m.parentId){const g=i.node(y);g?(d.set(y,{x:g.x-m.width/2,y:g.y-m.height/2}),D(`Positioned subgraph ${y} at (${g.x-m.width/2}, ${g.y-m.height/2})`)):D(`Warning: No position for subgraph ${y} in meta-graph`)}});const p=new Set;function f(m){const y=d.get(m),g=n.get(m);if(!y||!g)return!1;const E=[];if(n.forEach((H,J)=>{H.parentId===m&&E.push(J)}),E.length===0)return!1;let w=0;const N=dr(m,g);N>0&&(w=N,D(`Parent ${m} has nodes extending to Y=${w}, will position child subgraphs below this`));const T=new We.graphlib.Graph,x=o;T.setGraph({rankdir:x,nodesep:ir,ranksep:rr,marginx:ln,marginy:ln,ranker:kt}),T.setDefaultEdgeLabel(()=>({})),E.forEach(H=>{const J=n.get(H);T.setNode(H,{width:J.width,height:J.height})});let S=!1;if(E.forEach(H=>{const J=s.get(H);J&&J.forEach((ie,se)=>{E.includes(se)&&!T.hasEdge(H,se)&&(T.setEdge(H,se,{weight:ie}),S=!0)})}),!S&&E.length>1)for(let H=0;H<E.length-1;H++)T.setEdge(E[H],E[H+1],{weight:1});We.layout(T);let b=1/0,v=1/0,I=-1/0,C=-1/0;const M=new Map;E.forEach(H=>{const J=T.node(H),ie=n.get(H),se=J.x-ie.width/2,oe=J.y-ie.height/2,Ae=J.x+ie.width/2,Ie=J.y+ie.height/2;M.set(H,{x:se,y:oe}),b=Math.min(b,se),v=Math.min(v,oe),I=Math.max(I,Ae),C=Math.max(C,Ie)});let A=y.x+ge,k=y.y+Ge;const $=x==="LR"||x==="RL";if($){const H=Array.from(g.nodes.values()).reduce((J,ie)=>Math.max(J,ie.x+ie.width/2),0);if(H>0){const J=y.x+Math.max(ge,H+Mn);A=Math.max(A,J),D(`Adjusted child subgraph start position to X=${A} for LR/RL to avoid parent nodes`)}}else if(w>0){const H=w,J=y.y+H+Ct;k=Math.max(k,J),D(`Adjusted child subgraph start position to Y=${k} to avoid parent nodes (added ${Ct}px spacing)`)}const P=A-y.x,B=g.width-P-ge,U=k-y.y,q=g.height-U-ge,z=I-b,Y=C-v,G=$?Math.max(0,(B-z)/2):0,te=$?0:Math.max(0,(q-Y)/2);E.forEach(H=>{const J=M.get(H),ie=A+G+(J.x-b),se=k+te+(J.y-v);d.set(H,{x:ie,y:se}),p.add(H),D(`Positioned nested subgraph "${H}" within parent ${m} at (${ie}, ${se}) with centering`)});const Q=A+G+z-y.x+ge,ne=k+te+Y-y.y+ge;if(Q>g.width||ne>g.height){const H=g.width,J=g.height;g.width=Math.max(g.width,Q),g.height=Math.max(g.height,ne),D(`Expanded parent ${m} from ${H}x${J} to ${g.width}x${g.height} to fit nodes + ${E.length} child subgraphs (overflow-safe)`)}return!0}const c=new Set;let u=!0,h=0;for(;u&&h<100;)h++,u=!1,n.forEach((m,y)=>{d.has(y)&&!c.has(y)&&f(y)&&(u=!0,c.add(y))});return h===100&&D("Warning: nested subgraph layout reached iteration cap; potential cyclic dependency"),a.forEach(m=>{const y=i.node(m.id);if(y){const g=Ke(m.label,m.shape);l.set(m.id,{x:y.x-g.width/2,y:y.y-g.height/2}),D(`Positioned standalone node ${m.id} at (${y.x-g.width/2}, ${y.y-g.height/2})`)}else D(`Warning: No position for standalone node ${m.id} in meta-graph`)}),{subgraphPositions:d,standalonePositions:l}}function fr(e,t,n,o,r,i,s){const a=[];D("Creating React Flow elements");function d(h){const m={rect:["#1C2336","#3D5EA8"],diamond:["#1C2336","#3D5EA8"],circle:["#1C2336","#3D5EA8"],stadium:["#1C2336","#3D5EA8"],round:["#1C2336","#3D5EA8"]}[h]||["#1C2336","#3D5EA8"];return{backgroundColor:m[0],borderColor:m[1]}}function l(h){const m=[{bg:"rgba(100, 181, 246, 0.08)",border:"#64B5F6"},{bg:"rgba(129, 199, 132, 0.08)",border:"#81C784"},{bg:"rgba(186, 104, 200, 0.08)",border:"#BA68C8"},{bg:"rgba(255, 183, 77, 0.08)",border:"#FFB74D"},{bg:"rgba(240, 98, 146, 0.08)",border:"#F06292"}];return m[h%m.length]}const p=Bt(n);p.forEach((h,m)=>{const y=o.get(h.id),g=r.get(h.id);if(y&&g){const E=l(m);let w=g;if(y.parentId){const N=r.get(y.parentId);N&&(w={x:g.x-N.x,y:g.y-N.y})}a.push({id:`subgraph-${h.id}`,type:"group",position:w,data:{backgroundColor:E.bg,borderColor:E.border,childNodes:h.nodes,autoLayout:!0,componentFields:[me(h.title)]},style:{width:y.width,height:y.height,zIndex:0},selectable:!0,draggable:!0,connectable:!0,parentId:y.parentId?`subgraph-${y.parentId}`:void 0,extent:y.parentId?"parent":void 0,zIndex:y.parentId?1:0})}}),e.forEach(h=>{const m=d(h.shape),{imageUrl:y,cleanLabel:g}=Ft(h.label),{tag:E,displayLabel:w}=Zi(g),N=Vi(!!y,E);let T,x;if(h.subgraph){const k=o.get(h.subgraph),$=r.get(h.subgraph),P=k?.nodes.get(h.id);P&&$?(T={x:P.x-P.width/2,y:P.y-P.height/2},x=`subgraph-${h.subgraph}`,D(`Node ${h.id} positioned at (${T.x}, ${T.y}) within subgraph ${h.subgraph}`)):(T={x:0,y:0},D(`Warning: Missing layout data for node ${h.id} in subgraph ${h.subgraph}`))}else T=i.get(h.id)||{x:0,y:0},D(`Standalone node ${h.id} positioned at (${T.x}, ${T.y})`);const S=s==="LR"||s==="RL",b=S?nt.Right:nt.Bottom,v=S?nt.Left:nt.Top;let I=150,C=60;if(h.subgraph){const k=o.get(h.subgraph),$=k?.nodes.get(h.id);$&&(I=Math.max(20,Math.round($.width)),C=Math.max(20,Math.round($.height)))}else{const k=Ke(h.label,h.shape,!!y);I=Math.max(20,Math.round(k.width)),C=Math.max(20,Math.round(k.height))}let M;switch(N.toLowerCase()){case"image":M={src:y??""};break;case"shape":var A;M={shape:(A=tr[h.shape])!==null&&A!==void 0?A:"rectangle",componentFields:[me(w)],fill:m.backgroundColor,stroke:m.borderColor,strokeWidth:2};break;case"default":M={name:w,label:w,description:"",componentId:"file-note"};break;case"builder":M={componentName:"file-note",componentFields:[me(w),ke({label:"Label",data:w,type:L.TextInput}),ke({label:"Description",data:"",type:L.TextBox})]};break;case"text":M={componentFields:[ke({componentFieldId:"text",label:"Text",data:w,type:L.TextBox})]};break;case"code":M={componentFields:[me(w),ke({label:"Code",data:"",type:L.CodeEditor})]};break;case"table":M={componentFields:[me(w)],columns:["Task","Owner","Status","Due"],rows:[["Website revamp","Amara","In progress","May 12"],["Marketing sync","Liu","Blocked","May 15"]]};break;case"cloud":M={componentFields:[me(w)]};break;case"comment":M={componentFields:[me(w)]};break;default:M={name:w,label:w,description:"",componentId:"file-note"}}a.push({id:h.id,type:N,position:T,data:M,style:{width:I,height:C},sourcePosition:b,targetPosition:v,parentId:x,extent:x?"parent":void 0,draggable:!0,zIndex:1})});const f=new Map(e.map(h=>[h.id,h.subgraph])),c=t.filter(h=>h.isTargetSubgraph&&f.get(h.source)===h.target?(D(`Dropping edge ${h.source} -> ${h.target}: source already lives inside this subgraph`),!1):h.isSourceSubgraph&&f.get(h.target)===h.source?(D(`Dropping edge ${h.source} -> ${h.target}: target already lives inside this subgraph`),!1):!0),u=new Map;return p.forEach(h=>{const m=r.get(h.id);m&&u.set(`subgraph-${h.id}`,m)}),e.forEach(h=>{if(h.subgraph){const m=o.get(h.subgraph),y=r.get(h.subgraph),g=m?.nodes.get(h.id);g&&y&&u.set(h.id,{x:y.x+g.x,y:y.y+g.y})}else{const m=i.get(h.id);m&&u.set(h.id,m)}}),{nodes:a,edges:c.map((h,m)=>{const y={strokeWidth:2.5},g="smoothstep";switch(h.type){case"-->":case"->":break;case"---":y.strokeDasharray="8,4";break;case"-.-":y.strokeDasharray="4,4";break;case"==>":case"===>":y.strokeWidth=4;break}const E=h.isSourceSubgraph?`subgraph-${h.source}`:h.source,w=h.isTargetSubgraph?`subgraph-${h.target}`:h.target,N=s==="LR"||s==="RL";let T=N?"source-right":"source-bottom",x=N?"target-left":"target-top";const S=u.get(E),b=u.get(w);return S&&b&&(N?b.x<S.x&&(T="source-left",x="target-right"):b.y<S.y&&(T="source-top",x="target-bottom")),{id:`edge-${h.source}-${h.target}-${m}`,source:E,target:w,label:h.label,type:g,style:y,labelStyle:{fontSize:"12px",fontWeight:"500",color:"#E2E8F0",backgroundColor:"#1E293B",padding:"2px 6px"},markerEnd:{type:xe.ArrowClosed,width:20,height:20},sourceHandle:T,targetHandle:x,zIndex:0}})}}function pr(e,t,n,o){D("Starting graph layout with direction:",o),D(`Input: ${e.length} nodes, ${t.length} edges, ${n.length} subgraphs`);const r=sr(e,t,n,o),{subgraphPositions:i,standalonePositions:s}=hr(e,t,r,o);return lr(r,i,Bt(n)),fr(e,t,n,r,i,s,o)}function mr(e){return Rt.apply(this,arguments)}function Rt(){return Rt=Be(function*(e){D("Starting Mermaid to React Flow conversion"),D("Mermaid code:",e);const{nodes:t,edges:n,subgraphs:o,direction:r}=er(e);if(t.length===0)return D("No nodes found in Mermaid diagram"),{nodes:[],edges:[]};D(`Parsed ${t.length} nodes, ${n.length} edges, ${o.length} subgraphs`);const i=pr(t,n,o,r);return{nodes:i.nodes.map(s=>R(R({},s),{},{data:R(R({},s.data),{},{source:"mermaid"})})),edges:i.edges.map(s=>R(R({},s),{},{data:R(R({},s.data),{},{source:"mermaid"})}))}}),Rt.apply(this,arguments)}function gr(e,t){let n=1,o=0;for(const r of e){if(r.length>t){o>0&&(n+=1);const s=Math.ceil(r.length/t);n+=s-1,o=r.length-(s-1)*t;continue}const i=o===0?r.length:o+1+r.length;i>t?(n+=1,o=r.length):o=i}return n}function $n(e){const{MESSAGE_NODE_WIDTH:t,MESSAGE_NODE_HEIGHT:n,MESSAGE_MAX_WIDTH:o,MESSAGE_TARGET_WRAP_LINES:r,MESSAGE_CHAR_WIDTH:i,MESSAGE_LINE_HEIGHT:s,MESSAGE_HORIZONTAL_PADDING:a,MESSAGE_VERTICAL_PADDING:d}=De,l=e.trim();if(!l)return{width:t,height:n};if(l.includes(`
51
+ `)){const y=l.split(`
52
+ `).map(g=>$n(g));return{width:Math.max(...y.map(g=>g.width)),height:y.reduce((g,E)=>g+E.height-Number(d),Number(d))}}const p=l.split(/\s+/).filter(Boolean),f=Math.max(1,...p.map(y=>y.length)),c=Math.max(1,Math.ceil(l.length/r)),u=Math.max(c,f),h=Math.min(o,Math.max(t,a+u*i)),m=gr(p,Math.max(1,Math.floor((h-a)/i)));return{width:h,height:Math.max(n,m*s+d)}}const _t=[{token:"<<-->>",lineStyle:"dashed",arrowType:"bidirectional"},{token:"<<->>",lineStyle:"solid",arrowType:"bidirectional"},{token:"--|\\",lineStyle:"dashed",arrowType:"half",half:"top"},{token:"-|\\",lineStyle:"solid",arrowType:"half",half:"top"},{token:"--|/",lineStyle:"dashed",arrowType:"half",half:"bottom"},{token:"-|/",lineStyle:"solid",arrowType:"half",half:"bottom"},{token:"/|--",lineStyle:"dashed",arrowType:"half",half:"top",reversed:!0},{token:"/|-",lineStyle:"solid",arrowType:"half",half:"top",reversed:!0},{token:"\\--",lineStyle:"dashed",arrowType:"half",half:"bottom",reversed:!0},{token:"\\-",lineStyle:"solid",arrowType:"half",half:"bottom",reversed:!0},{token:"//--",lineStyle:"dashed",arrowType:"stick",half:"top",reversed:!0},{token:"//-",lineStyle:"solid",arrowType:"stick",half:"top",reversed:!0},{token:"--//",lineStyle:"dashed",arrowType:"stick",half:"bottom"},{token:"-//",lineStyle:"solid",arrowType:"stick",half:"bottom"},{token:"--\\",lineStyle:"dashed",arrowType:"stick",half:"top"},{token:"-\\",lineStyle:"solid",arrowType:"stick",half:"top"},{token:"-->>",lineStyle:"dashed",arrowType:"filled"},{token:"->>",lineStyle:"solid",arrowType:"filled"},{token:"--x",lineStyle:"dashed",arrowType:"cross"},{token:"-x",lineStyle:"solid",arrowType:"cross"},{token:"--)",lineStyle:"dashed",arrowType:"open"},{token:"-)",lineStyle:"solid",arrowType:"open"},{token:"-->",lineStyle:"dashed",arrowType:"none"},{token:"->",lineStyle:"solid",arrowType:"none"}];function yr(e){const t=_t.find(o=>o.lineStyle===e.lineStyle&&o.arrowType===e.arrowType&&o.half===e.half&&!!o.reversed==!!e.reversed);if(t)return t.token;const n=_t.find(o=>o.lineStyle===e.lineStyle&&o.arrowType===e.arrowType);return n?n.token:e.lineStyle==="dashed"?"-->>":"->>"}const vr=["loop","alt","opt","par","critical","break","rect"],br=["else","and","option"],wr=new Set(`transparent aliceblue antiquewhite aqua aquamarine azure beige bisque black blanchedalmond blue
53
53
  blueviolet brown burlywood cadetblue chartreuse chocolate coral cornflowerblue cornsilk crimson cyan
54
54
  darkblue darkcyan darkgoldenrod darkgray darkgreen darkgrey darkkhaki darkmagenta darkolivegreen
55
55
  darkorange darkorchid darkred darksalmon darkseagreen darkslateblue darkslategray darkslategrey
@@ -64,14 +64,14 @@ import{_ as Qe}from"./index-5E1tJ7yK.js";import{o as re,r as Ue,s as _,a as gt,b
64
64
  paleturquoise palevioletred papayawhip peachpuff peru pink plum powderblue purple rebeccapurple red
65
65
  rosybrown royalblue saddlebrown salmon sandybrown seagreen seashell sienna silver skyblue slateblue
66
66
  slategray slategrey snow springgreen steelblue tan teal thistle tomato turquoise violet wheat white
67
- whitesmoke yellow yellowgreen`.split(/\s+/).filter(Boolean)),wr={amp:"&",lt:"<",gt:">",quot:'"',apos:"'",nbsp:" "};function we(e){return e.replace(/<br\s*\/?>/gi,`
68
- `).replace(/&#x([0-9a-f]+);/gi,(t,n)=>String.fromCodePoint(parseInt(n,16))).replace(/&#(\d+);/g,(t,n)=>String.fromCodePoint(parseInt(n,10))).replace(/&([a-z]+);/gi,(t,n)=>{const o=wr[n.toLowerCase()];return o===void 0?t:o}).trim()}function xr(e){for(let t=0;t<e.length;t++)for(const n of _t)if(e.startsWith(n.token,t))return{arrow:n,start:t,end:t+n.token.length}}function ln(e){const t=e.trim();if(!t)return{label:""};const n=t.match(/^(rgba?|hsla?)\s*\([^)]*\)/i);if(n)return{color:n[0],label:t.slice(n[0].length).trim()};const[o,...r]=t.split(/\s+/);return br.has(o.toLowerCase())?{color:o,label:r.join(" ")}:{label:t}}function dn(e){const t=e.trim(),n=t.indexOf("@{");let o,r,i,s;if(n===-1){const c=t.match(/^(.*?)\s+as\s+(.+)$/i);return o=(c?c[1]:t).trim(),r=c?we(c[2]):"",{id:o,name:r||o,alias:r||void 0,type:i}}o=t.slice(0,n).trim();const a=t.indexOf("}",n),d=a===-1?"":t.slice(n+1,a+1);r=a===-1?"":t.slice(a+1).trim();try{const c=JSON.parse(d);typeof c.type=="string"&&(i=c.type),typeof c.alias=="string"&&(s=c.alias)}catch{}const l=r.match(/^as\s+(.+)$/i),p=l?we(l[1]):void 0,f=p??(s&&we(s));return{id:o,name:f??o,alias:f,type:i}}function Er(e){const t=[],n=new Map,o=[],r=[],i=[],s=[],a=[],d=new Map,l=[],p=[];let f,c,u,h,m,g=0,y;function E(b,v={}){var I,C;const M=n.get(b);if(M)return v.alias!==void 0&&(M.alias=v.alias,M.name=v.alias),v.type!==void 0&&(M.type=v.type),M;const S={id:b,name:(I=v.name)!==null&&I!==void 0?I:b,alias:v.alias,index:t.length,type:(C=v.type)!==null&&C!==void 0?C:"participant",links:[],boxId:f?.id};return t.push(S),n.set(b,S),f&&f.participants.push(b),S}function w(b,v){var I;const C=(I=d.get(b))!==null&&I!==void 0?I:[];C.push(v),d.set(b,C)}function A(b,v){const I=d.get(b);if(!I||I.length===0)return;const C=I.pop();a.push({participant:b,startRow:C,endRow:v})}const T=e.split(`
67
+ whitesmoke yellow yellowgreen`.split(/\s+/).filter(Boolean)),xr={amp:"&",lt:"<",gt:">",quot:'"',apos:"'",nbsp:" "};function we(e){return e.replace(/<br\s*\/?>/gi,`
68
+ `).replace(/&#x([0-9a-f]+);/gi,(t,n)=>String.fromCodePoint(parseInt(n,16))).replace(/&#(\d+);/g,(t,n)=>String.fromCodePoint(parseInt(n,10))).replace(/&([a-z]+);/gi,(t,n)=>{const o=xr[n.toLowerCase()];return o===void 0?t:o}).trim()}function Er(e){for(let t=0;t<e.length;t++)for(const n of _t)if(e.startsWith(n.token,t))return{arrow:n,start:t,end:t+n.token.length}}function dn(e){const t=e.trim();if(!t)return{label:""};const n=t.match(/^(rgba?|hsla?)\s*\([^)]*\)/i);if(n)return{color:n[0],label:t.slice(n[0].length).trim()};const[o,...r]=t.split(/\s+/);return wr.has(o.toLowerCase())?{color:o,label:r.join(" ")}:{label:t}}function un(e){const t=e.trim(),n=t.indexOf("@{");let o,r,i,s;if(n===-1){const c=t.match(/^(.*?)\s+as\s+(.+)$/i);return o=(c?c[1]:t).trim(),r=c?we(c[2]):"",{id:o,name:r||o,alias:r||void 0,type:i}}o=t.slice(0,n).trim();const a=t.indexOf("}",n),d=a===-1?"":t.slice(n+1,a+1);r=a===-1?"":t.slice(a+1).trim();try{const c=JSON.parse(d);typeof c.type=="string"&&(i=c.type),typeof c.alias=="string"&&(s=c.alias)}catch{}const l=r.match(/^as\s+(.+)$/i),p=l?we(l[1]):void 0,f=p??(s&&we(s));return{id:o,name:f??o,alias:f,type:i}}function Ir(e){const t=[],n=new Map,o=[],r=[],i=[],s=[],a=[],d=new Map,l=[],p=[];let f,c,u,h,m,y=0,g;function E(b,v={}){var I,C;const M=n.get(b);if(M)return v.alias!==void 0&&(M.alias=v.alias,M.name=v.alias),v.type!==void 0&&(M.type=v.type),M;const A={id:b,name:(I=v.name)!==null&&I!==void 0?I:b,alias:v.alias,index:t.length,type:(C=v.type)!==null&&C!==void 0?C:"participant",links:[],boxId:f?.id};return t.push(A),n.set(b,A),f&&f.participants.push(b),A}function w(b,v){var I;const C=(I=d.get(b))!==null&&I!==void 0?I:[];C.push(v),d.set(b,C)}function N(b,v){const I=d.get(b);if(!I||I.length===0)return;const C=I.pop();a.push({participant:b,startRow:C,endRow:v})}const T=e.split(`
69
69
  `);for(let b=0;b<T.length;b++){const v=T[b].replace(/%%.*$/,"").trim();if(!v||/^sequencediagram\b/i.test(v))continue;if(v.match(/^accDescr\s*\{$/i)){const O=[];for(b++;b<T.length&&!/^\s*\}\s*$/.test(T[b]);)O.push(T[b].trim()),b++;m=O.join(`
70
- `);continue}const I=v.match(/^title\s*:?\s*(.*)$/i);if(I){u=we(I[1]);continue}const C=v.match(/^accTitle\s*:\s*(.*)$/i);if(C){h=we(C[1]);continue}const M=v.match(/^accDescr\s*:\s*(.*)$/i);if(M){m=we(M[1]);continue}const S=v.match(/^autonumber(?:\s+(off|[\d.]+))?(?:\s+([\d.]+))?$/i);if(S){const[,O,X]=S;if(O?.toLowerCase()==="off"){c=void 0;continue}const ue=O===void 0?1:Number(O);c={start:ue,step:X===void 0?1:Number(X),next:ue,declaredStart:ue};continue}const k=v.match(/^box\b\s*(.*)$/i);if(k){const{color:O,label:X}=ln(k[1]),ue={id:`box-${s.length}`,label:we(X),color:O,participants:[]};s.push(ue),f=ue,p.push({kind:"box",id:ue.id});continue}if(/^end$/i.test(v)){const O=p.pop();if(O?.kind==="box"){f=void 0;continue}const X=l.pop();if(X){X.endRow=g-1;const ue=X.sections[X.sections.length-1];ue&&(ue.endRow=g-1)}continue}const $=yr.find(O=>new RegExp(`^${O}\\b`,"i").test(v));if($){const O=v.slice($.length).trim(),{color:X,label:ue}=$==="rect"?ln(O):{color:void 0,label:O},fe=l[l.length-1],Ye={id:`block-${i.length}`,type:$,label:we(ue),color:X,sections:[{label:we(ue),startRow:g,endRow:g}],startRow:g,endRow:g,depth:l.length,parentId:fe?.id};i.push(Ye),l.push(Ye),p.push({kind:"block",id:Ye.id});continue}const P=vr.find(O=>new RegExp(`^${O}\\b`,"i").test(v));if(P){const O=l[l.length-1];if(O){const X=O.sections[O.sections.length-1];X&&(X.endRow=g-1),O.sections.push({label:we(v.slice(P.length).trim()),startRow:g,endRow:g})}continue}const B=v.match(/^create\s+(participant|actor)\s+(.+)$/i);if(B){y={type:B[1].toLowerCase(),rest:B[2]};continue}const U=v.match(/^destroy\s+(.+)$/i);if(U){const O=E(U[1].trim());O.destroyedAtRow=g;continue}const q=v.match(/^(participant|actor)\s+(.+)$/i);if(q){var x;const O=q[1].toLowerCase(),X=dn(q[2]);E(X.id,{name:X.name,alias:X.alias,type:(x=X.type)!==null&&x!==void 0?x:O});continue}const z=v.match(/^(activate|deactivate)\s+(.+)$/i);if(z){const O=E(z[2].trim());z[1].toLowerCase()==="activate"?w(O.id,g):A(O.id,g-1);continue}const Y=v.match(/^note\s+(right of|left of|over)\s+([^:]+):\s*(.*)$/i);if(Y){const O=Y[2].split(",").map(X=>X.trim()).filter(Boolean);O.forEach(X=>E(X)),r.push({placement:Y[1].toLowerCase(),participants:O.map(X=>X),text:we(Y[3]),rowIndex:g}),g++;continue}const G=v.match(/^links\s+([^:]+):\s*(\{.*\})$/i);if(G){const O=E(G[1].trim());try{const X=JSON.parse(G[2]);for(const[ue,fe]of Object.entries(X))O.links.push({label:ue,url:fe})}catch{}continue}const te=v.match(/^link\s+([^:]+):\s*(.+?)\s*@\s*(\S+)$/i);if(te){E(te[1].trim()).links.push({label:te[2].trim(),url:te[3].trim()});continue}const Q=v.indexOf(":"),ne=xr(Q===-1?v:v.slice(0,Q));if(!ne||Q===-1)continue;const{arrow:H,start:J,end:ie}=ne;let se=v.slice(0,J).trim(),oe=v.slice(ie,Q).trim();const Ae=we(v.slice(Q+1)),Ie=se.endsWith("()");Ie&&(se=se.slice(0,-2).trim());let Ce=!1,F=!1,W=!1,ae=!0;for(;ae;)ae=!1,oe.startsWith("+")&&(Ce=!0,oe=oe.slice(1).trim(),ae=!0),oe.startsWith("-")&&(F=!0,oe=oe.slice(1).trim(),ae=!0),oe.startsWith("()")&&(W=!0,oe=oe.slice(2).trim(),ae=!0);if(!se||!oe)continue;if(E(se),y){var N;const O=dn(y.rest),X=E(O.id,{name:O.name,alias:O.alias,type:(N=O.type)!==null&&N!==void 0?N:y.type});X.createdAtRow=g,y=void 0,oe=O.id}const Te=E(oe),he={from:se,to:Te.id,label:Ae,lineStyle:H.lineStyle,arrowType:H.arrowType,rowIndex:g};H.half&&(he.half=H.half),H.reversed&&(he.reversed=!0),Ie&&(he.centralSource=!0),W&&(he.centralTarget=!0),Ce&&(he.activates=!0),F&&(he.deactivates=!0),c&&(he.sequenceNumber=c.next,c.next=Number((c.next+c.step).toFixed(2))),Ce&&w(Te.id,g),F&&A(se,g),o.push(he),g++}for(const[b,v]of d)for(const I of v)a.push({participant:b,startRow:I,endRow:Math.max(g-1,I)});for(const b of l){b.endRow=g-1;const v=b.sections[b.sections.length-1];v&&(v.endRow=g-1)}return a.sort((b,v)=>b.startRow-v.startRow),R(R(R(R({participants:t,messages:o,notes:r,blocks:i,boxes:s,activations:a},c?{autonumber:{start:c.declaredStart,step:c.step}}:{}),u===void 0?{}:{title:u}),h===void 0?{}:{accTitle:h}),m===void 0?{}:{accDescr:m})}const Ir={loop:{border:"#64748B",background:"rgba(100, 116, 139, 0.06)"},alt:{border:"#6366F1",background:"rgba(99, 102, 241, 0.06)"},opt:{border:"#0EA5E9",background:"rgba(14, 165, 233, 0.06)"},par:{border:"#22C55E",background:"rgba(34, 197, 94, 0.06)"},critical:{border:"#F97316",background:"rgba(249, 115, 22, 0.06)"},break:{border:"#EF4444",background:"rgba(239, 68, 68, 0.06)"},rect:{border:"transparent",background:"rgba(148, 163, 184, 0.10)"}};function Ee(e){const{COLUMN_WIDTH:t}=De;return e*t+t/2}function un(e,t,n){return`row-${e}-${t}-${n}`}function Tr(e){const{ROW_HEIGHT:t,ROW_VERTICAL_PADDING:n,HEADER_HEIGHT:o}=De,{BLOCK_TOP_PADDING:r,BLOCK_BOTTOM_PADDING:i,BLOCK_SECTION_PADDING:s,BLOCK_FRAME_GAP:a}=De,d=[...e.messages.map(x=>({kind:"message",parserRow:x.rowIndex,message:x})),...e.notes.map(x=>({kind:"note",parserRow:x.rowIndex,note:x}))].sort((x,N)=>x.parserRow-N.parserRow),l=new Map,p=new Map,f=new Map;let c=0;for(const x of d){const N=x.kind==="message"?x.message.label:x.note.text;l.set(x.parserRow,Mn(N)),p.set(x.parserRow,c);const b=x.kind==="message"&&x.message.from===x.message.to?2:1;f.set(x.parserRow,b),c+=b}const u=Math.max(c,1),h=Math.max(t,...[...l.values()].map(x=>x.height+n));function m(x){for(let N=x;N<x+d.length+1;N++){const b=p.get(N);if(b!==void 0)return b}return u}function g(x){for(let N=x;N>=0;N--){const b=p.get(N);if(b!==void 0)return b+f.get(N)-1}return 0}const y=new Array(u+1).fill(0),E=new Array(u+1).fill(0);for(const x of e.blocks)if(!(x.endRow<x.startRow)){y[m(x.startRow)]+=r+a,E[g(x.endRow)]+=i;for(const N of x.sections.slice(1))N.endRow<N.startRow||(y[m(N.startRow)]+=s)}const w=[];let A=o;for(let x=0;x<u;x++)A+=y[x],w.push(A),A+=h+E[x];const T=A;return{items:d,sizes:l,rowHeight:h,totalRows:u,rowTops:w,rowCenters:w.map(x=>x+h/2),contentHeight:T,padBefore:y,padAfter:E,toLayoutRow:m,toLastLayoutRow:g,layoutRowByParserRow:p}}function $n(e,t,n){const{SELF_LOOP_OFFSET:o}=De;return e===t?Ee(e)+o:(Ee(e)+Ee(t))/2-n/2}function Dn(e,t,n){const{NOTE_OFFSET:o,COLUMN_WIDTH:r}=De,i=e.participants.map(l=>n.get(l)).filter(l=>l!==void 0);if(i.length===0)return;const s=t.sizes.get(e.rowIndex),a=Ee(i[0]),d=Ee(i[i.length-1]);if(e.placement==="right of")return{x:a+o,width:s.width};if(e.placement==="left of")return{x:a-o-s.width,width:s.width};if(i.length>1){const l=Math.max(s.width,d-a+r/2);return{x:(a+d)/2-l/2,width:l}}return{x:a-s.width/2,width:s.width}}function Nr(e,t,n,o){if(e.endRow<e.startRow)return;const{BLOCK_SIDE_PADDING:r,BLOCK_TOP_PADDING:i,BLOCK_BOTTOM_PADDING:s,BLOCK_CONTENT_INSET:a}=De,d=new Set,l=[],p=[];function f(v){return a*(t.blocks.filter(I=>I.depth>e.depth&&I.endRow>=I.startRow&&I.startRow<=v&&I.endRow>=v).length+1)}for(const v of t.messages){if(v.rowIndex<e.startRow||v.rowIndex>e.endRow)continue;const I=o.get(v.from),C=o.get(v.to);if(I!==void 0&&d.add(I),C!==void 0&&d.add(C),I===void 0||C===void 0)continue;const M=n.sizes.get(v.rowIndex).width,S=$n(I,C,M),k=f(v.rowIndex);l.push(S-k),p.push(S+M+k)}for(const v of t.notes){if(v.rowIndex<e.startRow||v.rowIndex>e.endRow)continue;v.participants.forEach(M=>{const S=o.get(M);S!==void 0&&d.add(S)});const I=Dn(v,n,o);if(I===void 0)continue;const C=f(v.rowIndex);l.push(I.x-C),p.push(I.x+I.width+C)}d.size===0&&t.participants.forEach(v=>d.add(v.index));const c=Math.min(...d),u=Math.max(...d),h=n.toLayoutRow(e.startRow),m=n.toLastLayoutRow(e.endRow),g=Math.max(a,r-e.depth*a),y=t.blocks.filter(v=>v.id!==e.id&&v.depth>e.depth),E=y.filter(v=>v.endRow>=v.startRow&&n.toLayoutRow(v.startRow)===h).length,w=y.filter(v=>v.endRow>=v.startRow&&n.toLastLayoutRow(v.endRow)===m).length,A=Math.min(Ee(c)-g,...l),T=Math.max(Ee(u)+g,...p)-A,x=n.rowTops[h]-i*(E+1),N=n.rowTops[m]+n.rowHeight+s*(w+1)-x,b=Ir[e.type];return{id:`sequence-block-${e.id}`,type:"group",position:{x:A,y:x},width:T,height:N,zIndex:Math.min(-1,-10+e.depth),selectable:!0,data:{source:"mermaid",backgroundColor:b.background,borderColor:b.border,autoLayout:!1,sequenceBlock:{type:e.type,label:e.label,color:e.color,depth:e.depth,startRow:h,endRow:m,sections:e.sections.map(v=>({label:v.label,startRow:n.toLayoutRow(v.startRow),endRow:n.toLastLayoutRow(v.endRow)}))},componentFields:[me(e.label?`${e.type} ${e.label}`:e.type)]},style:{width:T,height:N}}}function Sr(e,t,n){const o=Dn(e,t,n);if(o===void 0)return;const{x:r,width:i}=o,s=t.sizes.get(e.rowIndex),a=t.toLayoutRow(e.rowIndex);return{id:`note-${e.rowIndex}`,type:"shape",position:{x:r,y:t.rowCenters[a]-s.height/2},width:i,height:s.height,data:{source:"mermaid",shape:"rectangle",fill:"#FEF3C7",stroke:"#F59E0B",strokeWidth:1,textColor:"#1F2937",sequenceNote:{placement:e.placement,participants:e.participants,row:a},componentFields:[me(e.text)]},style:{width:i,height:s.height}}}function hn(e,t){const n={width:16,height:16,color:t};return e.arrowType==="none"?{}:e.arrowType==="filled"?{markerEnd:R({type:xe.ArrowClosed},n)}:e.arrowType==="bidirectional"?{markerStart:R({type:xe.ArrowClosed},n),markerEnd:R({type:xe.ArrowClosed},n)}:e.reversed?{markerStart:R({type:xe.Arrow},n)}:{markerEnd:R({type:xe.Arrow},n)}}function Ar(e){const t=Er(e),{PARTICIPANT_NODE_WIDTH:n,COLUMN_WIDTH:o,BOX_TOP_INSET:r,BOX_BOTTOM_PADDING:i,BLOCK_SIDE_PADDING:s}=De,a=Tr(t),d=new Map(t.participants.map(c=>[c.id,c.index])),l=[],p=[];for(const c of t.boxes){var f;const u=c.participants.map(E=>d.get(E)).filter(E=>E!==void 0);if(u.length===0)continue;const h=Math.min(...u),m=Math.max(...u),g=Ee(h)-o/2+8,y=Ee(m)-Ee(h)+o-16;l.push({id:`sequence-box-${c.id}`,type:"group",position:{x:g,y:-r},width:y,height:a.contentHeight+r+i,zIndex:-20,data:{source:"mermaid",backgroundColor:(f=c.color)!==null&&f!==void 0?f:"rgba(148, 163, 184, 0.08)",borderColor:"#94A3B8",autoLayout:!1,sequenceBox:{label:c.label,participants:c.participants},componentFields:[me(c.label)]},style:{width:y,height:a.contentHeight+r+i}})}for(const c of t.blocks){const u=Nr(c,t,a,d);u&&l.push(u)}for(const c of t.participants){const u=t.activations.filter(h=>h.participant===c.id).map(h=>({startRow:a.toLayoutRow(h.startRow),endRow:a.toLastLayoutRow(h.endRow)}));l.push({id:`participant-${c.id}`,type:"sequenceParticipant",position:{x:Ee(c.index)-n/2,y:0},data:R(R(R({source:"mermaid",label:c.name,participantType:c.type,rowCount:a.totalRows,rowHeight:a.rowHeight,rowYs:a.rowCenters,lifelineHeight:a.contentHeight,activations:u,links:c.links},c.createdAtRow===void 0?{}:{lifelineStartRow:a.toLayoutRow(c.createdAtRow)}),c.destroyedAtRow===void 0?{}:{lifelineEndRow:a.toLastLayoutRow(c.destroyedAtRow)}),{},{componentFields:[me(c.name)]})})}for(const c of t.notes){const u=Sr(c,a,d);u&&l.push(u)}for(const c of t.messages){const u=d.get(c.from),h=d.get(c.to);if(u===void 0||h===void 0)continue;const m=u===h,g=u<h,y=a.sizes.get(c.rowIndex),E=a.toLayoutRow(c.rowIndex),w=$n(u,h,y.width),A=`message-${c.rowIndex}`;l.push({id:A,type:"shape",position:{x:w,y:a.rowCenters[E]-y.height/2},width:y.width,height:y.height,data:R(R({source:"mermaid",shape:"rectangle",fill:"#1E293B",stroke:"#475569",strokeWidth:1},c.sequenceNumber===void 0?{}:{sequenceNumber:c.sequenceNumber}),{},{componentFields:[me(c.label)]}),style:{width:y.width,height:y.height}});const T="#94a3b8",x=R({stroke:T,strokeWidth:2},c.lineStyle==="dashed"?{strokeDasharray:"4 4"}:{}),N=g||m?"right":"left",b=m?"right":g?"left":"right";p.push(R({id:`edge-${c.rowIndex}-a`,source:`participant-${c.from}`,target:A,sourceHandle:un(E,N,"source"),targetHandle:m?"target-top":N==="right"?"target-left":"target-right",type:"smoothstep",style:x,data:R(R(R({source:"mermaid",arrowType:c.arrowType},c.half?{half:c.half}:{}),c.reversed?{reversed:!0}:{}),c.centralSource?{centralSource:!0}:{})},c.reversed?hn(c,T):{})),p.push(R({id:`edge-${c.rowIndex}-b`,source:A,target:`participant-${c.to}`,sourceHandle:m?"source-bottom":g?"source-right":"source-left",targetHandle:un(E+(m?1:0),b,"target"),type:"smoothstep",style:x,data:R(R({source:"mermaid",arrowType:c.arrowType},c.half?{half:c.half}:{}),c.centralTarget?{centralTarget:!0}:{})},c.reversed?{}:hn(c,T)))}return t.title&&l.push({id:"sequence-title",type:"text",position:{x:Ee(0)-o/2,y:-r-s},data:{source:"mermaid",componentFields:[ke({componentFieldId:"text",label:"Text",type:L.TextBox,data:t.title,isReadonly:!0})]}}),{nodes:l,edges:p}}no.initialize({startOnLoad:!1,theme:"dark",flowchart:{htmlLabels:!1,curve:"linear"}});function Cr(e){const t=e.split(`
71
- `);for(const n of t){const o=n.trim().toLowerCase();if(o.startsWith("sequencediagram"))return"sequence";if(o.startsWith("c4"))return"c4";if(o.startsWith("flowchart")||o.startsWith("graph"))return"flowchart"}return"flowchart"}function kr(e){return Mt.apply(this,arguments)}function Mt(){return Mt=Be(function*(e){try{const t=Cr(e);return t==="sequence"?Ar(e):t==="c4"?ji(e):pr(e)}catch(t){return console.error("Error converting Mermaid to React Flow:",t),{nodes:[],edges:[]}}}),Mt.apply(this,arguments)}const Rr=new Set(["rectangle","rounded-rect","ellipse","diamond","triangle","parallelogram","trapezoid","hexagon","document","cylinder","delay","off-page-connector","display","collate","sort","terminator","or","database","multiple-documents","subroutine","manual-input","summing-junction","internal-storage"]),_r=new Set(Object.values(L)),Mr=32,$r=new Set(["componentFields","shape","fill","stroke","strokeWidth","strokeStyle","borderRadius","borderAnimationEnabled","strokeAnimation","src","animatedIcon","iconSrc","componentId","serviceTable","title","columns","rows","name","label","value","cloud","service","childNodes"]);function it(e){return _r.has(e)}function ve(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return e}function j(e){if(typeof e!="string")return;const t=e.trim();if(t)return t}function Dr(e){const t=ve(e);if(t&&!(typeof t.x!="number"||!Number.isFinite(t.x))&&!(typeof t.y!="number"||!Number.isFinite(t.y)))return{x:t.x,y:t.y}}function Ze(e){if(!Array.isArray(e)||e.length!==1)return e;const t=ve(e[0]);return t?"value"in t?t.value:t:e}function ct(e,t){return e.find(n=>{var o;return((o=j(n.label))===null||o===void 0?void 0:o.toLowerCase())===t.toLowerCase()&&j(n.type)})}function lt(e,t){const n=ct(e,t);if(n)return j(Ze(n.data))}function wt(e){return typeof e=="string"?e.trim().length===0:e==null}function On(e){if(typeof e!="string"||!e.trim())return;const t=e.replaceAll(","," ").replace(/\s+/g," ").trim();return t==="1 2"?"dotted":t==="4 2"||t==="4 4"||t==="8 4"?"dashed":"solid"}function fn(e){if(typeof e=="string")return{type:e};const t=ve(e);if(!t)return;const n=j(t.type);if(!n)return;const o=j(t.color);return o?{type:n,color:o}:{type:n}}function Or(e){return e.replaceAll('"','\\"')}function Lr(e){return!(e.length>Mr||e.includes(`
72
- `)||e.includes("\r"))}function Pr(e,t){const n={},o=new Map;for(const a of e){var r,i,s;const d=t.get(a.source),l=t.get(a.target);if(!d||!l)continue;const p=`${d}-${l}`,f=(r=o.get(p))!==null&&r!==void 0?r:0;o.set(p,f+1);const c={},u=j(a.type);u&&(c.type=u);const h=j(a.sourceHandle);h&&(c.sourceHandle=h);const m=j(a.targetHandle);m&&(c.targetHandle=m);const g=j(a.label);g&&(c.label=g);const y=(i=ve(a.style))!==null&&i!==void 0?i:{},E={},w=j(y.stroke);w&&(E.stroke=w),typeof y.strokeWidth=="number"&&(E.strokeWidth=y.strokeWidth);const A=On(y.strokeDasharray);A&&(E.strokeStyle=A),typeof a.animated=="boolean"&&(E.borderAnimationEnabled=a.animated),Object.keys(E).length>0&&(c.style=E);const T=fn(a.markerStart);T&&(c.markerStart=T);const x=fn(a.markerEnd);x&&(c.markerEnd=x);const N=(s=ve(a.data))!==null&&s!==void 0?s:{};Object.keys(N).length>0&&(c.___internal=N),Object.keys(c).length>0&&(f===0?n[p]=c:n[`${p}#${f}`]=c)}return n}function Fr(e,t){const n={};for(const r of e){var o;const i=(o=ve(r.data))!==null&&o!==void 0?o:{},s=Array.isArray(i.childNodes)?i.childNodes.map(d=>typeof d=="string"?t.get(d):void 0).filter(d=>d!==void 0):[],a=lt(Array.isArray(i.componentFields)?i.componentFields.map(d=>ve(d)).filter(d=>d!==void 0):[],"Name");!a&&s.length===0||(n[r.id]={name:a??void 0,nodes:s})}return n}function Br(e,t){const n={};for(const a of e){var o,r,i,s;const d=t.get(a.id);if(!d)continue;const l=(o=ve(a.data))!==null&&o!==void 0?o:{},p=(r=ve(a.style))!==null&&r!==void 0?r:{},f=Array.isArray(l.componentFields)?l.componentFields.map(F=>ve(F)).filter(F=>F!==void 0):[],c={},u=j(a.type);u&&(c.type=u);const h=ct(f,"Name"),m=h?Ze(h.data):void 0,g=j(m);g&&(c.name=g);const y=u==="text"?ct(f,"Text"):void 0,E=y?Ze(y.data):void 0,w=j(E);u==="text"&&w&&(c.value=w);const A=u==="code"?ct(f,"Code"):void 0,T=A?Ze(A.data):void 0,x=j(T);u==="code"&&x&&(c.value=x);const N=j(l.src);N&&(c.src=N);const b=j(l.animatedIcon);b&&(c.animatedIcon=b);const v=j(l.cloud);v&&(c.cloud=v);const I=j(l.service);I&&(c.service=I);const C=j(l.componentId);C&&(c.componentId=C);const M=j(l.shape);M&&Rr.has(M)&&(c.shape=M);const S={},k=typeof a.width=="number"?a.width:typeof p.width=="number"?p.width:void 0;typeof k=="number"&&(S.width=k);const $=typeof a.height=="number"?a.height:typeof p.height=="number"?p.height:void 0;typeof $=="number"&&(S.height=$);const P=(i=j(l.fill))!==null&&i!==void 0?i:j(p.fill);P&&(S.fill=P);const B=(s=j(l.stroke))!==null&&s!==void 0?s:j(p.stroke);B&&(S.stroke=B);const U=typeof l.strokeWidth=="number"?l.strokeWidth:typeof p.strokeWidth=="number"?p.strokeWidth:void 0;typeof U=="number"&&(S.strokeWidth=U);const q=typeof l.borderRadius=="number"?l.borderRadius:typeof p.borderRadius=="number"?p.borderRadius:void 0;typeof q=="number"&&(S.borderRadius=q);const z=j(l.strokeStyle);if(z==="solid"||z==="dashed"||z==="dotted")S.strokeStyle=z;else{const F=On(p.strokeDasharray);F&&(S.strokeStyle=F)}const Y=typeof l.borderAnimationEnabled=="boolean"?l.borderAnimationEnabled:l.strokeAnimation==="dash"?!0:void 0;typeof Y=="boolean"&&(S.borderAnimationEnabled=Y),Object.keys(S).length>0&&(c.style=S);const G=Array.isArray(l.columns)?l.columns.filter(F=>typeof F=="string"):void 0,te=Array.isArray(l.rows)?l.rows.map(F=>Array.isArray(F)?F.filter(W=>typeof W=="string"):void 0).filter(F=>F!==void 0):void 0;(G||te)&&(c.table={columns:G??[],rows:te??[]});const Q=ve(l.serviceTable),ne=j(Q?.serviceName),H=j(Q?.databaseName),J=j(Q?.tableName);ne&&H&&J&&(c.dbConfig={serviceName:ne,databaseName:H,tableName:J});const ie={};for(const F of f){const W=j(F.label),ae=j(F.type);if(!W||!ae||!it(ae))continue;const Te=ae,he=W.toLowerCase();if(he==="name"||u==="text"&&he==="text"||u==="code"&&he==="code")continue;const O=Array.isArray(F.options)?F.options.filter(X=>typeof X=="string"):void 0;ie[W]={type:Te,value:Ze(F.data),options:O&&O.length>0?O:void 0}}if(h&&!g&&wt(m)){const F=j(h.type);if(F&&it(F)){const W=Array.isArray(h.options)?h.options.filter(ae=>typeof ae=="string"):void 0;ie.Name={type:F,value:"",options:W&&W.length>0?W:void 0}}}if(y&&!w&&wt(E)){const F=j(y.type);if(F&&it(F)){const W=Array.isArray(y.options)?y.options.filter(ae=>typeof ae=="string"):void 0;ie.Text={type:F,value:"",options:W&&W.length>0?W:void 0}}}if(A&&!x&&wt(T)){const F=j(A.type);if(F&&it(F)){const W=Array.isArray(A.options)?A.options.filter(ae=>typeof ae=="string"):void 0;ie.Code={type:F,value:"",options:W&&W.length>0?W:void 0}}}Object.keys(ie).length>0&&(c.data=ie);const se=Dr(a.position);se&&(c.___position=se);const oe=Object.entries(l).reduce((F,[W,ae])=>($r.has(W)||(F[W]=ae),F),{});u==="builder"&&Array.isArray(l.componentFields)&&(oe.componentFields=l.componentFields);const Ae=j(l.iconSrc);Ae&&(oe.iconSrc=Ae);const Ie=j(l.label);Ie&&(oe.label=Ie);const Ce=j(l.cloud);Ce&&(oe.cloud=Ce),Object.keys(oe).length>0&&(c.___internal=oe),Object.keys(c).length>0&&(n[d]=c)}return n}function Gt(e,t,n,o){const r=Br(e,o),i=Pr(t,o),s=Fr(n,o),a={};return Object.keys(r).length>0&&(a.nodes=r),Object.keys(i).length>0&&(a.edges=i),Object.keys(s).length>0&&(a.groups=s),xn.parse(a)}function ze(e){var t;return(t=e.data)!==null&&t!==void 0?t:{}}function Ln(e){var t;return(t=e.data)!==null&&t!==void 0?t:{}}function Gr(e){return e.some(t=>t.type==="c4"||t.type==="c4Boundary")}function pn(e){if(e.type!=="c4"&&e.type!=="subDiagram")return!1;const t=ze(e).c4Kind;return t==="person"||t==="system"||t==="container"||t==="component"}function xt(e){return e.type==="c4Boundary"}function Se(e){return`"${e.replace(/"/g,'\\"').replace(/\r\n?/g,`
73
- `).replace(/\n/g,"<br/>").trim()}"`}function Hr(e){var t;const n=(t=e.data)===null||t===void 0?void 0:t.componentFields;if(Array.isArray(n)){var o;const i=n.find(a=>a?.componentFieldId==="name"),s=i==null||(o=i.data)===null||o===void 0||(o=o[0])===null||o===void 0?void 0:o.value;if(typeof s=="string"&&s.trim())return s}const r=ze(e).diagramName;return typeof r=="string"&&r?r:e.id}function Ur(e,t,n){let o;if(e==="person")o="Person";else if(e==="system")o="System";else if(e==="container")o="Container";else if(e==="component")o="Component";else throw new Error(`Unsupported C4 element kind: ${String(e)}`);return t==="db"&&(o+="Db"),t==="queue"&&(o+="Queue"),n&&(o+="_Ext"),o}function qr(e,t){return e==="enterprise"?"Enterprise_Boundary":e==="system"?"System_Boundary":e==="container"?"Container_Boundary":e==="node"?t==="nodeL"?"Node_L":t==="nodeR"?"Node_R":"Deployment_Node":"Boundary"}function Wr(e){if(e==="default")return"Rel";if(e==="bi")return"BiRel";if(e==="back")return"Rel_Back";if(e==="up")return"Rel_U";if(e==="down")return"Rel_D";if(e==="left")return"Rel_L";if(e==="right")return"Rel_R";throw new Error(`Unsupported C4 relationship direction: ${String(e)}`)}function Kr(e){const t=Ln(e).c4RelDirection;return t||(e.markerStart?"bi":e.sourceHandle==="source-top"?"up":e.sourceHandle==="source-bottom"?"down":e.sourceHandle==="source-left"?"left":e.sourceHandle==="source-right"?"right":"default")}function zr(e,t){const n=typeof e.label=="string"?e.label:"";if(!t)return n;const o=` [${t}]`;return n.endsWith(o)?n.slice(0,-o.length):n}function jr(e){for(const t of e){const n=ze(t).c4DiagramType;if(n)return n}return e.some(t=>ze(t).c4Kind==="component")?"C4Component":e.some(t=>ze(t).c4Kind==="container")?"C4Container":"C4Context"}function Et(e,t){const n=[...e];for(;n.length>t&&n[n.length-1]==="";)n.pop();return n}function Yr(e,t){const n=e.filter(l=>pn(l)||xt(l)),o=new Set(n.map(l=>l.id)),r=new Set(n.filter(l=>xt(l)).map(l=>l.id));function i(l){if(l.parentId&&r.has(l.parentId))return l.parentId}function s(l,p){const f=ze(l),c=Se(Hr(l));if(pn(l)){const g=[l.id,c];(f.c4Kind==="container"||f.c4Kind==="component")&&g.push(f.technology?Se(f.technology):""),g.push(f.description?Se(f.description):"");const y=Et(g,2),E=f.diagramId?`uig:${f.diagramId}`:f.link;return E&&y.push(`$link=${Se(E)}`),`${p}${Ur(f.c4Kind,f.c4Shape,f.isExternal===!0)}(${y.join(", ")})`}const u=qr(f.c4BoundaryKind,f.c4NodeType),h=[l.id,c];u==="Boundary"&&f.boundaryType&&h.push(Se(f.boundaryType)),f.c4BoundaryKind==="node"&&(h.push(f.boundaryType?Se(f.boundaryType):'"node"'),h.push(f.description?Se(f.description):""));const m=Et(h,2);return f.link&&m.push(`$link=${Se(f.link)}`),`${p}${u}(${m.join(", ")}) {`}function a(l,p){const f=[];for(const c of n)i(c)===l&&(f.push(s(c,p)),xt(c)&&(f.push(...a(c.id,`${p} `)),f.push(`${p}}`)));return f}const d=t.flatMap(l=>{if(!o.has(l.source)||!o.has(l.target))return[];const p=Ln(l),f=Kr(l),c=f==="back",u=[c?l.target:l.source,c?l.source:l.target,Se(zr(l,p.c4RelTechnology)),p.c4RelTechnology?Se(p.c4RelTechnology):"",p.c4RelDescription?Se(p.c4RelDescription):""];return`${Wr(f)}(${Et(u,3).join(", ")})`});return{mermaid:[jr(n),...a(void 0,""),...d].join(`
74
- `),nodeIdMap:new Map(n.map(l=>[l.id,l.id]))}}function _s(e,t){const{mermaid:n,nodeIdMap:o}=Yr(e,t);return{mermaid:n,context:Gt(e,t,[],o)}}function Xr(e){return e.some(t=>t.type==="sequenceParticipant")}function Pn(e,t){var n,o;const r=(n=e.data)===null||n===void 0?void 0:n.componentFields;if(!Array.isArray(r))return;const i=r.find(a=>a?.componentFieldId===t),s=i==null||(o=i.data)===null||o===void 0||(o=o[0])===null||o===void 0?void 0:o.value;if(typeof s=="string"&&s.trim())return s}function pt(e){var t;const n=Pn(e,"name");if(n!==void 0)return n;const o=(t=e.data)===null||t===void 0?void 0:t.label;return typeof o=="string"?o:""}function Fe(e){return e.replace(/#/g,"&#35;").replace(/\r\n?/g,`
75
- `).replace(/\n/g,"<br/>").trim()}function Qr(e,t,n){const o=e.replace(/[^A-Za-z0-9_]/g,"")||`P${t}`;let r=o,i=2;for(;n.has(r);)r=`${o}_${i}`,i++;return n.add(r),r}function Zr(e){const t=new Set;return e.filter(n=>n.type==="sequenceParticipant").sort((n,o)=>n.position.x-o.position.x).map((n,o)=>{var r,i,s,a,d;const l=pt(n)||`Participant ${o+1}`,p=(r=n.data)===null||r===void 0?void 0:r.participantType,f=(i=n.data)===null||i===void 0?void 0:i.activations,c=(s=n.data)===null||s===void 0?void 0:s.links,u=(a=n.data)===null||a===void 0?void 0:a.lifelineStartRow,h=(d=n.data)===null||d===void 0?void 0:d.lifelineEndRow;return R(R(R({nodeId:n.id,mermaidId:Qr(l,o,t),name:l,type:typeof p=="string"?p:"participant",links:Array.isArray(c)?c:[],activations:Array.isArray(f)?f:[]},typeof u=="number"?{createdRow:u}:{}),typeof h=="number"?{destroyedRow:h}:{}),{},{x:n.position.x})})}function Vr(e,t){const n=new Map;for(const o of e)t.has(o.source)&&n.set(o.target,R(R({},n.get(o.target)),{},{from:o.source})),t.has(o.target)&&n.set(o.source,R(R({},n.get(o.source)),{},{to:o.target}));return n}function Jr(e,t){var n,o,r,i,s,a,d,l,p;const f=(n=t==null||(o=t.data)===null||o===void 0?void 0:o.arrowType)!==null&&n!==void 0?n:e==null||(r=e.data)===null||r===void 0?void 0:r.arrowType,c=(i=t==null||(s=t.data)===null||s===void 0?void 0:s.half)!==null&&i!==void 0?i:e==null||(a=e.data)===null||a===void 0?void 0:a.half,u=(e==null||(d=e.data)===null||d===void 0?void 0:d.reversed)===!0;return gr(R(R({lineStyle:(t==null||(l=t.style)===null||l===void 0?void 0:l.strokeDasharray)!==void 0||(e==null||(p=e.style)===null||p===void 0?void 0:p.strokeDasharray)!==void 0?"dashed":"solid",arrowType:f??"filled"},c?{half:c}:{}),{},{reversed:u}))}function es(e,t,n){const o=(Array.isArray(e.participants)?e.participants.filter(i=>typeof i=="string"):[]).map(i=>t.find(s=>s.nodeId===`participant-${i}`)).filter(i=>!!i);if(o.length>0)return o.map(i=>i.nodeId);if(t.length===0)return[];const r=n.position.x+(Number(n.width)||0)/2;return[[...t].sort((i,s)=>Math.abs(i.x-r)-Math.abs(s.x-r))[0].nodeId]}function ts(e,t,n){const o=new Set(n.map(f=>f.nodeId)),r=Vr(t,o),i=[];for(const f of e){var s,a,d,l;if(o.has(f.id))continue;const c=(s=f.data)===null||s===void 0?void 0:s.sequenceNote;if(c){var p;i.push({item:{kind:"note",nodeId:f.id,text:pt(f),placement:(p=c.placement)!==null&&p!==void 0?p:"over",participantNodeIds:es(c,n,f)},y:f.position.y});continue}const u=r.get(f.id);if(!u?.from||!u.to)continue;const h=t.find(y=>y.target===f.id&&y.source===u.from),m=t.find(y=>y.source===f.id&&y.target===u.to),g=(a=f.data)===null||a===void 0?void 0:a.sequenceNumber;i.push({item:R({kind:"message",nodeId:f.id,fromNodeId:u.from,toNodeId:u.to,label:pt(f),token:Jr(h,m),centralSource:(h==null||(d=h.data)===null||d===void 0?void 0:d.centralSource)===!0,centralTarget:(m==null||(l=m.data)===null||l===void 0?void 0:l.centralTarget)===!0},typeof g=="number"?{sequenceNumber:g}:{}),y:f.position.y})}return i.sort((f,c)=>f.y-c.y).map(f=>f.item)}function ns(e){const t=[];for(const a of e){var n,o,r,i,s;const d=(n=a.data)===null||n===void 0?void 0:n.sequenceBlock;d&&typeof d.startRow=="number"&&typeof d.endRow=="number"&&t.push(R(R({nodeId:a.id,type:(o=d.type)!==null&&o!==void 0?o:"rect",label:(r=d.label)!==null&&r!==void 0?r:""},d.color?{color:d.color}:{}),{},{depth:(i=d.depth)!==null&&i!==void 0?i:0,startRow:d.startRow,endRow:d.endRow,sections:((s=d.sections)!==null&&s!==void 0?s:[]).filter(l=>typeof l.startRow=="number"&&typeof l.endRow=="number").map(l=>{var p;return{label:(p=l.label)!==null&&p!==void 0?p:"",startRow:l.startRow,endRow:l.endRow}})}))}return t}function os(e,t){const n=[];for(const s of e){var o,r,i;const a=(o=s.data)===null||o===void 0?void 0:o.sequenceBox;if(!a)continue;const d=(Array.isArray(a.participants)?a.participants.filter(u=>typeof u=="string"):[]).map(u=>t.find(h=>h.nodeId===`participant-${u}`)).filter(u=>!!u),l=s.position.x,p=s.position.x+(Number(s.width)||0),f=d.length>0?d:t.filter(u=>u.x>=l&&u.x<=p);if(f.length===0)continue;const c=(r=s.data)===null||r===void 0?void 0:r.backgroundColor;n.push(R(R({nodeId:s.id,label:(i=a.label)!==null&&i!==void 0?i:""},typeof c=="string"?{color:c}:{}),{},{participantNodeIds:f.map(u=>u.nodeId)}))}return n}function mn(e,t){const n=e.type==="participant"||e.type==="actor"?"":`@{ "type": "${e.type}" }`,o=e.mermaidId===e.name?"":` as ${Fe(e.name)}`;return`${t} ${e.mermaidId}${n}${o}`}function is(e,t){const n=new Map,o=Zr(e),r=ts(e,t,o),i=ns(e),s=os(e,o),a=new Map(o.map(v=>[v.nodeId,v]));for(const v of o)n.set(v.nodeId,`participant-${v.mermaidId}`);const d=new Map,l=new Map;let p=0;for(const v of r){d.set(v.nodeId,p);const I=v.kind==="message"&&v.fromNodeId===v.toNodeId;l.set(v.nodeId,I?p+1:p),p+=I?2:1}const f=p,c=["sequenceDiagram"],u=e.find(v=>v.id==="sequence-title");if(u){var h;const v=(h=Pn(u,"text"))!==null&&h!==void 0?h:pt(u);v&&(c.push(` title ${Fe(v)}`),n.set(u.id,"sequence-title"))}const m=new Map,g=new Map;for(const v of s){var y;const I=o.filter(C=>v.participantNodeIds.includes(C.nodeId));I.length!==0&&(m.set(I[0].nodeId,v),g.set(I[I.length-1].nodeId,((y=g.get(I[I.length-1].nodeId))!==null&&y!==void 0?y:0)+1))}let E=0;for(const v of o){var w;const I=m.get(v.nodeId);if(I){const M=I.color?`${I.color} `:"";c.push(` box ${M}${Fe(I.label)}`.trimEnd()),n.set(I.nodeId,`sequence-box-box-${E}`),E++}if(v.createdRow===void 0){const M=v.type==="actor"?"actor":"participant";c.push(` ${mn(v,M)}`)}const C=(w=g.get(v.nodeId))!==null&&w!==void 0?w:0;for(let M=0;M<C;M++)c.push(" end")}for(const v of o)for(const I of v.links)c.push(` link ${v.mermaidId}: ${I.label} @ ${I.url}`);const A=r.filter(v=>v.kind==="message"&&v.sequenceNumber!==void 0);if(A.length>0){const v=A[0].sequenceNumber,I=A.length>1?A[1].sequenceNumber-A[0].sequenceNumber:1;c.push(` autonumber ${v} ${I}`)}const T=[];let x=0,N=0;function b(){return" ".repeat(T.length+1)}for(let v=0;v<f;v++){const I=i.filter(S=>S.startRow===v).sort((S,k)=>S.depth-k.depth);for(const S of I){const k=Fe(S.label),$=S.type==="rect"&&S.color?`${S.color} `:"";c.push(`${b()}${S.type} ${$}${k}`.trimEnd()),n.set(S.nodeId,`sequence-block-block-${x}`),x++,T.push(S)}for(const[S,k]of T.entries())for(const $ of k.sections.slice(1)){if($.startRow!==v)continue;const P=k.type==="par"?"and":k.type==="critical"?"option":"else";c.push(`${" ".repeat(S+1)}${P} ${Fe($.label)}`.trimEnd())}const C=r.find(S=>d.get(S.nodeId)===v);if(C){for(const S of o){if(S.createdRow!==v)continue;const k=S.type==="actor"?"actor":"participant";c.push(`${b()}create ${mn(S,k)}`)}for(const S of o)S.destroyedRow===v&&c.push(`${b()}destroy ${S.mermaidId}`);for(const S of o)for(const k of S.activations)k.startRow===v&&c.push(`${b()}activate ${S.mermaidId}`);if(C.kind==="message"){const S=a.get(C.fromNodeId),k=a.get(C.toNodeId);if(S&&k){const $=C.centralSource?`${S.mermaidId}()`:S.mermaidId,P=C.centralTarget?`()${k.mermaidId}`:k.mermaidId;c.push(`${b()}${$}${C.token}${P}: ${Fe(C.label)}`),n.set(C.nodeId,`message-${N}`),N++}}if(C.kind==="note"){const S=C.participantNodeIds.map(k=>{var $;return($=a.get(k))===null||$===void 0?void 0:$.mermaidId}).filter(k=>k!==void 0);S.length>0&&(c.push(`${b()}Note ${C.placement} ${S.join(",")}: ${Fe(C.text)}`),n.set(C.nodeId,`note-${N}`),N++)}}const M=C?l.get(C.nodeId):v;for(const S of o)for(const k of S.activations)k.endRow===M&&c.push(`${b()}deactivate ${S.mermaidId}`);for(;T.length>0&&T[T.length-1].endRow<=M;)T.pop(),c.push(`${b()}end`)}for(;T.length>0;)T.pop(),c.push(`${b()}end`);return{mermaid:c.join(`
76
- `),nodeIdMap:n}}function Ms(e,t){const{mermaid:n,nodeIdMap:o}=is(e,t);return{mermaid:n,context:Gt(e,t,[],o)}}const rt=20;function rs(e){var t,n;return{id:(t=e.id)!==null&&t!==void 0?t:dt(),type:"group",position:{x:e.bounds.x,y:e.bounds.y},data:{childNodes:e.nodes,autoLayout:!0,componentFields:[me((n=e.name)!==null&&n!==void 0?n:"Group")]},style:{width:e.bounds.width+20,height:e.bounds.height+50}}}function ss(e,t,n){const o=n.map(d=>{var l,p,f,c,u,h,m,g,y,E;return{top:d.position.y,left:d.position.x,bottom:d.position.y+((l=(p=(f=d.height)!==null&&f!==void 0?f:(c=d.style)===null||c===void 0?void 0:c.height)!==null&&p!==void 0?p:(u=d.measured)===null||u===void 0?void 0:u.height)!==null&&l!==void 0?l:0),right:d.position.x+((h=(m=(g=d.width)!==null&&g!==void 0?g:(y=d.style)===null||y===void 0?void 0:y.width)!==null&&m!==void 0?m:(E=d.measured)===null||E===void 0?void 0:E.width)!==null&&h!==void 0?h:0)}}),r=Math.min(...o.map(d=>d.left)),i=Math.min(...o.map(d=>d.top)),s=Math.max(...o.map(d=>d.right)),a=Math.max(...o.map(d=>d.bottom));return rs({id:e,name:t,nodes:n.map(d=>d.id),bounds:{x:r-rt,y:i-rt,width:s-r+rt*2,height:a-i+rt*2}})}function as(e,t){return $t.apply(this,arguments)}function $t(){return $t=Be(function*(e,t){const n=e?.toLowerCase(),o=(n==="azure"?[...(yield Qe(()=>import("./__azure-icons.DgR1F6C6-DcLey4UX.js"),[])).default]:n==="aws"?[...(yield Qe(()=>import("./__aws-icons.agWBtDk7-CePtapr2.js"),[])).default]:[...(yield Qe(()=>import("./__aws-icons.agWBtDk7-CePtapr2.js"),[])).default,...(yield Qe(()=>import("./__azure-icons.DgR1F6C6-DcLey4UX.js"),[])).default]).find(r=>r.name.toLowerCase()===t.toLowerCase());return o?`/${o.cloud.toLowerCase()}-icons/${o.relativePath}`:null}),$t.apply(this,arguments)}function cs(e){return Dt.apply(this,arguments)}function Dt(){return Dt=Be(function*(e){const t=(yield Qe(()=>import("./__animated-nodes.DI0XYTuw-C-Pp0d4E.js"),[])).default.find(n=>n.name.toLowerCase()===e.toLowerCase());return t?`/animated-nodes/${t.fileName}`:null}),Dt.apply(this,arguments)}const Fn={databaseTableSQL:{width:500,height:400},table:{width:600,height:400},code:{width:300,height:400}},st=20,ls=20,ds=50,us=140,hs=80;function qe(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function It(e){var t,n,o,r,i,s,a,d,l,p,f,c;const u=e.type?Fn[e.type]:void 0;return{width:(t=(n=(o=(r=qe(e.width))!==null&&r!==void 0?r:qe((i=e.style)===null||i===void 0?void 0:i.width))!==null&&o!==void 0?o:qe((s=e.measured)===null||s===void 0?void 0:s.width))!==null&&n!==void 0?n:u?.width)!==null&&t!==void 0?t:0,height:(a=(d=(l=(p=qe(e.height))!==null&&p!==void 0?p:qe((f=e.style)===null||f===void 0?void 0:f.height))!==null&&l!==void 0?l:qe((c=e.measured)===null||c===void 0?void 0:c.height))!==null&&d!==void 0?d:u?.height)!==null&&a!==void 0?a:0}}function fs(e){const t=e.map(s=>{if(!s.type)return;const a=Fn[s.type];if(!a)return;const d=It(s);return{startX:s.position.x+a.width,startY:s.position.y+a.height,deltaX:Math.max(0,d.width-a.width),deltaY:Math.max(0,d.height-a.height)}}).filter(s=>!!s),n=e.map(s=>{var a;const d=(a=s.data)===null||a===void 0?void 0:a.childNodes;if(Array.isArray(d))return R({},s);const l=t.reduce((f,c)=>!c||c.deltaX===0||s.position.x<c.startX?f:f+c.deltaX,0),p=t.reduce((f,c)=>!c||c.deltaY===0||s.position.y<c.startY?f:f+c.deltaY,0);return l===0&&p===0?s:R(R({},s),{},{position:{x:s.position.x+l,y:s.position.y+p}})}),o=new Map(n.map(s=>[s.id,s])),r=n.filter(s=>{var a;return!Array.isArray((a=s.data)===null||a===void 0?void 0:a.childNodes)}).sort((s,a)=>s.position.y===a.position.y?s.position.x-a.position.x:s.position.y-a.position.y),i=[];for(const s of r){const a=i.find(d=>Math.abs(d[0].position.y-s.position.y)<=hs);if(a){a.push(s);continue}i.push([s])}for(const s of i){s.sort((a,d)=>a.position.x-d.position.x);for(let a=1;a<s.length;a+=1){const d=s[a-1],l=s[a],p=It(d),f=d.position.x+p.width+us;if(l.position.x>=f)continue;const c=R(R({},l),{},{position:{x:f,y:l.position.y}});s[a]=c,o.set(c.id,c)}}return n.map(s=>{var a,d;const l=(a=o.get(s.id))!==null&&a!==void 0?a:s,p=(d=s.data)===null||d===void 0?void 0:d.childNodes;if(!Array.isArray(p))return l;const f=p.map(y=>typeof y=="string"?o.get(y):void 0).filter(y=>!!y);if(f.length===0)return l;const c=f.map(y=>{const E=It(y);return{left:y.position.x,top:y.position.y,right:y.position.x+E.width,bottom:y.position.y+E.height}}),u=Math.min(...c.map(y=>y.left)),h=Math.min(...c.map(y=>y.top)),m=Math.max(...c.map(y=>y.right)),g=Math.max(...c.map(y=>y.bottom));return R(R({},l),{},{position:{x:u-st,y:h-st},style:R(R({},l.style),{},{width:m-u+st*2+ls,height:g-h+st*2+ds})})})}function ps(e){return e?Number.isFinite(e.x)&&Number.isFinite(e.y):!1}function gn(e){if(!e)return;const t=e.type.trim().toLowerCase();let n;if(t==="arrow"?n=xe.Arrow:(t==="arrowclosed"||t==="arrow-closed"||t==="arrow_closed")&&(n=xe.ArrowClosed),!!n)return e.color?{type:n,color:e.color}:{type:n}}function $s(e,t,n){return Ot.apply(this,arguments)}function Ot(){return Ot=Be(function*(e,t,n){var o;const r=xn.parse(t),i=yield kr(e),s=i.nodes.map((function(){var h=Be(function*(m){var g,y,E,w,A,T,x,N;const b=(g=r.nodes)===null||g===void 0?void 0:g[m.id];if(!b)return m;const v=JSON.parse(JSON.stringify(m)),I=(y=v.data.componentFields)!==null&&y!==void 0?y:[];if((E=b.data)!==null&&E!==void 0||(b.data={}),(w=v.data)!==null&&w!==void 0||(v.data={}),ps(b.___position)&&(v.position={x:b.___position.x,y:b.___position.y}),b.type){if(v.type=b.type,delete v.style,b.type==="cloud"&&(v.height=150,v.width=150,b.service)){const $=n?.resolveCloudIcon?yield n.resolveCloudIcon(b.cloud,b.service):yield as(b.cloud,b.service);$&&(v.data.iconSrc=$)}if(b.type==="image"&&b.src&&(v.data=R(R({},v.data),{},{src:b.src})),b.type==="gif")if(b.animatedIcon){const $=yield cs(b.animatedIcon);$&&(v.data=R(R({},v.data),{},{src:$}))}else b.src&&(v.data=R(R({},v.data),{},{src:b.src}));if(b.type==="text"&&(b.value||b.name)){const $=ke({type:L.TextInput,componentFieldId:"text",label:"Text",data:b.value||b.name,isReadonly:!0});I.unshift($)}if(b.type==="code"&&b.value){const $=ke({type:L.CodeEditor,componentFieldId:"code",label:"Code",data:b.value,isReadonly:!0});I.unshift($)}if(b.type==="table"&&b.table){var C,M;v.data.title=b.name,v.data.rows=(C=b.table.rows)!==null&&C!==void 0?C:[],v.data.columns=(M=b.table.columns)!==null&&M!==void 0?M:[]}if((b.type==="data-source"||b.type==="db-table")&&(b.type="databaseTableSQL",v.type="databaseTableSQL"),b.type==="component"&&(b.type="builder",v.type="builder",v.data.componentId=b.componentId),b.type==="shape"&&b.shape&&(v.data.shape=b.shape,b.shape==="or"||b.shape==="summing-junction")){var S,k;const $=Math.max((S=v.width)!==null&&S!==void 0?S:0,(k=v.height)!==null&&k!==void 0?k:0,200);v.width=$,v.height=$}}b.name&&(b.data.Name={type:L.TextInput,value:b.name});for(const $ in b.data){const P=b.data[$];if(P===void 0)continue;const B=Ni(I,$),U=ke({label:$,type:P.type,data:P.value,options:P.options});B?(B.type=U.type,B.data=U.data):I.push(U)}return b.dbConfig&&(v.data.serviceTable={serviceName:b.dbConfig.serviceName,databaseName:b.dbConfig.databaseName,tableName:b.dbConfig.tableName}),!((A=b.style)===null||A===void 0)&&A.height&&(v.height=b.style.height),!((T=b.style)===null||T===void 0)&&T.width&&(v.width=b.style.width),v.data=R(R(R({},v.data),to((x=b.style)!==null&&x!==void 0?x:{},["color","fill","stroke","strokeWidth","strokeStyle","borderRadius","borderAnimationEnabled"])),{},{componentFields:I,strokeAnimation:!((N=b.style)===null||N===void 0)&&N.borderAnimationEnabled?"dash":void 0},b?.___internal),v});return function(m){return h.apply(this,arguments)}})()),a=yield Promise.all(s),d=Object.entries((o=t.groups)!==null&&o!==void 0?o:{}).map(([h,m])=>{var g,y;const E=wn(((g=m.nodes)!==null&&g!==void 0?g:[]).map(w=>a.find(A=>A.id===w)));return ss(h,(y=m.name)!==null&&y!==void 0?y:"Group",E)}),l=new Map,p=i.edges.map(h=>{var m;const g=`${h.source}-${h.target}`,y=(m=l.get(g))!==null&&m!==void 0?m:0;return l.set(g,y+1),y===0?{pair:g,key:g}:{pair:g,key:`${g}#${y}`}}),f=i.edges.map((function(){var h=Be(function*(m,g){var y,E,w,A,T,x,N,b,v,I,C,M,S,k,$,P,B,U,q,z,Y,G;const{pair:te,key:Q}=p[g],ne=(y=(E=(w=r.edges)===null||w===void 0?void 0:w[Q])!==null&&E!==void 0?E:(A=r.edges)===null||A===void 0?void 0:A[te])!==null&&y!==void 0?y:null;return ne?R(R({},m),{},{type:(T=ne.type)!==null&&T!==void 0?T:m.type,sourceHandle:(x=ne.sourceHandle)!==null&&x!==void 0?x:m.sourceHandle,targetHandle:(N=ne.targetHandle)!==null&&N!==void 0?N:m.targetHandle,markerStart:(b=gn(ne.markerStart))!==null&&b!==void 0?b:m.markerStart,markerEnd:(v=gn(ne.markerEnd))!==null&&v!==void 0?v:m.markerEnd,data:R(R({},m.data),ne?.___internal),label:(I=ne.label)!==null&&I!==void 0?I:m.label,animated:(C=(M=ne.style)===null||M===void 0?void 0:M.borderAnimationEnabled)!==null&&C!==void 0?C:m.animated,style:R(R({},m.style),{},{stroke:(S=(k=ne.style)===null||k===void 0?void 0:k.stroke)!==null&&S!==void 0?S:($=m.style)===null||$===void 0?void 0:$.stroke,strokeWidth:(P=(B=ne.style)===null||B===void 0?void 0:B.strokeWidth)!==null&&P!==void 0?P:(U=m.style)===null||U===void 0?void 0:U.strokeWidth,strokeDasharray:((q=ne.style)===null||q===void 0?void 0:q.strokeStyle)==="dashed"?"4 2":((z=ne.style)===null||z===void 0?void 0:z.strokeStyle)==="dotted"?"1 2":((Y=ne.style)===null||Y===void 0?void 0:Y.strokeStyle)==="solid"||(G=m.style)===null||G===void 0?void 0:G.strokeDasharray})}):m});return function(m,g){return h.apply(this,arguments)}})()),c=yield Promise.all(f),u=[...d,...a.map(h=>{const m=d.find(g=>{var y;return(y=g.data.childNodes)===null||y===void 0?void 0:y.includes(h.id)});return m?R(R({},h),{},{parentId:m.id}):h})];return Xr(u)?{edges:c,nodes:u}:Gr(u)?{edges:c,nodes:u}:{edges:c,nodes:n?.repositionNodes?fs(u):u}}),Ot.apply(this,arguments)}function ms(e,t){const n=new Map(e.map(d=>[d.id,d]));let o=0,r=0,i=0;for(const d of t){const l=n.get(d.source),p=n.get(d.target);!l||!p||(o+=Math.abs(p.position.x-l.position.x),r+=Math.abs(p.position.y-l.position.y),i+=1)}if(i>0)return o>=r?"LR":"TB";const s=e.map(d=>d.position.x),a=e.map(d=>d.position.y);return Math.max(...s,0)-Math.min(...s,0)>=Math.max(...a,0)-Math.min(...a,0)?"LR":"TB"}function gs(e){return/^[A-Za-z]+$/.test(e)}function yn(e){let t=e,n="";for(;t>=0;)n=String.fromCharCode(t%26+65)+n,t=Math.floor(t/26)-1;return n}function ys(e){const t=new Set,n=new Map;let o=0;return e.forEach(r=>{if(gs(r.id)&&!t.has(r.id)){n.set(r.id,r.id),t.add(r.id);return}let i=yn(o);for(o+=1;t.has(i);)i=yn(o),o+=1;n.set(r.id,i),t.add(i)}),n}function vs(e){const t=e.type,n=ve(e.data),o=Array.isArray(n?.componentFields)?n.componentFields.map(i=>ve(i)).filter(i=>i!==void 0):[],r=lt(o,"Name");if(t==="text")return lt(o,"Text");if(t==="code")return lt(o,"Code");if(t==="shape"||t==="cloud"||t==="table"||t==="gif")return r}function bs(e,t,n){return e.map(o=>{var r;const i=(r=t.get(o.id))!==null&&r!==void 0?r:o.id,s=vs(o);return!s||!Lr(s)?i:`${i}["${Or(s)}"]`})}function ws(e,t,n){const o=[];for(const r of e){const i=t.get(r.source),s=t.get(r.target);!i||!s||o.push(`${i} --> ${s}`)}return o}function Ds(e,t){const n=e.nodes.filter(l=>l.type==="group"),o=e.nodes.filter(l=>l.type!=="group"),r=ms(o,e.edges),i=ys(o),s=bs(o,i),a=ws(e.edges,i),d=Gt(o,e.edges,n,i);return{mermaid:[`flowchart ${r}`,...s,...a].join(`
77
- `),context:d}}export{As as A,L as C,ks as S,_s as a,Ti as b,kr as c,Xr as d,Ms as e,Rs as f,Ds as g,$s as h,Gr as i,vt as j,Cs as k,nn as l,De as m,Mn as n};
70
+ `);continue}const I=v.match(/^title\s*:?\s*(.*)$/i);if(I){u=we(I[1]);continue}const C=v.match(/^accTitle\s*:\s*(.*)$/i);if(C){h=we(C[1]);continue}const M=v.match(/^accDescr\s*:\s*(.*)$/i);if(M){m=we(M[1]);continue}const A=v.match(/^autonumber(?:\s+(off|[\d.]+))?(?:\s+([\d.]+))?$/i);if(A){const[,O,X]=A;if(O?.toLowerCase()==="off"){c=void 0;continue}const ue=O===void 0?1:Number(O);c={start:ue,step:X===void 0?1:Number(X),next:ue,declaredStart:ue};continue}const k=v.match(/^box\b\s*(.*)$/i);if(k){const{color:O,label:X}=dn(k[1]),ue={id:`box-${s.length}`,label:we(X),color:O,participants:[]};s.push(ue),f=ue,p.push({kind:"box",id:ue.id});continue}if(/^end$/i.test(v)){const O=p.pop();if(O?.kind==="box"){f=void 0;continue}const X=l.pop();if(X){X.endRow=y-1;const ue=X.sections[X.sections.length-1];ue&&(ue.endRow=y-1)}continue}const $=vr.find(O=>new RegExp(`^${O}\\b`,"i").test(v));if($){const O=v.slice($.length).trim(),{color:X,label:ue}=$==="rect"?dn(O):{color:void 0,label:O},fe=l[l.length-1],Ye={id:`block-${i.length}`,type:$,label:we(ue),color:X,sections:[{label:we(ue),startRow:y,endRow:y}],startRow:y,endRow:y,depth:l.length,parentId:fe?.id};i.push(Ye),l.push(Ye),p.push({kind:"block",id:Ye.id});continue}const P=br.find(O=>new RegExp(`^${O}\\b`,"i").test(v));if(P){const O=l[l.length-1];if(O){const X=O.sections[O.sections.length-1];X&&(X.endRow=y-1),O.sections.push({label:we(v.slice(P.length).trim()),startRow:y,endRow:y})}continue}const B=v.match(/^create\s+(participant|actor)\s+(.+)$/i);if(B){g={type:B[1].toLowerCase(),rest:B[2]};continue}const U=v.match(/^destroy\s+(.+)$/i);if(U){const O=E(U[1].trim());O.destroyedAtRow=y;continue}const q=v.match(/^(participant|actor)\s+(.+)$/i);if(q){var x;const O=q[1].toLowerCase(),X=un(q[2]);E(X.id,{name:X.name,alias:X.alias,type:(x=X.type)!==null&&x!==void 0?x:O});continue}const z=v.match(/^(activate|deactivate)\s+(.+)$/i);if(z){const O=E(z[2].trim());z[1].toLowerCase()==="activate"?w(O.id,y):N(O.id,y-1);continue}const Y=v.match(/^note\s+(right of|left of|over)\s+([^:]+):\s*(.*)$/i);if(Y){const O=Y[2].split(",").map(X=>X.trim()).filter(Boolean);O.forEach(X=>E(X)),r.push({placement:Y[1].toLowerCase(),participants:O.map(X=>X),text:we(Y[3]),rowIndex:y}),y++;continue}const G=v.match(/^links\s+([^:]+):\s*(\{.*\})$/i);if(G){const O=E(G[1].trim());try{const X=JSON.parse(G[2]);for(const[ue,fe]of Object.entries(X))O.links.push({label:ue,url:fe})}catch{}continue}const te=v.match(/^link\s+([^:]+):\s*(.+?)\s*@\s*(\S+)$/i);if(te){E(te[1].trim()).links.push({label:te[2].trim(),url:te[3].trim()});continue}const Q=v.indexOf(":"),ne=Er(Q===-1?v:v.slice(0,Q));if(!ne||Q===-1)continue;const{arrow:H,start:J,end:ie}=ne;let se=v.slice(0,J).trim(),oe=v.slice(ie,Q).trim();const Ae=we(v.slice(Q+1)),Ie=se.endsWith("()");Ie&&(se=se.slice(0,-2).trim());let Ce=!1,F=!1,W=!1,ae=!0;for(;ae;)ae=!1,oe.startsWith("+")&&(Ce=!0,oe=oe.slice(1).trim(),ae=!0),oe.startsWith("-")&&(F=!0,oe=oe.slice(1).trim(),ae=!0),oe.startsWith("()")&&(W=!0,oe=oe.slice(2).trim(),ae=!0);if(!se||!oe)continue;if(E(se),g){var S;const O=un(g.rest),X=E(O.id,{name:O.name,alias:O.alias,type:(S=O.type)!==null&&S!==void 0?S:g.type});X.createdAtRow=y,g=void 0,oe=O.id}const Te=E(oe),he={from:se,to:Te.id,label:Ae,lineStyle:H.lineStyle,arrowType:H.arrowType,rowIndex:y};H.half&&(he.half=H.half),H.reversed&&(he.reversed=!0),Ie&&(he.centralSource=!0),W&&(he.centralTarget=!0),Ce&&(he.activates=!0),F&&(he.deactivates=!0),c&&(he.sequenceNumber=c.next,c.next=Number((c.next+c.step).toFixed(2))),Ce&&w(Te.id,y),F&&N(se,y),o.push(he),y++}for(const[b,v]of d)for(const I of v)a.push({participant:b,startRow:I,endRow:Math.max(y-1,I)});for(const b of l){b.endRow=y-1;const v=b.sections[b.sections.length-1];v&&(v.endRow=y-1)}return a.sort((b,v)=>b.startRow-v.startRow),R(R(R(R({participants:t,messages:o,notes:r,blocks:i,boxes:s,activations:a},c?{autonumber:{start:c.declaredStart,step:c.step}}:{}),u===void 0?{}:{title:u}),h===void 0?{}:{accTitle:h}),m===void 0?{}:{accDescr:m})}const Tr={loop:{border:"#64748B",background:"rgba(100, 116, 139, 0.06)"},alt:{border:"#6366F1",background:"rgba(99, 102, 241, 0.06)"},opt:{border:"#0EA5E9",background:"rgba(14, 165, 233, 0.06)"},par:{border:"#22C55E",background:"rgba(34, 197, 94, 0.06)"},critical:{border:"#F97316",background:"rgba(249, 115, 22, 0.06)"},break:{border:"#EF4444",background:"rgba(239, 68, 68, 0.06)"},rect:{border:"transparent",background:"rgba(148, 163, 184, 0.10)"}};function Ee(e){const{COLUMN_WIDTH:t}=De;return e*t+t/2}function hn(e,t,n){return`row-${e}-${t}-${n}`}function Nr(e){const{ROW_HEIGHT:t,ROW_VERTICAL_PADDING:n,HEADER_HEIGHT:o}=De,{BLOCK_TOP_PADDING:r,BLOCK_BOTTOM_PADDING:i,BLOCK_SECTION_PADDING:s,BLOCK_FRAME_GAP:a}=De,d=[...e.messages.map(x=>({kind:"message",parserRow:x.rowIndex,message:x})),...e.notes.map(x=>({kind:"note",parserRow:x.rowIndex,note:x}))].sort((x,S)=>x.parserRow-S.parserRow),l=new Map,p=new Map,f=new Map;let c=0;for(const x of d){const S=x.kind==="message"?x.message.label:x.note.text;l.set(x.parserRow,$n(S)),p.set(x.parserRow,c);const b=x.kind==="message"&&x.message.from===x.message.to?2:1;f.set(x.parserRow,b),c+=b}const u=Math.max(c,1),h=Math.max(t,...[...l.values()].map(x=>x.height+n));function m(x){for(let S=x;S<x+d.length+1;S++){const b=p.get(S);if(b!==void 0)return b}return u}function y(x){for(let S=x;S>=0;S--){const b=p.get(S);if(b!==void 0)return b+f.get(S)-1}return 0}const g=new Array(u+1).fill(0),E=new Array(u+1).fill(0);for(const x of e.blocks)if(!(x.endRow<x.startRow)){g[m(x.startRow)]+=r+a,E[y(x.endRow)]+=i;for(const S of x.sections.slice(1))S.endRow<S.startRow||(g[m(S.startRow)]+=s)}const w=[];let N=o;for(let x=0;x<u;x++)N+=g[x],w.push(N),N+=h+E[x];const T=N;return{items:d,sizes:l,rowHeight:h,totalRows:u,rowTops:w,rowCenters:w.map(x=>x+h/2),contentHeight:T,padBefore:g,padAfter:E,toLayoutRow:m,toLastLayoutRow:y,layoutRowByParserRow:p}}function Dn(e,t,n){const{SELF_LOOP_OFFSET:o}=De;return e===t?Ee(e)+o:(Ee(e)+Ee(t))/2-n/2}function On(e,t,n){const{NOTE_OFFSET:o,COLUMN_WIDTH:r}=De,i=e.participants.map(l=>n.get(l)).filter(l=>l!==void 0);if(i.length===0)return;const s=t.sizes.get(e.rowIndex),a=Ee(i[0]),d=Ee(i[i.length-1]);if(e.placement==="right of")return{x:a+o,width:s.width};if(e.placement==="left of")return{x:a-o-s.width,width:s.width};if(i.length>1){const l=Math.max(s.width,d-a+r/2);return{x:(a+d)/2-l/2,width:l}}return{x:a-s.width/2,width:s.width}}function Sr(e,t,n,o){if(e.endRow<e.startRow)return;const{BLOCK_SIDE_PADDING:r,BLOCK_TOP_PADDING:i,BLOCK_BOTTOM_PADDING:s,BLOCK_CONTENT_INSET:a}=De,d=new Set,l=[],p=[];function f(v){return a*(t.blocks.filter(I=>I.depth>e.depth&&I.endRow>=I.startRow&&I.startRow<=v&&I.endRow>=v).length+1)}for(const v of t.messages){if(v.rowIndex<e.startRow||v.rowIndex>e.endRow)continue;const I=o.get(v.from),C=o.get(v.to);if(I!==void 0&&d.add(I),C!==void 0&&d.add(C),I===void 0||C===void 0)continue;const M=n.sizes.get(v.rowIndex).width,A=Dn(I,C,M),k=f(v.rowIndex);l.push(A-k),p.push(A+M+k)}for(const v of t.notes){if(v.rowIndex<e.startRow||v.rowIndex>e.endRow)continue;v.participants.forEach(M=>{const A=o.get(M);A!==void 0&&d.add(A)});const I=On(v,n,o);if(I===void 0)continue;const C=f(v.rowIndex);l.push(I.x-C),p.push(I.x+I.width+C)}d.size===0&&t.participants.forEach(v=>d.add(v.index));const c=Math.min(...d),u=Math.max(...d),h=n.toLayoutRow(e.startRow),m=n.toLastLayoutRow(e.endRow),y=Math.max(a,r-e.depth*a),g=t.blocks.filter(v=>v.id!==e.id&&v.depth>e.depth),E=g.filter(v=>v.endRow>=v.startRow&&n.toLayoutRow(v.startRow)===h).length,w=g.filter(v=>v.endRow>=v.startRow&&n.toLastLayoutRow(v.endRow)===m).length,N=Math.min(Ee(c)-y,...l),T=Math.max(Ee(u)+y,...p)-N,x=n.rowTops[h]-i*(E+1),S=n.rowTops[m]+n.rowHeight+s*(w+1)-x,b=Tr[e.type];return{id:`sequence-block-${e.id}`,type:"group",position:{x:N,y:x},width:T,height:S,zIndex:Math.min(-1,-10+e.depth),selectable:!0,data:{source:"mermaid",backgroundColor:b.background,borderColor:b.border,autoLayout:!1,sequenceBlock:{type:e.type,label:e.label,color:e.color,depth:e.depth,startRow:h,endRow:m,sections:e.sections.map(v=>({label:v.label,startRow:n.toLayoutRow(v.startRow),endRow:n.toLastLayoutRow(v.endRow)}))},componentFields:[me(e.label?`${e.type} ${e.label}`:e.type)]},style:{width:T,height:S}}}function Ar(e,t,n){const o=On(e,t,n);if(o===void 0)return;const{x:r,width:i}=o,s=t.sizes.get(e.rowIndex),a=t.toLayoutRow(e.rowIndex);return{id:`note-${e.rowIndex}`,type:"shape",position:{x:r,y:t.rowCenters[a]-s.height/2},width:i,height:s.height,data:{source:"mermaid",shape:"rectangle",fill:"#FEF3C7",stroke:"#F59E0B",strokeWidth:1,textColor:"#1F2937",sequenceNote:{placement:e.placement,participants:e.participants,row:a},componentFields:[me(e.text)]},style:{width:i,height:s.height}}}function fn(e,t){const n={width:16,height:16,color:t};return e.arrowType==="none"?{}:e.arrowType==="filled"?{markerEnd:R({type:xe.ArrowClosed},n)}:e.arrowType==="bidirectional"?{markerStart:R({type:xe.ArrowClosed},n),markerEnd:R({type:xe.ArrowClosed},n)}:e.reversed?{markerStart:R({type:xe.Arrow},n)}:{markerEnd:R({type:xe.Arrow},n)}}function Cr(e){const t=Ir(e),{PARTICIPANT_NODE_WIDTH:n,COLUMN_WIDTH:o,BOX_TOP_INSET:r,BOX_BOTTOM_PADDING:i,BLOCK_SIDE_PADDING:s}=De,a=Nr(t),d=new Map(t.participants.map(c=>[c.id,c.index])),l=[],p=[];for(const c of t.boxes){var f;const u=c.participants.map(E=>d.get(E)).filter(E=>E!==void 0);if(u.length===0)continue;const h=Math.min(...u),m=Math.max(...u),y=Ee(h)-o/2+8,g=Ee(m)-Ee(h)+o-16;l.push({id:`sequence-box-${c.id}`,type:"group",position:{x:y,y:-r},width:g,height:a.contentHeight+r+i,zIndex:-20,data:{source:"mermaid",backgroundColor:(f=c.color)!==null&&f!==void 0?f:"rgba(148, 163, 184, 0.08)",borderColor:"#94A3B8",autoLayout:!1,sequenceBox:{label:c.label,participants:c.participants},componentFields:[me(c.label)]},style:{width:g,height:a.contentHeight+r+i}})}for(const c of t.blocks){const u=Sr(c,t,a,d);u&&l.push(u)}for(const c of t.participants){const u=t.activations.filter(h=>h.participant===c.id).map(h=>({startRow:a.toLayoutRow(h.startRow),endRow:a.toLastLayoutRow(h.endRow)}));l.push({id:`participant-${c.id}`,type:"sequenceParticipant",position:{x:Ee(c.index)-n/2,y:0},data:R(R(R({source:"mermaid",label:c.name,participantType:c.type,rowCount:a.totalRows,rowHeight:a.rowHeight,rowYs:a.rowCenters,lifelineHeight:a.contentHeight,activations:u,links:c.links},c.createdAtRow===void 0?{}:{lifelineStartRow:a.toLayoutRow(c.createdAtRow)}),c.destroyedAtRow===void 0?{}:{lifelineEndRow:a.toLastLayoutRow(c.destroyedAtRow)}),{},{componentFields:[me(c.name)]})})}for(const c of t.notes){const u=Ar(c,a,d);u&&l.push(u)}for(const c of t.messages){const u=d.get(c.from),h=d.get(c.to);if(u===void 0||h===void 0)continue;const m=u===h,y=u<h,g=a.sizes.get(c.rowIndex),E=a.toLayoutRow(c.rowIndex),w=Dn(u,h,g.width),N=`message-${c.rowIndex}`;l.push({id:N,type:"shape",position:{x:w,y:a.rowCenters[E]-g.height/2},width:g.width,height:g.height,data:R(R({source:"mermaid",shape:"rectangle",fill:"#1E293B",stroke:"#475569",strokeWidth:1},c.sequenceNumber===void 0?{}:{sequenceNumber:c.sequenceNumber}),{},{componentFields:[me(c.label)]}),style:{width:g.width,height:g.height}});const T="#94a3b8",x=R({stroke:T,strokeWidth:2},c.lineStyle==="dashed"?{strokeDasharray:"4 4"}:{}),S=y||m?"right":"left",b=m?"right":y?"left":"right";p.push(R({id:`edge-${c.rowIndex}-a`,source:`participant-${c.from}`,target:N,sourceHandle:hn(E,S,"source"),targetHandle:m?"target-top":S==="right"?"target-left":"target-right",type:"smoothstep",style:x,data:R(R(R({source:"mermaid",arrowType:c.arrowType},c.half?{half:c.half}:{}),c.reversed?{reversed:!0}:{}),c.centralSource?{centralSource:!0}:{})},c.reversed?fn(c,T):{})),p.push(R({id:`edge-${c.rowIndex}-b`,source:N,target:`participant-${c.to}`,sourceHandle:m?"source-bottom":y?"source-right":"source-left",targetHandle:hn(E+(m?1:0),b,"target"),type:"smoothstep",style:x,data:R(R({source:"mermaid",arrowType:c.arrowType},c.half?{half:c.half}:{}),c.centralTarget?{centralTarget:!0}:{})},c.reversed?{}:fn(c,T)))}return t.title&&l.push({id:"sequence-title",type:"text",position:{x:Ee(0)-o/2,y:-r-s},data:{source:"mermaid",componentFields:[ke({componentFieldId:"text",label:"Text",type:L.TextBox,data:t.title,isReadonly:!0})]}}),{nodes:l,edges:p}}oo.initialize({startOnLoad:!1,theme:"dark",flowchart:{htmlLabels:!1,curve:"linear"}});function kr(e){const t=e.split(`
71
+ `);for(const n of t){const o=n.trim().toLowerCase();if(o.startsWith("sequencediagram"))return"sequence";if(o.startsWith("c4"))return"c4";if(o.startsWith("flowchart")||o.startsWith("graph"))return"flowchart"}return"flowchart"}function Rr(e){return Mt.apply(this,arguments)}function Mt(){return Mt=Be(function*(e){try{const t=kr(e);return t==="sequence"?Cr(e):t==="c4"?Yi(e):mr(e)}catch(t){return console.error("Error converting Mermaid to React Flow:",t),{nodes:[],edges:[]}}}),Mt.apply(this,arguments)}const _r=new Set(["rectangle","rounded-rect","ellipse","diamond","triangle","parallelogram","trapezoid","hexagon","document","cylinder","delay","off-page-connector","display","collate","sort","terminator","or","database","multiple-documents","subroutine","manual-input","summing-junction","internal-storage"]),Mr=new Set(Object.values(L)),$r=32,Dr=new Set(["componentFields","shape","fill","stroke","strokeWidth","strokeStyle","borderRadius","borderAnimationEnabled","strokeAnimation","src","animatedIcon","iconSrc","componentId","serviceTable","title","columns","rows","name","label","value","cloud","service","childNodes"]);function it(e){return Mr.has(e)}function ve(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return e}function j(e){if(typeof e!="string")return;const t=e.trim();if(t)return t}function Or(e){const t=ve(e);if(t&&!(typeof t.x!="number"||!Number.isFinite(t.x))&&!(typeof t.y!="number"||!Number.isFinite(t.y)))return{x:t.x,y:t.y}}function Ze(e){if(!Array.isArray(e)||e.length!==1)return e;const t=ve(e[0]);return t?"value"in t?t.value:t:e}function ct(e,t){return e.find(n=>{var o;return((o=j(n.label))===null||o===void 0?void 0:o.toLowerCase())===t.toLowerCase()&&j(n.type)})}function lt(e,t){const n=ct(e,t);if(n)return j(Ze(n.data))}function wt(e){return typeof e=="string"?e.trim().length===0:e==null}function Ln(e){if(typeof e!="string"||!e.trim())return;const t=e.replaceAll(","," ").replace(/\s+/g," ").trim();return t==="1 2"?"dotted":t==="4 2"||t==="4 4"||t==="8 4"?"dashed":"solid"}function pn(e){if(typeof e=="string")return{type:e};const t=ve(e);if(!t)return;const n=j(t.type);if(!n)return;const o=j(t.color);return o?{type:n,color:o}:{type:n}}function Lr(e){return e.replaceAll('"','\\"')}function Pr(e){return!(e.length>$r||e.includes(`
72
+ `)||e.includes("\r"))}function Fr(e,t){const n={},o=new Map;for(const a of e){var r,i,s;const d=t.get(a.source),l=t.get(a.target);if(!d||!l)continue;const p=`${d}-${l}`,f=(r=o.get(p))!==null&&r!==void 0?r:0;o.set(p,f+1);const c={},u=j(a.type);u&&(c.type=u);const h=j(a.sourceHandle);h&&(c.sourceHandle=h);const m=j(a.targetHandle);m&&(c.targetHandle=m);const y=j(a.label);y&&(c.label=y);const g=(i=ve(a.style))!==null&&i!==void 0?i:{},E={},w=j(g.stroke);w&&(E.stroke=w),typeof g.strokeWidth=="number"&&(E.strokeWidth=g.strokeWidth);const N=Ln(g.strokeDasharray);N&&(E.strokeStyle=N),typeof a.animated=="boolean"&&(E.borderAnimationEnabled=a.animated),Object.keys(E).length>0&&(c.style=E);const T=pn(a.markerStart);T&&(c.markerStart=T);const x=pn(a.markerEnd);x&&(c.markerEnd=x);const S=(s=ve(a.data))!==null&&s!==void 0?s:{};Object.keys(S).length>0&&(c.___internal=S),Object.keys(c).length>0&&(f===0?n[p]=c:n[`${p}#${f}`]=c)}return n}function Br(e,t){const n={};for(const r of e){var o;const i=(o=ve(r.data))!==null&&o!==void 0?o:{},s=Array.isArray(i.childNodes)?i.childNodes.map(d=>typeof d=="string"?t.get(d):void 0).filter(d=>d!==void 0):[],a=lt(Array.isArray(i.componentFields)?i.componentFields.map(d=>ve(d)).filter(d=>d!==void 0):[],"Name");!a&&s.length===0||(n[r.id]={name:a??void 0,nodes:s})}return n}function Gr(e,t){const n={};for(const a of e){var o,r,i,s;const d=t.get(a.id);if(!d)continue;const l=(o=ve(a.data))!==null&&o!==void 0?o:{},p=(r=ve(a.style))!==null&&r!==void 0?r:{},f=Array.isArray(l.componentFields)?l.componentFields.map(F=>ve(F)).filter(F=>F!==void 0):[],c={},u=j(a.type);u&&(c.type=u);const h=ct(f,"Name"),m=h?Ze(h.data):void 0,y=j(m);y&&(c.name=y);const g=u==="text"?ct(f,"Text"):void 0,E=g?Ze(g.data):void 0,w=j(E);u==="text"&&w&&(c.value=w);const N=u==="code"?ct(f,"Code"):void 0,T=N?Ze(N.data):void 0,x=j(T);u==="code"&&x&&(c.value=x);const S=j(l.src);S&&(c.src=S);const b=j(l.animatedIcon);b&&(c.animatedIcon=b);const v=j(l.cloud);v&&(c.cloud=v);const I=j(l.service);I&&(c.service=I);const C=j(l.componentId);C&&(c.componentId=C);const M=j(l.shape);M&&_r.has(M)&&(c.shape=M);const A={},k=typeof a.width=="number"?a.width:typeof p.width=="number"?p.width:void 0;typeof k=="number"&&(A.width=k);const $=typeof a.height=="number"?a.height:typeof p.height=="number"?p.height:void 0;typeof $=="number"&&(A.height=$);const P=(i=j(l.fill))!==null&&i!==void 0?i:j(p.fill);P&&(A.fill=P);const B=(s=j(l.stroke))!==null&&s!==void 0?s:j(p.stroke);B&&(A.stroke=B);const U=typeof l.strokeWidth=="number"?l.strokeWidth:typeof p.strokeWidth=="number"?p.strokeWidth:void 0;typeof U=="number"&&(A.strokeWidth=U);const q=typeof l.borderRadius=="number"?l.borderRadius:typeof p.borderRadius=="number"?p.borderRadius:void 0;typeof q=="number"&&(A.borderRadius=q);const z=j(l.strokeStyle);if(z==="solid"||z==="dashed"||z==="dotted")A.strokeStyle=z;else{const F=Ln(p.strokeDasharray);F&&(A.strokeStyle=F)}const Y=typeof l.borderAnimationEnabled=="boolean"?l.borderAnimationEnabled:l.strokeAnimation==="dash"?!0:void 0;typeof Y=="boolean"&&(A.borderAnimationEnabled=Y),Object.keys(A).length>0&&(c.style=A);const G=Array.isArray(l.columns)?l.columns.filter(F=>typeof F=="string"):void 0,te=Array.isArray(l.rows)?l.rows.map(F=>Array.isArray(F)?F.filter(W=>typeof W=="string"):void 0).filter(F=>F!==void 0):void 0;(G||te)&&(c.table={columns:G??[],rows:te??[]});const Q=ve(l.serviceTable),ne=j(Q?.serviceName),H=j(Q?.databaseName),J=j(Q?.tableName);ne&&H&&J&&(c.dbConfig={serviceName:ne,databaseName:H,tableName:J});const ie={};for(const F of f){const W=j(F.label),ae=j(F.type);if(!W||!ae||!it(ae))continue;const Te=ae,he=W.toLowerCase();if(he==="name"||u==="text"&&he==="text"||u==="code"&&he==="code")continue;const O=Array.isArray(F.options)?F.options.filter(X=>typeof X=="string"):void 0;ie[W]={type:Te,value:Ze(F.data),options:O&&O.length>0?O:void 0}}if(h&&!y&&wt(m)){const F=j(h.type);if(F&&it(F)){const W=Array.isArray(h.options)?h.options.filter(ae=>typeof ae=="string"):void 0;ie.Name={type:F,value:"",options:W&&W.length>0?W:void 0}}}if(g&&!w&&wt(E)){const F=j(g.type);if(F&&it(F)){const W=Array.isArray(g.options)?g.options.filter(ae=>typeof ae=="string"):void 0;ie.Text={type:F,value:"",options:W&&W.length>0?W:void 0}}}if(N&&!x&&wt(T)){const F=j(N.type);if(F&&it(F)){const W=Array.isArray(N.options)?N.options.filter(ae=>typeof ae=="string"):void 0;ie.Code={type:F,value:"",options:W&&W.length>0?W:void 0}}}Object.keys(ie).length>0&&(c.data=ie);const se=Or(a.position);se&&(c.___position=se);const oe=Object.entries(l).reduce((F,[W,ae])=>(Dr.has(W)||(F[W]=ae),F),{});u==="builder"&&Array.isArray(l.componentFields)&&(oe.componentFields=l.componentFields);const Ae=j(l.iconSrc);Ae&&(oe.iconSrc=Ae);const Ie=j(l.label);Ie&&(oe.label=Ie);const Ce=j(l.cloud);Ce&&(oe.cloud=Ce),Object.keys(oe).length>0&&(c.___internal=oe),Object.keys(c).length>0&&(n[d]=c)}return n}function Gt(e,t,n,o){const r=Gr(e,o),i=Fr(t,o),s=Br(n,o),a={};return Object.keys(r).length>0&&(a.nodes=r),Object.keys(i).length>0&&(a.edges=i),Object.keys(s).length>0&&(a.groups=s),En.parse(a)}function ze(e){var t;return(t=e.data)!==null&&t!==void 0?t:{}}function Pn(e){var t;return(t=e.data)!==null&&t!==void 0?t:{}}function Hr(e){return e.some(t=>t.type==="c4"||t.type==="c4Boundary")}function mn(e){if(e.type!=="c4"&&e.type!=="subDiagram")return!1;const t=ze(e).c4Kind;return t==="person"||t==="system"||t==="container"||t==="component"}function xt(e){return e.type==="c4Boundary"}function Se(e){return`"${e.replace(/"/g,'\\"').replace(/\r\n?/g,`
73
+ `).replace(/\n/g,"<br/>").trim()}"`}function Ur(e){var t;const n=(t=e.data)===null||t===void 0?void 0:t.componentFields;if(Array.isArray(n)){var o;const i=n.find(a=>a?.componentFieldId==="name"),s=i==null||(o=i.data)===null||o===void 0||(o=o[0])===null||o===void 0?void 0:o.value;if(typeof s=="string"&&s.trim())return s}const r=ze(e).diagramName;return typeof r=="string"&&r?r:e.id}function qr(e,t,n){let o;if(e==="person")o="Person";else if(e==="system")o="System";else if(e==="container")o="Container";else if(e==="component")o="Component";else throw new Error(`Unsupported C4 element kind: ${String(e)}`);return t==="db"&&(o+="Db"),t==="queue"&&(o+="Queue"),n&&(o+="_Ext"),o}function Wr(e,t){return e==="enterprise"?"Enterprise_Boundary":e==="system"?"System_Boundary":e==="container"?"Container_Boundary":e==="node"?t==="nodeL"?"Node_L":t==="nodeR"?"Node_R":"Deployment_Node":"Boundary"}function Kr(e){if(e==="default")return"Rel";if(e==="bi")return"BiRel";if(e==="back")return"Rel_Back";if(e==="up")return"Rel_U";if(e==="down")return"Rel_D";if(e==="left")return"Rel_L";if(e==="right")return"Rel_R";throw new Error(`Unsupported C4 relationship direction: ${String(e)}`)}function zr(e){const t=Pn(e).c4RelDirection;return t||(e.markerStart?"bi":e.sourceHandle==="source-top"?"up":e.sourceHandle==="source-bottom"?"down":e.sourceHandle==="source-left"?"left":e.sourceHandle==="source-right"?"right":"default")}function jr(e,t){const n=typeof e.label=="string"?e.label:"";if(!t)return n;const o=` [${t}]`;return n.endsWith(o)?n.slice(0,-o.length):n}function Yr(e){for(const t of e){const n=ze(t).c4DiagramType;if(n)return n}return e.some(t=>ze(t).c4Kind==="component")?"C4Component":e.some(t=>ze(t).c4Kind==="container")?"C4Container":"C4Context"}function Et(e,t){const n=[...e];for(;n.length>t&&n[n.length-1]==="";)n.pop();return n}function Xr(e,t){const n=e.filter(l=>mn(l)||xt(l)),o=new Set(n.map(l=>l.id)),r=new Set(n.filter(l=>xt(l)).map(l=>l.id));function i(l){if(l.parentId&&r.has(l.parentId))return l.parentId}function s(l,p){const f=ze(l),c=Se(Ur(l));if(mn(l)){const y=[l.id,c];(f.c4Kind==="container"||f.c4Kind==="component")&&y.push(f.technology?Se(f.technology):""),y.push(f.description?Se(f.description):"");const g=Et(y,2),E=f.diagramId?`uig:${f.diagramId}`:f.link;return E&&g.push(`$link=${Se(E)}`),`${p}${qr(f.c4Kind,f.c4Shape,f.isExternal===!0)}(${g.join(", ")})`}const u=Wr(f.c4BoundaryKind,f.c4NodeType),h=[l.id,c];u==="Boundary"&&f.boundaryType&&h.push(Se(f.boundaryType)),f.c4BoundaryKind==="node"&&(h.push(f.boundaryType?Se(f.boundaryType):'"node"'),h.push(f.description?Se(f.description):""));const m=Et(h,2);return f.link&&m.push(`$link=${Se(f.link)}`),`${p}${u}(${m.join(", ")}) {`}function a(l,p){const f=[];for(const c of n)i(c)===l&&(f.push(s(c,p)),xt(c)&&(f.push(...a(c.id,`${p} `)),f.push(`${p}}`)));return f}const d=t.flatMap(l=>{if(!o.has(l.source)||!o.has(l.target))return[];const p=Pn(l),f=zr(l),c=f==="back",u=[c?l.target:l.source,c?l.source:l.target,Se(jr(l,p.c4RelTechnology)),p.c4RelTechnology?Se(p.c4RelTechnology):"",p.c4RelDescription?Se(p.c4RelDescription):""];return`${Kr(f)}(${Et(u,3).join(", ")})`});return{mermaid:[Yr(n),...a(void 0,""),...d].join(`
74
+ `),nodeIdMap:new Map(n.map(l=>[l.id,l.id]))}}function Ms(e,t){const{mermaid:n,nodeIdMap:o}=Xr(e,t);return{mermaid:n,context:Gt(e,t,[],o)}}function Qr(e){return e.some(t=>t.type==="sequenceParticipant")}function Fn(e,t){var n,o;const r=(n=e.data)===null||n===void 0?void 0:n.componentFields;if(!Array.isArray(r))return;const i=r.find(a=>a?.componentFieldId===t),s=i==null||(o=i.data)===null||o===void 0||(o=o[0])===null||o===void 0?void 0:o.value;if(typeof s=="string"&&s.trim())return s}function pt(e){var t;const n=Fn(e,"name");if(n!==void 0)return n;const o=(t=e.data)===null||t===void 0?void 0:t.label;return typeof o=="string"?o:""}function Fe(e){return e.replace(/#/g,"&#35;").replace(/\r\n?/g,`
75
+ `).replace(/\n/g,"<br/>").trim()}function Zr(e,t,n){const o=e.replace(/[^A-Za-z0-9_]/g,"")||`P${t}`;let r=o,i=2;for(;n.has(r);)r=`${o}_${i}`,i++;return n.add(r),r}function Vr(e){const t=new Set;return e.filter(n=>n.type==="sequenceParticipant").sort((n,o)=>n.position.x-o.position.x).map((n,o)=>{var r,i,s,a,d;const l=pt(n)||`Participant ${o+1}`,p=(r=n.data)===null||r===void 0?void 0:r.participantType,f=(i=n.data)===null||i===void 0?void 0:i.activations,c=(s=n.data)===null||s===void 0?void 0:s.links,u=(a=n.data)===null||a===void 0?void 0:a.lifelineStartRow,h=(d=n.data)===null||d===void 0?void 0:d.lifelineEndRow;return R(R(R({nodeId:n.id,mermaidId:Zr(l,o,t),name:l,type:typeof p=="string"?p:"participant",links:Array.isArray(c)?c:[],activations:Array.isArray(f)?f:[]},typeof u=="number"?{createdRow:u}:{}),typeof h=="number"?{destroyedRow:h}:{}),{},{x:n.position.x})})}function Jr(e,t){const n=new Map;for(const o of e)t.has(o.source)&&n.set(o.target,R(R({},n.get(o.target)),{},{from:o.source})),t.has(o.target)&&n.set(o.source,R(R({},n.get(o.source)),{},{to:o.target}));return n}function es(e,t){var n,o,r,i,s,a,d,l,p;const f=(n=t==null||(o=t.data)===null||o===void 0?void 0:o.arrowType)!==null&&n!==void 0?n:e==null||(r=e.data)===null||r===void 0?void 0:r.arrowType,c=(i=t==null||(s=t.data)===null||s===void 0?void 0:s.half)!==null&&i!==void 0?i:e==null||(a=e.data)===null||a===void 0?void 0:a.half,u=(e==null||(d=e.data)===null||d===void 0?void 0:d.reversed)===!0;return yr(R(R({lineStyle:(t==null||(l=t.style)===null||l===void 0?void 0:l.strokeDasharray)!==void 0||(e==null||(p=e.style)===null||p===void 0?void 0:p.strokeDasharray)!==void 0?"dashed":"solid",arrowType:f??"filled"},c?{half:c}:{}),{},{reversed:u}))}function ts(e,t,n){const o=(Array.isArray(e.participants)?e.participants.filter(i=>typeof i=="string"):[]).map(i=>t.find(s=>s.nodeId===`participant-${i}`)).filter(i=>!!i);if(o.length>0)return o.map(i=>i.nodeId);if(t.length===0)return[];const r=n.position.x+(Number(n.width)||0)/2;return[[...t].sort((i,s)=>Math.abs(i.x-r)-Math.abs(s.x-r))[0].nodeId]}function ns(e,t,n){const o=new Set(n.map(f=>f.nodeId)),r=Jr(t,o),i=[];for(const f of e){var s,a,d,l;if(o.has(f.id))continue;const c=(s=f.data)===null||s===void 0?void 0:s.sequenceNote;if(c){var p;i.push({item:{kind:"note",nodeId:f.id,text:pt(f),placement:(p=c.placement)!==null&&p!==void 0?p:"over",participantNodeIds:ts(c,n,f)},y:f.position.y});continue}const u=r.get(f.id);if(!u?.from||!u.to)continue;const h=t.find(g=>g.target===f.id&&g.source===u.from),m=t.find(g=>g.source===f.id&&g.target===u.to),y=(a=f.data)===null||a===void 0?void 0:a.sequenceNumber;i.push({item:R({kind:"message",nodeId:f.id,fromNodeId:u.from,toNodeId:u.to,label:pt(f),token:es(h,m),centralSource:(h==null||(d=h.data)===null||d===void 0?void 0:d.centralSource)===!0,centralTarget:(m==null||(l=m.data)===null||l===void 0?void 0:l.centralTarget)===!0},typeof y=="number"?{sequenceNumber:y}:{}),y:f.position.y})}return i.sort((f,c)=>f.y-c.y).map(f=>f.item)}function os(e){const t=[];for(const a of e){var n,o,r,i,s;const d=(n=a.data)===null||n===void 0?void 0:n.sequenceBlock;d&&typeof d.startRow=="number"&&typeof d.endRow=="number"&&t.push(R(R({nodeId:a.id,type:(o=d.type)!==null&&o!==void 0?o:"rect",label:(r=d.label)!==null&&r!==void 0?r:""},d.color?{color:d.color}:{}),{},{depth:(i=d.depth)!==null&&i!==void 0?i:0,startRow:d.startRow,endRow:d.endRow,sections:((s=d.sections)!==null&&s!==void 0?s:[]).filter(l=>typeof l.startRow=="number"&&typeof l.endRow=="number").map(l=>{var p;return{label:(p=l.label)!==null&&p!==void 0?p:"",startRow:l.startRow,endRow:l.endRow}})}))}return t}function is(e,t){const n=[];for(const s of e){var o,r,i;const a=(o=s.data)===null||o===void 0?void 0:o.sequenceBox;if(!a)continue;const d=(Array.isArray(a.participants)?a.participants.filter(u=>typeof u=="string"):[]).map(u=>t.find(h=>h.nodeId===`participant-${u}`)).filter(u=>!!u),l=s.position.x,p=s.position.x+(Number(s.width)||0),f=d.length>0?d:t.filter(u=>u.x>=l&&u.x<=p);if(f.length===0)continue;const c=(r=s.data)===null||r===void 0?void 0:r.backgroundColor;n.push(R(R({nodeId:s.id,label:(i=a.label)!==null&&i!==void 0?i:""},typeof c=="string"?{color:c}:{}),{},{participantNodeIds:f.map(u=>u.nodeId)}))}return n}function gn(e,t){const n=e.type==="participant"||e.type==="actor"?"":`@{ "type": "${e.type}" }`,o=e.mermaidId===e.name?"":` as ${Fe(e.name)}`;return`${t} ${e.mermaidId}${n}${o}`}function rs(e,t){const n=new Map,o=Vr(e),r=ns(e,t,o),i=os(e),s=is(e,o),a=new Map(o.map(v=>[v.nodeId,v]));for(const v of o)n.set(v.nodeId,`participant-${v.mermaidId}`);const d=new Map,l=new Map;let p=0;for(const v of r){d.set(v.nodeId,p);const I=v.kind==="message"&&v.fromNodeId===v.toNodeId;l.set(v.nodeId,I?p+1:p),p+=I?2:1}const f=p,c=["sequenceDiagram"],u=e.find(v=>v.id==="sequence-title");if(u){var h;const v=(h=Fn(u,"text"))!==null&&h!==void 0?h:pt(u);v&&(c.push(` title ${Fe(v)}`),n.set(u.id,"sequence-title"))}const m=new Map,y=new Map;for(const v of s){var g;const I=o.filter(C=>v.participantNodeIds.includes(C.nodeId));I.length!==0&&(m.set(I[0].nodeId,v),y.set(I[I.length-1].nodeId,((g=y.get(I[I.length-1].nodeId))!==null&&g!==void 0?g:0)+1))}let E=0;for(const v of o){var w;const I=m.get(v.nodeId);if(I){const M=I.color?`${I.color} `:"";c.push(` box ${M}${Fe(I.label)}`.trimEnd()),n.set(I.nodeId,`sequence-box-box-${E}`),E++}if(v.createdRow===void 0){const M=v.type==="actor"?"actor":"participant";c.push(` ${gn(v,M)}`)}const C=(w=y.get(v.nodeId))!==null&&w!==void 0?w:0;for(let M=0;M<C;M++)c.push(" end")}for(const v of o)for(const I of v.links)c.push(` link ${v.mermaidId}: ${I.label} @ ${I.url}`);const N=r.filter(v=>v.kind==="message"&&v.sequenceNumber!==void 0);if(N.length>0){const v=N[0].sequenceNumber,I=N.length>1?N[1].sequenceNumber-N[0].sequenceNumber:1;c.push(` autonumber ${v} ${I}`)}const T=[];let x=0,S=0;function b(){return" ".repeat(T.length+1)}for(let v=0;v<f;v++){const I=i.filter(A=>A.startRow===v).sort((A,k)=>A.depth-k.depth);for(const A of I){const k=Fe(A.label),$=A.type==="rect"&&A.color?`${A.color} `:"";c.push(`${b()}${A.type} ${$}${k}`.trimEnd()),n.set(A.nodeId,`sequence-block-block-${x}`),x++,T.push(A)}for(const[A,k]of T.entries())for(const $ of k.sections.slice(1)){if($.startRow!==v)continue;const P=k.type==="par"?"and":k.type==="critical"?"option":"else";c.push(`${" ".repeat(A+1)}${P} ${Fe($.label)}`.trimEnd())}const C=r.find(A=>d.get(A.nodeId)===v);if(C){for(const A of o){if(A.createdRow!==v)continue;const k=A.type==="actor"?"actor":"participant";c.push(`${b()}create ${gn(A,k)}`)}for(const A of o)A.destroyedRow===v&&c.push(`${b()}destroy ${A.mermaidId}`);for(const A of o)for(const k of A.activations)k.startRow===v&&c.push(`${b()}activate ${A.mermaidId}`);if(C.kind==="message"){const A=a.get(C.fromNodeId),k=a.get(C.toNodeId);if(A&&k){const $=C.centralSource?`${A.mermaidId}()`:A.mermaidId,P=C.centralTarget?`()${k.mermaidId}`:k.mermaidId;c.push(`${b()}${$}${C.token}${P}: ${Fe(C.label)}`),n.set(C.nodeId,`message-${S}`),S++}}if(C.kind==="note"){const A=C.participantNodeIds.map(k=>{var $;return($=a.get(k))===null||$===void 0?void 0:$.mermaidId}).filter(k=>k!==void 0);A.length>0&&(c.push(`${b()}Note ${C.placement} ${A.join(",")}: ${Fe(C.text)}`),n.set(C.nodeId,`note-${S}`),S++)}}const M=C?l.get(C.nodeId):v;for(const A of o)for(const k of A.activations)k.endRow===M&&c.push(`${b()}deactivate ${A.mermaidId}`);for(;T.length>0&&T[T.length-1].endRow<=M;)T.pop(),c.push(`${b()}end`)}for(;T.length>0;)T.pop(),c.push(`${b()}end`);return{mermaid:c.join(`
76
+ `),nodeIdMap:n}}function $s(e,t){const{mermaid:n,nodeIdMap:o}=rs(e,t);return{mermaid:n,context:Gt(e,t,[],o)}}const rt=20;function ss(e){var t,n;return{id:(t=e.id)!==null&&t!==void 0?t:dt(),type:"group",position:{x:e.bounds.x,y:e.bounds.y},data:{childNodes:e.nodes,autoLayout:!0,componentFields:[me((n=e.name)!==null&&n!==void 0?n:"Group")]},style:{width:e.bounds.width+20,height:e.bounds.height+50}}}function as(e,t,n){const o=n.map(d=>{var l,p,f,c,u,h,m,y,g,E;return{top:d.position.y,left:d.position.x,bottom:d.position.y+((l=(p=(f=d.height)!==null&&f!==void 0?f:(c=d.style)===null||c===void 0?void 0:c.height)!==null&&p!==void 0?p:(u=d.measured)===null||u===void 0?void 0:u.height)!==null&&l!==void 0?l:0),right:d.position.x+((h=(m=(y=d.width)!==null&&y!==void 0?y:(g=d.style)===null||g===void 0?void 0:g.width)!==null&&m!==void 0?m:(E=d.measured)===null||E===void 0?void 0:E.width)!==null&&h!==void 0?h:0)}}),r=Math.min(...o.map(d=>d.left)),i=Math.min(...o.map(d=>d.top)),s=Math.max(...o.map(d=>d.right)),a=Math.max(...o.map(d=>d.bottom));return ss({id:e,name:t,nodes:n.map(d=>d.id),bounds:{x:r-rt,y:i-rt,width:s-r+rt*2,height:a-i+rt*2}})}function cs(e,t){return $t.apply(this,arguments)}function $t(){return $t=Be(function*(e,t){const n=e?.toLowerCase(),o=(n==="azure"?[...(yield Qe(()=>import("./__azure-icons.DgR1F6C6-DcLey4UX.js"),[])).default]:n==="aws"?[...(yield Qe(()=>import("./__aws-icons.agWBtDk7-CePtapr2.js"),[])).default]:[...(yield Qe(()=>import("./__aws-icons.agWBtDk7-CePtapr2.js"),[])).default,...(yield Qe(()=>import("./__azure-icons.DgR1F6C6-DcLey4UX.js"),[])).default]).find(r=>r.name.toLowerCase()===t.toLowerCase());return o?`/${o.cloud.toLowerCase()}-icons/${o.relativePath}`:null}),$t.apply(this,arguments)}function ls(e){return Dt.apply(this,arguments)}function Dt(){return Dt=Be(function*(e){const t=(yield Qe(()=>import("./__animated-nodes.DI0XYTuw-C-Pp0d4E.js"),[])).default.find(n=>n.name.toLowerCase()===e.toLowerCase());return t?`/animated-nodes/${t.fileName}`:null}),Dt.apply(this,arguments)}const Bn={databaseTableSQL:{width:500,height:400},table:{width:600,height:400},code:{width:300,height:400}},st=20,ds=20,us=50,hs=140,fs=80;function qe(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function It(e){var t,n,o,r,i,s,a,d,l,p,f,c;const u=e.type?Bn[e.type]:void 0;return{width:(t=(n=(o=(r=qe(e.width))!==null&&r!==void 0?r:qe((i=e.style)===null||i===void 0?void 0:i.width))!==null&&o!==void 0?o:qe((s=e.measured)===null||s===void 0?void 0:s.width))!==null&&n!==void 0?n:u?.width)!==null&&t!==void 0?t:0,height:(a=(d=(l=(p=qe(e.height))!==null&&p!==void 0?p:qe((f=e.style)===null||f===void 0?void 0:f.height))!==null&&l!==void 0?l:qe((c=e.measured)===null||c===void 0?void 0:c.height))!==null&&d!==void 0?d:u?.height)!==null&&a!==void 0?a:0}}function ps(e){const t=e.map(s=>{if(!s.type)return;const a=Bn[s.type];if(!a)return;const d=It(s);return{startX:s.position.x+a.width,startY:s.position.y+a.height,deltaX:Math.max(0,d.width-a.width),deltaY:Math.max(0,d.height-a.height)}}).filter(s=>!!s),n=e.map(s=>{var a;const d=(a=s.data)===null||a===void 0?void 0:a.childNodes;if(Array.isArray(d))return R({},s);const l=t.reduce((f,c)=>!c||c.deltaX===0||s.position.x<c.startX?f:f+c.deltaX,0),p=t.reduce((f,c)=>!c||c.deltaY===0||s.position.y<c.startY?f:f+c.deltaY,0);return l===0&&p===0?s:R(R({},s),{},{position:{x:s.position.x+l,y:s.position.y+p}})}),o=new Map(n.map(s=>[s.id,s])),r=n.filter(s=>{var a;return!Array.isArray((a=s.data)===null||a===void 0?void 0:a.childNodes)}).sort((s,a)=>s.position.y===a.position.y?s.position.x-a.position.x:s.position.y-a.position.y),i=[];for(const s of r){const a=i.find(d=>Math.abs(d[0].position.y-s.position.y)<=fs);if(a){a.push(s);continue}i.push([s])}for(const s of i){s.sort((a,d)=>a.position.x-d.position.x);for(let a=1;a<s.length;a+=1){const d=s[a-1],l=s[a],p=It(d),f=d.position.x+p.width+hs;if(l.position.x>=f)continue;const c=R(R({},l),{},{position:{x:f,y:l.position.y}});s[a]=c,o.set(c.id,c)}}return n.map(s=>{var a,d;const l=(a=o.get(s.id))!==null&&a!==void 0?a:s,p=(d=s.data)===null||d===void 0?void 0:d.childNodes;if(!Array.isArray(p))return l;const f=p.map(g=>typeof g=="string"?o.get(g):void 0).filter(g=>!!g);if(f.length===0)return l;const c=f.map(g=>{const E=It(g);return{left:g.position.x,top:g.position.y,right:g.position.x+E.width,bottom:g.position.y+E.height}}),u=Math.min(...c.map(g=>g.left)),h=Math.min(...c.map(g=>g.top)),m=Math.max(...c.map(g=>g.right)),y=Math.max(...c.map(g=>g.bottom));return R(R({},l),{},{position:{x:u-st,y:h-st},style:R(R({},l.style),{},{width:m-u+st*2+ds,height:y-h+st*2+us})})})}function ms(e){return e?Number.isFinite(e.x)&&Number.isFinite(e.y):!1}function yn(e){if(!e)return;const t=e.type.trim().toLowerCase();let n;if(t==="arrow"?n=xe.Arrow:(t==="arrowclosed"||t==="arrow-closed"||t==="arrow_closed")&&(n=xe.ArrowClosed),!!n)return e.color?{type:n,color:e.color}:{type:n}}function Ds(e,t,n){return Ot.apply(this,arguments)}function Ot(){return Ot=Be(function*(e,t,n){var o;const r=En.parse(t),i=yield Rr(e),s=i.nodes.map((function(){var h=Be(function*(m){var y,g,E,w,N,T,x,S;const b=(y=r.nodes)===null||y===void 0?void 0:y[m.id];if(!b)return m;const v=JSON.parse(JSON.stringify(m)),I=(g=v.data.componentFields)!==null&&g!==void 0?g:[];if((E=b.data)!==null&&E!==void 0||(b.data={}),(w=v.data)!==null&&w!==void 0||(v.data={}),ms(b.___position)&&(v.position={x:b.___position.x,y:b.___position.y}),b.type){if(v.type=b.type,delete v.style,b.type==="cloud"&&(v.height=150,v.width=150,b.service)){const $=n?.resolveCloudIcon?yield n.resolveCloudIcon(b.cloud,b.service):yield cs(b.cloud,b.service);$&&(v.data.iconSrc=$)}if(b.type==="image"&&b.src&&(v.data=R(R({},v.data),{},{src:b.src})),b.type==="gif")if(b.animatedIcon){const $=yield ls(b.animatedIcon);$&&(v.data=R(R({},v.data),{},{src:$}))}else b.src&&(v.data=R(R({},v.data),{},{src:b.src}));if(b.type==="text"&&(b.value||b.name)){const $=ke({type:L.TextInput,componentFieldId:"text",label:"Text",data:b.value||b.name,isReadonly:!0});I.unshift($)}if(b.type==="code"&&b.value){const $=ke({type:L.CodeEditor,componentFieldId:"code",label:"Code",data:b.value,isReadonly:!0});I.unshift($)}if(b.type==="table"&&b.table){var C,M;v.data.title=b.name,v.data.rows=(C=b.table.rows)!==null&&C!==void 0?C:[],v.data.columns=(M=b.table.columns)!==null&&M!==void 0?M:[]}if((b.type==="data-source"||b.type==="db-table")&&(b.type="databaseTableSQL",v.type="databaseTableSQL"),b.type==="component"&&(b.type="builder",v.type="builder",v.data.componentId=b.componentId),b.type==="shape"&&b.shape&&(v.data.shape=b.shape,b.shape==="or"||b.shape==="summing-junction")){var A,k;const $=Math.max((A=v.width)!==null&&A!==void 0?A:0,(k=v.height)!==null&&k!==void 0?k:0,200);v.width=$,v.height=$}}b.name&&(b.data.Name={type:L.TextInput,value:b.name});for(const $ in b.data){const P=b.data[$];if(P===void 0)continue;const B=Si(I,$),U=ke({label:$,type:P.type,data:P.value,options:P.options});B?(B.type=U.type,B.data=U.data):I.push(U)}return b.dbConfig&&(v.data.serviceTable={serviceName:b.dbConfig.serviceName,databaseName:b.dbConfig.databaseName,tableName:b.dbConfig.tableName}),!((N=b.style)===null||N===void 0)&&N.height&&(v.height=b.style.height),!((T=b.style)===null||T===void 0)&&T.width&&(v.width=b.style.width),v.data=R(R(R({},v.data),no((x=b.style)!==null&&x!==void 0?x:{},["color","fill","stroke","strokeWidth","strokeStyle","borderRadius","borderAnimationEnabled"])),{},{componentFields:I,strokeAnimation:!((S=b.style)===null||S===void 0)&&S.borderAnimationEnabled?"dash":void 0},b?.___internal),v});return function(m){return h.apply(this,arguments)}})()),a=yield Promise.all(s),d=Object.entries((o=t.groups)!==null&&o!==void 0?o:{}).map(([h,m])=>{var y,g;const E=xn(((y=m.nodes)!==null&&y!==void 0?y:[]).map(w=>a.find(N=>N.id===w)));return as(h,(g=m.name)!==null&&g!==void 0?g:"Group",E)}),l=new Map,p=i.edges.map(h=>{var m;const y=`${h.source}-${h.target}`,g=(m=l.get(y))!==null&&m!==void 0?m:0;return l.set(y,g+1),g===0?{pair:y,key:y}:{pair:y,key:`${y}#${g}`}}),f=i.edges.map((function(){var h=Be(function*(m,y){var g,E,w,N,T,x,S,b,v,I,C,M,A,k,$,P,B,U,q,z,Y,G;const{pair:te,key:Q}=p[y],ne=(g=(E=(w=r.edges)===null||w===void 0?void 0:w[Q])!==null&&E!==void 0?E:(N=r.edges)===null||N===void 0?void 0:N[te])!==null&&g!==void 0?g:null;return ne?R(R({},m),{},{type:(T=ne.type)!==null&&T!==void 0?T:m.type,sourceHandle:(x=ne.sourceHandle)!==null&&x!==void 0?x:m.sourceHandle,targetHandle:(S=ne.targetHandle)!==null&&S!==void 0?S:m.targetHandle,markerStart:(b=yn(ne.markerStart))!==null&&b!==void 0?b:m.markerStart,markerEnd:(v=yn(ne.markerEnd))!==null&&v!==void 0?v:m.markerEnd,data:R(R({},m.data),ne?.___internal),label:(I=ne.label)!==null&&I!==void 0?I:m.label,animated:(C=(M=ne.style)===null||M===void 0?void 0:M.borderAnimationEnabled)!==null&&C!==void 0?C:m.animated,style:R(R({},m.style),{},{stroke:(A=(k=ne.style)===null||k===void 0?void 0:k.stroke)!==null&&A!==void 0?A:($=m.style)===null||$===void 0?void 0:$.stroke,strokeWidth:(P=(B=ne.style)===null||B===void 0?void 0:B.strokeWidth)!==null&&P!==void 0?P:(U=m.style)===null||U===void 0?void 0:U.strokeWidth,strokeDasharray:((q=ne.style)===null||q===void 0?void 0:q.strokeStyle)==="dashed"?"4 2":((z=ne.style)===null||z===void 0?void 0:z.strokeStyle)==="dotted"?"1 2":((Y=ne.style)===null||Y===void 0?void 0:Y.strokeStyle)==="solid"||(G=m.style)===null||G===void 0?void 0:G.strokeDasharray})}):m});return function(m,y){return h.apply(this,arguments)}})()),c=yield Promise.all(f),u=[...d,...a.map(h=>{const m=d.find(y=>{var g;return(g=y.data.childNodes)===null||g===void 0?void 0:g.includes(h.id)});return m?R(R({},h),{},{parentId:m.id}):h})];return Qr(u)?{edges:c,nodes:u}:Hr(u)?{edges:c,nodes:u}:{edges:c,nodes:n?.repositionNodes?ps(u):u}}),Ot.apply(this,arguments)}function gs(e,t){const n=new Map(e.map(d=>[d.id,d]));let o=0,r=0,i=0;for(const d of t){const l=n.get(d.source),p=n.get(d.target);!l||!p||(o+=Math.abs(p.position.x-l.position.x),r+=Math.abs(p.position.y-l.position.y),i+=1)}if(i>0)return o>=r?"LR":"TB";const s=e.map(d=>d.position.x),a=e.map(d=>d.position.y);return Math.max(...s,0)-Math.min(...s,0)>=Math.max(...a,0)-Math.min(...a,0)?"LR":"TB"}function ys(e){return/^[A-Za-z]+$/.test(e)}function vn(e){let t=e,n="";for(;t>=0;)n=String.fromCharCode(t%26+65)+n,t=Math.floor(t/26)-1;return n}function vs(e){const t=new Set,n=new Map;let o=0;return e.forEach(r=>{if(ys(r.id)&&!t.has(r.id)){n.set(r.id,r.id),t.add(r.id);return}let i=vn(o);for(o+=1;t.has(i);)i=vn(o),o+=1;n.set(r.id,i),t.add(i)}),n}function bs(e){const t=e.type,n=ve(e.data),o=Array.isArray(n?.componentFields)?n.componentFields.map(i=>ve(i)).filter(i=>i!==void 0):[],r=lt(o,"Name");if(t==="text")return lt(o,"Text");if(t==="code")return lt(o,"Code");if(t==="shape"||t==="cloud"||t==="table"||t==="gif")return r}function ws(e,t,n){return e.map(o=>{var r;const i=(r=t.get(o.id))!==null&&r!==void 0?r:o.id,s=bs(o);return!s||!Pr(s)?i:`${i}["${Lr(s)}"]`})}function xs(e,t,n){const o=[];for(const r of e){const i=t.get(r.source),s=t.get(r.target);!i||!s||o.push(`${i} --> ${s}`)}return o}function Os(e,t){const n=e.nodes.filter(l=>l.type==="group"),o=e.nodes.filter(l=>l.type!=="group"),r=gs(o,e.edges),i=vs(o),s=ws(o,i),a=xs(e.edges,i),d=Gt(o,e.edges,n,i);return{mermaid:[`flowchart ${r}`,...s,...a].join(`
77
+ `),context:d}}export{Cs as A,L as C,Rs as S,Ms as a,Ni as b,Rr as c,Qr as d,$s as e,_s as f,Os as g,Ds as h,Hr as i,vt as j,ks as k,on as l,De as m,$n as n};