@neuralis/brain-core 0.1.0 → 0.2.1

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 (401) hide show
  1. package/README.md +26 -35
  2. package/app/README.md +1 -1
  3. package/app/cards/DiffView.tsx +9 -7
  4. package/app/cards/README.md +1 -1
  5. package/app/cards/diffLine.tsx +2 -4
  6. package/app/filesystem/README.md +4 -4
  7. package/app/filesystem/api/README.md +3 -3
  8. package/app/filesystem/api/index.ts +137 -123
  9. package/app/filesystem/domain/types.ts +36 -5
  10. package/app/filesystem/hooks/README.md +5 -5
  11. package/app/filesystem/hooks/useDiscoverableSources.ts +4 -2
  12. package/app/filesystem/hooks/useFilesystemSSE.ts +31 -23
  13. package/app/filesystem/hooks/useGitChangesInventory.ts +4 -2
  14. package/app/filesystem/host/README.md +3 -2
  15. package/app/filesystem/host/installFilesystemHostComponents.tsx +22 -9
  16. package/app/filesystem/store/README.md +11 -7
  17. package/app/filesystem/store/filesystemStore.ts +454 -162
  18. package/app/filesystem/store/gitSlice.ts +6 -6
  19. package/app/filesystem/store/listSlice.ts +10 -6
  20. package/app/filesystem/store/searchSlice.ts +27 -4
  21. package/app/filesystem/ui/FileEditor.tsx +48 -35
  22. package/app/filesystem/ui/FileTree.tsx +10 -9
  23. package/app/filesystem/ui/FileTreeSearch.tsx +29 -2
  24. package/app/filesystem/ui/GitCommitChangesView.tsx +5 -3
  25. package/app/filesystem/ui/GitCommitGraph.tsx +6 -5
  26. package/app/filesystem/ui/GitControlPanel.tsx +14 -13
  27. package/app/filesystem/ui/GitDiffView.tsx +2 -1
  28. package/app/filesystem/ui/GitFileDiff.tsx +7 -6
  29. package/app/filesystem/ui/PendingChangesPanel.tsx +88 -28
  30. package/app/filesystem/ui/PendingReviewDialog.tsx +52 -24
  31. package/app/filesystem/ui/README.md +8 -7
  32. package/app/filesystem/ui/ReembedDialog.tsx +22 -9
  33. package/app/filesystem/ui/SourceDeleteConfirm.tsx +1 -1
  34. package/app/filesystem/ui/SourcesPanel.tsx +135 -42
  35. package/app/filesystem/ui/VectorHealthPanel.tsx +20 -4
  36. package/app/filesystem/ui/pendingChangesModel.ts +9 -5
  37. package/dist/app/chunks/{astro-LRAFGXNX.js → astro-B2J4AS2D.js} +1 -1
  38. package/dist/app/chunks/bash-KY6SAQTH.js +1 -0
  39. package/dist/app/chunks/c-OBOPYVZ7.js +1 -0
  40. package/dist/app/chunks/{chunk-5H7ZCOD3.js → chunk-2X3GNKJ3.js} +1 -1
  41. package/dist/app/chunks/{chunk-XIFGTNRM.js → chunk-JPJIVRFI.js} +1 -1
  42. package/dist/app/chunks/{chunk-RH3QY5LF.js → chunk-LEFIFWND.js} +1 -1
  43. package/dist/app/chunks/{chunk-G4RZ3UNX.js → chunk-N6RXX3PH.js} +1 -1
  44. package/dist/app/chunks/{chunk-QXXJ73P5.js → chunk-PZAW4HPB.js} +1 -1
  45. package/dist/app/chunks/{chunk-3QLE7Y4L.js → chunk-ZBYWWTO6.js} +1 -1
  46. package/dist/app/chunks/cpp-TVWVOTEQ.js +1 -0
  47. package/dist/app/chunks/css-MANZBYA4.js +1 -0
  48. package/dist/app/chunks/{elixir-M36XROA6.js → elixir-S725Z7EH.js} +1 -1
  49. package/dist/app/chunks/{elm-7BG6QAIK.js → elm-5WUUSTNB.js} +1 -1
  50. package/dist/app/chunks/graphql-UGOPR3WU.js +1 -0
  51. package/dist/app/chunks/html-F6FWTBSG.js +1 -0
  52. package/dist/app/chunks/java-ANIVV5H5.js +1 -0
  53. package/dist/app/chunks/javascript-IH374YWG.js +1 -0
  54. package/dist/app/chunks/json-WGGVVXSB.js +1 -0
  55. package/dist/app/chunks/jsx-OTXJQD32.js +1 -0
  56. package/dist/app/chunks/{latex-ZWK7SXB6.js → latex-QCZNITGN.js} +1 -1
  57. package/dist/app/chunks/lua-4CRZ64PU.js +1 -0
  58. package/dist/app/chunks/{nginx-2L6VRV3A.js → nginx-V4CYS7WR.js} +1 -1
  59. package/dist/app/chunks/{perl-PBUAXXK6.js → perl-BHTX7F5B.js} +1 -1
  60. package/dist/app/chunks/{php-QJX57PA6.js → php-AYGJ5WYZ.js} +1 -1
  61. package/dist/app/chunks/r-4YFCFA4B.js +1 -0
  62. package/dist/app/chunks/{ruby-RLOWMVPO.js → ruby-42NMJWAL.js} +1 -1
  63. package/dist/app/chunks/{scss-B5CAI3HR.js → scss-XD7VU2CU.js} +1 -1
  64. package/dist/app/chunks/sql-B55MH6JJ.js +1 -0
  65. package/dist/app/chunks/{svelte-GT3D4C44.js → svelte-WR3QPIJU.js} +1 -1
  66. package/dist/app/chunks/tsx-S73GAE2L.js +1 -0
  67. package/dist/app/chunks/typescript-NEWOAB5Z.js +1 -0
  68. package/dist/app/chunks/{vue-JOW62MHD.js → vue-CCDS4VZK.js} +1 -1
  69. package/dist/app/chunks/xml-UXKAGLDR.js +1 -0
  70. package/dist/app/chunks/yaml-UMWKDTK7.js +1 -0
  71. package/dist/app/host.js +46 -46
  72. package/dist/scripts/embeddingLockV3.d.ts +30 -0
  73. package/dist/scripts/embeddingLockV3.d.ts.map +1 -0
  74. package/dist/scripts/embeddingLockV3.js +100 -0
  75. package/dist/scripts/embeddingLockV3.js.map +1 -0
  76. package/dist/scripts/vectorProofV1.d.ts +90 -0
  77. package/dist/scripts/vectorProofV1.d.ts.map +1 -0
  78. package/dist/scripts/vectorProofV1.js +220 -0
  79. package/dist/scripts/vectorProofV1.js.map +1 -0
  80. package/dist/src/config/env.d.ts +21 -0
  81. package/dist/src/config/env.d.ts.map +1 -1
  82. package/dist/src/config/env.js +55 -0
  83. package/dist/src/config/env.js.map +1 -1
  84. package/dist/src/connectors/AppSourceConfigStore.d.ts +12 -2
  85. package/dist/src/connectors/AppSourceConfigStore.d.ts.map +1 -1
  86. package/dist/src/connectors/AppSourceConfigStore.js +48 -40
  87. package/dist/src/connectors/AppSourceConfigStore.js.map +1 -1
  88. package/dist/src/connectors/LocalDiskConnector.d.ts +11 -14
  89. package/dist/src/connectors/LocalDiskConnector.d.ts.map +1 -1
  90. package/dist/src/connectors/LocalDiskConnector.js +87 -107
  91. package/dist/src/connectors/LocalDiskConnector.js.map +1 -1
  92. package/dist/src/connectors/sourceConfigMutation.d.ts +11 -1
  93. package/dist/src/connectors/sourceConfigMutation.d.ts.map +1 -1
  94. package/dist/src/connectors/sourceConfigMutation.js +36 -3
  95. package/dist/src/connectors/sourceConfigMutation.js.map +1 -1
  96. package/dist/src/domain/chunker.js +8 -3
  97. package/dist/src/domain/chunker.js.map +1 -1
  98. package/dist/src/domain/healthTypes.d.ts +11 -0
  99. package/dist/src/domain/healthTypes.d.ts.map +1 -1
  100. package/dist/src/domain/mime.d.ts +1 -0
  101. package/dist/src/domain/mime.d.ts.map +1 -1
  102. package/dist/src/domain/mime.js +48 -0
  103. package/dist/src/domain/mime.js.map +1 -1
  104. package/dist/src/domain/pendingChange.d.ts +7 -0
  105. package/dist/src/domain/pendingChange.d.ts.map +1 -1
  106. package/dist/src/domain/pendingChange.js +11 -0
  107. package/dist/src/domain/pendingChange.js.map +1 -1
  108. package/dist/src/domain/sourceConfig.d.ts +7 -14
  109. package/dist/src/domain/sourceConfig.d.ts.map +1 -1
  110. package/dist/src/domain/sourceConfig.js +1 -13
  111. package/dist/src/domain/sourceConfig.js.map +1 -1
  112. package/dist/src/domain/sourcePackages.d.ts +11 -2
  113. package/dist/src/domain/sourcePackages.d.ts.map +1 -1
  114. package/dist/src/domain/syncTrigger.d.ts +2 -3
  115. package/dist/src/domain/syncTrigger.d.ts.map +1 -1
  116. package/dist/src/domain/syncTrigger.js +2 -3
  117. package/dist/src/domain/syncTrigger.js.map +1 -1
  118. package/dist/src/domain/syncTypes.d.ts +21 -4
  119. package/dist/src/domain/syncTypes.d.ts.map +1 -1
  120. package/dist/src/domain/syncTypes.js.map +1 -1
  121. package/dist/src/domain/text.d.ts +3 -0
  122. package/dist/src/domain/text.d.ts.map +1 -1
  123. package/dist/src/domain/text.js +5 -0
  124. package/dist/src/domain/text.js.map +1 -1
  125. package/dist/src/domain/types.d.ts +9 -0
  126. package/dist/src/domain/types.d.ts.map +1 -1
  127. package/dist/src/embeddings/clients/GeminiEmbedder.d.ts.map +1 -1
  128. package/dist/src/embeddings/clients/GeminiEmbedder.js +11 -5
  129. package/dist/src/embeddings/clients/GeminiEmbedder.js.map +1 -1
  130. package/dist/src/embeddings/clients/OllamaEmbedder.d.ts.map +1 -1
  131. package/dist/src/embeddings/clients/OllamaEmbedder.js +13 -6
  132. package/dist/src/embeddings/clients/OllamaEmbedder.js.map +1 -1
  133. package/dist/src/embeddings/clients/OpenAIEmbedder.d.ts.map +1 -1
  134. package/dist/src/embeddings/clients/OpenAIEmbedder.js +12 -9
  135. package/dist/src/embeddings/clients/OpenAIEmbedder.js.map +1 -1
  136. package/dist/src/embeddings/clients/QwenEmbedder.d.ts.map +1 -1
  137. package/dist/src/embeddings/clients/QwenEmbedder.js +12 -5
  138. package/dist/src/embeddings/clients/QwenEmbedder.js.map +1 -1
  139. package/dist/src/embeddings/clients/VoyageEmbedder.d.ts.map +1 -1
  140. package/dist/src/embeddings/clients/VoyageEmbedder.js +12 -5
  141. package/dist/src/embeddings/clients/VoyageEmbedder.js.map +1 -1
  142. package/dist/src/embeddings/factory.d.ts +2 -0
  143. package/dist/src/embeddings/factory.d.ts.map +1 -1
  144. package/dist/src/embeddings/factory.js +23 -3
  145. package/dist/src/embeddings/factory.js.map +1 -1
  146. package/dist/src/embeddings/lock.d.ts +22 -11
  147. package/dist/src/embeddings/lock.d.ts.map +1 -1
  148. package/dist/src/embeddings/lock.js +47 -29
  149. package/dist/src/embeddings/lock.js.map +1 -1
  150. package/dist/src/embeddings/retry.d.ts +5 -0
  151. package/dist/src/embeddings/retry.d.ts.map +1 -1
  152. package/dist/src/embeddings/retry.js +35 -0
  153. package/dist/src/embeddings/retry.js.map +1 -1
  154. package/dist/src/events/pending.d.ts +56 -0
  155. package/dist/src/events/pending.d.ts.map +1 -0
  156. package/dist/src/events/pending.js +108 -0
  157. package/dist/src/events/pending.js.map +1 -0
  158. package/dist/src/events/source.d.ts +60 -14
  159. package/dist/src/events/source.d.ts.map +1 -1
  160. package/dist/src/events/source.js +149 -31
  161. package/dist/src/events/source.js.map +1 -1
  162. package/dist/src/events/vector.d.ts +33 -0
  163. package/dist/src/events/vector.d.ts.map +1 -0
  164. package/dist/src/events/vector.js +57 -0
  165. package/dist/src/events/vector.js.map +1 -0
  166. package/dist/src/git/GitRunner.d.ts.map +1 -1
  167. package/dist/src/git/GitRunner.js +11 -8
  168. package/dist/src/git/GitRunner.js.map +1 -1
  169. package/dist/src/git/sourceGitControl.d.ts.map +1 -1
  170. package/dist/src/git/sourceGitControl.js +2 -1
  171. package/dist/src/git/sourceGitControl.js.map +1 -1
  172. package/dist/src/index.d.ts +5 -4
  173. package/dist/src/index.d.ts.map +1 -1
  174. package/dist/src/index.js +4 -3
  175. package/dist/src/index.js.map +1 -1
  176. package/dist/src/lifecycle.d.ts +20 -4
  177. package/dist/src/lifecycle.d.ts.map +1 -1
  178. package/dist/src/lifecycle.js +5 -1
  179. package/dist/src/lifecycle.js.map +1 -1
  180. package/dist/src/routes/health.js +6 -1
  181. package/dist/src/routes/health.js.map +1 -1
  182. package/dist/src/routes/pending.d.ts.map +1 -1
  183. package/dist/src/routes/pending.js +2 -1
  184. package/dist/src/routes/pending.js.map +1 -1
  185. package/dist/src/routes/sources.d.ts.map +1 -1
  186. package/dist/src/routes/sources.js +60 -11
  187. package/dist/src/routes/sources.js.map +1 -1
  188. package/dist/src/services/BridgeService.d.ts +2 -2
  189. package/dist/src/services/BridgeService.d.ts.map +1 -1
  190. package/dist/src/services/BridgeService.js +11 -2
  191. package/dist/src/services/BridgeService.js.map +1 -1
  192. package/dist/src/services/FilesystemService.d.ts +3 -1
  193. package/dist/src/services/FilesystemService.d.ts.map +1 -1
  194. package/dist/src/services/FilesystemService.js +3 -1
  195. package/dist/src/services/FilesystemService.js.map +1 -1
  196. package/dist/src/services/FilesystemUiService.js +1 -1
  197. package/dist/src/services/FilesystemUiService.js.map +1 -1
  198. package/dist/src/services/SyncScheduler.d.ts.map +1 -1
  199. package/dist/src/services/SyncScheduler.js +0 -14
  200. package/dist/src/services/SyncScheduler.js.map +1 -1
  201. package/dist/src/services/VectorHealthService.d.ts.map +1 -1
  202. package/dist/src/services/VectorHealthService.js +2 -46
  203. package/dist/src/services/VectorHealthService.js.map +1 -1
  204. package/dist/src/services/baselineRepair.d.ts +2 -2
  205. package/dist/src/services/baselineRepair.js +2 -2
  206. package/dist/src/services/declaredSources.d.ts +8 -1
  207. package/dist/src/services/declaredSources.d.ts.map +1 -1
  208. package/dist/src/services/declaredSources.js +19 -19
  209. package/dist/src/services/declaredSources.js.map +1 -1
  210. package/dist/src/store/dataFormats.d.ts +14 -3
  211. package/dist/src/store/dataFormats.d.ts.map +1 -1
  212. package/dist/src/store/dataFormats.js +15 -5
  213. package/dist/src/store/dataFormats.js.map +1 -1
  214. package/dist/src/sync/DeltaSyncRunner.d.ts.map +1 -1
  215. package/dist/src/sync/DeltaSyncRunner.js +78 -243
  216. package/dist/src/sync/DeltaSyncRunner.js.map +1 -1
  217. package/dist/src/sync/SyncJobQueue.d.ts +33 -4
  218. package/dist/src/sync/SyncJobQueue.d.ts.map +1 -1
  219. package/dist/src/sync/SyncJobQueue.js +179 -19
  220. package/dist/src/sync/SyncJobQueue.js.map +1 -1
  221. package/dist/src/sync/moveDetector.d.ts +2 -1
  222. package/dist/src/sync/moveDetector.d.ts.map +1 -1
  223. package/dist/src/sync/moveDetector.js +2 -1
  224. package/dist/src/sync/moveDetector.js.map +1 -1
  225. package/dist/src/tools/fs_search.d.ts.map +1 -1
  226. package/dist/src/tools/fs_search.js +8 -0
  227. package/dist/src/tools/fs_search.js.map +1 -1
  228. package/dist/src/tools/fs_write.js +3 -1
  229. package/dist/src/tools/fs_write.js.map +1 -1
  230. package/dist/src/usecases/chunkUpsert.d.ts +4 -0
  231. package/dist/src/usecases/chunkUpsert.d.ts.map +1 -1
  232. package/dist/src/usecases/chunkUpsert.js +103 -60
  233. package/dist/src/usecases/chunkUpsert.js.map +1 -1
  234. package/dist/src/usecases/embeddingBacklog.d.ts +31 -0
  235. package/dist/src/usecases/embeddingBacklog.d.ts.map +1 -0
  236. package/dist/src/usecases/embeddingBacklog.js +244 -0
  237. package/dist/src/usecases/embeddingBacklog.js.map +1 -0
  238. package/dist/src/usecases/listSourcePackages.js +17 -1
  239. package/dist/src/usecases/listSourcePackages.js.map +1 -1
  240. package/dist/src/usecases/mediaLane.d.ts +11 -4
  241. package/dist/src/usecases/mediaLane.d.ts.map +1 -1
  242. package/dist/src/usecases/mediaLane.js +67 -30
  243. package/dist/src/usecases/mediaLane.js.map +1 -1
  244. package/dist/src/usecases/pendingReview.d.ts.map +1 -1
  245. package/dist/src/usecases/pendingReview.js +24 -7
  246. package/dist/src/usecases/pendingReview.js.map +1 -1
  247. package/dist/src/usecases/purgeExcludedPoints.d.ts +2 -0
  248. package/dist/src/usecases/purgeExcludedPoints.d.ts.map +1 -1
  249. package/dist/src/usecases/purgeExcludedPoints.js +3 -2
  250. package/dist/src/usecases/purgeExcludedPoints.js.map +1 -1
  251. package/dist/src/usecases/readFiles.d.ts.map +1 -1
  252. package/dist/src/usecases/readFiles.js +33 -6
  253. package/dist/src/usecases/readFiles.js.map +1 -1
  254. package/dist/src/usecases/reconcileSourcePackageRoots.d.ts +31 -0
  255. package/dist/src/usecases/reconcileSourcePackageRoots.d.ts.map +1 -0
  256. package/dist/src/usecases/reconcileSourcePackageRoots.js +114 -0
  257. package/dist/src/usecases/reconcileSourcePackageRoots.js.map +1 -0
  258. package/dist/src/usecases/searchFiles.d.ts.map +1 -1
  259. package/dist/src/usecases/searchFiles.js +62 -64
  260. package/dist/src/usecases/searchFiles.js.map +1 -1
  261. package/dist/src/usecases/syncIndexedFile.d.ts +42 -0
  262. package/dist/src/usecases/syncIndexedFile.d.ts.map +1 -0
  263. package/dist/src/usecases/syncIndexedFile.js +242 -0
  264. package/dist/src/usecases/syncIndexedFile.js.map +1 -0
  265. package/dist/src/usecases/syncPointWrites.d.ts +5 -0
  266. package/dist/src/usecases/syncPointWrites.d.ts.map +1 -1
  267. package/dist/src/usecases/syncPointWrites.js +32 -5
  268. package/dist/src/usecases/syncPointWrites.js.map +1 -1
  269. package/dist/src/usecases/uploadBinary.d.ts.map +1 -1
  270. package/dist/src/usecases/uploadBinary.js +36 -49
  271. package/dist/src/usecases/uploadBinary.js.map +1 -1
  272. package/dist/src/usecases/vector/endpointGuard.js +2 -1
  273. package/dist/src/usecases/vector/endpointGuard.js.map +1 -1
  274. package/dist/src/usecases/vector/estimate.d.ts +7 -4
  275. package/dist/src/usecases/vector/estimate.d.ts.map +1 -1
  276. package/dist/src/usecases/vector/estimate.js +8 -5
  277. package/dist/src/usecases/vector/estimate.js.map +1 -1
  278. package/dist/src/usecases/vector/rebuildGeneration.d.ts +29 -5
  279. package/dist/src/usecases/vector/rebuildGeneration.d.ts.map +1 -1
  280. package/dist/src/usecases/vector/rebuildGeneration.js +224 -82
  281. package/dist/src/usecases/vector/rebuildGeneration.js.map +1 -1
  282. package/dist/src/usecases/vectorMaintenance.d.ts +46 -4
  283. package/dist/src/usecases/vectorMaintenance.d.ts.map +1 -1
  284. package/dist/src/usecases/vectorMaintenance.js +190 -11
  285. package/dist/src/usecases/vectorMaintenance.js.map +1 -1
  286. package/dist/src/usecases/write/commit.d.ts +6 -8
  287. package/dist/src/usecases/write/commit.d.ts.map +1 -1
  288. package/dist/src/usecases/write/commit.js +96 -112
  289. package/dist/src/usecases/write/commit.js.map +1 -1
  290. package/dist/src/usecases/write/content.js +1 -2
  291. package/dist/src/usecases/write/content.js.map +1 -1
  292. package/dist/src/usecases/write/ports.d.ts +1 -0
  293. package/dist/src/usecases/write/ports.d.ts.map +1 -1
  294. package/dist/src/vector/FilesystemVectorIndex.d.ts +34 -3
  295. package/dist/src/vector/FilesystemVectorIndex.d.ts.map +1 -1
  296. package/dist/src/vector/FilesystemVectorIndex.js +254 -20
  297. package/dist/src/vector/FilesystemVectorIndex.js.map +1 -1
  298. package/dist/src/vector/InMemoryVectorIndex.d.ts +9 -2
  299. package/dist/src/vector/InMemoryVectorIndex.d.ts.map +1 -1
  300. package/dist/src/vector/InMemoryVectorIndex.js +25 -6
  301. package/dist/src/vector/InMemoryVectorIndex.js.map +1 -1
  302. package/dist/src/vector/QdrantVectorIndex.d.ts +35 -9
  303. package/dist/src/vector/QdrantVectorIndex.d.ts.map +1 -1
  304. package/dist/src/vector/QdrantVectorIndex.js +209 -90
  305. package/dist/src/vector/QdrantVectorIndex.js.map +1 -1
  306. package/dist/src/vector/qdrantFilter.d.ts +3 -1
  307. package/dist/src/vector/qdrantFilter.d.ts.map +1 -1
  308. package/dist/src/vector/qdrantFilter.js +2 -0
  309. package/dist/src/vector/qdrantFilter.js.map +1 -1
  310. package/dist/src/vector/types.d.ts +81 -0
  311. package/dist/src/vector/types.d.ts.map +1 -1
  312. package/dist/src/vector/types.js +2 -0
  313. package/dist/src/vector/types.js.map +1 -1
  314. package/dist/src/wiring.d.ts +6 -0
  315. package/dist/src/wiring.d.ts.map +1 -1
  316. package/dist/src/wiring.js +62 -3
  317. package/dist/src/wiring.js.map +1 -1
  318. package/dist/tools/fs_search.json +2 -2
  319. package/docs/drive-overview.md +2 -2
  320. package/instructions/brain-model.md +1 -1
  321. package/package.json +1000 -11
  322. package/rules/brain-rules.md +1 -1
  323. package/skills/connect-business-data/SKILL.md +6 -4
  324. package/skills/create-package/SKILL.md +14 -12
  325. package/skills/create-package/references/config-and-credentials.md +3 -3
  326. package/skills/create-package/references/connectors-and-uri-policies.md +5 -3
  327. package/skills/create-package/references/manifest-and-discovery.md +5 -4
  328. package/skills/create-package/references/runtime-and-build.md +9 -9
  329. package/skills/create-package/references/skills-and-context.md +3 -3
  330. package/skills/create-package/references/surfaces-and-design.md +9 -6
  331. package/skills/create-package/references/team-and-workflows.md +2 -2
  332. package/skills/create-package/references/test-and-ship.md +15 -15
  333. package/skills/create-package/references/tools-and-schemas.md +1 -1
  334. package/skills/create-package/scripts/check-package.sh +50 -4
  335. package/skills/create-package/scripts/verify-loaded.sh +16 -16
  336. package/skills/manage-files/SKILL.md +2 -2
  337. package/skills/manage-sources/SKILL.md +16 -15
  338. package/skills/manage-sources/scripts/reembed.sh +9 -3
  339. package/skills/sync/SKILL.md +4 -4
  340. package/tools/fs_search.json +2 -2
  341. package/app/filesystem/hooks/useContainerWidth.ts +0 -39
  342. package/dist/app/chunks/bash-M45GHPBQ.js +0 -1
  343. package/dist/app/chunks/c-X3REOAWD.js +0 -1
  344. package/dist/app/chunks/cpp-VOWI743W.js +0 -1
  345. package/dist/app/chunks/css-2ZVPHE25.js +0 -1
  346. package/dist/app/chunks/graphql-7V2NP54C.js +0 -1
  347. package/dist/app/chunks/html-UF3LFLNA.js +0 -1
  348. package/dist/app/chunks/java-PNTAU4L3.js +0 -1
  349. package/dist/app/chunks/javascript-4JJTQGEL.js +0 -1
  350. package/dist/app/chunks/json-VLQ6D3JH.js +0 -1
  351. package/dist/app/chunks/jsx-KQKSLAAH.js +0 -1
  352. package/dist/app/chunks/lua-UFPYUJ2O.js +0 -1
  353. package/dist/app/chunks/r-QEZB45SR.js +0 -1
  354. package/dist/app/chunks/sql-DTZHNUZP.js +0 -1
  355. package/dist/app/chunks/tsx-WPR2WRZD.js +0 -1
  356. package/dist/app/chunks/typescript-LWO362OA.js +0 -1
  357. package/dist/app/chunks/xml-A5H72RTS.js +0 -1
  358. package/dist/app/chunks/yaml-MXHSIJCI.js +0 -1
  359. package/dist/src/services/purgePendingNodes.d.ts +0 -32
  360. package/dist/src/services/purgePendingNodes.d.ts.map +0 -1
  361. package/dist/src/services/purgePendingNodes.js +0 -61
  362. package/dist/src/services/purgePendingNodes.js.map +0 -1
  363. /package/dist/app/chunks/{chunk-737Y24HS.js → chunk-3JASFUPF.js} +0 -0
  364. /package/dist/app/chunks/{chunk-DKD2L57N.js → chunk-6EYLOQ4F.js} +0 -0
  365. /package/dist/app/chunks/{chunk-KYH5EHHY.js → chunk-7YRZ5LOQ.js} +0 -0
  366. /package/dist/app/chunks/{chunk-6TC3DVWV.js → chunk-C7LU4RID.js} +0 -0
  367. /package/dist/app/chunks/{chunk-TY33BMKR.js → chunk-CD52YDZP.js} +0 -0
  368. /package/dist/app/chunks/{chunk-OLEIKJ3X.js → chunk-DCJKTCJ5.js} +0 -0
  369. /package/dist/app/chunks/{chunk-QLBZ4JR2.js → chunk-EXIU2KBV.js} +0 -0
  370. /package/dist/app/chunks/{chunk-SFUNBBEA.js → chunk-FDP4LO4P.js} +0 -0
  371. /package/dist/app/chunks/{chunk-BGRVFATT.js → chunk-HNETUS7U.js} +0 -0
  372. /package/dist/app/chunks/{chunk-4QNMHAIR.js → chunk-LBFZJEDR.js} +0 -0
  373. /package/dist/app/chunks/{chunk-TRRUHDPN.js → chunk-ULRXL5VM.js} +0 -0
  374. /package/dist/app/chunks/{chunk-S6B4WWIF.js → chunk-XJK47SMJ.js} +0 -0
  375. /package/dist/app/chunks/{chunk-DZ5C5FKI.js → chunk-YYAAIAU2.js} +0 -0
  376. /package/dist/app/chunks/{clojure-OC6KPSJO.js → clojure-4QCN4GHG.js} +0 -0
  377. /package/dist/app/chunks/{core-KGE7TQJ3.js → core-ZHTX3P2Q.js} +0 -0
  378. /package/dist/app/chunks/{csharp-E7VIFITL.js → csharp-HQWR4N52.js} +0 -0
  379. /package/dist/app/chunks/{dark-plus-BOSCZXE4.js → dark-plus-GYPKKZES.js} +0 -0
  380. /package/dist/app/chunks/{dart-6Y3X27SZ.js → dart-FO4TTVO2.js} +0 -0
  381. /package/dist/app/chunks/{diff-TR2NPA64.js → diff-SHANV4YC.js} +0 -0
  382. /package/dist/app/chunks/{dist-T32U2VVR.js → dist-WSDF34DM.js} +0 -0
  383. /package/dist/app/chunks/{docker-N33HOW54.js → docker-VX55HTDS.js} +0 -0
  384. /package/dist/app/chunks/{go-6DGG5UTP.js → go-5UCPEC6S.js} +0 -0
  385. /package/dist/app/chunks/{haskell-KK36PMMM.js → haskell-25PJ3OSG.js} +0 -0
  386. /package/dist/app/chunks/{ini-VHVQ5TPB.js → ini-BJIVD5MK.js} +0 -0
  387. /package/dist/app/chunks/{kotlin-44WS3JHE.js → kotlin-MNR6XOEQ.js} +0 -0
  388. /package/dist/app/chunks/{less-5WZ3KLAK.js → less-KA5JURX6.js} +0 -0
  389. /package/dist/app/chunks/{light-plus-HGGBC43G.js → light-plus-QXH2UUWZ.js} +0 -0
  390. /package/dist/app/chunks/{make-X7RXMVW7.js → make-LPD5KOCO.js} +0 -0
  391. /package/dist/app/chunks/{markdown-46IKUAIB.js → markdown-LMWF6MQR.js} +0 -0
  392. /package/dist/app/chunks/{mdx-DGLHDAO7.js → mdx-WPMNN5BS.js} +0 -0
  393. /package/dist/app/chunks/{nix-Q6FYQZLX.js → nix-QGWLUUMZ.js} +0 -0
  394. /package/dist/app/chunks/{powershell-L4KJJ6DK.js → powershell-7GSBBEFF.js} +0 -0
  395. /package/dist/app/chunks/{prisma-IKS4LVH2.js → prisma-FPMPQISO.js} +0 -0
  396. /package/dist/app/chunks/{proto-AYCDOTJO.js → proto-7KDX5Z2U.js} +0 -0
  397. /package/dist/app/chunks/{python-KXMCSAFQ.js → python-CFG4FTQW.js} +0 -0
  398. /package/dist/app/chunks/{rust-J3BC3P6V.js → rust-X7A37WU3.js} +0 -0
  399. /package/dist/app/chunks/{scala-AYIIHBJK.js → scala-OYHJSUG2.js} +0 -0
  400. /package/dist/app/chunks/{swift-QPHHCQD3.js → swift-PE7VNYW5.js} +0 -0
  401. /package/dist/app/chunks/{toml-UV7JK7K7.js → toml-ETQRDILP.js} +0 -0
package/dist/app/host.js CHANGED
@@ -1,55 +1,55 @@
1
- import{a as Vo,c as W}from"./chunks/chunk-DCANE7XH.js";var $e=Vo((pB,k0)=>{var qf=globalThis.__neuralis_shared_modules__,v0=qf&&Object.prototype.hasOwnProperty.call(qf,"react")?qf.react:void 0;if(v0===void 0)throw new Error("[neuralis-ui] shared module react is not provided by the host");k0.exports=v0});var mr=Vo((mB,C0)=>{var Vf=globalThis.__neuralis_shared_modules__,S0=Vf&&Object.prototype.hasOwnProperty.call(Vf,"@neuralis/package-system/client")?Vf["@neuralis/package-system/client"]:void 0;if(S0===void 0)throw new Error("[neuralis-ui] shared module @neuralis/package-system/client is not provided by the host");C0.exports=S0});var Qr=Vo((gB,I0)=>{var $f=globalThis.__neuralis_shared_modules__,L0=$f&&Object.prototype.hasOwnProperty.call($f,"@neuralis/agent-core/app/chat")?$f["@neuralis/agent-core/app/chat"]:void 0;if(L0===void 0)throw new Error("[neuralis-ui] shared module @neuralis/agent-core/app/chat is not provided by the host");I0.exports=L0});var le=Vo((IU,Rb)=>{var mh=globalThis.__neuralis_shared_modules__,Nb=mh&&Object.prototype.hasOwnProperty.call(mh,"react/jsx-runtime")?mh["react/jsx-runtime"]:void 0;if(Nb===void 0)throw new Error("[neuralis-ui] shared module react/jsx-runtime is not provided by the host");Rb.exports=Nb});var Ya=Vo((_8,Fb)=>{var yh=globalThis.__neuralis_shared_modules__,Db=yh&&Object.prototype.hasOwnProperty.call(yh,"react-dom")?yh["react-dom"]:void 0;if(Db===void 0)throw new Error("[neuralis-ui] shared module react-dom is not provided by the host");Fb.exports=Db});var YI=Vo((Y$,XI)=>{var u0=globalThis.__neuralis_shared_modules__,KI=u0&&Object.prototype.hasOwnProperty.call(u0,"@neuralis/agent-core/app/chat/store")?u0["@neuralis/agent-core/app/chat/store"]:void 0;if(KI===void 0)throw new Error("[neuralis-ui] shared module @neuralis/agent-core/app/chat/store is not provided by the host");XI.exports=KI});var Hf=W($e(),1),Uf=W(mr(),1),d2=W(Qr(),1);var Mn=W($e(),1);var A0=n=>{let e,t=new Set,r=(u,c)=>{let d=typeof u=="function"?u(e):u;if(!Object.is(d,e)){let f=e;e=c??(typeof d!="object"||d===null)?d:Object.assign({},e,d),t.forEach(h=>h(e,f))}},a=()=>e,i={setState:r,getState:a,getInitialState:()=>l,subscribe:u=>(t.add(u),()=>t.delete(u))},l=e=n(r,a,i);return i},P0=(n=>n?A0(n):A0);var sl=W($e(),1);var I2=n=>n;function A2(n,e=I2){let t=sl.default.useSyncExternalStore(n.subscribe,sl.default.useCallback(()=>e(n.getState()),[n,e]),sl.default.useCallback(()=>e(n.getInitialState()),[n,e]));return sl.default.useDebugValue(t),t}var N0=n=>{let e=P0(n),t=r=>A2(e,r);return Object.assign(t,e),t},R0=(n=>n?N0(n):N0);function Xf(n,e){let t;try{t=n()}catch{return}return{getItem:a=>{var s;let o=l=>l===null?null:JSON.parse(l,e?.reviver),i=(s=t.getItem(a))!=null?s:null;return i instanceof Promise?i.then(o):o(i)},setItem:(a,s)=>t.setItem(a,JSON.stringify(s,e?.replacer)),removeItem:a=>t.removeItem(a)}}var Kf=n=>e=>{try{let t=n(e);return t instanceof Promise?t:{then(r){return Kf(r)(t)},catch(r){return this}}}catch(t){return{then(r){return this},catch(r){return Kf(r)(t)}}}},P2=(n,e)=>(t,r,a)=>{let s={storage:Xf(()=>window.localStorage),partialize:g=>g,version:0,merge:(g,x)=>({...x,...g}),...e},o=!1,i=0,l=new Set,u=new Set,c=s.storage;if(!c)return n((...g)=>{console.warn(`[zustand persist middleware] Unable to update item '${s.name}', the given storage is currently unavailable.`),t(...g)},r,a);let d=()=>{let g=s.partialize({...r()});return c.setItem(s.name,{state:g,version:s.version})},f=a.setState;a.setState=(g,x)=>(f(g,x),d());let h=n((...g)=>(t(...g),d()),r,a);a.getInitialState=()=>h;let p,m=()=>{var g,x;if(!c)return;let w=++i;o=!1,l.forEach(C=>{var k;return C((k=r())!=null?k:h)});let y=((x=s.onRehydrateStorage)==null?void 0:x.call(s,(g=r())!=null?g:h))||void 0;return Kf(c.getItem.bind(c))(s.name).then(C=>{if(C)if(typeof C.version=="number"&&C.version!==s.version){if(s.migrate){let k=s.migrate(C.state,C.version);return k instanceof Promise?k.then(v=>[!0,v]):[!0,k]}console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}else return[!1,C.state];return[!1,void 0]}).then(C=>{var k;if(w!==i)return;let[v,b]=C;if(p=s.merge(b,(k=r())!=null?k:h),t(p,!0),v)return d()}).then(()=>{w===i&&(y?.(r(),void 0),p=r(),o=!0,u.forEach(C=>C(p)))}).catch(C=>{w===i&&y?.(void 0,C)})};return a.persist={setOptions:g=>{s={...s,...g},g.storage&&(c=g.storage)},clearStorage:()=>{++i,c?.removeItem(s.name)},getOptions:()=>s,rehydrate:()=>m(),hasHydrated:()=>o,onHydrate:g=>(l.add(g),()=>{l.delete(g)}),onFinishHydration:g=>(u.add(g),()=>{u.delete(g)})},s.skipHydration||m(),p||h},M0=P2;var T0=W(mr(),1);function Ze(){return(0,T0.tryGetPackageApiImperativeAsync)("brain-core")}async function $o(n,e,t){let r=await Ze(),a={agentId:n};return e&&(a.projectId=e),t?.uri&&(a.uri=t.uri),typeof t?.recursive=="boolean"&&(a.recursive=t.recursive),t?.include&&(a.include=t.include),typeof t?.summary_chars=="number"&&(a.summary_chars=t.summary_chars),typeof t?.include_metadata=="boolean"&&(a.include_metadata=t.include_metadata),typeof t?.only_indexed=="boolean"&&(a.only_indexed=t.only_indexed),typeof t?.sources_only=="boolean"&&(a.sources_only=t.sources_only),typeof t?.include_counts=="boolean"&&(a.include_counts=t.include_counts),typeof t?.limit=="number"&&(a.limit=t.limit),r.post("list",a)}async function D0(n,e,t){return(await $o(n,e,{uri:`${t}://`,recursive:!1,include:"folders",include_counts:!0,limit:1})).sources?.[0]??null}async function Ko(n){return(await Ze()).post("read",n)}async function F0(n){let e={agentId:n.agentId};return n.projectId&&(e.projectId=n.projectId),n.scope&&(e.scope=n.scope),n.observed&&(e.observed="1"),(await Ze()).get("sources",e)}async function Yf(n){return(await Ze()).patch("sources",{agentId:n.agentId,...n.projectId?{projectId:n.projectId}:{},...n.config})}async function E0(n){return(await Ze()).post("sources/sync",n)}async function B0(n){let e={agentId:n.agentId};return n.projectId&&(e.projectId=n.projectId),n.source&&(e.source=n.source),(await Ze()).get("sources/sync-status",e)}async function O0(n){return(await Ze()).post("sources/enabled",{agentId:n.agentId,...n.projectId?{projectId:n.projectId}:{},source:n.source,enabled:n.enabled})}async function Zu(n){let e=new URLSearchParams;return e.set("agentId",n.agentId),n.projectId&&e.set("projectId",n.projectId),(await Ze()).get("sources/discoverable",Object.fromEntries(e))}function ds(n){return n?{repo:n}:{}}function gr(n){return n?{repo:n}:{}}async function Xo(n){let e={agentId:n.agentId,source:n.source};return n.projectId&&(e.projectId=n.projectId),(await Ze()).get("git/repos",e)}async function Qu(n){let e={agentId:n.agentId,source:n.source,...ds(n.repo)};return n.projectId&&(e.projectId=n.projectId),(await Ze()).get("git/status",e)}async function _0(n){let e={agentId:n.agentId,source:n.source,...ds(n.repo)};return n.projectId&&(e.projectId=n.projectId),(await Ze()).get("git/branch",e)}async function ec(n){let e={agentId:n.agentId,source:n.source,...ds(n.repo),path:n.path};return typeof n.commit=="string"&&(e.commit=n.commit),typeof n.base=="string"&&(e.base=n.base),typeof n.head=="string"&&(e.head=n.head),typeof n.staged=="boolean"&&(e.staged=n.staged?"1":"0"),n.projectId&&(e.projectId=n.projectId),(await Ze()).get("git/diff",e)}async function tc(n){let e={agentId:n.agentId,source:n.source,...ds(n.repo)};return n.projectId&&(e.projectId=n.projectId),typeof n.maxCount=="number"&&(e.maxCount=String(n.maxCount)),typeof n.skip=="number"&&(e.skip=String(n.skip)),n.ref&&(e.ref=n.ref),(await Ze()).get("git/log",e)}async function H0(n){let e={agentId:n.agentId,source:n.source,...ds(n.repo)};return n.projectId&&(e.projectId=n.projectId),typeof n.maxCount=="number"&&(e.maxCount=String(n.maxCount)),typeof n.skip=="number"&&(e.skip=String(n.skip)),n.ref&&(e.ref=n.ref),(await Ze()).get("git/log-stats",e)}async function nc(n){let e={agentId:n.agentId,source:n.source,...ds(n.repo),sha:n.sha};return n.projectId&&(e.projectId=n.projectId),(await Ze()).get("git/commit",e)}async function ol(n){let e={agentId:n.agentId,source:n.source,...ds(n.repo)};return n.projectId&&(e.projectId=n.projectId),(await Ze()).get("git/outgoing",e)}async function U0(n){let e={agentId:n.agentId,source:n.source,...ds(n.repo),path:n.path,rev:n.rev};return n.projectId&&(e.projectId=n.projectId),(await Ze()).get("git/show",e)}var xr=()=>Ze();async function G0(n){return(await xr()).post("git/stage",{source:n.source,...gr(n.repo),paths:n.paths,...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function z0(n){return(await xr()).post("git/unstage",{source:n.source,...gr(n.repo),paths:n.paths,...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function W0(n){return(await xr()).post("git/stage",{source:n.source,...gr(n.repo),hunk:n.hunk,...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function j0(n){return(await xr()).post("git/unstage",{source:n.source,...gr(n.repo),hunk:n.hunk,...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function q0(n){return(await xr()).post("git/discard",{source:n.source,...gr(n.repo),paths:n.paths,...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function V0(n){return(await xr()).post("git/commit",{source:n.source,...gr(n.repo),message:n.message,...n.amend?{amend:!0}:{},...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function $0(n){return(await xr()).post("git/branch",{source:n.source,...gr(n.repo),action:"create",name:n.name,...n.startPoint?{startPoint:n.startPoint}:{},...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function K0(n){return(await xr()).post("git/branch",{source:n.source,...gr(n.repo),action:"delete",name:n.name,...n.force?{force:!0}:{},...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function X0(n){return(await xr()).post("git/restore",{source:n.source,...gr(n.repo),rescue:n.rescue,...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function Jf(n){return(await xr()).post("git/checkout",{source:n.source,...gr(n.repo),ref:n.ref,...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function Y0(n){return(await xr()).post("git/fetch",{source:n.source,...gr(n.repo),...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function J0(n){return(await xr()).post("git/pull",{source:n.source,...gr(n.repo),...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function Z0(n){return(await xr()).post("git/push",{source:n.source,...gr(n.repo),...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function Q0(n){return(await Ze()).post("search",n)}async function rc(n){let e=new FormData;return e.append("agentId",n.agentId),n.projectId&&e.append("projectId",n.projectId),e.append("file",n.file),n.uri&&e.append("uri",n.uri),n.tags?.length&&e.append("tags",n.tags.join(",")),(await Ze()).upload("upload",e)}async function yr(n){return(await Ze()).post("write",n)}function ma(n,e){return n?.code==="destination_exists"?"Something is already there \u2014 nothing was overwritten. Pick another name.":n?.message||n?.error||e}async function ac(n){return(await Ze()).post("approve",n)}async function il(n){return(await(await Ze()).post("pending",{...n,action:"preview"})).preview}async function ex(n){let e=await(await Ze()).post("pending",n);return{ok:e?.ok!==!1,changes:Array.isArray(e?.changes)?e.changes:[],orphanIds:Array.isArray(e?.orphanIds)?e.orphanIds:[]}}async function tx(n){let e={agentId:n.agentId,count_only:"1"};n.projectId&&(e.projectId=n.projectId);let t=await(await Ze()).get("pending",e);return typeof t?.count=="number"?t.count:0}async function nx(n){return(await Ze()).post("pending",{...n,action:"revert"})}async function rx(n){return(await Ze()).post("pending",{...n,action:"discard"})}async function ax(n){return(await Ze()).post("pending",{...n,action:"dismiss"})}async function sx(n){let e=await(await Ze()).post("pending",{...n,action:"discard-orphans"});return{ok:e?.ok!==!1,discarded:typeof e?.discarded=="number"?e.discarded:0}}function ox(n,e,t){let r=new URLSearchParams({agentId:n,uri:e});return t&&r.set("projectId",t),`/api/packages/brain-core/raw?${r.toString()}`}async function ix(n){return(await Ze()).post("health",n)}async function lx(n){return(await Ze()).post("health/scan",n)}async function ux(n){return(await Ze()).post("health/gc",n)}async function cx(n){return(await Ze()).post("sources",n)}async function dx(n){let e=new URLSearchParams({agentId:n.agentId});return n.projectId&&e.set("projectId",n.projectId),n.purgeVectors&&e.set("purge","1"),(await Ze()).del(`sources/${encodeURIComponent(n.source)}?${e.toString()}`)}async function fx(n){return(await Ze()).post("sources/reset",n)}async function hx(n){return(await Ze()).post("sources/reindex",n)}async function px(n){return(await Ze()).post("sources/purge",n)}function Qs(n){return typeof n=="number"&&Number.isFinite(n)?n:null}function N2(n){let e=n&&typeof n=="object"?n:null,t=e?.estimate&&typeof e.estimate=="object"?e.estimate:null,r=Qs(t?.points),a=Qs(t?.tokens);if(!e||!t||r===null||a===null)return null;let s=Qs(t.relStdErr),o=Qs(t.usd);return{documents:Qs(e.documents),truncated:e.truncated===!0,points:r,tokens:a,tokensMargin:s!==null?Math.round(a*s):null,usd:o,usdMargin:s!==null&&o!==null?o*s:null,durationSeconds:Qs(t.seconds)}}async function mx(n){return N2(await(await Ze()).post("sources/reindex",{...n,force:!0,estimate:!0}))}async function gx(n){let e=await(await Ze()).post("sources/reindex",{...n,force:!0}),t=e?.job&&typeof e.job=="object"?e.job:null;return{documents:Qs(e?.documents),truncated:e?.truncated===!0,job:t}}async function xx(n){return(await Ze()).post("sources/cancel",n)}async function yx(n){let e={agentId:n.agentId};return n.projectId&&(e.projectId=n.projectId),(await Ze()).get("sources/health",e)}async function Zf(n){let e={path:n.path,agentId:n.agentId};return n.projectId&&(e.projectId=n.projectId),(await Ze()).get("sources/browse",e)}async function bx(){return(await Ze()).get("sources/kinds",{})}function Ve(n){let e=n.indexOf("://");return e>0?n.slice(0,e):"brain"}function rr(n){let e=n.indexOf("://");return e>0?n.slice(0,e+3):`${n}://`}function ot(n){let e=n.indexOf("://");if(e<1)return n;let t=n.slice(0,e+3),r=n.lastIndexOf("/");return r<=e+2?t:n.slice(0,r)}function ga(n){let e=n.indexOf("://");if(e<1)return[];let r=`${n.slice(0,e)}://`,a=n.slice(e+3);if(!a)return[];let s=a.split("/").filter(Boolean);if(s.length===0)return[];let o=[r],i=r;for(let l=0;l<s.length-1;l++)i=i.endsWith("/")?`${i}${s[l]}`:`${i}/${s[l]}`,o.push(i);return o}function yt(n){let e=n.indexOf("://"),t=e>=0?n.slice(e+3):n,r=t.lastIndexOf("/");return r>=0?t.slice(r+1):t}var wx=n=>n;function Wa(n){return n.uri}function R2(n,e,t){for(let r of e){if(n[r]?.type==="folder")continue;let a=r.endsWith("://")?r.slice(0,r.indexOf("://")):r.split("/").pop()||"",s=ot(r),o=n[r];n[r]={...o||{},storeKey:r,name:a,uri:r,type:"folder",parentUri:s===r?void 0:s,lastUpdated:t}}}function eo(n,e,t){R2(n,ga(e),t)}function ll(n){if(typeof n=="string")return n;if(Array.isArray(n)){let e=n.map(t=>{if(t){if(typeof t=="string")return t;if(typeof t=="object"){let r=typeof t.text=="string"?t.text:void 0,a=typeof t.content=="string"?t.content:void 0;return r??a}}}).filter(t=>!!(t&&t.trim()));if(e.length>0)return e.join(`
2
- `)}if(n&&typeof n=="object"){let e=n;if(typeof e.text=="string")return e.text;if(typeof e.content=="string")return e.content;if(Array.isArray(e.content)){let t=ll(e.content);if(t)return t}try{return JSON.stringify(n,null,2)}catch{return}}}function Yo(n){return Array.isArray(n?.files)?n.files:Array.isArray(n?.widget?.files)?n.widget.files:Array.isArray(n?.state?.files)?n.state.files:Array.isArray(n?.data?.files)?n.data.files:[]}function Jo(n){return ll(n?.text)??ll(n?.content)??ll(n?.file_content)??ll(n?.fileContent)??""}function sc(n){if(!n||typeof n!="object")return;let e=n;if(e.content!=null)return{content:typeof e.content=="string"?e.content:JSON.stringify(e.content,null,2),updatedAt:typeof e.updatedAt=="string"?e.updatedAt:"",...typeof e.uri=="string"?{uri:e.uri}:{},...typeof e.status=="string"?{status:e.status}:{},...typeof e.sourceVersion=="string"?{sourceVersion:e.sourceVersion}:{},...e.metadata&&typeof e.metadata=="object"?{metadata:e.metadata}:{}}}function oc(n,e){return typeof n.fileErrorByPath[e]=="string"||typeof n.fileBaseContentByPath[e]=="string"}function fs(n,e,t){return`${n??""}::${e??""}::${t}`}var Qf=0,eh={glob:"",category:"",status:"",tags:"",createdAfter:"",createdBefore:"",scopeToFolder:!1},vx={searchQuery:"",searchMode:"keyword",searchFilters:eh,searchResults:[],searchLoading:!1,searchError:void 0};function th(n,e,t){let r=typeof n=="string"&&n.includes("://")?n:null;if(t&&r)return r.startsWith("brain://")?null:r;let a=r?rr(r):null;return a&&!a.startsWith("brain://")?a:(e??[]).find(o=>o.source_kind!=="brain"&&typeof o.uri_root=="string")?.uri_root??null}function kx(n,e){return{setSearchQuery:t=>n(()=>({searchQuery:t})),setSearchMode:t=>n(()=>({searchMode:t})),setSearchFilters:t=>n(r=>({searchFilters:{...r.searchFilters,...t}})),clearSearch:()=>n(()=>({searchQuery:"",searchFilters:eh,searchResults:[],searchLoading:!1,searchError:void 0})),async runSearch({agentId:t,projectId:r}){let{searchQuery:a,searchMode:s,searchFilters:o,activeFolderPath:i,sources:l}=e(),u=(a??"").trim(),c=o??eh,d=c.glob.trim(),f=s==="keyword"?u.length>=2||d.length>=2:u.length>=2;if(!t||!f){n(()=>({searchResults:[],searchLoading:!1,searchError:void 0}));return}let h=typeof i=="string"&&i.includes("://")?i:void 0,p=s==="grep"?th(i,l,c.scopeToFolder):c.scopeToFolder?h:void 0;if(s==="grep"&&!p){n(()=>({searchResults:[],searchLoading:!1,searchError:"Grep needs a non-brain folder scope \u2014 select a folder in a disk-backed source."}));return}let m=c.tags.split(",").map(x=>x.trim()).filter(x=>x.length>0),g=++Qf;n(()=>({searchLoading:!0,searchError:void 0}));try{let x=await Q0({agentId:t,...r?{projectId:r}:{},search_mode:s==="keyword"?"filter":s,...u?{query:u}:{},...p?{folder_uri:p}:{},...d?{glob:d}:{},...s!=="grep"&&c.category.trim()?{category:c.category.trim()}:{},...s!=="grep"&&c.status.trim()?{status:c.status.trim()}:{},...s!=="grep"&&m.length>0?{tags:m}:{},...s!=="grep"&&c.createdAfter.trim()?{created_after:c.createdAfter.trim()}:{},...s!=="grep"&&c.createdBefore.trim()?{created_before:c.createdBefore.trim()}:{},limit:s==="semantic"?30:50});if(g!==Qf)return;let w=x.results||[],y=w.find(k=>typeof k.error=="string"&&k.error.length>0),C=w.filter(k=>typeof k.uri=="string"&&k.uri.includes("://")&&!k.error).map(k=>({id:k.id||`fs:${k.uri}:${k.chunk_start??""}`,uri:k.uri,filename:k.filename||String(k.uri).split("/").pop(),content_preview:k.content_preview,snippet:k.snippet,chunk_start:k.chunk_start,chunk_end:k.chunk_end,match_type:k.match_type,score:k.score}));n(()=>({searchResults:C,searchLoading:!1,searchError:y?String(y.error):void 0}))}catch(x){if(g!==Qf)return;n(()=>({searchResults:[],searchLoading:!1,searchError:x instanceof Error?x.message:"Search failed"}))}}}}var nh=new Map;function Zo(){return{files:{},folderBadges:{},fileContentByPath:{},fileBaseContentByPath:{},fileErrorByPath:{},filePrevByPath:{},openFiles:[],activeFile:null,tabMeta:{},pendingReviewPaths:new Set,pendingCount:0,expandedFolders:new Set,sidebarView:"tree",activeWorkspaceTab:"file",workspacePanels:{upload:!1,sources:!1,packages:!1,pending:!1},pendingSourceSuggestion:null,searchQuery:"",searchResults:[],searchLoading:!1,searchError:void 0,gitStatus:null,gitTotals:null,gitOutgoingStat:null,gitBranches:[],gitLoading:!1,gitError:void 0,gitDiffTarget:null,gitCommitTarget:null,sources:[],sourcesLoading:!0,activeSource:null,activeRepoRel:"",loadedFolders:{},hydrationState:{},dirtySources:{},sourceChangeRevision:{},organizeError:null,pendingPanelFilter:{},activeFolderPath:"brain://docs",snapshotError:void 0}}var M2=200;function ic(n,e=M2){let t=[...n],r=[],a=!0;for(;t.length>e&&a;){a=!1;for(let s=0;s<t.length&&t.length>e;){let o=t[s],i=`${o}/`;if(o.endsWith("://")||t.some(l=>l.startsWith(i))){s+=1;continue}t.splice(s,1),r.push(o),a=!0}}return{kept:t,evicted:r}}var T2=Object.keys(Zo());function D2(n){let e={};for(let t of T2)e[t]=n[t];return e}function lc(n){let e=n.expandedFolders;return{openFiles:Array.isArray(n.openFiles)?n.openFiles:[],activeFile:typeof n.activeFile=="string"?n.activeFile:null,tabMeta:n.tabMeta??{},expandedFolders:e instanceof Set?ic(Array.from(e)).kept:[],sidebarView:n.sidebarView??"tree",activeWorkspaceTab:n.activeWorkspaceTab??"file",workspacePanels:n.workspacePanels??{upload:!1,sources:!1,packages:!1,pending:!1},activeFolderPath:n.activeFolderPath??"brain://docs"}}function rh(n){let e=Zo();return n?{...e,openFiles:Array.isArray(n.openFiles)?n.openFiles:[],activeFile:typeof n.activeFile=="string"?n.activeFile:null,tabMeta:n.tabMeta??{},expandedFolders:new Set(Array.isArray(n.expandedFolders)?ic(n.expandedFolders).kept:[]),sidebarView:n.sidebarView??e.sidebarView,activeWorkspaceTab:n.activeWorkspaceTab??e.activeWorkspaceTab,workspacePanels:n.workspacePanels??e.workspacePanels,activeFolderPath:n.activeFolderPath??e.activeFolderPath}:e}function Sx(n,e){return{async loadList({agentId:t,projectId:r,userId:a,withCounts:s}){if(!t)return;let o=`${t}:${r||""}:${s?"c":""}`,i=nh.get(o);if(i){await i;return}let l="brain://",u=e(),c=a===void 0?u.activeUserId:a,d=u.activeUserId!==null&&u.activeUserId!==c,f=u.activeAgentId!==t||u.activeProjectId!==r||d,h;if(f?(e().fenceInFlightWriters(),n(m=>{let g={...m.contextStateByKey};m.activeAgentId&&(g[fs(m.activeUserId,m.activeProjectId,m.activeAgentId)]=D2(m));let x=fs(c,r,t);return h=g[x],delete g[x],{activeUserId:c,activeAgentId:t,activeProjectId:r,...Zo(),...h??{},contextStateByKey:g}})):n(()=>({activeUserId:c,activeAgentId:t,activeProjectId:r,sourcesLoading:!0})),h){let m=h.loadedFolders??{},g=new Set;for(let[x,w]of Object.entries(m)){if(!w)continue;let y=Ve(x);y&&g.add(y)}for(let x of g)e().reconcileSourceFolders({agentId:t,projectId:r,source:x})}e().rehydrateActiveTab();let p=(async()=>{let m;try{m=await $o(t,r??void 0,{sources_only:!0,recursive:!1,...s?{include_counts:!0}:{}})}catch{n(()=>({snapshotError:"Filesystem service unavailable",sourcesLoading:!1}));return}let g=Array.isArray(m.folders)?m.folders:[],x=Array.isArray(m.files)?m.files:[],w=Array.isArray(m.sources)?m.sources:[];n(y=>{let C=y.activeAgentId===t&&y.activeProjectId===r,k=C?{...y.files}:{},v=Date.now();k[l]||(k[l]={storeKey:l,name:"brain",uri:l,type:"folder",lastUpdated:v,presence:"brain"});for(let N of g){let M=typeof N=="string"?N:typeof N?.uri=="string"?N.uri:"";if(!M)continue;let U=typeof N?.name=="string"?N.name:M.split("/").pop()||"folder",I=N?.presence??(Ve(M)==="brain"?"brain":"stale_indexed");eo(k,`${M}/placeholder`,v),k[M]={storeKey:M,name:U,uri:M,type:"folder",parentUri:M.endsWith("://")?void 0:ot(M),lastUpdated:v,presence:I,git:typeof N.git=="string"?String(N.git):void 0}}for(let N of x){let M=typeof N?.uri=="string"?String(N.uri):"";if(!M)continue;let U=typeof N?.id=="string"?String(N.id):void 0,I=typeof N.status=="string"?String(N.status):void 0,A=Array.isArray(N.tags)&&N.tags.length>0?N.tags:void 0,G=typeof N.category=="string"?String(N.category):void 0,V=N.version&&typeof N.version=="object"?N.version:void 0,K=typeof N.agent_id=="string"?String(N.agent_id):void 0,L=typeof N.project_id=="string"?String(N.project_id):void 0,R=N?.presence??(Ve(M)==="brain"?"brain":"stale_indexed"),z=typeof N.git=="string"?String(N.git):void 0;eo(k,M,v),k[M]={storeKey:M,id:U,name:String(N.filename||N.name||yt(M)),uri:M,os_uri:typeof N.os_uri=="string"?String(N.os_uri):void 0,type:"file",status:I,parentUri:ot(M),lastUpdated:v,category:G,tags:A,metadata:N.metadata&&typeof N.metadata=="object"?N.metadata:void 0,createdAt:typeof N.createdAt=="string"?String(N.createdAt):void 0,updatedAt:typeof N.updatedAt=="string"?String(N.updatedAt):void 0,version:V,sourceAgentId:K,sourceProjectId:L,presence:R,git:z};let J=ot(M),Q=k[J];Q&&Q.type==="folder"&&(k[J]={...Q,sourceAgentId:K??Q.sourceAgentId,sourceProjectId:L??Q.sourceProjectId,lastUpdated:v})}let b=C?{...y.loadedFolders||{}}:{},P=C?{...y.hydrationState||{}}:{};for(let N of w)!b[N.uri_root]&&!P[N.uri_root]&&(P[N.uri_root]="idle");return{files:k,sources:w,sourcesLoading:!1,snapshotError:void 0,loadedFolders:b,hydrationState:P}})})();nh.set(o,p);try{await p}finally{nh.delete(o)}},async refresh({agentId:t,projectId:r,withCounts:a}){await e().loadList({agentId:t,projectId:r,withCounts:a})}}}var ah=0,sh=0,Lx={gitStatus:null,gitTotals:null,gitOutgoingStat:null,gitBranches:[],gitLoading:!1,gitError:void 0,gitViewMode:"list",gitDiffTarget:null,gitCommitTarget:null,gitLogNonce:0};function oh(n,e){let t=n??(typeof e=="string"?e:"");return t?t.includes("://")?Ve(t):t:""}function Cx(n,e){return typeof n=="string"?n:typeof e=="string"?e:""}function Ix(n,e){return{setGitViewMode:t=>n(()=>({gitViewMode:t})),setGitDiffTarget:t=>n(()=>({gitDiffTarget:t})),setGitCommitTarget:t=>n(r=>({gitCommitTarget:t,...t===null&&r.activeWorkspaceTab==="git-commit"?{activeWorkspaceTab:"file"}:{}})),notifyGitLogChanged:t=>{if(!t)return;let r=oh(void 0,e().activeSource);t===r&&n(a=>({gitLogNonce:(typeof a.gitLogNonce=="number"?a.gitLogNonce:0)+1}))},clearGit:()=>n(t=>({gitStatus:null,gitBranches:[],gitLoading:!1,gitError:void 0,gitDiffTarget:null,gitCommitTarget:null,...t.activeWorkspaceTab==="git-commit"?{activeWorkspaceTab:"file"}:{}})),setGitOutgoingStat(t){n(()=>({gitOutgoingStat:t}))},async loadGitStatus({agentId:t,projectId:r,source:a,repo:s}){let o=oh(a,e().activeSource),i=Cx(s,e().activeRepoRel);if(!t||!o){n(()=>({gitStatus:null,gitTotals:null,gitLoading:!1,gitError:void 0}));return}let l=++ah;n(()=>({gitLoading:!0,gitError:void 0}));try{let u=await Qu({agentId:t,...r?{projectId:r}:{},source:o,...i?{repo:i}:{}});if(l!==ah)return;n(()=>({gitStatus:u?.status??null,gitTotals:u?.totals??null,gitLoading:!1,gitError:void 0}))}catch(u){if(l!==ah)return;n(()=>({gitStatus:null,gitTotals:null,gitLoading:!1,gitError:u instanceof Error?u.message:"Git status failed"}))}},async loadGitBranches({agentId:t,projectId:r,source:a,repo:s}){let o=oh(a,e().activeSource),i=Cx(s,e().activeRepoRel);if(!t||!o){n(()=>({gitBranches:[]}));return}let l=++sh;try{let u=await _0({agentId:t,...r?{projectId:r}:{},source:o,...i?{repo:i}:{}});if(l!==sh)return;n(()=>({gitBranches:Array.isArray(u?.branches)?u.branches:[]}))}catch(u){if(l!==sh)return;n(()=>({gitBranches:[],gitError:u instanceof Error?u.message:"Git branches failed"}))}}}}var ih=5e4,Fr=0,Ax=0,uc=new Set,cc=new Map,lh=new Map,F2=3,pc=new Map;function dh(n){let e=(pc.get(n)??0)+1;return pc.set(n,e),e}function Nx(n,e){return pc.get(n)===e}function uh(n){return{storeKey:n,uri:n,name:yt(n),type:"file",parentUri:ot(n)}}function Px(n,e,t){let r=ot(e);if(r===e||t.parentUri===r)return t;let a={...t,parentUri:r};return n[e]=a,a}function Rx(n,e,t,r){let a=r?.issuedAt??t,s=r?.pending;for(let o of e.folders||[]){let i=typeof o=="string"?o:typeof o?.uri=="string"?o.uri:"";if(!i)continue;let l=typeof o?.name=="string"?o.name:i.split("/").pop()||"folder",u=o?.presence??"unindexed",c=typeof o?.git=="string"?String(o.git):void 0,d=typeof o?.status=="string"?o.status:void 0,f=n[i];if(!f){n[i]={storeKey:i,name:l,uri:i,type:"folder",parentUri:i.endsWith("://")?void 0:ot(i),lastUpdated:t,presence:u,git:c,status:d};continue}f=Px(n,i,f),!((f.lastUpdated??0)>=a)&&(f.git!==c||f.presence!==u||f.name!==l||f.status!==d)&&(n[i]={...f,name:l,presence:u,git:c,status:d})}for(let o of e.files||[]){let i=typeof o?.uri=="string"?String(o.uri):"";if(!i)continue;eo(n,i,t);let l=typeof o.git=="string"?String(o.git):void 0,u=typeof o.status=="string"?o.status:void 0,c=o.presence??"unindexed",d=typeof o.os_uri=="string"?o.os_uri:void 0,f=n[i];if(!f){n[i]={storeKey:i,name:yt(i),uri:i,type:"file",id:typeof o.id=="string"?o.id:void 0,os_uri:d,status:u,parentUri:ot(i),lastUpdated:t,category:typeof o.category=="string"?o.category:void 0,presence:c,pinned:o.pinned===!0,git:l},s&&u==="pending_review"&&s.add.add(i);continue}if(f=Px(n,i,f),(f.lastUpdated??0)>=a)continue;let h={...f,name:yt(i)||f.name,presence:c,status:u,os_uri:d,git:l};typeof o.id=="string"&&(h.id=o.id),"category"in o&&(h.category=typeof o.category=="string"?o.category:void 0),"version"in o&&(h.version=o.version),"pinned"in o&&(h.pinned=o.pinned===!0),n[i]=h,s&&f.status!==u&&(u==="pending_review"?s.add.add(i):f.status==="pending_review"&&s.remove.add(i))}}function fh(n,e,t){if(t.add.size===0&&t.remove.size===0)return n;let r=new Set(e);for(let a of t.add)r.add(a);for(let a of t.remove)r.delete(a);return n.pendingReviewPaths=r,n}var E2=4;function B2(n,e){if(n.endsWith("://"))return!0;if(!e.has(n))return!1;for(let t of ga(n))if(!t.endsWith("://")&&!e.has(t))return!1;return!0}function Mx(n,e){return e.some(t=>n===t||n.startsWith(t.endsWith("://")?t:`${t}/`))}function Tx(n,e){let t=n;for(let[r,a]of Object.entries(n))a!==!0||!Mx(r,e)||(t===n&&(t={...n}),t[r]=!1);return t}function dc(n,e){let t=new Set(e),r=Array.from(n.expandedFolders).filter(l=>!t.has(l));r.push(...t);let{kept:a,evicted:s}=ic(r);if(s.length===0)return{expandedFolders:new Set(a)};let o=n.loadedFolders||{},i=Tx(o,s);return i===o?{expandedFolders:new Set(a)}:{expandedFolders:new Set(a),loadedFolders:i}}async function O2(n,e,t){if(n.length===0)return[];let r=Math.max(1,Math.min(e,n.length)),a=new Array(n.length),s=0;return await Promise.all(Array.from({length:r},async()=>{for(;;){let o=s++;if(o>=n.length)return;a[o]=await t(n[o])}})),a}async function _2(n,e){let{agentId:t,projectId:r,source:a,extraTargets:s,wide:o}=e,i=Fr,l=n.get(),u=l.loadedFolders||{},c=new Set;if(o)for(let p of Object.keys(u))Ve(p)===a&&B2(p,l.expandedFolders)&&c.add(p);for(let p of s)Ve(p)===a&&u[p]!==void 0&&c.add(p);let d=p=>{let m=p.indexOf("://"),g=(m>=0?p.slice(m+3):p).replace(/\/+$/,"");return g?g.split("/").length:0},f=Array.from(c).sort((p,m)=>d(m)-d(p));if(f.length===0)return;let h=await O2(f,E2,async p=>{let m=dh(p),g=Date.now();try{let x=await $o(t,r??void 0,{uri:p,recursive:!1});return Nx(p,m)?{folderKey:p,res:x,issuedAt:g,ok:!0}:{folderKey:p,res:null,issuedAt:g,ok:!1}}catch{return{folderKey:p,res:null,issuedAt:g,ok:!1}}});n.set(p=>{if(i!==Fr)return p;let m={...p.files},g=Date.now(),x={add:new Set,remove:new Set},w=[],y=!1,C=!1;for(let M of h){if(!M.ok||!M.res){C=!0;continue}Rx(m,M.res,g,{issuedAt:M.issuedAt,pending:x}),M.res.truncated?C=!0:y=!0}let k=C===!!p.dirtySources[a]?p.dirtySources:(()=>{let M={...p.dirtySources};return C?M[a]=!0:delete M[a],M})(),v=p.loadedFolders;for(let M of h)!M.ok||!M.res||v?.[M.folderKey]!==!1||(v===p.loadedFolders&&(v={...v}),v[M.folderKey]=!0);if(!y)return fh({files:hh(m,p.expandedFolders,p.openFiles),dirtySources:k,loadedFolders:v},p.pendingReviewPaths,x);let b=new Map;for(let M of Object.keys(m)){let U=m[M]?.parentUri;if(!U)continue;let I=b.get(U);I?I.push(M):b.set(U,[M])}for(let M of h){if(!M.ok||!M.res)continue;let U=M.res;if(U.truncated)continue;let I=new Set;for(let A of U.files||[]){let G=typeof A?.uri=="string"?A.uri:"";G&&I.add(G)}for(let A of U.folders||[]){let G=typeof A=="string"?A:typeof A?.uri=="string"?A.uri:"";G&&I.add(G)}for(let A of b.get(M.folderKey)||[]){let G=m[A];if(G&&!I.has(A)&&!((G.lastUpdated??0)>=M.issuedAt)){if(G.type==="folder"){let K=(b.get(A)||[]).filter(R=>m[R]!==void 0);if(K.filter(R=>m[R].status!=="deleted").length>0)continue;K.length===0?delete m[A]:G.status!=="deleted"&&(m[A]={...G,status:"deleted",lastUpdated:g});continue}G.presence==="unindexed"?(delete m[A],w.push(A),G.status==="pending_review"&&x.remove.add(A)):G.status!=="deleted"&&(m[A]={...G,status:"deleted",lastUpdated:g},G.status==="pending_review"&&x.remove.add(A))}}}let N={files:hh(m,p.expandedFolders,p.openFiles),dirtySources:k,loadedFolders:v};if(w.length){let M=new Set(w),U=p.openFiles.filter(L=>!M.has(L));N.openFiles=U;let I={...p.tabMeta};for(let L of w)delete I[L];N.tabMeta=I,N.activeFile=p.activeFile&&M.has(p.activeFile)?U.length?U[U.length-1]:null:p.activeFile;let A={...p.fileContentByPath},G={...p.fileBaseContentByPath},V={...p.fileErrorByPath},K={...p.filePrevByPath};for(let L of w)delete A[L],delete G[L],delete V[L],delete K[L];N.fileContentByPath=A,N.fileBaseContentByPath=G,N.fileErrorByPath=V,N.filePrevByPath=K}return fh(N,p.pendingReviewPaths,x)})}async function fc(n,e){let{agentId:t,projectId:r,source:a,targets:s}=e,o=e.wide!==!1;if(!t||!a)return;let i=lh.get(a);if(i){if(i.rerun=!0,o&&(i.wide=!0),s)for(let u of s)i.extra.add(u);await i.promise;return}let l={rerun:!1,wide:o,extra:new Set(s??[]),promise:Promise.resolve()};lh.set(a,l),l.promise=(async()=>{try{for(let u=0;u<F2;u++){l.rerun=!1;let c=l.wide;l.wide=!1;let d=Array.from(l.extra);if(l.extra.clear(),await _2(n,{agentId:t,projectId:r,source:a,extraTargets:d,wide:c}),!l.rerun)break}}finally{lh.delete(a)}})(),await l.promise}function hc(n,e){let t=`${e}/`,r=Object.keys(n.get().files).filter(a=>a===e||a.startsWith(t));r.length!==0&&n.set(a=>{let s={...a.files};for(let h of r)delete s[h];let o=new Set(r),i=a.openFiles.filter(h=>!o.has(h)),l={...a.tabMeta},u={...a.fileContentByPath},c={...a.fileBaseContentByPath},d={...a.fileErrorByPath},f={...a.filePrevByPath};for(let h of r)delete l[h],delete u[h],delete c[h],delete d[h],delete f[h];return{files:s,openFiles:i,activeFile:a.activeFile&&o.has(a.activeFile)?i.length?i[i.length-1]:null:a.activeFile,tabMeta:l,fileContentByPath:u,fileBaseContentByPath:c,fileErrorByPath:d,filePrevByPath:f}})}var H2=30;function hh(n,e,t){let r=Object.keys(n);if(r.length<=ih)return n;let a=new Set;for(let u of e){a.add(u);let c=u;for(;c;){a.add(c);let d=ot(c);if(!d||d===c)break;c=d}}for(let u of t){a.add(u);let c=ot(u);for(;c;){a.add(c);let d=ot(c);if(!d||d===c)break;c=d}}for(let u of r)u.endsWith("://")&&a.add(u);let s=r.filter(u=>{if(a.has(u))return!1;let c=n[u].parentUri;return!(c&&e.has(c))}).map(u=>({key:u,ts:n[u].lastUpdated??0})).sort((u,c)=>u.ts-c.ts),o=r.length-ih;if(o<=0||s.length===0)return n;let i={...n},l=Math.min(o,s.length);for(let u=0;u<l;u++)delete i[s[u].key];return console.warn("[Filesystem] cold-row eviction",{total:r.length,cap:ih,removed:l,protected:r.length-s.length}),i}var U2="filesystem",ul=120,ch=240,Dx="neuralis.filesystem.sidebarWidth";function G2(){if(typeof window>"u")return ch;try{let n=window.localStorage.getItem(Dx),e=n?Number(n):NaN;return Number.isFinite(e)&&e>=ul?e:ch}catch{return ch}}var B=R0()(M0((n,e)=>({files:{},folderBadges:{},fileContentByPath:{},fileBaseContentByPath:{},fileErrorByPath:{},filePrevByPath:{},openFiles:[],activeFile:null,tabMeta:{},activeUserId:null,contextStateByKey:{},previewEditorsEnabled:!1,expandedFolders:new Set,sidebarOpen:!0,sidebarWidth:G2(),sidebarView:"tree",activeAgentId:null,activeProjectId:null,sources:[],sourcesLoading:!0,activeSource:null,activeRepoRel:"",activeFolderPath:"brain://docs",uploading:!1,workspacePanels:{upload:!1,sources:!1,packages:!1,pending:!1},activeWorkspaceTab:"file",pendingSourceSuggestion:null,diffViewMode:"auto",pendingPanelFilter:{},loadedFolders:{},hydrationState:{},dirtySources:{},sourceChangeRevision:{},organizeError:null,snapshotError:void 0,pendingReviewPaths:new Set,pendingCount:0,...vx,...kx(n,e),...Sx(n,e),...Lx,...Ix(n,e),toggleSidebar:()=>n(t=>({sidebarOpen:!t.sidebarOpen})),setSidebarView:t=>n(()=>({sidebarView:t})),setSidebarWidth:t=>n(()=>{let r=Math.max(ul,Math.round(t));if(typeof window<"u")try{window.localStorage.setItem(Dx,String(r))}catch{}return{sidebarWidth:r}}),setActiveFolderPath:t=>n(()=>({activeFolderPath:t?String(t):null})),setActiveSource:(t,r)=>n(()=>({activeSource:t,activeRepoRel:typeof r=="string"?r:"",gitOutgoingStat:null})),setWorkspacePanelOpen:(t,r)=>n(a=>{let s={upload:!1,sources:!1,packages:!1,pending:!1};r?s[t]=!0:(s.upload=a.workspacePanels.upload,s.sources=a.workspacePanels.sources,s.packages=a.workspacePanels.packages,s.pending=a.workspacePanels.pending,s[t]=!1);let o=r?t:a.activeWorkspaceTab===t?"file":a.activeWorkspaceTab;return{workspacePanels:s,activeWorkspaceTab:o}}),setPendingSourceSuggestion:t=>n(()=>({pendingSourceSuggestion:t})),setActiveWorkspaceTab:t=>n(()=>({activeWorkspaceTab:t})),setDiffViewMode:t=>n(()=>({diffViewMode:t})),setPreviewEditorsEnabled:t=>n(()=>({previewEditorsEnabled:t})),reorderOpenFiles:(t,r)=>n(a=>{if(t===r)return a;let s=[...a.openFiles],o=s.indexOf(t),i=s.indexOf(r);if(o<0||i<0)return a;let[l]=s.splice(o,1);return s.splice(i,0,l),{openFiles:s}}),toggleTabPin:t=>n(r=>{let a=r.tabMeta[t]||{};return{tabMeta:{...r.tabMeta,[t]:{...a,pinned:!a.pinned,preview:!1}}}}),promoteTab:t=>n(r=>{let a=r.tabMeta[t];return!a||!a.preview?r:{tabMeta:{...r.tabMeta,[t]:{...a,preview:!1}}}}),closeAllFiles:()=>n(t=>{let r=t.openFiles.filter(s=>t.tabMeta[s]?.pinned),a=t.activeFile&&r.includes(t.activeFile)?t.activeFile:r[r.length-1]??null;return{openFiles:r,activeFile:a}}),closeSavedFiles:()=>n(t=>{let r=o=>{let i=t.fileBaseContentByPath[o],l=t.fileContentByPath[o];return typeof i=="string"&&i!==l},a=t.openFiles.filter(o=>t.tabMeta[o]?.pinned||r(o)||t.files[o]?.status==="pending_review"),s=t.activeFile&&a.includes(t.activeFile)?t.activeFile:a[a.length-1]??null;return{openFiles:a,activeFile:s}}),closeOtherFiles:t=>n(r=>{let a=r.openFiles.filter(s=>s===t||r.tabMeta[s]?.pinned);return{openFiles:a,activeFile:a.includes(t)?t:a[a.length-1]??null}}),setPendingPanelFilter:t=>n(()=>({pendingPanelFilter:t})),toggleFolder:t=>n(r=>{if(r.expandedFolders.has(t)){let o=new Set(Array.from(r.expandedFolders).filter(u=>!Mx(u,[t]))),i=r.loadedFolders||{},l=Tx(i,[t]);return l===i?{expandedFolders:o}:{expandedFolders:o,loadedFolders:l}}let a=!!r.folderBadges[t],s=a?{...r.folderBadges}:r.folderBadges;return a&&delete s[t],{...dc(r,[t]),folderBadges:s}}),async ensureFolderLoaded({agentId:t,projectId:r,uri:a,force:s}){if(!t||!a)return;let o=e().loadedFolders?.[a];if(!s&&o)return;if(!s&&o===!1){await fc({get:e,set:n},{agentId:t,projectId:r,source:Ve(a),targets:[a],wide:!1});return}let i=cc.get(a);if(i){await i;return}n(u=>({hydrationState:{...u.hydrationState||{},[a]:"loading"}}));let l=(async()=>{let u=dh(a),c=Date.now();try{let d=await $o(t,r??void 0,{uri:a,recursive:!1});if(!Nx(a,u)){n(f=>({hydrationState:{...f.hydrationState||{},[a]:f.loadedFolders?.[a]?"ready":"idle"}}));return}n(f=>{let h={...f.files},p={add:new Set,remove:new Set};return Rx(h,d,Date.now(),{issuedAt:c,pending:p}),fh({files:hh(h,f.expandedFolders,f.openFiles),loadedFolders:{...f.loadedFolders||{},[a]:!0},hydrationState:{...f.hydrationState||{},[a]:"ready"}},f.pendingReviewPaths,p)})}catch(d){console.error("[Filesystem] subfolder load failed",d),n(f=>({hydrationState:{...f.hydrationState||{},[a]:"error"}}))}})();cc.set(a,l);try{await l}finally{cc.delete(a)}},clearOrganizeError:()=>n(()=>({organizeError:null})),clearSnapshotError:()=>n(()=>({snapshotError:void 0})),setSourceDirty:(t,r)=>n(a=>{if(!!a.dirtySources[t]===r)return a;let o={...a.dirtySources};return r?o[t]=!0:delete o[t],{dirtySources:o}}),async reconcileSourceFolders({agentId:t,projectId:r,source:a}){await fc({get:e,set:n},{agentId:t,projectId:r,source:a})},fenceInFlightWriters(){Fr+=1;for(let t of Array.from(pc.keys()))dh(t);cc.clear(),uc.clear()},resetClientState(t){let r=e();if(!r.activeProjectId||t.projectId!==r.activeProjectId||t.level!=="project"&&t.agentId!==r.activeAgentId||t.level==="widget"&&t.widgetType!==U2)return;e().fenceInFlightWriters();let a=`${r.activeUserId??""}::${r.activeProjectId}::`,s=fs(r.activeUserId,r.activeProjectId,r.activeAgentId??""),o={};for(let[i,l]of Object.entries(r.contextStateByKey))(t.level==="project"?i.startsWith(a):i===s)||(o[i]=l);n(()=>({...Zo(),contextStateByKey:o}))},async reconcileFolders({agentId:t,projectId:r,folders:a}){if(!t||!Array.isArray(a)||a.length===0)return;let s=new Map,o=e().loadedFolders||{};for(let i of a){if(!i)continue;let l=Ve(i);if(!l||o[i]===!1)continue;if(!o[i]){e().setSourceDirty(l,!0);continue}let u=s.get(l);u?u.push(i):s.set(l,[i])}s.size!==0&&await Promise.all(Array.from(s.entries()).map(([i,l])=>fc({get:e,set:n},{agentId:t,projectId:r,source:i,targets:l})))},async refreshTree({agentId:t,projectId:r}){if(!t)return;await e().loadList({agentId:t,projectId:r});let a=e(),s=new Set;for(let[o,i]of Object.entries(a.loadedFolders||{})){if(!i)continue;let l=Ve(o);l&&s.add(l)}await Promise.all(Array.from(s).map(o=>fc({get:e,set:n},{agentId:t,projectId:r,source:o})))},setActiveFile:t=>{n({activeFile:t,activeWorkspaceTab:"file"}),e().rehydrateActiveTab()},async rehydrateActiveTab(){let t=e(),r=t.activeFile,a=t.activeAgentId;if(!(!r||!a)&&!oc(t,r)&&!uc.has(r)){uc.add(r);try{let s=t.tabMeta[r]?.sourceAgentId,o=s&&s!==a&&!/^__.*__$/.test(s)?s:void 0;await t.openFile({agentId:a,projectId:t.activeProjectId,uri:r,readAgentId:o,revealPane:!1})}finally{uc.delete(r)}}},closeFile:t=>n(r=>{let a=r.openFiles.filter(i=>i!==t),s=r.activeFile===t?a.length?a[a.length-1]:null:r.activeFile,o={...r.tabMeta};return delete o[t],{openFiles:a,activeFile:s,tabMeta:o}}),replaceFilePath:(t,r)=>n(a=>{if(!t||!r||t===r)return a;let s=a.files[t],o={...a.files};s&&(delete o[t],o[r]={...s,storeKey:r,uri:r,name:yt(r)||s.name,parentUri:ot(r),lastUpdated:Date.now()});let i={...a.fileContentByPath},l={...a.fileBaseContentByPath},u={...a.fileErrorByPath},c={...a.filePrevByPath};Object.prototype.hasOwnProperty.call(i,t)&&(i[r]=i[t],delete i[t]),Object.prototype.hasOwnProperty.call(l,t)&&(l[r]=l[t],delete l[t]),Object.prototype.hasOwnProperty.call(u,t)&&(u[r]=u[t],delete u[t]),Object.prototype.hasOwnProperty.call(c,t)&&(c[r]=c[t],delete c[t]);let d=[];for(let f of a.openFiles){let h=f===t?r:f;d.includes(h)||d.push(h)}return{files:o,fileContentByPath:i,fileBaseContentByPath:l,fileErrorByPath:u,filePrevByPath:c,openFiles:d,activeFile:a.activeFile===t?r:a.activeFile}}),patchFileNode:(t,r)=>n(a=>{let s=a.files[t];return s?{files:{...a.files,[t]:{...s,...r,lastUpdated:Date.now()}}}:a}),clearFilePrev:t=>n(r=>{if(!r.filePrevByPath[t])return r;let a={...r.filePrevByPath};return delete a[t],{filePrevByPath:a}}),upsertFileNodeFromEvent:({id:t,uri:r,folder_ancestors:a,status:s,sourceAgentId:o,sourceProjectId:i})=>n(l=>{if(!r||!l.files[r]&&s==="deleted")return l;let u=Date.now(),c={...l.files},d=a||ga(r);eo(c,r,u);let f=ot(r),h=c[f];h&&h.type==="folder"&&(c[f]={...h,sourceAgentId:o??h.sourceAgentId,sourceProjectId:i??h.sourceProjectId});let p=c[r],m=Ve(r)==="brain";c[r]={...p||uh(r),id:t??p?.id,name:yt(r)||p?.name||"file",type:"file",uri:r,status:s??p?.status,parentUri:f,sourceAgentId:o??p?.sourceAgentId,sourceProjectId:i??p?.sourceProjectId,lastUpdated:u,presence:p?.presence??(m?"brain":"synced"),git:p?.git};let g=new Set(l.pendingReviewPaths);if(s==="pending_review"?g.add(r):p?.status==="pending_review"&&s&&s!=="pending_review"&&g.delete(r),s==="active"&&p?.status==="pending_review"&&l.filePrevByPath[r]){let w={...l.filePrevByPath};return delete w[r],{files:c,filePrevByPath:w,pendingReviewPaths:g}}return{files:c,pendingReviewPaths:g}}),removeFilePath:t=>n(r=>{if(!t||!r.files[t]&&!r.openFiles.includes(t)&&!r.tabMeta[t])return r;let a={...r.files};delete a[t];let s=r.openFiles.filter(f=>f!==t),o=r.activeFile===t?s.length?s[s.length-1]:null:r.activeFile,i={...r.fileContentByPath},l={...r.fileBaseContentByPath},u={...r.fileErrorByPath},c={...r.filePrevByPath};delete i[t],delete l[t],delete u[t],delete c[t];let d={...r.tabMeta};return delete d[t],{files:a,openFiles:s,activeFile:o,tabMeta:d,fileContentByPath:i,fileBaseContentByPath:l,fileErrorByPath:u,filePrevByPath:c}}),incrementFolderBadges:t=>n(r=>{if(!Array.isArray(t)||t.length===0)return r;let a={...r.folderBadges};for(let s of t)s&&(r.expandedFolders.has(s)||(a[s]=(a[s]||0)+1));return{folderBadges:a}}),clearFolderBadge:t=>n(r=>{if(!t||!r.folderBadges[t])return r;let a={...r.folderBadges};return delete a[t],{folderBadges:a}}),autoExpandToFile:t=>n(r=>dc(r,[rr(t),...ga(t)])),updateFileContent:(t,r)=>n(a=>({fileContentByPath:{...a.fileContentByPath,[t]:r},fileErrorByPath:{...a.fileErrorByPath,[t]:void 0}})),async saveFileInPlace({agentId:t,projectId:r,readAgentId:a,node:s,targetUri:o,content:i,currentContent:l}){let u=s.uri,c=!!o&&o!==u,d=i!==l;if(!c&&!d)return{uri:u,moved:!1,contentChanged:!1};let f=Fr,h=()=>f!==Fr,p=u;if(c){let m=await yr({agentId:t,...r?{projectId:r}:{},id:s.id,uri:u,move:o});if(!m||m.ok!==!0)throw new Error(ma(m,"Move failed"));if(p=o,h())return{uri:p,moved:c,contentChanged:!1};e().replaceFilePath(s.storeKey||u,o)}if(d){let m=await yr({agentId:t,...r?{projectId:r}:{},id:s.id,uri:p,overwrite:{content:i}});if(!m||m.ok!==!0)throw new Error(ma(m,"Save failed"));if(h())return{uri:p,moved:c,contentChanged:d};let g=c?p:s.storeKey||u;e().updateFileContent(g,i),e().patchFileNode(g,{status:"pending_review"})}return await e().reconcileFolders({agentId:t,projectId:r,folders:Array.from(new Set([ot(u),ot(p)]))}),h()?{uri:p,moved:c,contentChanged:d}:(await e().openFile({agentId:t,projectId:r,uri:p,readAgentId:a,force:!0}),{uri:p,moved:c,contentChanged:d})},async refreshPendingCount({agentId:t,projectId:r}){if(!t)return;let a=++Ax,s;try{s=await tx({agentId:t,...r?{projectId:r}:{}})}catch{return}if(a!==Ax)return;let o=e();o.activeAgentId!==t||o.activeProjectId!==r||n(()=>({pendingCount:s}))},async markFileDeleted({agentId:t,projectId:r,node:a}){let s=Fr,o=await yr({agentId:t,...r?{projectId:r}:{},id:a.id,uri:a.uri,delete:!0});if(!o||o.ok!==!0)throw new Error(ma(o,"Delete failed"));s===Fr&&await e().reconcileFolders({agentId:t,projectId:r,folders:[ot(a.uri)]})},async moveFileToFolder({agentId:t,projectId:r,fromUri:a,toFolderUri:s,id:o}){if(!t||!a||!s)return;let i=yt(a);if(!i)return;let l=s.endsWith("://")?`${s}${i}`:`${s}/${i}`;if(l===a)return;let u=ot(a),c=e().files[a]?.type==="folder",d;try{d=await yr({agentId:t,...r?{projectId:r}:{},id:o,uri:a,move:l})}catch(h){console.error("[Filesystem] move failed",a,h),n(()=>({organizeError:"Move failed"}));return}if(d&&d.ok===!1){console.error("[Filesystem] move rejected",a,d.code,d.error),n(()=>({organizeError:ma(d,"Move rejected")})),await e().reconcileFolders({agentId:t,projectId:r,folders:[u,s]});return}let f=d?.warning==="moved_with_source_retained";f&&n(()=>({organizeError:"Copied to the destination, but the original could not be removed \u2014 both copies exist."})),c?(f||hc({get:e,set:n},a),await e().ensureFolderLoaded({agentId:t,projectId:r,uri:s,force:!0})):(n(h=>{let p=h.openFiles.map(m=>m===a?l:m);return{activeFolderPath:s,openFiles:Array.from(new Set(p)),activeFile:h.activeFile===a?l:h.activeFile}}),f||e().replaceFilePath(a,l)),await e().reconcileFolders({agentId:t,projectId:r,folders:[u,s]})},async renameNode({agentId:t,projectId:r,uri:a,id:s,newName:o}){let i=(o??"").trim();if(!t||!a||!i||i===yt(a))return;let l=ot(a),u=l.endsWith("://")?`${l}${i}`:`${l}/${i}`;if(u===a)return;let c=e().files[a]?.type==="folder",d;try{d=await yr({agentId:t,...r?{projectId:r}:{},id:s,uri:a,move:c?u:i})}catch(f){console.error("[Filesystem] rename failed",a,f),n(()=>({organizeError:"Rename failed"}));return}if(d&&d.ok===!1){console.error("[Filesystem] rename rejected",a,d.code,d.error),n(()=>({organizeError:ma(d,"Rename rejected")})),await e().reconcileFolders({agentId:t,projectId:r,folders:[l]});return}c?(hc({get:e,set:n},a),await e().ensureFolderLoaded({agentId:t,projectId:r,uri:l,force:!0})):e().replaceFilePath(a,u),await e().reconcileFolders({agentId:t,projectId:r,folders:[l]})},async createNode({agentId:t,projectId:r,parentUri:a,name:s,kind:o}){let i=(s??"").trim();if(!t||!a||!i)return;let l=a.endsWith("://")?`${a}${i}`:`${a}/${i}`,u=Fr;try{if(o==="folder"){let c=await yr({agentId:t,...r?{projectId:r}:{},uri:l,mkdir:!0});c?.ok&&u===Fr?n(d=>({...dc(d,[a]),files:{...d.files,[l]:{storeKey:l,name:i,uri:l,type:"folder",parentUri:a,presence:"unindexed",lastUpdated:Date.now()}}})):c&&c.ok===!1&&(console.error("[Filesystem] create folder rejected",l,c.code,c.error),n(()=>({organizeError:ma(c,"Could not create folder")})))}else await rc({agentId:t,...r?{projectId:r}:{},file:new File([""],i),uri:a,tags:[]})}catch(c){console.error("[Filesystem] create failed",o,l,c),n(()=>({organizeError:`Could not create ${o==="folder"?"folder":"file"}`}))}await e().reconcileFolders({agentId:t,projectId:r,folders:[a]})},async pasteNodes({agentId:t,projectId:r,targetFolderUri:a,op:s,uris:o}){if(!t||!a||!Array.isArray(o)||o.length===0)return;let i=new Set([a]),l=[];for(let u of o){if(!u)continue;let c=yt(u);if(!c)continue;let d=a.endsWith("://")?`${a}${c}`:`${a}/${c}`;if(d!==u){i.add(ot(u));try{if(s==="copy"){let f=await yr({agentId:t,...r?{projectId:r}:{},uri:u,copy:d});f&&f.ok===!1&&l.push(c)}else{let f=await yr({agentId:t,...r?{projectId:r}:{},uri:u,move:d});f&&f.ok===!1?l.push(c):f?.warning==="moved_with_source_retained"?l.push(`${c} (original retained)`):e().files[u]?.type==="folder"&&hc({get:e,set:n},u)}}catch(f){console.error("[Filesystem] paste failed",s,u,f),l.push(c)}}}l.length&&n(()=>({organizeError:`${s==="copy"?"Copy":"Move"} incomplete: ${l.join(", ")}`})),await e().reconcileFolders({agentId:t,projectId:r,folders:Array.from(i)})},async deleteNodes({agentId:t,projectId:r,targets:a}){if(!t||!Array.isArray(a)||a.length===0)return;let s=new Set,o=[],i=null;for(let l of a){if(!l?.uri)continue;s.add(ot(l.uri));let u=e().files[l.uri]?.type==="folder";try{let c=await yr({agentId:t,...r?{projectId:r}:{},id:l.id,uri:l.uri,delete:!0});if(c&&c.ok===!1){console.error("[Filesystem] delete rejected",l.uri,c.code,c.error),o.push(yt(l.uri)||l.uri),(typeof c.affected=="number"||c.failed?.length)&&(i={affected:c.affected,failed:c.failed});continue}u?hc({get:e,set:n},l.uri):e().patchFileNode(l.uri,{status:"deleted"})}catch(c){console.error("[Filesystem] delete failed",l.uri,c),o.push(yt(l.uri)||l.uri)}}if(o.length){let l=i?.failed?.length?` \u2014 ${i.affected??0} removed, could not remove: ${i.failed.slice(0,5).join(", ")}${i.failed.length>5?"\u2026":""}`:"";n(()=>({organizeError:`Delete failed: ${o.join(", ")}${l}`}))}await e().reconcileFolders({agentId:t,projectId:r,folders:Array.from(s)})},async openFile({agentId:t,projectId:r,uri:a,readAgentId:s,force:o,revealPane:i=!0}){if(!t||!a)return;n(d=>{let f=d.openFiles.includes(a),h=d.previewEditorsEnabled&&!f&&!d.tabMeta[a]?.pinned,p=d.openFiles,m=d.tabMeta;if(h){let x=d.openFiles.find(w=>w!==a&&d.tabMeta[w]?.preview&&!d.tabMeta[w]?.pinned);x&&(p=p.filter(w=>w!==x),m={...m},delete m[x]),m={...m,[a]:{...m[a]||{},preview:!0}}}let g=p.includes(a)?p:[...p,a];if(g.length>H2){let x=g.findIndex(w=>w!==a&&!d.tabMeta[w]?.pinned);x>=0&&(g=g.filter((w,y)=>y!==x))}return{openFiles:g,activeFile:a,activeAgentId:t,activeProjectId:r,...i?{activeWorkspaceTab:"file"}:{},tabMeta:m}}),e().autoExpandToFile(a);{let d=new Set([rr(a),...ga(a)]);for(let f of d)!f||f===a||e().ensureFolderLoaded({agentId:t,projectId:r,uri:f})}let l=e(),u=typeof l.fileBaseContentByPath[a]=="string"||typeof l.fileContentByPath[a]=="string"&&(l.fileContentByPath[a]?.length||0)>0;if(!o&&u)return;let c=Fr;try{let d=await Ko({agentId:s||t,...r?{projectId:r}:{},files:[a]});if(c!==Fr)return;let f=Yo(d);if(f.length>0){let h=f[0],p=Jo(h),m=typeof h.error=="string"?h.error:void 0,g=typeof h.code=="string"&&h.code==="not_found";if(m&&g){e().removeFilePath(a);return}let x=typeof h.status=="string"?String(h.status):void 0,w=typeof h.category=="string"?h.category:void 0,y=Array.isArray(h.tags)?h.tags:void 0,C=h.metadata&&typeof h.metadata=="object"?h.metadata:void 0,k=typeof h.createdAt=="string"?h.createdAt:void 0,v=typeof h.updatedAt=="string"?h.updatedAt:void 0,b=h.version&&typeof h.version=="object"?h.version:void 0,P=typeof h.readSource=="string"?h.readSource:void 0,N=typeof h.id=="string"?h.id:void 0,M=typeof h.uri=="string"?String(h.uri):a,U=typeof h.agent_id=="string"?String(h.agent_id):s||t,I=typeof h.project_id=="string"?String(h.project_id):r||void 0,A=Ve(M)==="brain",G=b?.sync?.status,V=sc(b?.baseline);n(K=>{let L=K.files[M],R=K.fileContentByPath[M],z=K.fileBaseContentByPath[M],J=m&&typeof R=="string"?R:p,Q=m&&typeof z=="string"?z:p,re={...K.files},pe=!!N||!!x||!!b,ee=A?"brain":L?.presence??(pe?"synced":P==="live"?"unindexed":"synced");eo(re,M,Date.now());let ce=K.openFiles.includes(M)?K.openFiles:K.openFiles.map(ue=>ue===a?M:ue);return{files:{...re,[M]:{...L||uh(M),id:N??L?.id,name:String(h.filename||L?.name||yt(M)),type:"file",uri:M,parentUri:ot(M),status:x??L?.status,sourceAgentId:U,sourceProjectId:I??L?.sourceProjectId,lastUpdated:L?.lastUpdated??Date.now(),category:w??L?.category,tags:y??L?.tags,metadata:C??L?.metadata,createdAt:k??L?.createdAt,updatedAt:v??L?.updatedAt,version:b??L?.version,presence:ee,readSource:P??L?.readSource}},fileContentByPath:{...K.fileContentByPath,[M]:J},fileBaseContentByPath:{...K.fileBaseContentByPath,[M]:Q},fileErrorByPath:{...K.fileErrorByPath,[M]:m},filePrevByPath:{...K.filePrevByPath,[M]:V},openFiles:Array.from(new Set(ce)),activeFile:M,tabMeta:{...K.tabMeta,[M]:{...K.tabMeta[M]||K.tabMeta[a]||{},name:String(h.filename||L?.name||yt(M)),status:x??L?.status,sourceAgentId:U}}}})}}catch(d){let f=d instanceof Error?d.message:"Read failed";if(console.error("[Filesystem] read failed",d),c!==Fr)return;n(h=>({files:{...h.files,[a]:{...h.files[a]||uh(a),sourceAgentId:s||t,sourceProjectId:r||void 0,lastUpdated:h.files[a]?.lastUpdated??Date.now()}},fileErrorByPath:{...h.fileErrorByPath,[a]:f}}))}},async applyNav({agentId:t,projectId:r,nav:a,readAgentId:s,force:o}){if(!t||!a||a.kind!=="filesystem")return;let i=String(a.action||""),l=a.uri;if((i==="read"||i==="open"||i==="modify"||i==="save")&&l){await e().openFile({agentId:t,projectId:r,uri:l,readAgentId:s,force:o});return}if(i==="open-pending"){n(()=>({activeAgentId:t,activeProjectId:r})),e().setPendingPanelFilter(a.filter??{}),e().setWorkspacePanelOpen("pending",!0);return}i==="list"&&l&&n(u=>{let c=rr(l),d=u.expandedFolders.has(l)&&u.expandedFolders.has(c),f=u.activeAgentId===t,h=u.activeProjectId===r;return d&&f&&h?u:{...dc(u,[c,l]),activeAgentId:t,activeProjectId:r}})},async upload({agentId:t,projectId:r,file:a,uri:s}){if(!t)return;let o=s||"brain://docs";n(()=>({uploading:!0}));try{await rc({agentId:t,...r?{projectId:r}:{},file:a,uri:o,tags:["upload"]}),await e().reconcileFolders({agentId:t,projectId:r,folders:[o]})}finally{n(()=>({uploading:!1}))}},async uploadMany({agentId:t,projectId:r,files:a,uri:s}){if(!t)return;let o=Array.isArray(a)?a.filter(Boolean):[];if(o.length===0)return;let i=s||"brain://docs";n(()=>({uploading:!0}));try{for(let l of o)await rc({agentId:t,...r?{projectId:r}:{},file:l,uri:i,tags:["upload"]});await e().reconcileFolders({agentId:t,projectId:r,folders:[i]})}finally{n(()=>({uploading:!1}))}}}),{name:"neuralis.filesystem.tabs",version:2,migrate:(n,e)=>{if(e>=2)return n;let t=n??{},r=t.activeAgentId?fs(null,t.activeProjectId??null,t.activeAgentId):null;return{previewEditorsEnabled:t.previewEditorsEnabled??!1,diffViewMode:t.diffViewMode??"auto",activeUserId:null,activeAgentId:t.activeAgentId??null,activeProjectId:t.activeProjectId??null,contexts:r?{[r]:lc({...Zo(),openFiles:t.openFiles??[],activeFile:t.activeFile??null,tabMeta:t.tabMeta??{}})}:{}}},merge:(n,e)=>{let t=n;if(!t)return e;let r=t.contexts??{},a=t.activeAgentId?fs(t.activeUserId??null,t.activeProjectId??null,t.activeAgentId):null,s={};for(let[i,l]of Object.entries(r))i!==a&&(s[i]=rh(l));let o=a&&r[a]?rh(r[a]):{};return{...e,previewEditorsEnabled:t.previewEditorsEnabled??e.previewEditorsEnabled,diffViewMode:t.diffViewMode??e.diffViewMode,activeUserId:t.activeUserId??null,activeAgentId:t.activeAgentId??null,activeProjectId:t.activeProjectId??null,...o,contextStateByKey:s}},storage:Xf(()=>typeof window<"u"&&window.localStorage?window.localStorage:{getItem:()=>null,setItem:()=>{},removeItem:()=>{}}),partialize:n=>{let e={};for(let[t,r]of Object.entries(n.contextStateByKey))e[t]=lc(r);return n.activeAgentId&&(e[fs(n.activeUserId,n.activeProjectId,n.activeAgentId)]=lc(n)),{previewEditorsEnabled:n.previewEditorsEnabled,diffViewMode:n.diffViewMode,activeUserId:n.activeUserId,activeAgentId:n.activeAgentId,activeProjectId:n.activeProjectId,contexts:e}}}));var zl=W(mr(),1);var mc=W($e(),1);var Fx=n=>n?.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();function Ex(n,e,t=[]){if(e==null)throw new Error("[lucide]: iconNode is required when icon name is used");return{name:Fx(n),size:24,node:e,...t.length>0?{aliases:t}:{}}}var Bx=n=>{let e="",t=!1;for(let r of n){if(r==="-"||r==="_"||r<=" "){t=e.length>0;continue}e.length===0?e+=r.toLowerCase():e+=t?r.toUpperCase():r,t=!1}return e};var Ox=n=>{let e=Bx(n);return e.charAt(0).toUpperCase()+e.slice(1)};var dl=W($e(),1);var cl=(...n)=>n.filter((e,t,r)=>!!e&&e.trim()!==""&&r.indexOf(e)===t).join(" ").trim();var hs={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":2,"stroke-linecap":"round","stroke-linejoin":"round"};function ph(n){return n!=null}function _x(n,e={}){let t=e.attributeNames??{},r=f=>t[f]??f,a=n.size??n.width??hs.width,s=n.size??n.height??hs.height,o=n.aliases?.filter(f=>typeof f=="string"&&f.trim()!=="").map(f=>`lucide-${f}`)??[],i=[...n.name?[`lucide-${n.name}`]:[],...o],l=e.className?.split(" ").filter(Boolean)??[],u=e.includeDefaultClasses===!1?cl(...l):cl("lucide",...i,...l),c=e.absoluteStrokeWidth?Number(e.strokeWidth??hs["stroke-width"])*Number(n.size??n.width??hs.width)/Number(e.size??e.width??hs.width):e.strokeWidth??hs["stroke-width"];return["svg",{...Object.entries(hs).reduce((f,[h,p])=>(f[r(h)]=p,f),{}),..."color"in e&&e.color&&{[r("stroke")]:e.color},..."size"in e&&ph(e.size)&&{[r("width")]:e.size,[r("height")]:e.size},..."width"in e&&ph(e.width)&&{[r("width")]:e.width},..."height"in e&&ph(e.height)&&{[r("height")]:e.height},[r("stroke-width")]:c,...u&&{[r("class")]:u},[r("viewBox")]:`0 0 ${a} ${s}`,...e.hasA11yProp===!1?{[r("aria-hidden")]:"true"}:{},..."attributes"in e&&e.attributes},n.node.map(f=>{let[h,p,m]=f,g=e.nonScalingStroke?{[r("vector-effect")]:"non-scaling-stroke",...p}:p;return m?[h,g,m]:[h,g]})]}function Hx(n,e={}){return _x(n,{...e,attributeNames:{...e.attributeNames,class:"className","stroke-width":"strokeWidth","stroke-linecap":"strokeLinecap","stroke-linejoin":"strokeLinejoin","vector-effect":"vectorEffect"}})}var Ux=n=>{for(let e in n)if(e.startsWith("aria-")||e==="role"||e==="title")return!0;return!1};var Qo=W($e(),1);var z2=(0,Qo.createContext)({});var Gx=()=>(0,Qo.useContext)(z2);var zx=(0,dl.forwardRef)(({color:n,size:e,width:t,height:r,strokeWidth:a,absoluteStrokeWidth:s,nonScalingStroke:o,className:i="",children:l,iconNode:u=[],icon:c={node:u,aliases:[],size:24},...d},f)=>{let{size:h=24,strokeWidth:p=2,absoluteStrokeWidth:m=!1,nonScalingStroke:g=!1,color:x="currentColor",className:w=""}=Gx()??{},y=!!l||Ux(d),[C,k,v=[]]=Hx(c,{color:n??x,width:t??e??h,height:r??e??h,strokeWidth:a??p,absoluteStrokeWidth:s??m,nonScalingStroke:o??g,className:cl(w,i),hasA11yProp:y,attributes:d});return(0,dl.createElement)(C,{ref:f,...k},[...v.map(([b,P])=>(0,dl.createElement)(b,P)),...Array.isArray(l)?l:[l]])});function H(n,e=[],t=[]){let r=typeof n=="string"?Ex(n,e,t):n,a=(0,mc.forwardRef)(({className:s,...o},i)=>(0,mc.createElement)(zx,{ref:i,icon:r,className:s,...o}));return r.name&&(a.displayName=Ox(r.name)),a}var Wx={name:"archive",size:24,node:[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]]};Wx.node;var ei=H(Wx);var jx={name:"arrow-down",size:24,node:[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]};jx.node;var fl=H(jx);var qx={name:"arrow-right",size:24,node:[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]};qx.node;var ti=H(qx);var Vx={name:"arrow-up-down",size:24,node:[["path",{d:"m21 16-4 4-4-4",key:"f6ql7i"}],["path",{d:"M17 20V4",key:"1ejh1v"}],["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}]]};Vx.node;var hl=H(Vx);var $x={name:"arrow-up",size:24,node:[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]};$x.node;var pl=H($x);var Kx={name:"bot",size:24,node:[["path",{d:"M12 8V4H8",key:"hb8ula"}],["rect",{width:"16",height:"12",x:"4",y:"8",rx:"2",key:"enze0r"}],["path",{d:"M2 14h2",key:"vft8re"}],["path",{d:"M20 14h2",key:"4cs60a"}],["path",{d:"M15 13v2",key:"1xurst"}],["path",{d:"M9 13v2",key:"rq6x2g"}]]};Kx.node;var ml=H(Kx);var Xx={name:"braces",size:24,node:[["path",{d:"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1",key:"ezmyqa"}],["path",{d:"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1",key:"e1hn23"}]],aliases:["curly-braces"]};Xx.node;var xa=H(Xx);var Yx={name:"check-check",size:24,node:[["path",{d:"M18 6 7 17l-5-5",key:"116fxf"}],["path",{d:"m22 10-7.5 7.5L13 16",key:"ke71qq"}]]};Yx.node;var ps=H(Yx);var Jx={name:"check",size:24,node:[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]};Jx.node;var Dn=H(Jx);var Zx={name:"chevron-down",size:24,node:[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]};Zx.node;var Tt=H(Zx);var Qx={name:"chevron-left",size:24,node:[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]]};Qx.node;var gl=H(Qx);var ey={name:"chevron-right",size:24,node:[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]};ey.node;var un=H(ey);var ty={name:"chevron-up",size:24,node:[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]]};ty.node;var ja=H(ty);var ny={name:"circle-alert",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]],aliases:["alert-circle"]};ny.node;var ms=H(ny);var ry={name:"circle-check",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m16 9-5.5 5.5L8 12",key:"xofnsj"}]],aliases:["check-circle-2"]};ry.node;var ea=H(ry);var ay={name:"circle-question-mark",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3",key:"1u773s"}],["path",{d:"M12 17h.01",key:"p32p05"}]],aliases:["help-circle","circle-help"]};ay.node;var ta=H(ay);var sy={name:"circle-x",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]],aliases:["x-circle"]};sy.node;var na=H(sy);var oy={name:"clipboard-paste",size:24,node:[["path",{d:"M11 14h10",key:"1w8e9d"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v1.344",key:"1e62lh"}],["path",{d:"m17 18 4-4-4-4",key:"z2g111"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 1.793-1.113",key:"bjbb7m"}],["rect",{x:"8",y:"2",width:"8",height:"4",rx:"1",key:"ublpy"}]]};oy.node;var xl=H(oy);var iy={name:"clock-3",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 6v6h4",key:"135r8i"}]]};iy.node;var ya=H(iy);var ly={name:"cloud",size:24,node:[["path",{d:"M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z",key:"p7xjir"}]]};ly.node;var yl=H(ly);var uy={name:"cloud-upload",size:24,node:[["path",{d:"M12 13v8",key:"1l5pq0"}],["path",{d:"M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242",key:"1pljnt"}],["path",{d:"m8 17 4-4 4 4",key:"1quai1"}]],aliases:["upload-cloud"]};uy.node;var Er=H(uy);var cy={name:"columns-2",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M12 3v18",key:"108xh3"}]],aliases:["columns"]};cy.node;var gs=H(cy);var dy={name:"copy",size:24,node:[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]};dy.node;var ra=H(dy);var fy={name:"corner-up-right",size:24,node:[["path",{d:"m15 14 5-5-5-5",key:"12vg1m"}],["path",{d:"M4 20v-7a4 4 0 0 1 4-4h12",key:"1lu4f8"}]]};fy.node;var bl=H(fy);var hy={name:"database",size:24,node:[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]]};hy.node;var br=H(hy);var py={name:"ellipsis",size:24,node:[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]],aliases:["more-horizontal"]};py.node;var xs=H(py);var my={name:"eye",size:24,node:[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]};my.node;var wl=H(my);var gy={name:"file-code",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 12.5 8 15l2 2.5",key:"1tg20x"}],["path",{d:"m14 12.5 2 2.5-2 2.5",key:"yinavb"}]]};gy.node;var vl=H(gy);var xy={name:"file-code-corner",size:24,node:[["path",{d:"M4 12.15V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2h-3.35",key:"1wthlu"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"m5 16-3 3 3 3",key:"331omg"}],["path",{d:"m9 22 3-3-3-3",key:"lsp7cz"}]],aliases:["file-code-2"]};xy.node;var qa=H(xy);var yy={name:"file-diff",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M9 10h6",key:"9gxzsh"}],["path",{d:"M12 13V7",key:"h0r20n"}],["path",{d:"M9 17h6",key:"r8uit2"}]]};yy.node;var Va=H(yy);var by={name:"file-exclamation-point",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]],aliases:["file-warning"]};by.node;var ys=H(by);var wy={name:"file-image",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["circle",{cx:"10",cy:"12",r:"2",key:"737tya"}],["path",{d:"m20 17-1.296-1.296a2.41 2.41 0 0 0-3.408 0L9 22",key:"wt3hpn"}]]};wy.node;var kl=H(wy);var vy={name:"file-pen",size:24,node:[["path",{d:"M12.659 22H18a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v9.34",key:"o6klzx"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10.378 12.622a1 1 0 0 1 3 3.003L8.36 20.637a2 2 0 0 1-.854.506l-2.867.837a.5.5 0 0 1-.62-.62l.836-2.869a2 2 0 0 1 .506-.853z",key:"zhnas1"}]],aliases:["file-edit"]};vy.node;var bs=H(vy);var ky={name:"file-play",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M15.033 13.44a.647.647 0 0 1 0 1.12l-4.065 2.352a.645.645 0 0 1-.968-.56v-4.704a.645.645 0 0 1 .967-.56z",key:"1tzo1f"}]],aliases:["file-video"]};ky.node;var ws=H(ky);var Sy={name:"file-plus-corner",size:24,node:[["path",{d:"M11.35 22H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v5.35",key:"17jvcc"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M14 19h6",key:"bvotb8"}],["path",{d:"M17 16v6",key:"18yu1i"}]],aliases:["file-plus-2"]};Sy.node;var vs=H(Sy);var Cy={name:"file-plus",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M9 15h6",key:"cctwl0"}],["path",{d:"M12 18v-6",key:"17g6i2"}]]};Cy.node;var ks=H(Cy);var Ly={name:"file-text",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]]};Ly.node;var ba=H(Ly);var Iy={name:"file",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}]]};Iy.node;var Sl=H(Iy);var Ay={name:"folder-open",size:24,node:[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]]};Ay.node;var Ss=H(Ay);var Py={name:"folder-plus",size:24,node:[["path",{d:"M12 10v6",key:"1bos4e"}],["path",{d:"M9 13h6",key:"1uhe8q"}],["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]};Py.node;var wr=H(Py);var Ny={name:"folder-tree",size:24,node:[["path",{d:"M20 10a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1h-2.5a1 1 0 0 1-.8-.4l-.9-1.2A1 1 0 0 0 15 3h-2a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z",key:"hod4my"}],["path",{d:"M20 21a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1h-2.9a1 1 0 0 1-.88-.55l-.42-.85a1 1 0 0 0-.92-.6H13a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z",key:"w4yl2u"}],["path",{d:"M3 5a2 2 0 0 0 2 2h3",key:"f2jnh7"}],["path",{d:"M3 3v13a2 2 0 0 0 2 2h3",key:"k8epm1"}]]};Ny.node;var Cl=H(Ny);var Ry={name:"folder",size:24,node:[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]};Ry.node;var Br=H(Ry);var My={name:"git-branch",size:24,node:[["path",{d:"M15 6a9 9 0 0 0-9 9V3",key:"1cii5b"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}]]};My.node;var Ln=H(My);var Ty={name:"git-commit-horizontal",size:24,node:[["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}],["line",{x1:"3",x2:"9",y1:"12",y2:"12",key:"1dyftd"}],["line",{x1:"15",x2:"21",y1:"12",y2:"12",key:"oup4p8"}]],aliases:["git-commit"]};Ty.node;var Or=H(Ty);var Dy={name:"git-compare-arrows",size:24,node:[["circle",{cx:"5",cy:"6",r:"3",key:"1qnov2"}],["path",{d:"M12 6h5a2 2 0 0 1 2 2v7",key:"1yj91y"}],["path",{d:"m15 9-3-3 3-3",key:"1lwv8l"}],["circle",{cx:"19",cy:"18",r:"3",key:"1qljk2"}],["path",{d:"M12 18H7a2 2 0 0 1-2-2V9",key:"16sdep"}],["path",{d:"m9 15 3 3-3 3",key:"1m3kbl"}]]};Dy.node;var ar=H(Dy);var Fy={name:"git-compare",size:24,node:[["circle",{cx:"18",cy:"18",r:"3",key:"1xkwt0"}],["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M13 6h3a2 2 0 0 1 2 2v7",key:"1yeb86"}],["path",{d:"M11 18H8a2 2 0 0 1-2-2V9",key:"19pyzm"}]]};Fy.node;var ni=H(Fy);var Ey={name:"hard-drive",size:24,node:[["path",{d:"M10 16h.01",key:"1bzywj"}],["path",{d:"M2.212 11.577a2 2 0 0 0-.212.896V18a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-5.527a2 2 0 0 0-.212-.896L18.55 5.11A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"18tbho"}],["path",{d:"M21.946 12.013H2.054",key:"zqlbp7"}],["path",{d:"M6 16h.01",key:"1pmjb7"}]]};Ey.node;var Gn=H(Ey);var By={name:"info",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]]};By.node;var Ll=H(By);var Oy={name:"link-2",size:24,node:[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]]};Oy.node;var Il=H(Oy);var _y={name:"link-2-off",size:24,node:[["path",{d:"M9 17H7A5 5 0 0 1 7 7",key:"10o201"}],["path",{d:"M15 7h2a5 5 0 0 1 4 8",key:"1d3206"}],["line",{x1:"8",x2:"12",y1:"12",y2:"12",key:"rvw6j4"}],["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}]]};_y.node;var Al=H(_y);var Hy={name:"list",size:24,node:[["path",{d:"M3 5h.01",key:"18ugdj"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 19h.01",key:"noohij"}],["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 19h13",key:"m83p4d"}]]};Hy.node;var to=H(Hy);var Uy={name:"loader-circle",size:24,node:[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],aliases:["loader-2"]};Uy.node;var ze=H(Uy);var Gy={name:"lock",size:24,node:[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 10 0v4",key:"fwvmzm"}]]};Gy.node;var no=H(Gy);var zy={name:"minus",size:24,node:[["path",{d:"M5 12h14",key:"1ays0h"}]]};zy.node;var ro=H(zy);var Wy={name:"mouse-pointer-click",size:24,node:[["path",{d:"M14 4.1 12 6",key:"ita8i4"}],["path",{d:"m5.1 8-2.9-.8",key:"1go3kf"}],["path",{d:"m6 12-1.9 2",key:"mnht97"}],["path",{d:"M7.2 2.2 8 5.1",key:"1cfko1"}],["path",{d:"M9.037 9.69a.498.498 0 0 1 .653-.653l11 4.5a.5.5 0 0 1-.074.949l-4.349 1.041a1 1 0 0 0-.74.739l-1.04 4.35a.5.5 0 0 1-.95.074z",key:"s0h3yz"}]]};Wy.node;var Pl=H(Wy);var jy={name:"move-right",size:24,node:[["path",{d:"M18 8L22 12L18 16",key:"1r0oui"}],["path",{d:"M2 12H22",key:"1m8cig"}]]};jy.node;var Nl=H(jy);var qy={name:"music-4",size:24,node:[["path",{d:"M9 18V5l12-2v13",key:"1jmyc2"}],["path",{d:"m9 9 12-2",key:"1e64n2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["circle",{cx:"18",cy:"16",r:"3",key:"1hluhg"}]]};qy.node;var Rl=H(qy);var Vy={name:"network",size:24,node:[["rect",{x:"16",y:"16",width:"6",height:"6",rx:"1",key:"4q2zg0"}],["rect",{x:"2",y:"16",width:"6",height:"6",rx:"1",key:"8cvhb9"}],["rect",{x:"9",y:"2",width:"6",height:"6",rx:"1",key:"1egb70"}],["path",{d:"M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3",key:"1jsf9p"}],["path",{d:"M12 12V8",key:"2874zd"}]]};Vy.node;var Ml=H(Vy);var $y={name:"package",size:24,node:[["path",{d:"M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z",key:"1a0edw"}],["path",{d:"M12 22V12",key:"d0xqtd"}],["polyline",{points:"3.29 7 12 12 20.71 7",key:"ousv84"}],["path",{d:"m7.5 4.27 9 5.15",key:"1c824w"}]]};$y.node;var vr=H($y);var Ky={name:"panel-left",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}]],aliases:["sidebar"]};Ky.node;var Cs=H(Ky);var Xy={name:"pen-line",size:24,node:[["path",{d:"M13 21h8",key:"1jsn5i"}],["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}]],aliases:["edit-3"]};Xy.node;var Ls=H(Xy);var Yy={name:"pencil",size:24,node:[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]};Yy.node;var ao=H(Yy);var Jy={name:"pin",size:24,node:[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]]};Jy.node;var so=H(Jy);var Zy={name:"play",size:24,node:[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z",key:"10ikf1"}]]};Zy.node;var Tl=H(Zy);var Qy={name:"plus",size:24,node:[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]};Qy.node;var Fn=H(Qy);var eb={name:"radio",size:24,node:[["path",{d:"M16.247 7.761a6 6 0 0 1 0 8.478",key:"1fwjs5"}],["path",{d:"M19.075 4.933a10 10 0 0 1 0 14.134",key:"ehdyv1"}],["path",{d:"M4.925 19.067a10 10 0 0 1 0-14.134",key:"1q22gi"}],["path",{d:"M7.753 16.239a6 6 0 0 1 0-8.478",key:"r2q7qm"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]]};eb.node;var $a=H(eb);var tb={name:"refresh-ccw",size:24,node:[["path",{d:"M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"14sxne"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16",key:"1hlbsb"}],["path",{d:"M16 16h5v5",key:"ccwih5"}]]};tb.node;var wa=H(tb);var nb={name:"refresh-cw",size:24,node:[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]};nb.node;var Ht=H(nb);var rb={name:"rotate-ccw",size:24,node:[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]]};rb.node;var oo=H(rb);var ab={name:"save",size:24,node:[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]]};ab.node;var io=H(ab);var sb={name:"scan-search",size:24,node:[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2",key:"aa7l1z"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2",key:"4qcy5o"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2",key:"6vwrx8"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2",key:"ioqczr"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}],["path",{d:"m16 16-1.9-1.9",key:"1dq9hf"}]]};sb.node;var Ka=H(sb);var ob={name:"scissors",size:24,node:[["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M8.12 8.12 12 12",key:"1alkpv"}],["path",{d:"M20 4 8.12 15.88",key:"xgtan2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M14.8 14.8 20 20",key:"ptml3r"}]]};ob.node;var Dl=H(ob);var ib={name:"search",size:24,node:[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]]};ib.node;var Fl=H(ib);var lb={name:"settings",size:24,node:[["path",{d:"M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915",key:"1i5ecw"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]};lb.node;var ri=H(lb);var ub={name:"shield-alert",size:24,node:[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]]};ub.node;var va=H(ub);var cb={name:"shield-check",size:24,node:[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]};cb.node;var ai=H(cb);var db={name:"shield-off",size:24,node:[["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71",key:"1jlk70"}],["path",{d:"M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264",key:"18rp1v"}]]};db.node;var El=H(db);var fb={name:"shield",size:24,node:[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]]};fb.node;var Is=H(fb);var hb={name:"sigma",size:24,node:[["path",{d:"M18 7V5a1 1 0 0 0-1-1H6.5a.5.5 0 0 0-.4.8l4.5 6a2 2 0 0 1 0 2.4l-4.5 6a.5.5 0 0 0 .4.8H17a1 1 0 0 0 1-1v-2",key:"wuwx1p"}]]};hb.node;var Bl=H(hb);var pb={name:"sliders-horizontal",size:24,node:[["path",{d:"M10 5H3",key:"1qgfaw"}],["path",{d:"M12 19H3",key:"yhmn1j"}],["path",{d:"M14 3v4",key:"1sua03"}],["path",{d:"M16 17v4",key:"1q0r14"}],["path",{d:"M21 12h-9",key:"1o4lsq"}],["path",{d:"M21 19h-5",key:"1rlt1p"}],["path",{d:"M21 5h-7",key:"1oszz2"}],["path",{d:"M8 10v4",key:"tgpxqk"}],["path",{d:"M8 12H3",key:"a7s4jb"}]]};pb.node;var lo=H(pb);var mb={name:"square",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]};mb.node;var Ol=H(mb);var gb={name:"tag",size:24,node:[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]]};gb.node;var _l=H(gb);var xb={name:"terminal",size:24,node:[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]]};xb.node;var si=H(xb);var yb={name:"text-align-justify",size:24,node:[["path",{d:"M3 5h18",key:"1u36vt"}],["path",{d:"M3 12h18",key:"1i2n21"}],["path",{d:"M3 19h18",key:"awlh7x"}]],aliases:["align-justify"]};yb.node;var As=H(yb);var bb={name:"trash",size:24,node:[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]],aliases:["trash-2"]};bb.node;var It=H(bb);var wb={name:"triangle-alert",size:24,node:[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]],aliases:["alert-triangle"]};wb.node;var dt=H(wb);var vb={name:"undo-2",size:24,node:[["path",{d:"M9 14 4 9l5-5",key:"102s5s"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11",key:"f3b9sd"}]]};vb.node;var ka=H(vb);var kb={name:"unfold-vertical",size:24,node:[["path",{d:"M12 22v-6",key:"6o8u61"}],["path",{d:"M12 8V2",key:"1wkif3"}],["path",{d:"M4 12H2",key:"rhcxmi"}],["path",{d:"M10 12H8",key:"s88cx1"}],["path",{d:"M16 12h-2",key:"10asgb"}],["path",{d:"M22 12h-2",key:"14jgyd"}],["path",{d:"m15 19-3 3-3-3",key:"11eu04"}],["path",{d:"m15 5-3-3-3 3",key:"itvq4r"}]]};kb.node;var Hl=H(kb);var Sb={name:"unlink",size:24,node:[["path",{d:"m18.84 12.25 1.72-1.71h-.02a5.004 5.004 0 0 0-.12-7.07 5.006 5.006 0 0 0-6.95 0l-1.72 1.71",key:"yqzxt4"}],["path",{d:"m5.17 11.75-1.71 1.71a5.004 5.004 0 0 0 .12 7.07 5.006 5.006 0 0 0 6.95 0l1.71-1.71",key:"4qinb0"}],["line",{x1:"8",x2:"8",y1:"2",y2:"5",key:"1041cp"}],["line",{x1:"2",x2:"5",y1:"8",y2:"8",key:"14m1p5"}],["line",{x1:"16",x2:"16",y1:"19",y2:"22",key:"rzdirn"}],["line",{x1:"19",x2:"22",y1:"16",y2:"16",key:"ox905f"}]]};Sb.node;var Ul=H(Sb);var Cb={name:"upload",size:24,node:[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]]};Cb.node;var Sa=H(Cb);var Lb={name:"wand-sparkles",size:24,node:[["path",{d:"m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72",key:"ul74o6"}],["path",{d:"m14 7 3 3",key:"1r5n42"}],["path",{d:"M5 6v4",key:"ilb8ba"}],["path",{d:"M19 14v4",key:"blhpug"}],["path",{d:"M10 2v2",key:"7u0qdc"}],["path",{d:"M7 8H3",key:"zfb6yr"}],["path",{d:"M21 16h-4",key:"1cnmox"}],["path",{d:"M11 3H9",key:"1obp7u"}]],aliases:["wand-2"]};Lb.node;var Ps=H(Lb);var Ib={name:"wrench",size:24,node:[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z",key:"1ngwbx"}]]};Ib.node;var uo=H(Ib);var Ab={name:"x",size:24,node:[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]};Ab.node;var Ut=H(Ab);var Pb={name:"zap",size:24,node:[["path",{d:"M15.914 4a1.5 1.5 0 00-2.474-1.561l-9 9A1.5 1.5 0 005.5 14h4.002a.5.5 0 01.471.666L8.086 20a1.5 1.5 0 002.475 1.56l9-9A1.5 1.5 0 0018.5 10h-3.997a.5.5 0 01-.472-.667z",key:"1v7up4"}]]};Pb.node;var Gl=H(Pb);var Jt=W(le(),1);function gh(n){let{agentId:e,agentName:t,agentIcon:r,agentAccent:a,supportsSources:s=!0}=n,o=(0,zl.resolveAgentIcon)(r),i=B(g=>g.toggleSidebar),l=B(g=>g.sidebarOpen),u=B(g=>g.refreshTree),c=B(g=>g.activeProjectId),d=B(g=>g.uploading),f=B(g=>g.workspacePanels),h=B(g=>g.setWorkspacePanelOpen),p=B(g=>g.activeWorkspaceTab),m=B(g=>g.pendingCount);return(0,Jt.jsxs)("div",{className:"h-10 flex items-center px-3 shrink-0 gap-2.5",style:{backgroundColor:"transparent",borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[(0,Jt.jsx)("div",{className:"flex items-center gap-1",children:(0,Jt.jsx)("button",{onClick:i,className:`p-1.5 rounded-lg transition-colors ${l?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white"}`,title:"Toggle Sidebar",children:(0,Jt.jsx)(Cs,{className:"w-4 h-4"})})}),(0,Jt.jsx)("div",{className:"h-4 w-[1px] bg-white/10"}),(0,Jt.jsx)("span",{className:"inline-flex h-6 w-6 shrink-0 items-center justify-center",style:{color:a||"var(--icon-muted)"},title:t||"Agent","aria-label":t||"Agent",children:(0,Jt.jsx)(o,{className:"h-4 w-4"})}),(0,Jt.jsxs)("div",{className:"flex items-center gap-1",children:[(0,Jt.jsx)("button",{onClick:()=>u({agentId:e,projectId:c??null}),className:"p-1.5 rounded-lg text-white/50 hover:bg-white/5 hover:text-white transition-colors",title:"Refresh",children:(0,Jt.jsx)(Ht,{className:"w-4 h-4"})}),(0,Jt.jsx)("button",{className:"p-1.5 rounded-lg text-white/50 hover:bg-white/5 hover:text-white transition-colors disabled:opacity-50 disabled:cursor-not-allowed",title:"Upload files",disabled:d,onClick:()=>{if(f.upload&&p==="upload"){h("upload",!1);return}h("upload",!0)},children:d?(0,Jt.jsx)(ze,{className:"w-4 h-4 animate-spin"}):(0,Jt.jsx)(Sa,{className:"w-4 h-4"})}),s?(0,Jt.jsx)("button",{className:`p-1.5 rounded-lg transition-colors ${f.sources&&p==="sources"?"bg-cyan-500/15 text-cyan-400":"text-white/50 hover:bg-white/5 hover:text-cyan-300"}`,title:"Data Sources & Sync",onClick:()=>{if(f.sources&&p==="sources"){h("sources",!1);return}h("sources",!0)},children:(0,Jt.jsx)(br,{className:"w-4 h-4"})}):null,s?(0,Jt.jsx)(zl.SkillLauncher,{variant:"icon",size:"sm",skill:"sync",packageId:"@neuralis/brain-core",label:"Sync sources with the agent",icon:"brain"}):null,(0,Jt.jsx)(zl.SkillLauncher,{variant:"icon",size:"sm",skill:"manage-files",packageId:"@neuralis/brain-core",scripts:["scripts/mkdir.sh","scripts/copy.sh","scripts/modify.sh","scripts/search.sh"],label:"Create, copy, edit or search files with the agent",icon:"Folder"}),(0,Jt.jsx)("button",{className:`p-1.5 rounded-lg transition-colors ${f.packages&&p==="packages"?"bg-violet-500/15 text-violet-300":"text-white/50 hover:bg-white/5 hover:text-violet-200"}`,title:"Packages \u2014 trust & build",onClick:()=>{if(f.packages&&p==="packages"){h("packages",!1);return}h("packages",!0)},children:(0,Jt.jsx)(vr,{className:"w-4 h-4"})}),(0,Jt.jsxs)("button",{className:`relative p-1.5 rounded-lg transition-colors ${f.pending&&p==="pending"?"bg-amber-500/15 text-amber-300":"text-white/50 hover:bg-white/5 hover:text-amber-200"}`,title:m>0?`Pending changes \u2014 ${m} to review`:"Pending changes \u2014 review, approve & revert",onClick:()=>{if(f.pending&&p==="pending"){h("pending",!1);return}h("pending",!0)},children:[(0,Jt.jsx)(Va,{className:"w-4 h-4"}),m>0?(0,Jt.jsx)("span",{"data-testid":"pending-count-badge",className:"absolute -top-1 -right-1 min-w-[14px] rounded-full px-1 text-center text-[9px] leading-[14px] font-semibold bg-amber-500/15 text-amber-300",children:m>=1e3?"1000+":m}):null]})]})]})}var _e=W($e(),1),M1=W(mr(),1);function Xa(n,e){let t=n.grantedFeatures;return t?t.includes("*")||t.includes(e):!1}function oi(n,e){let t=e?.features;return!t||t.length===0?!0:t.every(r=>Xa(n,r))}var xh={owner:1,admin:2,manager:10,member:20,viewer:30};var W2=xh.member,Mb=Number.MAX_SAFE_INTEGER;var aa=W($e(),1),Wb=W(Ya(),1);function Eb(n){return typeof n=="object"?n.key:n}function Bb(n,e){let t=n.length;return new Proxy(n,{get(r,a,s){if(typeof a=="string"){let o=a.charCodeAt(0);if(o>=48&&o<=57){let i=+a;if(Number.isInteger(i)&&i>=0&&i<t){let l=r[i];if(typeof l!="object"){let u=e[i*2];l=r[i]={index:i,key:l,start:u,size:e[i*2+1],end:u+e[i*2+1],lane:0}}return l}}if(a==="length")return t}return Reflect.get(r,a,s)}})}function co(n,e,t){let r=t.initialDeps??[],a,s=!0;function o(){var i;let u=0,c=n();if(!(c.length!==r.length||c.some((h,p)=>r[p]!==h)))return a;r=c;let f=0;return a=e(...c),t?.onChange&&!(s&&t.skipInitialOnChange)&&t.onChange(a),s=!1,a}return o.updateDeps=i=>{r=i},o}function bh(n,e){if(n===void 0)throw new Error(`Unexpected undefined${e?`: ${e}`:""}`);return n}var wh=(n,e)=>Math.abs(n-e)<1.01,Ob=(n,e,t)=>{let r;return Object.assign(function(...a){n.clearTimeout(r),r=n.setTimeout(()=>e.apply(this,a),t)},{cancel:()=>{n.clearTimeout(r)}})};var Wl,vh=()=>{if(Wl!==void 0)return Wl;if(typeof navigator>"u")return Wl=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return Wl=!0;let n=navigator.maxTouchPoints;return Wl=navigator.platform==="MacIntel"&&n!==void 0&&n>0};var _b=n=>{let{offsetWidth:e,offsetHeight:t}=n;return{width:e,height:t}},Y2=n=>n,J2=n=>{let e=Math.max(n.startIndex-n.overscan,0),r=Math.min(n.endIndex+n.overscan,n.count-1)-e+1,a=new Array(r);for(let s=0;s<r;s++)a[s]=e+s;return a},Hb=(n,e)=>{let t=n.scrollElement;if(!t)return;let r=n.targetWindow;if(!r)return;let a=o=>{let{width:i,height:l}=o;e({width:Math.round(i),height:Math.round(l)})};if(a(_b(t)),!r.ResizeObserver)return()=>{};let s=new r.ResizeObserver(o=>{let i=()=>{let l=o[0];if(l?.borderBoxSize){let u=l.borderBoxSize[0];if(u){a({width:u.inlineSize,height:u.blockSize});return}}a(_b(t))};n.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(i):i()});return s.observe(t,{box:"border-box"}),()=>{s.unobserve(t)}},gc={passive:!0};var Z2=typeof window>"u"?!0:"onscrollend"in window,Q2=(n,e,t)=>{let r=n.scrollElement;if(!r)return;let a=n.targetWindow;if(!a)return;let s=n.options.useScrollendEvent&&Z2,o=0,i=s?null:Ob(a,()=>e(t(r),!1),n.options.isScrollingResetDelay),l=d=>()=>{o=t(r),i?.(),e(o,d)},u=l(!0),c=l(!1);return r.addEventListener("scroll",u,gc),s&&r.addEventListener("scrollend",c,gc),()=>{r.removeEventListener("scroll",u),s&&r.removeEventListener("scrollend",c),i?.cancel()}},Ub=(n,e)=>Q2(n,e,t=>{let{horizontal:r,isRtl:a}=n.options;return r?t.scrollLeft*(a&&-1||1):t.scrollTop});var eA=(n,e,t)=>{if(t.options.useCachedMeasurements){let r=t.indexFromElement(n),a=t.options.getItemKey(r);return t.itemSizeCache.get(a)??t.options.estimateSize(r)}if(e?.borderBoxSize){let r=e.borderBoxSize[0];if(r)return Math.round(r[t.options.horizontal?"inlineSize":"blockSize"])}if(!e){let r=t.indexFromElement(n),a=t.options.getItemKey(r),s=t.itemSizeCache.get(a);if(s!==void 0)return s}return n[t.options.horizontal?"offsetWidth":"offsetHeight"]},tA=(n,{adjustments:e=0,behavior:t},r)=>{var a,s;(s=(a=r.scrollElement)==null?void 0:a.scrollTo)==null||s.call(a,{[r.options.horizontal?"left":"top"]:n+e,behavior:t})};var Gb=tA;function nA(n,e,t,r){if(e===0)return!1;let a=r(0),s=new Set,o=0;for(;o<n;){let l=t(o);if(l===a)break;s.add(l),o++}let i=n-o;if(i===0||i>=e)return!1;for(let l=0;l<i;l++)if(r(l)!==t(o+l))return!1;for(let l=i;l<e;l++)if(s.has(r(l)))return!1;return!0}var xc=class{constructor(e){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache=new Map,this.itemSizeCacheVersion=0,this.laneAssignments=new Map,this.pendingMin=null,this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.pendingScrollAnchor=null,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._intendedScrollOffset=null,this._clampedAdjustment=null,this.elementsCache=new Map,this.now=()=>{var t,r,a;return((a=(r=(t=this.targetWindow)==null?void 0:t.performance)==null?void 0:r.now)==null?void 0:a.call(r))??Date.now()},this.observer=(()=>{let t=null,r=()=>t||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:t=new this.targetWindow.ResizeObserver(a=>{a.forEach(s=>{let o=()=>{let i=s.target,l=this.indexFromElement(i);if(!i.isConnected){this.observer.unobserve(i);for(let[u,c]of this.elementsCache)if(c===i){this.elementsCache.delete(u);break}return}this.isIndexInRange(l)&&this.shouldMeasureDuringScroll(l)&&this.resizeItem(l,this.options.measureElement(i,s,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(o):o()})}));return{disconnect:()=>{var a;(a=r())==null||a.disconnect(),t=null},observe:a=>{var s;return(s=r())==null?void 0:s.observe(a,{box:"border-box"})},unobserve:a=>{var s;return(s=r())==null?void 0:s.unobserve(a)}}})(),this.range=null,this.setOptions=t=>{var r;let a={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:Y2,rangeExtractor:J2,onChange:()=>{},measureElement:eA,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,anchorTo:"start",followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:"estimate",useCachedMeasurements:!1};for(let d in t){let f=t[d];f!==void 0&&(a[d]=f)}let s=this.options,o=null,i=null,l=!1;if(s!==void 0&&s.enabled&&a.enabled&&a.anchorTo==="end"&&this.scrollElement!==null){let d=s.count,f=a.count,h=this.getMeasurements(),p=((r=this._singleLaneMeasurements)==null?void 0:r.items)??h,m=C=>Eb(p[C]),g=d>0?m(0):null,x=d>0?m(d-1):null;if(f!==d||d>0&&f>0&&(a.getItemKey(0)!==g||a.getItemKey(f-1)!==x)){l=!0;let C=d>0?this.getVirtualItemForOffset(this.getScrollOffset())??h[0]:null;C&&(o=[C.key,this.getScrollOffset()-C.start]);let k=a.followOnAppend===!0?"auto":a.followOnAppend||null;k&&f>0&&this.isAtEnd(s.scrollEndThreshold)&&(d===0||a.getItemKey(f-1)!==x)&&(f>d||nA(d,f,m,a.getItemKey))&&(i=k)}}this.options=a,l&&(this.pendingMin=0,this.itemSizeCacheVersion++);let u=!1,c=0;if(o&&this.scrollOffset!==null){let[d,f]=o,h=this.getMeasurements(),{count:p,getItemKey:m}=this.options,g=0;for(;g<p&&m(g)!==d;)g++;if(g<p){let x=h[g];if(x){let w=Math.max(0,x.start+f);!i&&w!==this.scrollOffset&&(c=w-this.scrollOffset,this.scrollOffset=w,u=!0)}}}(u||i)&&(this.pendingScrollAnchor=[u?o[0]:null,u?o[1]:0,i,c])},this.notify=t=>{var r,a;(a=(r=this.options).onChange)==null||a.call(r,this,t)},this.maybeNotify=co(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),t=>{this.notify(t)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(t=>t()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.isScrolling=!1,this.scrollDirection=null,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._clampedAdjustment=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var t,r;let a=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==a){if(this.cleanup(),!a){this.maybeNotify();return}if(this.scrollElement=a,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((t=this.scrollElement)==null?void 0:t.window)??null,this.elementsCache.forEach(o=>{this.observer.observe(o)}),this.unsubs.push(this.options.observeElementRect(this,o=>{this.scrollRect=o,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(o,i)=>{if(i&&this._intendedScrollOffset===null&&o===this.scrollOffset)return;this._intendedScrollOffset!==null&&Math.abs(o-this._intendedScrollOffset)<1.5&&(o=this._intendedScrollOffset),this._intendedScrollOffset=null,this._clampedAdjustment!==null&&Math.abs(o-this._clampedAdjustment.maxAtWrite)>=1.5&&(this._clampedAdjustment=null),this.scrollAdjustments=0;let l=this.getScrollOffset();this.scrollDirection=i?l===o?this.scrollDirection:l<o?"forward":"backward":null,this.scrollOffset=o,this.isScrolling=i,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),"addEventListener"in this.scrollElement){let o=this.scrollElement,i=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},l=()=>{this._iosTouching=!1,!(!vh()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};o.addEventListener("touchstart",i,gc),o.addEventListener("touchend",l,gc),this.unsubs.push(()=>{o.removeEventListener("touchstart",i),o.removeEventListener("touchend",l),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}let s=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,s&&this.scrollElement&&this.options.enabled){let[o,i,l,u]=s;o!==null&&!l&&(vh()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?u!==0&&(this._iosDeferredAdjustment+=u):((r=this.scrollState)==null?void 0:r.behavior)==="smooth"&&!wh(this.getScrollOffset()-u,this.scrollState.lastTargetOffset)||this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),l&&this.scrollToEnd({behavior:l})}this._retryClampedAdjustment()},this._retryClampedAdjustment=()=>{if(this._clampedAdjustment===null||!this.scrollElement||!this.options.enabled)return;let{target:t,maxAtWrite:r}=this._clampedAdjustment,a=this.getMaxScrollOffset();a>r+.5&&(this._clampedAdjustment=t>a+.5?{target:t,maxAtWrite:a}:null,this._scrollToOffset(t,{adjustments:void 0,behavior:void 0}))},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;let t=this.getScrollOffset(),r=this.getMaxScrollOffset();if(t<0||t>r)return;if(this._iosDeferredAdjustment<0&&t>=r-1){this._iosDeferredAdjustment=0;return}let a=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(t,{adjustments:this.scrollAdjustments+=a,behavior:void 0})},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getMeasurementOptions=co(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode,this.options.gap],(t,r,a,s,o,i,l,u)=>(this.prevLanes!==void 0&&this.prevLanes!==i&&(this.lanesChangedFlag=!0),this.prevLanes=i,this.pendingMin=null,{count:t,paddingStart:r,scrollMargin:a,getItemKey:s,enabled:o,lanes:i,laneAssignmentMode:l,gap:u}),{key:!1}),this.isIndexInRange=t=>t>=0&&t<this.options.count,this.getMeasurements=co(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:t,paddingStart:r,scrollMargin:a,getItemKey:s,enabled:o,lanes:i,laneAssignmentMode:l,gap:u},c)=>{var d;let f=this.itemSizeCache;if(!o)return this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>t)for(let w of this.laneAssignments.keys())w>=t&&this.laneAssignments.delete(w);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(w=>{this.itemSizeCache.set(w.key,w.size)}));let h=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===t&&(this.lanesSettling=!1),i===1){let w=t*2,y=(d=this._singleLaneMeasurements)==null?void 0:d.flat;if(!y||y.length<w){let b=new Float64Array(w);y&&h>0&&b.set(y.subarray(0,h*2)),y=b}let C=h===0?new Array(t):this._singleLaneMeasurements.items.slice(),k;if(h===0)k=r+a;else{let b=h-1;k=y[b*2]+y[b*2+1]+u}for(let b=h;b<t;b++){let P=s(b);C[b]=P;let N=f.get(P),M=typeof N=="number"?N:this.options.estimateSize(b);y[b*2]=k,y[b*2+1]=M,k+=M+u}this._singleLaneMeasurements={flat:y,items:C};let v=Bb(C,y);return this.measurementsCache=v,v}let p=this.measurementsCache.slice(0,h),m=new Array(i).fill(void 0),g=new Float64Array(i),x=0;for(let w=0;w<h;w++){let y=p[w];y&&(m[y.lane]===void 0&&x++,m[y.lane]=w,g[y.lane]=y.end)}for(let w=h;w<t;w++){let y=s(w),C=this.laneAssignments.get(w),k,v,b=l==="estimate"||f.has(y);if(C!==void 0&&this.options.lanes>1){k=C;let U=m[k],I=U!==void 0?p[U]:void 0;v=I?I.end+u:r+a}else if(x===i){let U=0,I=g[0],A=m[0];for(let G=1;G<i;G++){let V=g[G];(V<I||V===I&&m[G]<A)&&(U=G,I=V,A=m[G])}k=U,v=I+u,b&&this.laneAssignments.set(w,k)}else k=w%this.options.lanes,v=r+a,b&&this.laneAssignments.set(w,k);let P=f.get(y),N=typeof P=="number"?P:this.options.estimateSize(w),M=v+N;p[w]={index:w,start:v,size:N,end:M,key:y,lane:k},m[k]===void 0&&x++,m[k]=w,g[k]=M}return this.measurementsCache=p,p},{key:!1,debug:()=>this.options.debug}),this.calculateRange=co(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(t,r,a,s)=>t.length===0||r===0?(this.range=null,null):(this.range=aA(t,r,a,s,s===1&&this._singleLaneMeasurements!==null?this._singleLaneMeasurements.flat:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=co(()=>{let t=null,r=null,a=this.calculateRange();return a&&(t=a.startIndex,r=a.endIndex),this.maybeNotify.updateDeps([this.isScrolling,t,r]),[this.options.rangeExtractor,this.options.overscan,this.options.count,t,r]},(t,r,a,s,o)=>s===null||o===null?[]:t({startIndex:s,endIndex:o,overscan:r,count:a}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=t=>{let r=this.options.indexAttribute,a=t.getAttribute(r);return a?parseInt(a,10):(console.warn(`Missing attribute name '${r}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=t=>{var r;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;let a=this.scrollState.index??((r=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:r.index);if(a!==void 0&&this.range){let s=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),o=Math.max(0,a-s),i=Math.min(this.options.count-1,a+s);return t>=o&&t<=i}return!0},this.measureElement=t=>{if(!t){this.elementsCache.forEach((o,i)=>{o.isConnected||(this.observer.unobserve(o),this.elementsCache.delete(i))});return}let r=this.indexFromElement(t);if(!this.isIndexInRange(r))return;let a=this.options.getItemKey(r),s=this.elementsCache.get(a);s!==t&&(s&&this.observer.unobserve(s),this.observer.observe(t),this.elementsCache.set(a,t)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(r)&&this.resizeItem(r,this.options.measureElement(t,void 0,this))},this.resizeItem=(t,r)=>{var a,s,o;if(!this.isIndexInRange(t))return;let i,l,u,c=(a=this._singleLaneMeasurements)==null?void 0:a.flat;if(this.options.lanes===1&&c!=null)u=this.options.getItemKey(t),l=c[t*2],i=c[t*2+1];else{let h=this.measurementsCache[t];if(!h)return;u=h.key,l=h.start,i=h.size}let d=this.itemSizeCache.get(u)??i,f=r-d;if(f!==0){let h=this.options.anchorTo==="end"&&((s=this.scrollState)==null?void 0:s.behavior)!=="smooth"&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,p=h?this.getTotalSize():0,m=this.getScrollOffset()+this.scrollAdjustments,x=!this.itemSizeCache.has(u)?l<m:l+d<=m&&this.scrollDirection!=="backward",w=((o=this.scrollState)==null?void 0:o.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[t]??{index:t,key:u,start:l,size:i,end:l+i,lane:0},f,this):x);(this.pendingMin===null||t<this.pendingMin)&&(this.pendingMin=t),this.itemSizeCache.set(u,r),this.itemSizeCacheVersion++;let y=!1;h?y=this.applyScrollAdjustment(this.getTotalSize()-p):w&&(y=this.applyScrollAdjustment(f)),this.notify(y),this._retryClampedAdjustment()}},this.getVirtualItems=co(()=>[this.getVirtualIndexes(),this.getMeasurements()],(t,r)=>{let a=[];for(let s=0,o=t.length;s<o;s++){let i=t[s],l=r[i];a.push(l)}return a},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=t=>{var r;let a=this.getMeasurements();if(a.length===0)return;let s=(r=this._singleLaneMeasurements)==null?void 0:r.flat,o=this.options.lanes===1&&s!=null,i=zb(0,a.length-1,o?l=>s[l*2]:l=>bh(a[l]).start,t);return bh(a[i])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{let t=this.scrollElement.document.documentElement;return this.options.horizontal?t.scrollWidth-this.scrollElement.innerWidth:t.scrollHeight-this.scrollElement.innerHeight}},this.getVirtualDistanceFromEnd=()=>Math.max(this.getTotalSize()-this.getSize()-this.getScrollOffset(),0),this.getDistanceFromEnd=()=>Math.max(this.getMaxScrollOffset()-this.getScrollOffset(),0),this.isAtEnd=(t=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=t,this.getOffsetForAlignment=(t,r,a=0)=>{if(!this.scrollElement)return 0;let s=this.getSize(),o=this.getScrollOffset();r==="auto"&&(r=t>=o+s?"end":"start"),r==="center"?t+=(a-s)/2:r==="end"&&(t-=s);let i=this.getMaxScrollOffset();return Math.max(Math.min(i,t),0)},this.getOffsetForIndex=(t,r="auto")=>{t=Math.max(0,Math.min(t,this.options.count-1));let a=this.getSize(),s=this.getScrollOffset(),o=this.measurementsCache[t];if(!o)return;if(r==="auto")if(o.end>=s+a-this.options.scrollPaddingEnd)r="end";else if(o.start<=s+this.options.scrollPaddingStart)r="start";else return[s,r];if(r==="end"&&t===this.options.count-1)return[this.getMaxScrollOffset(),r];let i=r==="end"?o.end+this.options.scrollPaddingEnd:o.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(i,r,o.size),r]},this.scrollToOffset=(t,{align:r="start",behavior:a="auto"}={})=>{this._iosDeferredAdjustment=0;let s=this.getOffsetForAlignment(t,r),o=this.now();this.scrollState={index:null,align:r,behavior:a,startedAt:o,lastTargetOffset:s,stableFrames:0},this._scrollToOffset(s,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollToIndex=(t,{align:r="auto",behavior:a="auto"}={})=>{this._iosDeferredAdjustment=0,t=Math.max(0,Math.min(t,this.options.count-1));let s=this.getOffsetForIndex(t,r);if(!s)return;let[o,i]=s,l=this.now();this.scrollState={index:t,align:i,behavior:a,startedAt:l,lastTargetOffset:o,stableFrames:0},this._scrollToOffset(o,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollBy=(t,{behavior:r="auto"}={})=>{let a=this.getScrollOffset()+t,s=this.now();this.scrollState={index:null,align:"start",behavior:r,startedAt:s,lastTargetOffset:a,stableFrames:0},this._scrollToOffset(a,{adjustments:void 0,behavior:r}),this.scheduleScrollReconcile()},this.scrollToEnd=({behavior:t="auto"}={})=>{if(this.options.count>0){this.scrollToIndex(this.options.count-1,{align:"end",behavior:t});return}this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:t})},this.getTotalSize=()=>{var t,r;let a=this.getMeasurements(),s;if(a.length===0)s=this.options.paddingStart;else if(this.options.lanes===1){let o=a.length-1,i=(t=this._singleLaneMeasurements)==null?void 0:t.flat;i!=null?s=i[o*2]+i[o*2+1]:s=((r=a[o])==null?void 0:r.end)??0}else{let o=Array(this.options.lanes).fill(null),i=a.length-1;for(;i>=0&&o.some(l=>l===null);){let l=a[i];o[l.lane]===null&&(o[l.lane]=l.end),i--}s=Math.max(...o.filter(l=>l!==null))}return Math.max(s-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{let t=[];if(this.itemSizeCache.size===0)return t;let r=this.getMeasurements();for(let a of r)a&&this.itemSizeCache.has(a.key)&&t.push({index:a.index,key:a.key,start:a.start,size:a.size,end:a.end,lane:a.lane});return t},this._scrollToOffset=(t,{adjustments:r,behavior:a})=>{this._intendedScrollOffset=t+(r??0),this.options.scrollToFn(t,{behavior:a,adjustments:r},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(e)}applyScrollAdjustment(e,t){if(e===0)return!1;if(vh()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded))return this._iosDeferredAdjustment+=e,!1;{let r=this.getScrollOffset()+this.scrollAdjustments+e,a=this.scrollElement,s=a!==null&&("scrollHeight"in a||"document"in a)?this.getMaxScrollOffset():null;return this._clampedAdjustment=s!==null&&r>s+.5?{target:r,maxAtWrite:s}:null,this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=e,behavior:t}),this.scrollOffset!==null&&(this.scrollOffset+=this.scrollAdjustments,this.scrollOffset<0&&(this.scrollOffset=0),this.scrollAdjustments=0),!0}}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}let r=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,a=r?r[0]:this.scrollState.lastTargetOffset,s=1,o=a!==this.scrollState.lastTargetOffset;if(!o&&wh(a,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=s){this.getScrollOffset()!==a&&this._scrollToOffset(a,{adjustments:void 0,behavior:"auto"}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,o){let i=this.getSize()||600,l=Math.abs(a-this.getScrollOffset()),u=this.scrollState.behavior==="smooth"&&l>i;this.scrollState.lastTargetOffset=a,u||(this.scrollState.behavior="auto"),this._scrollToOffset(a,{adjustments:void 0,behavior:u?"smooth":"auto"})}this.scheduleScrollReconcile()}},zb=(n,e,t,r)=>{for(;n<=e;){let a=(n+e)/2|0,s=t(a);if(s<r)n=a+1;else if(s>r)e=a-1;else return a}return n>0?n-1:0};function rA(n,e,t){let r=0;for(;r<=e;){let a=(r+e)/2|0,s=n[a*2];if(s<t)r=a+1;else if(s>t)e=a-1;else return a}return r>0?r-1:0}function aA(n,e,t,r,a){let s=n.length-1;if(n.length<=r)return{startIndex:0,endIndex:s};if(r===1&&a!==null){let u=rA(a,s,t),c=u,d=t+e;for(;c<s&&a[c*2]+a[c*2+1]<d;)c++;return{startIndex:u,endIndex:c}}let i=zb(0,s,u=>n[u].start,t),l=i;if(r===1)for(;l<s&&n[l].end<t+e;)l++;else if(r>1){let u=Array(r).fill(0);for(;l<s&&u.some(d=>d<t+e);){let d=n[l];u[d.lane]=d.end,l++}let c=Array(r).fill(t+e);for(;i>=0&&c.some(d=>d>=t);){let d=n[i];c[d.lane]=d.start,i--}i=Math.max(0,i-i%r),l=Math.min(s,l+(r-1-l%r))}return{startIndex:i,endIndex:l}}var kh=typeof document<"u"?aa.useLayoutEffect:aa.useEffect;function sA({useFlushSync:n=!0,directDomUpdates:e=!1,directDomUpdatesMode:t="transform",...r}){let a=aa.useReducer(d=>d+1,0)[1],s=aa.useRef({enabled:e,mode:t,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});s.current.enabled=e,s.current.mode=t;let o=aa.useRef(!1),i=d=>{let f=s.current;if(!f.enabled||!f.container)return;let h=d.getTotalSize();if(h!==f.lastSize){f.lastSize=h;let p=d.options.horizontal?"width":"height";f.container.style[p]=`${h}px`}},l=d=>{let f=s.current;if(!f.enabled||!f.container)return;i(d);let h=!!d.options.horizontal,p=f.mode==="transform",m=h?"left":"top",g=d.options.scrollMargin,x=d.getVirtualItems();for(let w of x){let y=w.start-g,C=d.elementsCache.get(w.key);C&&f.lastPositions.get(C)!==y&&(f.lastPositions.set(C,y),p?C.style.transform=h?`translate3d(${y}px, 0, 0)`:`translate3d(0, ${y}px, 0)`:C.style[m]=`${y}px`)}},u={...r,onChange:(d,f)=>{var h;let p=s.current,m=!0;if(p.enabled){l(d);let g=d.range,x=p.prevRange;m=!x||x.isScrolling!==d.isScrolling||x.startIndex!==g?.startIndex||x.endIndex!==g?.endIndex,m&&(p.prevRange=g?{startIndex:g.startIndex,endIndex:g.endIndex,isScrolling:d.isScrolling}:null)}m&&(n&&f&&!o.current?(0,Wb.flushSync)(a):a()),(h=r.onChange)==null||h.call(r,d,f)}},[c]=aa.useState(()=>{let d=new xc(u),f=d.measureElement;return d.measureElement=h=>{o.current=!0;try{f(h)}finally{o.current=!1}},Object.assign(d,{containerRef:h=>{let p=s.current;if(p.container=h,p.lastSize=null,h&&p.enabled){let m=d.getTotalSize();p.lastSize=m;let g=d.options.horizontal?"width":"height";h.style[g]=`${m}px`}}})});return c.setOptions(u),kh(()=>c._didMount(),[]),kh(()=>(i(c),c._willUpdate())),kh(()=>{l(c)}),c}function ii(n){return sA({observeElementRect:Hb,observeElementOffset:Ub,scrollToFn:Gb,...n})}var Ja=W($e(),1);function jb(n){let{agentId:e,projectId:t,enabled:r}=n,[a,s]=(0,Ja.useState)([]),o=(0,Ja.useRef)(!0);(0,Ja.useEffect)(()=>(o.current=!0,()=>{o.current=!1}),[]);let i=(0,Ja.useRef)(!1);return(0,Ja.useEffect)(()=>{i.current=!1,s([])},[e,t]),(0,Ja.useEffect)(()=>{!e||!r||i.current||(i.current=!0,Zu({agentId:e,...t?{projectId:t}:{}}).then(l=>{o.current&&s(l.suggestions??[])}).catch(()=>{o.current&&s([])}))},[e,t,r]),a}var wc=W($e(),1);var sr=W(mr(),1);var Ca=W(le(),1);function oA({className:n}){return(0,Ca.jsxs)("svg",{viewBox:"0 0 64 64",className:n,"aria-hidden":"true",children:[(0,Ca.jsx)("path",{d:"M10 52L24 28L36 36L52 12",fill:"none",stroke:"currentColor",strokeWidth:"3.5",strokeLinecap:"round",strokeLinejoin:"round"}),(0,Ca.jsx)("circle",{cx:"10",cy:"52",r:"5.2",fill:"#fb923c",stroke:"currentColor",strokeWidth:"2.4"}),(0,Ca.jsx)("circle",{cx:"24",cy:"28",r:"5.2",fill:"#fb923c",stroke:"currentColor",strokeWidth:"2.4"}),(0,Ca.jsx)("circle",{cx:"36",cy:"36",r:"5.2",fill:"#fb923c",stroke:"currentColor",strokeWidth:"2.4"}),(0,Ca.jsx)("circle",{cx:"52",cy:"12",r:"5.2",fill:"#fb923c",stroke:"currentColor",strokeWidth:"2.4"})]})}function iA(n){if(!n)return"aged";let e=Date.parse(n);if(!Number.isFinite(e))return"aged";let t=Math.max(0,(Date.now()-e)/6e4);return t<=15?"fresh":t<=180?"recent":t<=1440?"aged":"stale"}function fo(n){switch(iA(n)){case"fresh":return{pillClassName:"border-emerald-400/25 bg-emerald-500/14 text-emerald-100",iconClassName:"text-emerald-300/85",label:"Changed just now"};case"recent":return{pillClassName:"border-amber-400/22 bg-amber-500/10 text-amber-100/92",iconClassName:"text-amber-300/76",label:"Changed recently"};case"aged":return{pillClassName:"border-white/10 bg-white/[0.05] text-white/60",iconClassName:"text-white/40",label:"Older change"};default:return{pillClassName:"border-rose-400/18 bg-rose-500/10 text-rose-100/80",iconClassName:"text-rose-300/70",label:"Older indexed change"}}}function jl(n){let e=n.status==="deleted",t=n.status==="pending_review",r=n.status==="pinned";return e?{tone:"text-red-100/70",iconTone:"text-red-300/70",secondaryTone:"text-red-200/60",highlightTone:"bg-red-500/12",icon:ms,label:"Deleted",title:"Marked as deleted",ghosted:!0}:t?{tone:"text-amber-50/95",iconTone:"text-amber-300/85",secondaryTone:"text-amber-200/75",highlightTone:"bg-amber-500/10",icon:dt,label:"Review pending",title:"Pending review before approval"}:n.presence==="brain"?{tone:"text-violet-50/92",iconTone:"text-violet-300/80",secondaryTone:"text-violet-200/68",highlightTone:"bg-violet-500/10",icon:br,label:"Brain node",title:"Stored in brain index"}:n.presence==="stale_indexed"?{tone:"text-rose-100/78",iconTone:"text-rose-300/75",secondaryTone:"text-rose-200/65",highlightTone:"bg-rose-500/8",icon:Ka,label:"Missing from disk",title:"Indexed but not found in live source",ghosted:!0}:n.presence==="unindexed"?{tone:"text-white/55",iconTone:"text-white/70",secondaryTone:"text-white/45",highlightTone:"bg-white/[0.04]",icon:$a,label:"Unindexed",title:"Connector entry not vector-indexed yet"}:r?{tone:"text-white/82",iconTone:"text-amber-200/80",secondaryTone:"text-amber-100/65",highlightTone:"bg-amber-500/8",icon:so,label:"Pinned",title:"Pinned item"}:n.presence==="synced"?{tone:"text-white",iconTone:"text-sky-300/80",secondaryTone:"text-white/82",highlightTone:"bg-sky-500/10",icon:oA,label:"Synced",title:"Indexed and present on the connector"}:{tone:"text-white/72",iconTone:"text-white/48",secondaryTone:"text-white/48",highlightTone:"bg-white/[0.04]",icon:ya,label:"Neutral",title:"File entry"}}function qb(n){return n?Ss:Br}function Vb(n){let t=[jl(n).label];return n.version?.changedAt&&t.push(fo(n.version.changedAt).label),n.status==="pinned"&&t.push("Pinned"),t}function yc(n){return{iconClassName:"text-white/35",labelClassName:"text-white/45",detailClassName:"text-white/30",containerClassName:"opacity-55",title:n==="disabled"?"Source disabled in this scope \u2014 toggle in the Sources panel.":"Source discovered but not yet attached \u2014 click to add."}}function bc(n){let e=n.enabled===!1,t=n.enabled==="auto"&&n.enabled_effective===!1;return e||t?{iconClassName:"text-white/35",labelClassName:"text-white/45",detailClassName:"text-white/30"}:n.live===!1?{iconClassName:"text-white/35",labelClassName:"text-white/45",detailClassName:"text-white/30"}:n.sync_status==="error"?{iconClassName:"text-rose-300/80",labelClassName:"text-rose-50/92",detailClassName:"text-rose-200/65"}:n.sync_status==="paused"?{iconClassName:"text-amber-300/80",labelClassName:"text-amber-50/90",detailClassName:"text-amber-200/65"}:n.sync_status==="active"?{iconClassName:"text-sky-300/80",labelClassName:"text-sky-50/90",detailClassName:"text-sky-200/62"}:n.source_kind==="brain"?{iconClassName:"text-violet-300/85",labelClassName:"text-violet-50/92",detailClassName:"text-violet-200/60"}:{iconClassName:"text-white/80",labelClassName:"text-white/90",detailClassName:"text-white/55"}}var lA={runtime_offline:"Machine offline \u2014 container not running",fs_unreachable:"Filesystem unreachable \u2014 mount missing",fs_permission:"Filesystem unreadable \u2014 permission denied",store_unreachable:"Store offline \u2014 backing service unreachable"};function Sh(n){return(n?lA[n]:void 0)??"Disconnected \u2014 connector cannot reach its backing filesystem"}function $b(n){return n.enabled===!1?"Source disabled":n.enabled==="auto"&&n.enabled_effective===!1?"Source auto \u2014 currently stopped":n.live===!1?Sh(n.live_reason):n.sync_status==="error"?n.last_error??"Sync error":n.sync_status==="paused"?"Sync paused":n.sync_status==="active"?"Sync active":null}function Ch(n){if(!n)return null;let e=Date.parse(n);if(!Number.isFinite(e))return null;let t=Math.max(0,Math.round((Date.now()-e)/6e4));if(t<1)return"now";if(t<60)return`${t}m`;let r=Math.round(t/60);return r<24?`${r}h`:`${Math.round(r/24)}d`}function Kb({className:n,title:e}){return(0,Ca.jsx)("span",{title:e,className:"inline-flex",children:(0,Ca.jsx)(ar,{className:n})})}function q(...n){return n.filter(Boolean).join(" ")}var Qn=W(le(),1),uA=5,Xb=28;function Yb({suggestions:n,expanded:e,onToggleExpanded:t,onPick:r,overlay:a}){return n.length===0?null:(0,Qn.jsxs)("div",{className:q("group/discover shrink-0 border-t border-white/[0.06] bg-[#0b0b0f]/95",a?"absolute inset-x-0 bottom-0 z-20 shadow-[0_-8px_24px_rgba(0,0,0,0.45)]":""),"data-testid":"discover-dock",children:[(0,Qn.jsxs)("div",{className:"flex items-center justify-between px-2 pt-1.5 pb-1",children:[(0,Qn.jsx)("span",{className:"text-[10px] font-bold uppercase tracking-wider text-white/40",children:"Discover"}),(0,Qn.jsx)("button",{type:"button",onClick:t,className:"inline-flex h-4 w-4 items-center justify-center rounded text-white/40 opacity-0 transition-opacity hover:text-white/70 focus-visible:opacity-100 group-hover/discover:opacity-60",title:e?"Collapse discoverable sources":"Show all discoverable sources","aria-label":e?"Collapse discoverable sources":"Show all discoverable sources","aria-expanded":e,children:e?(0,Qn.jsx)(Tt,{className:"h-3 w-3"}):(0,Qn.jsx)(ja,{className:"h-3 w-3"})})]}),(0,Qn.jsx)("ul",{className:"overlay-scroll overflow-y-auto pb-1",style:{maxHeight:e?"60vh":uA*Xb},children:n.map(s=>(0,Qn.jsx)(cA,{suggestion:s,onPick:r},s.id))})]})}var cA=wc.default.memo(function({suggestion:e,onPick:t}){let r=yc("unattached"),a=(0,sr.resolveLucideIcon)(e.icon??null)??Gn,s=(0,wc.useCallback)(()=>t(e),[t,e]),o=[e.description,e.root].filter(Boolean).join(`
3
- `);return(0,Qn.jsx)("li",{children:(0,Qn.jsxs)("button",{type:"button",onClick:s,title:o||r.title,style:{height:Xb},className:q("flex w-full items-center gap-2 px-2 text-left transition-colors hover:bg-white/[0.05]",r.containerClassName),children:[(0,Qn.jsx)(a,{className:q("h-4 w-4 shrink-0",r.iconClassName)}),(0,Qn.jsx)("span",{className:q("truncate text-xs font-medium",r.labelClassName),children:e.label}),(0,Qn.jsxs)("span",{className:q("shrink-0 font-mono text-[9px]",r.detailClassName),children:[e.suggestedScheme,"://"]})]})})});var li=W($e(),1),ew=W(le(),1),Jb=(0,li.createContext)(null),Lh=null;function hn(){let n=(0,li.useContext)(Jb);if(!n)throw new Error("useFilesystemHost must be used within a FilesystemHostProvider");return n}function Zb(){return Lh}function Qb({value:n,children:e}){return Lh=n,(0,li.useEffect)(()=>{Lh=n},[n]),(0,ew.jsx)(Jb.Provider,{value:n,children:e})}var nw=W(mr(),1);function tw(n){return String(n||"").trim().toLowerCase().replace(/[\s_]+/g,"-")}function Ns(n){let e=new Map,t=new Map,r=new Map;return n.ids.forEach((a,s)=>{let o=n.byId[a];if(!o)return;e.set(a,o);let i=o.slug?tw(o.slug):"";i&&t.set(i,o);let l=o.name?tw(o.name):"";l&&t.set(l,o);let u=o.config?.appearance?.color,c=(0,nw.resolveAgentColor)(u,s);r.set(a,c)}),{byId:e,bySlug:t,accentById:r}}function ui(n,e){if(n)return e.accentById.get(n)}var kr=W($e(),1);var rw=W(Qr(),1);var hA=W(le(),1);function ci(n){let e=yt(n)||n.split("/").pop()||"",t=dA(e);return fA(e.toLowerCase(),t)}function dA(n){return n.includes(".")?n.split(".").pop().toLowerCase():""}function fA(n,e){if(n==="dockerfile")return ei;if(n==="package.json")return xa;if(n===".gitignore"||n===".env"||n.startsWith(".env."))return ba;if(n==="tsconfig.json"||n==="tsconfig.base.json")return xa;if(n.endsWith(".d.ts"))return qa;let t=new Set(["ts","tsx","js","jsx","py","java","kt","php","go","rs","cpp","c","hpp","cs","swift","sh","bash","zsh","ps1","prisma"]),r=new Set(["md","mdx","txt","yml","yaml","xml","ini","toml","css","scss","html","csv","xls","xlsx"]),a=new Set(["png","jpg","jpeg","gif","webp","svg"]),s=new Set(["mp4","mov","webm"]),o=new Set(["mp3","wav"]),i=new Set(["zip","gz","tar","rar","lock"]);return e==="json"||e==="jsonl"?xa:t.has(e)?qa:r.has(e)?ba:a.has(e)?kl:s.has(e)?ws:o.has(e)?Rl:i.has(e)?ei:Sl}var Ah=W(le(),1),pA={M:"text-amber-400",A:"text-emerald-400",D:"text-rose-400",R:"text-sky-400",C:"text-sky-400",U:"text-rose-400","?":"text-emerald-400"},mA={M:"bg-amber-400",A:"bg-emerald-400",D:"bg-rose-400",R:"bg-sky-400",C:"bg-sky-400",U:"bg-rose-400","?":"bg-emerald-400"},Ih={M:"Modified",A:"Added",D:"Deleted",R:"Renamed",C:"Copied",U:"Unmerged","?":"Untracked"};function gA(n){let e=n[0]??" ",t=n[1]??" ";if(e==="?"||t==="?")return"?";let r=t!==" "?t:e;return r===" "?null:r}function vc({code:n,dot:e=!1}){let t=gA(n);if(!t)return null;let r=n[0]!==" "&&n[0]!=="?",a=n[1]!==" "&&n[1]!=="?",s=(Ih[t]??"Changed")+(r&&a?" (staged + unstaged)":r?" (staged)":"");if(e)return(0,Ah.jsx)("span",{className:q("shrink-0 w-1.5 h-1.5 rounded-full",mA[t]??"bg-white/60"),title:`Git: contains ${(Ih[t]??"changes").toLowerCase()}`,"aria-label":`Git: folder contains changes (${Ih[t]??"changed"})`});let o=t==="?"?"U":t;return(0,Ah.jsx)("span",{className:q("shrink-0 text-[10px] font-bold leading-none tabular-nums",pA[t]??"text-white/60"),title:`Git: ${s}`,"aria-label":`Git status: ${s}`,children:o})}var sn=W(le(),1),ql="application/x-neuralis-fs-node";function xA({uri:n,tone:e,title:t}){let r=ci(n);return(0,sn.jsx)("span",{className:q("inline-flex items-center justify-center shrink-0",e),title:t,children:(0,sn.jsx)(r,{className:"w-4 h-4"})})}var aw=kr.default.memo(function({node:e,depth:t=0,agentId:r,projectId:a,isActive:s,isExpanded:o,badgeCount:i,isDrop:l,isSelectedFolder:u,mark:c,agentIndex:d,fallbackAgent:f,uploading:h,packageIconBySlug:p,onToggleFolder:m,onOpenFile:g,onClearFileMark:x,onSetDropTarget:w,onUploadMany:y,onMoveFileToFolder:C,pendingReviewCount:k,isSelected:v,isCut:b,renaming:P,onNodeClick:N,onNodeContextMenu:M,onRenameCommit:U,onRenameCancel:I}){let A=e.type==="folder",G=e.status==="deleted",V=e.status==="pending_review",K=!A&&e.version?.diff?e.version.diff:void 0,L=e.storeKey||Wa(e),R=(0,kr.useRef)(null),z=e.sourceAgentId?d.byId.get(e.sourceAgentId)??null:f,J=ui(z?.id,d),Q=(0,kr.useMemo)(()=>jl(e),[e]),re=!!(K&&(K.added>0||K.removed>0)),pe=!!(A&&i),ee=!!c,ce=!!e.git,ue=fo(e.version?.changedAt),He=(0,kr.useMemo)(()=>{if(!A||!p)return null;let Ne=e.uri.match(/^(packages|data):\/\/([^/]+)\/?$/);return Ne?Ne[2]:null},[A,e.uri,p]),je=(He?p?.[He]:void 0)??qb(o),et=Vb(e).join(" \u2022 "),Dt=re||pe||ee||V||ce,at=(0,kr.useCallback)(()=>{m({key:L})},[L,m]),vt=(0,kr.useCallback)(()=>{g({agentId:r,projectId:a??null,uri:e.uri,readAgentId:z?.id}),c&&x({agentId:r,path:e.uri})},[r,e.uri,z?.id,g,x,a,c]),Pt=(0,kr.useCallback)(Ne=>{let tt=Ne.metaKey||Ne.ctrlKey,Je=Ne.shiftKey;if(tt||Je){N?.({node:e,additive:tt,range:Je});return}N?.({node:e,additive:!1,range:!1}),A?at():vt()},[e,A,N,at,vt]),Ye=(0,kr.useCallback)(Ne=>{Ne.preventDefault(),Ne.stopPropagation(),M?.({node:e,x:Ne.clientX,y:Ne.clientY})},[e,M]);return(0,sn.jsxs)("div",{ref:R,className:q("group flex h-7 items-center gap-1.5 px-2 rounded-md cursor-pointer select-none transition-colors",s?"bg-white/10 text-white":"text-white/70 hover:bg-white/5 hover:text-white",u?"bg-sky-500/15 text-sky-100":"",v&&!s?"bg-sky-400/20 ring-1 ring-inset ring-sky-400/30 text-white":"",V&&!s?"bg-amber-500/[0.08] border-l-2 border-l-amber-400/60":"",G?"opacity-70":"",b?"opacity-45":"",l?"bg-white/10":""),style:{paddingLeft:`${t*12+8}px`},draggable:!P,onDragStart:Ne=>{let tt={kind:"filesystem",action:A?"list":"read",uri:e.uri};Ne.dataTransfer.setData("application/x-neuralis-fs-ref",JSON.stringify(tt)),Ne.dataTransfer.setData(ql,JSON.stringify({type:e.type,uri:e.uri,id:e.id,name:e.name})),Ne.dataTransfer.setData("text/plain",`\u27E6fs:${A?"list":"read"}:${e.uri}\u27E7`),Ne.dataTransfer.effectAllowed="copyMove"},onClick:Pt,onContextMenu:Ye,onDragOver:Ne=>{if(!A||h)return;let tt=Array.from(Ne.dataTransfer.types||[]);(tt.includes("Files")||tt.includes(ql))&&(Ne.preventDefault(),Ne.dataTransfer.dropEffect=tt.includes(ql)?"move":"copy",w(L))},onDragLeave:()=>{l&&w(null)},onDrop:async Ne=>{if(!A||h)return;let tt=Array.from(Ne.dataTransfer.types||[]),Je=tt.includes("Files"),Ft=tt.includes(ql);if(!(!Je&&!Ft)){if(Ne.preventDefault(),w(null),Ft){let Mt=Ne.dataTransfer.getData(ql);if(!Mt)return;try{let Te=JSON.parse(Mt);if(!Te.uri||Te.uri===e.uri||e.uri===Te.uri||e.uri.startsWith(`${Te.uri}/`))return;await C({fromUri:Te.uri,id:Te.id,toFolderUri:e.uri});return}catch{return}}if(Je){let Mt=Array.from(Ne.dataTransfer.files||[]);if(Mt.length===0)return;await y({agentId:r,projectId:a??null,files:Mt,uri:e.uri})}}},title:`${e.uri}${et?`
4
- ${et}`:""}`,"aria-label":`${e.name} \u2014 ${et}`,children:[(0,sn.jsx)("span",{className:"shrink-0 text-white/40",children:A?o?(0,sn.jsx)(Tt,{className:"w-3.5 h-3.5"}):(0,sn.jsx)(un,{className:"w-3.5 h-3.5"}):(0,sn.jsx)("span",{className:"w-3.5 h-3.5 inline-block"})}),A?(0,sn.jsx)("span",{title:Q.title,children:(0,sn.jsx)(je,{className:q("w-4 h-4 shrink-0",Q.iconTone),style:{color:e.presence==="brain"&&J||void 0}})}):(0,sn.jsx)(xA,{uri:e.uri,tone:Q.iconTone,title:Q.title}),P?(0,sn.jsx)(yA,{initial:e.name,onCommit:Ne=>U?.({node:e,newName:Ne}),onCancel:()=>I?.()}):(0,sn.jsx)("span",{className:q("min-w-0 text-xs truncate flex-1 transition-colors",Q.tone,Q.ghosted&&"opacity-70",G&&"line-through"),children:e.name}),Dt?(0,sn.jsxs)("span",{className:"ml-1 shrink-0 flex items-center justify-end gap-1",children:[V?(0,sn.jsx)("span",{title:"Pending review",className:"shrink-0 flex items-center",children:(0,sn.jsx)(rw.LivePulseDot,{className:"text-amber-400/80 shrink-0"})}):null,ee?(0,sn.jsx)("span",{className:q("w-1.5 h-1.5 rounded-full shrink-0",c?.kind==="new"?"bg-emerald-400":"bg-blue-400"),title:c?.kind==="new"?"New file":"Modified"}):null,ce&&e.git?(0,sn.jsx)(vc,{code:e.git,dot:A}):null,re?(0,sn.jsx)(Kb,{className:q("w-3.5 h-3.5 shrink-0",ue.iconClassName),title:ue.label}):null,pe?(0,sn.jsx)("span",{className:q("inline-flex items-center justify-center min-w-[16px] h-4 px-1 rounded-full text-[9px] font-semibold",k?"bg-amber-500/20 text-amber-200":"bg-sky-500/15 text-sky-200"),children:i}):null]}):null]})});function yA({initial:n,onCommit:e,onCancel:t}){let r=(0,kr.useRef)(!1);return(0,sn.jsx)("input",{autoFocus:!0,defaultValue:n,spellCheck:!1,onFocus:a=>{let s=a.currentTarget.value,o=s.lastIndexOf(".");a.currentTarget.setSelectionRange(0,o>0?o:s.length)},onClick:a=>a.stopPropagation(),onMouseDown:a=>a.stopPropagation(),onKeyDown:a=>{a.stopPropagation(),a.key==="Enter"?r.current||(r.current=!0,e(a.currentTarget.value)):a.key==="Escape"&&(r.current||(r.current=!0,t()))},onBlur:a=>{r.current||(r.current=!0,e(a.currentTarget.value))},className:"min-w-0 flex-1 rounded border border-sky-400/60 bg-black/50 px-1 py-0 text-xs text-white outline-none"})}var Ms=W($e(),1),sw=W(Ya(),1);var Rs=W(le(),1),bA=[{kind:"item",action:"new-file",label:"New File\u2026",Icon:ks},{kind:"item",action:"new-folder",label:"New Folder\u2026",Icon:wr},{kind:"sep"},{kind:"item",action:"cut",label:"Cut",Icon:Dl,shortcut:"\u2318X"},{kind:"item",action:"copy",label:"Copy",Icon:ra,shortcut:"\u2318C"},{kind:"item",action:"paste",label:"Paste",Icon:xl,shortcut:"\u2318V"},{kind:"sep"},{kind:"item",action:"copy-path",label:"Copy Path",Icon:Il},{kind:"item",action:"copy-relative-path",label:"Copy Relative Path",Icon:bl},{kind:"sep"},{kind:"item",action:"reembed",label:"Re-embed\u2026",Icon:wa},{kind:"sep"},{kind:"item",action:"rename",label:"Rename",Icon:Ls,shortcut:"F2"},{kind:"item",action:"delete",label:"Delete",Icon:It,danger:!0,shortcut:"Del"}],wA=[{kind:"item",action:"new-file",label:"New File\u2026",Icon:ks},{kind:"item",action:"new-folder",label:"New Folder\u2026",Icon:wr}],vA=210;function ow({x:n,y:e,enabled:t,onAction:r,onClose:a,variant:s="node"}){let o=s==="source"?wA:bA,i=(0,Ms.useRef)(null),[l,u]=(0,Ms.useState)({top:e,left:n});return(0,Ms.useLayoutEffect)(()=>{let c=i.current;if(!c)return;let d=c.getBoundingClientRect(),f=n,h=e;f+d.width>window.innerWidth-4&&(f=Math.max(4,window.innerWidth-d.width-4)),h+d.height>window.innerHeight-4&&(h=Math.max(4,window.innerHeight-d.height-4)),u({top:h,left:f})},[n,e]),(0,Ms.useEffect)(()=>{let c=h=>{i.current?.contains(h.target)||a()},d=h=>{h.key==="Escape"&&a()},f=()=>a();return document.addEventListener("mousedown",c,!0),document.addEventListener("keydown",d,!0),window.addEventListener("resize",f),window.addEventListener("scroll",f,!0),()=>{document.removeEventListener("mousedown",c,!0),document.removeEventListener("keydown",d,!0),window.removeEventListener("resize",f),window.removeEventListener("scroll",f,!0)}},[a]),(0,sw.createPortal)((0,Rs.jsx)("div",{ref:i,role:"menu",style:{position:"fixed",top:l.top,left:l.left,width:vA},className:"z-[1000] rounded-lg border border-white/10 bg-[#14141b] py-1 text-[11px] text-white/80 shadow-[0_18px_46px_-20px_rgba(0,0,0,0.8)]",onContextMenu:c=>c.preventDefault(),children:o.map((c,d)=>{if(c.kind==="sep")return(0,Rs.jsx)("div",{className:"my-1 h-px bg-white/[0.06]"},`s${d}`);let f=t[c.action]===!0,h=c.Icon;return(0,Rs.jsxs)("button",{type:"button",role:"menuitem",disabled:!f,onClick:()=>{f&&(r(c.action),a())},className:q("flex w-full items-center gap-2 px-3 py-1.5 text-left transition",f?"hover:bg-white/[0.06]":"opacity-35 cursor-not-allowed",c.danger&&f?"text-rose-200 hover:bg-rose-500/10":""),children:[(0,Rs.jsx)(h,{className:q("w-3.5 h-3.5 shrink-0",c.danger?"text-rose-300/80":"text-white/45")}),(0,Rs.jsx)("span",{className:"flex-1 truncate",children:c.label}),c.shortcut?(0,Rs.jsx)("span",{className:"text-[9px] text-white/30 tabular-nums",children:c.shortcut}):null]},c.action)})}),document.body)}var iw=W($e(),1),lw=W(Ya(),1);var bn=W(le(),1);function uw({names:n,busy:e,onCancel:t,onConfirm:r}){(0,iw.useEffect)(()=>{let o=i=>{e||(i.key==="Escape"?(i.preventDefault(),t()):i.key==="Enter"&&(i.preventDefault(),r()))};return document.addEventListener("keydown",o,!0),()=>document.removeEventListener("keydown",o,!0)},[e,t,r]);let a=n.length>1,s=a?`Delete ${n.length} items?`:`Delete '${n[0]}'?`;return(0,lw.createPortal)((0,bn.jsx)("div",{className:"fixed inset-0 z-[1100] flex items-center justify-center bg-black/40 backdrop-blur-[1px]",onMouseDown:o=>{o.target===o.currentTarget&&!e&&t()},children:(0,bn.jsxs)("div",{className:"w-[340px] rounded-xl border border-rose-400/25 bg-[#15151d] p-4 shadow-[0_30px_80px_-24px_rgba(0,0,0,0.85)]",children:[(0,bn.jsxs)("div",{className:"flex items-start gap-2.5",children:[(0,bn.jsx)(dt,{className:"h-4 w-4 text-rose-300 shrink-0 mt-0.5"}),(0,bn.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,bn.jsx)("div",{className:"text-[12px] font-semibold text-white/90",children:s}),(0,bn.jsxs)("div",{className:"mt-1 text-[10.5px] text-white/55 leading-relaxed",children:[a?"The selected files move to Pending Changes. ":"The file moves to Pending Changes. ",(0,bn.jsx)("span",{className:"text-white/75",children:"You can restore"})," ",a?"them":"it"," from there \u2014 this is not a permanent erase."]}),a?(0,bn.jsxs)("div",{className:"mt-2 max-h-24 overflow-auto rounded-md bg-white/[0.03] px-2 py-1.5 text-[10px] font-mono text-white/50 space-y-0.5 overlay-scroll",children:[n.slice(0,12).map(o=>(0,bn.jsx)("div",{className:"truncate",children:o},o)),n.length>12?(0,bn.jsxs)("div",{className:"text-white/35",children:["+",n.length-12," more\u2026"]}):null]}):null]})]}),(0,bn.jsxs)("div",{className:"mt-4 flex items-center justify-end gap-2",children:[(0,bn.jsxs)("button",{type:"button",onClick:t,disabled:e,className:"h-7 px-2.5 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[11px] font-medium text-white/70 transition disabled:opacity-40 inline-flex items-center gap-1",children:[(0,bn.jsx)(Ut,{className:"h-3 w-3"}),"Cancel"]}),(0,bn.jsxs)("button",{type:"button",onClick:r,disabled:e,className:q("h-7 px-3 rounded-md text-[11px] font-semibold transition disabled:opacity-40 inline-flex items-center gap-1.5","bg-rose-500/20 hover:bg-rose-500/30 border border-rose-400/40 text-rose-100"),children:[e?(0,bn.jsx)(ze,{className:"h-3 w-3 animate-spin"}):(0,bn.jsx)(It,{className:"h-3 w-3"}),"Delete"]})]})]})}),document.body)}var Za=W($e(),1),cw=W(Ya(),1);var Nt=W(le(),1);function kA(n){return n.usd===null?"unpriced \u2014 the active model has no price":`~$${n.usd.toFixed(2)}${n.usdMargin!==null?` \xB1 $${n.usdMargin.toFixed(2)}`:""}`}function SA(n){return n===null?"time unknown":n<90?`~${Math.round(n)} s`:n<5400?`~${Math.round(n/60)} min`:`~${(n/3600).toFixed(1)} h`}function kc({agentId:n,projectId:e,target:t,onClose:r,onStarted:a}){let[s,o]=(0,Za.useState)(null),[i,l]=(0,Za.useState)(!0),[u,c]=(0,Za.useState)(!1),[d,f]=(0,Za.useState)(null),[h,p]=(0,Za.useState)(!1),m={agentId:n,...e?{projectId:e}:{},source:t.source,...t.folder?{folder:t.folder}:{},...t.uri?{uri:t.uri}:{}};(0,Za.useEffect)(()=>{let x=!0;return l(!0),mx(m).then(w=>{x&&o(w)}).catch(w=>{x&&f(w instanceof Error?w.message:"Estimate failed")}).finally(()=>{x&&l(!1)}),()=>{x=!1}},[]),(0,Za.useEffect)(()=>{let x=w=>{w.key==="Escape"&&!u&&(w.preventDefault(),r())};return document.addEventListener("keydown",x,!0),()=>document.removeEventListener("keydown",x,!0)},[u,r]);let g=async()=>{c(!0),f(null);try{if(!(await gx(m)).job){p(!0),c(!1);return}a?.(),r()}catch(x){f(x instanceof Error?x.message:"Re-embed failed"),c(!1)}};return(0,cw.createPortal)((0,Nt.jsx)("div",{className:"fixed inset-0 z-[1100] flex items-center justify-center bg-black/40 backdrop-blur-[1px]",onMouseDown:x=>{x.target===x.currentTarget&&!u&&r()},children:(0,Nt.jsxs)("div",{role:"dialog","aria-label":`Re-embed ${t.label}`,className:"w-[360px] rounded-xl border border-cyan-400/25 bg-[#15151d] p-4 shadow-[0_30px_80px_-24px_rgba(0,0,0,0.85)]",children:[(0,Nt.jsxs)("div",{className:"flex items-start gap-2.5",children:[(0,Nt.jsx)(wa,{className:"h-4 w-4 text-cyan-300 shrink-0 mt-0.5"}),(0,Nt.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,Nt.jsxs)("div",{className:"truncate text-[12px] font-semibold text-white/90",children:["Re-embed ",t.label,"?"]}),(0,Nt.jsxs)("div",{className:"mt-1 text-[10.5px] text-white/55 leading-relaxed",children:["Every file in this scope is read again and embedded with the ",(0,Nt.jsx)("span",{className:"text-white/75",children:"active"})," ","model, whether it changed or not. File contents and history are not touched \u2014 only the vectors are replaced."]}),(0,Nt.jsx)("div",{className:"mt-2 rounded-md bg-white/[0.03] px-2 py-1.5 text-[10.5px] text-white/65 space-y-0.5",children:i?(0,Nt.jsxs)("div",{className:"inline-flex items-center gap-1.5 text-white/45",children:[(0,Nt.jsx)(ze,{className:"h-3 w-3 animate-spin"}),"Estimating from a sample\u2026"]}):s?(0,Nt.jsxs)(Nt.Fragment,{children:[(0,Nt.jsxs)("div",{children:[s.documents!==null?`${s.documents.toLocaleString()} documents \xB7 `:null,s.points.toLocaleString()," points"]}),(0,Nt.jsxs)("div",{children:["~",s.tokens.toLocaleString(),s.tokensMargin!==null?` \xB1 ${s.tokensMargin.toLocaleString()}`:""," tokens"]}),(0,Nt.jsxs)("div",{children:[kA(s)," \xB7 ",SA(s.durationSeconds)]}),s.truncated?(0,Nt.jsx)("div",{className:"text-amber-300/80",children:"The scope is larger than one listing \u2014 these figures cover its first part."}):null]}):d?null:(0,Nt.jsx)("div",{className:"text-white/45",children:"No estimate available for this scope."})}),d?(0,Nt.jsx)("div",{className:"mt-2 text-[10px] text-rose-300/90",children:d}):null,h?(0,Nt.jsx)("div",{className:"mt-2 text-[10px] text-white/55",children:"Nothing readable in this scope \u2014 nothing was queued."}):null]})]}),(0,Nt.jsxs)("div",{className:"mt-4 flex items-center justify-end gap-2",children:[(0,Nt.jsxs)("button",{type:"button",onClick:r,disabled:u,className:"h-7 px-2.5 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[11px] font-medium text-white/70 transition disabled:opacity-40 inline-flex items-center gap-1",children:[(0,Nt.jsx)(Ut,{className:"h-3 w-3"}),"Cancel"]}),(0,Nt.jsxs)("button",{type:"button",onClick:()=>{g()},disabled:u||i||h,className:"h-7 px-3 rounded-md text-[11px] font-semibold transition disabled:opacity-40 inline-flex items-center gap-1.5 bg-cyan-500/20 hover:bg-cyan-500/30 border border-cyan-400/40 text-cyan-100",children:[u?(0,Nt.jsx)(ze,{className:"h-3 w-3 animate-spin"}):(0,Nt.jsx)(wa,{className:"h-3 w-3"}),"Re-embed"]})]})]})}),document.body)}var di=W($e(),1);var fw=W(Qr(),1);var In=W(le(),1);function CA(n){if(!n)return null;if(n.isRepo&&n.repoName)return{label:n.repoName,title:`Repository: ${n.repoName}`};if(n.containsRepos&&n.repoNames&&n.repoNames.length>0){let e=n.repoNames,t=e.slice(0,2).join(", ");return{label:e.length>2?`${t} +${e.length-2}`:t,title:`Repositories: ${e.join(", ")}`}}return null}function LA({info:n}){let e=(0,sr.resolveIconWithFallback)(n.kind_icon??void 0,Gn),t=n.source_kind==="brain"||n.source_kind==="local-disk",r=!!(n.git?.isRepo||n.git?.containsRepos);return(0,In.jsxs)("span",{className:"relative inline-flex items-center justify-center",children:[(0,In.jsx)(e,{className:"w-4 h-4"}),t?(0,In.jsx)(Ml,{className:"absolute -right-1.5 -bottom-1.5 w-2.5 h-2.5 text-current bg-black/80 rounded-full p-[1px] opacity-80"}):null,r?(0,In.jsx)(Ln,{className:"absolute -right-1.5 -top-1.5 w-2.5 h-2.5 text-violet-300/90 bg-black/80 rounded-full p-[1px]"}):null]})}function dw(n){return n.source_kind==="brain"?"brain":Ve(n.uri_root)}var hw=di.default.memo(function({info:e,expanded:t,onToggle:r,onContextMenu:a,onRefresh:s,hydration:o="ready",dirty:i=!1,hideChevron:l=!0,compact:u=!1}){let c=(0,di.useCallback)(()=>r(e.uri_root),[r,e.uri_root]),d=(0,di.useCallback)(x=>a?.(e.uri_root,x),[a,e.uri_root]),f=(0,di.useCallback)(x=>{x.stopPropagation(),x.preventDefault(),s?.(e.uri_root)},[s,e.uri_root]),h=bc(e),p=$b(e),m=CA(e.git),g=o==="loading";return(0,In.jsxs)("div",{className:q("group flex w-full items-center gap-2 rounded-md select-none text-left transition-colors",u?"py-1 px-1.5":"py-1.5 px-2","hover:bg-white/5",t&&"bg-white/[0.03]"),onContextMenu:d,"aria-busy":g||void 0,children:[(0,In.jsxs)("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-2 bg-transparent text-left outline-none",onClick:c,"aria-expanded":t,title:p?`${e.uri_root} \u2014 ${p}`:e.uri_root,children:[l?null:(0,In.jsx)("span",{className:"w-0","aria-hidden":"true"}),(0,In.jsx)("span",{className:q("shrink-0",h.iconClassName,o==="idle"||o==="error"?"opacity-50":""),children:(0,In.jsx)(LA,{info:e})}),(0,In.jsx)("span",{className:q("text-xs font-medium flex-1 truncate transition-colors",h.labelClassName,o==="idle"||o==="error"?"opacity-70":""),children:dw(e)})]}),m?(0,In.jsxs)("span",{className:"ml-1 inline-flex max-w-[120px] shrink-0 items-center gap-0.5 text-[10px] text-violet-300/70",title:m.title,children:[(0,In.jsx)(Ln,{className:"h-2.5 w-2.5 shrink-0"}),(0,In.jsx)("span",{className:"truncate",children:m.label})]}):null,s?(0,In.jsx)("button",{type:"button",onClick:f,disabled:g,"aria-label":`Refresh ${dw(e)}`,title:o==="error"?"Last listing failed \u2014 click to retry":i?"This source may be out of date \u2014 click to refresh":"Refresh this source",className:q("shrink-0 inline-flex h-4 w-4 items-center justify-center rounded transition-opacity","text-white/40 hover:text-white/80 focus-visible:opacity-100",g||i||o==="error"?"opacity-100":"opacity-0 group-hover:opacity-100",i||o==="error"?"text-amber-300/80 hover:text-amber-200":""),children:g?(0,In.jsx)(fw.LiveSpinner,{className:"h-3 w-3"}):(0,In.jsx)(Ht,{className:"h-3 w-3","aria-hidden":"true"})}):null]})});var hi=W($e(),1);var ht=W(le(),1),IA=[{id:"keyword",label:"Keyword",hint:"Indexed word search (primary)"},{id:"semantic",label:"Semantic",hint:"Embedding search by meaning"},{id:"grep",label:"Grep",hint:"Literal scan of live connector content"}],fi="h-6 w-full bg-transparent border border-white/[0.06] rounded px-1.5 text-[11px] text-white/80 placeholder:text-white/25 outline-none focus:border-white/20";function pw({agentId:n}){let e=B(v=>v.activeProjectId),t=B(v=>v.setActiveFolderPath),r=B(v=>v.openFile),a=B(v=>v.searchQuery),s=B(v=>v.searchMode),o=B(v=>v.setSearchMode),i=B(v=>v.searchFilters),l=B(v=>v.setSearchFilters),u=B(v=>v.searchResults),c=B(v=>v.searchLoading),d=B(v=>v.searchError),f=B(v=>v.runSearch),h=B(v=>v.activeFolderPath),p=B(v=>v.sources),[m,g]=(0,hi.useState)(!1),x=a.trim(),w=i.glob.trim(),y=s==="keyword"?x.length>=2||w.length>=2:x.length>=2,C=(0,hi.useMemo)(()=>th(h,p,i.scopeToFolder),[h,p,i.scopeToFolder]);(0,hi.useEffect)(()=>{if(!y)return;let v=setTimeout(()=>{f({agentId:n,projectId:e??null})},250);return()=>clearTimeout(v)},[n,e,y,s,a,i,f]);let k=(w?1:0)+(i.category.trim()?1:0)+(i.status.trim()?1:0)+(i.tags.trim()?1:0)+(i.createdAfter.trim()?1:0)+(i.createdBefore.trim()?1:0)+(i.scopeToFolder?1:0);return(0,ht.jsxs)("div",{className:"px-2 pb-2",children:[(0,ht.jsxs)("div",{className:"flex items-center gap-1 pb-1.5",children:[(0,ht.jsx)("div",{className:"flex-1 flex items-center rounded-md border border-white/[0.06] overflow-hidden",children:IA.map(v=>{let b=v.id==="grep"&&!C;return(0,ht.jsx)("button",{type:"button",disabled:b,onClick:()=>o(v.id),title:b?"Grep needs a disk-backed source (brain:// has no live text)":v.hint,className:`flex-1 h-6 text-[10px] uppercase tracking-wide transition-colors ${s===v.id?"bg-white/[0.08] text-white/85":b?"text-white/20 cursor-not-allowed":"text-white/40 hover:text-white/70"}`,"aria-pressed":s===v.id,children:v.label},v.id)})}),(0,ht.jsxs)("button",{type:"button",onClick:()=>g(v=>!v),className:`h-6 w-6 shrink-0 rounded-md inline-flex items-center justify-center transition-colors ${m||k>0?"text-white/85":"text-white/40 hover:text-white/70"}`,title:"Search filters","aria-label":"Toggle search filters","aria-pressed":m,children:[(0,ht.jsx)(lo,{className:"w-3.5 h-3.5"}),k>0?(0,ht.jsx)("span",{className:"absolute translate-x-2.5 -translate-y-2 text-[8px] text-white/70",children:k}):null]})]}),m?(0,ht.jsxs)("div",{className:"pb-2 space-y-1",children:[(0,ht.jsxs)("div",{className:"flex items-center gap-1",children:[(0,ht.jsx)("input",{type:"text",value:i.glob,onChange:v=>l({glob:v.target.value}),placeholder:"Filename\u2026",className:fi}),(0,ht.jsxs)("label",{className:"flex items-center gap-1 shrink-0 text-[10px] text-white/45 select-none cursor-pointer",title:"Scope to the active folder",children:[(0,ht.jsx)("input",{type:"checkbox",checked:i.scopeToFolder,onChange:v=>l({scopeToFolder:v.target.checked}),className:"accent-white/60"}),"folder"]})]}),s!=="grep"?(0,ht.jsxs)(ht.Fragment,{children:[(0,ht.jsxs)("div",{className:"flex items-center gap-1",children:[(0,ht.jsx)("input",{type:"text",value:i.category,onChange:v=>l({category:v.target.value}),placeholder:"Category\u2026",className:fi}),(0,ht.jsx)("input",{type:"text",value:i.status,onChange:v=>l({status:v.target.value}),placeholder:"Status\u2026",className:fi})]}),(0,ht.jsx)("input",{type:"text",value:i.tags,onChange:v=>l({tags:v.target.value}),placeholder:"Tags (comma-separated)\u2026",className:fi}),(0,ht.jsxs)("div",{className:"flex items-center gap-1",children:[(0,ht.jsx)("input",{type:"date",value:i.createdAfter,onChange:v=>l({createdAfter:v.target.value}),title:"Created after",className:fi}),(0,ht.jsx)("input",{type:"date",value:i.createdBefore,onChange:v=>l({createdBefore:v.target.value}),title:"Created before",className:fi})]})]}):null]}):null,y?c?(0,ht.jsx)("div",{className:"px-2 py-3 text-[11px] text-white/35",children:"Searching\u2026"}):d?(0,ht.jsx)("div",{className:"px-2 py-3 text-[11px] text-red-300/70",children:d}):u.length===0?(0,ht.jsx)("div",{className:"px-2 py-3 text-[11px] text-white/35",children:"No matches"}):(0,ht.jsx)("div",{className:"space-y-1",children:u.map(v=>(0,ht.jsxs)("button",{type:"button",className:"w-full text-left px-2 py-2 rounded-md hover:bg-white/5 border border-white/[0.04] transition-colors",onClick:()=>{t(ot(v.uri)),r({agentId:n,projectId:e??null,uri:v.uri})},children:[(0,ht.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,ht.jsx)("span",{className:"text-[11px] text-white/80 truncate flex-1",children:v.filename}),typeof v.score=="number"?(0,ht.jsx)("span",{className:"text-[9px] text-white/30 shrink-0",children:v.score.toFixed(2)}):null,v.match_type?(0,ht.jsx)("span",{className:"text-[9px] px-1 py-0.5 rounded bg-white/[0.06] text-white/40 shrink-0",children:v.match_type==="hybrid"?"H":v.match_type==="semantic"?"S":"K"}):null]}),(0,ht.jsxs)("div",{className:"text-[10px] text-white/35 font-mono truncate",children:[v.uri,s==="grep"&&typeof v.chunk_start=="number"?`:${v.chunk_start}`:""]}),v.snippet??v.content_preview?(0,ht.jsx)("div",{className:"text-[10px] text-white/45 mt-1 line-clamp-2",children:v.snippet??v.content_preview}):null]},`${v.id}:${v.uri}:${v.chunk_start??""}`))}):(0,ht.jsx)("div",{className:"px-2 py-3 text-[11px] text-white/35",children:s==="keyword"?"Type to search (or set a filename filter)\u2026":"Type to search\u2026"})]})}var ye=W($e(),1),C1=W(Ya(),1);var L1=W(mr(),1);var it=W($e(),1);var c1=W(Qr(),1);var ho=W(le(),1);function AA(n){return n<1e4?String(n):n<1e6?`${Math.round(n/1e3)}k`:`${(n/1e6).toFixed(1)}M`}function La({added:n,removed:e,binary:t,unknown:r,compact:a,className:s}){if(t)return(0,ho.jsx)("span",{className:q("shrink-0 text-[9px] tabular-nums text-white/40",s),title:"Binary file \u2014 git reports no line count",children:"bin"});if(!(typeof n=="number"&&typeof e=="number")||n===0&&e===0&&!r)return null;let i=a?AA:String,l=r?"+":"";return(0,ho.jsxs)("span",{className:q("flex shrink-0 items-center gap-1 text-[9px] tabular-nums",s),title:r?`+${n} \u2212${e} across the counted files; ${r} more could not be measured`:`+${n} \u2212${e}`,children:[n>0?(0,ho.jsx)("span",{className:"text-emerald-400/80",children:`+${i(n)}${l}`}):null,e>0?(0,ho.jsx)("span",{className:"text-rose-400/80",children:`\u2212${i(e)}${l}`}):null,n===0&&e===0?(0,ho.jsx)("span",{className:"text-white/35",children:`0${l}`}):null]})}function PA(n){return(n.refs??[]).some(e=>e==="HEAD"||e.startsWith("HEAD ")||e.startsWith("HEAD-")||e.includes("HEAD ->"))}function mw(n){let e=[],t=[];if(!Array.isArray(n)||n.length===0)return{nodes:e,edges:t,rowSegments:[],laneCount:0};let r=[],a=new Map,s=0,o=u=>{let c=r.indexOf(u);if(c>=0)return c;let d=r.indexOf(null);return d>=0?(r[d]=u,d):(r.push(u),r.length-1)};for(let u=0;u<n.length;u++){let c=n[u],d=c.sha,f=r.indexOf(d);f<0&&(f=o(d));for(let p=0;p<r.length;p++)r[p]===d&&(r[p]=null);f>s&&(s=f),a.set(d,{row:u,lane:f});let h=Array.isArray(c.parents)?c.parents:[];if(h.length!==0){r[f]=h[0];for(let p=1;p<h.length;p++){let m=o(h[p]);m>s&&(s=m)}}e.push({commit:c,row:u,lane:f,isHead:PA(c),isMerge:h.length>=2})}let i=n.map(()=>[]),l=(u,c)=>{u>=0&&u<i.length&&i[u].push(c)};for(let u of e){let c=Array.isArray(u.commit.parents)?u.commit.parents:[];for(let d=0;d<c.length;d++){let f=a.get(c[d]);if(f){t.push({fromRow:u.row,fromLane:u.lane,toRow:f.row,toLane:f.lane,colorLane:u.lane,open:!1});let h=u.row,p=f.row,m=u.lane,g=f.lane,x=u.lane;if(p<=h)continue;if(m===g){l(h,{kind:"pass",fromLane:m,toLane:m,fromY:"center",toY:"edge",colorLane:x});for(let w=h+1;w<p;w++)l(w,{kind:"pass",fromLane:m,toLane:m,fromY:"edge",toY:"edge",colorLane:x});l(p,{kind:"pass",fromLane:m,toLane:m,fromY:"edge",toY:"center",colorLane:x})}else{let w=(m+g)/2,y=d>0?"merge":"fork";if(d>0){if(l(h,{kind:y,fromLane:m,toLane:w,fromY:"center",toY:"edge",colorLane:x}),l(h+1,{kind:y,fromLane:w,toLane:g,fromY:"edge",toY:"center",colorLane:x}),h+1<p){l(h+1,{kind:"pass",fromLane:g,toLane:g,fromY:"center",toY:"edge",colorLane:x});for(let C=h+2;C<p;C++)l(C,{kind:"pass",fromLane:g,toLane:g,fromY:"edge",toY:"edge",colorLane:x});l(p,{kind:"pass",fromLane:g,toLane:g,fromY:"edge",toY:"center",colorLane:x})}}else{if(p-1>h){l(h,{kind:"pass",fromLane:m,toLane:m,fromY:"center",toY:"edge",colorLane:x});for(let C=h+1;C<p-1;C++)l(C,{kind:"pass",fromLane:m,toLane:m,fromY:"edge",toY:"edge",colorLane:x});l(p-1,{kind:"pass",fromLane:m,toLane:m,fromY:"edge",toY:"center",colorLane:x})}l(p-1,{kind:y,fromLane:m,toLane:w,fromY:"center",toY:"edge",colorLane:x}),l(p,{kind:y,fromLane:w,toLane:g,fromY:"edge",toY:"center",colorLane:x})}}}else t.push({fromRow:u.row,fromLane:u.lane,toRow:u.row+1,toLane:u.lane,colorLane:u.lane,open:!0}),l(u.row,{kind:"stub",fromLane:u.lane,toLane:u.lane,fromY:"center",toY:"edge",colorLane:u.lane})}}return{nodes:e,edges:t,rowSegments:i,laneCount:s+1}}function gw(n,e){if(!Array.isArray(n)||e<=0||e>=n.length)return[];let t=[],r=new Set;for(let a of n[e]??[]){if(a.fromY!=="edge")continue;let s=`${a.fromLane}|${a.colorLane}`;r.has(s)||(r.add(s),t.push({kind:"pass",fromLane:a.fromLane,toLane:a.fromLane,fromY:"edge",toY:"edge",colorLane:a.colorLane}))}return t}var Ph={commits:[],nextSkip:0,hasMore:!1};function xw(n,e){let t=[];for(let r of e.commits)!r||typeof r.sha!="string"||n.has(r.sha)||(n.add(r.sha),t.push(r));return t}function yw(n,e){let t=new Set(n.commits.map(a=>a.sha)),r=xw(t,e);return{commits:r.length>0?[...n.commits,...r]:n.commits,nextSkip:n.nextSkip+e.commits.length,hasMore:e.hasMore,outgoing:n.outgoing}}function bw(n){return{commits:xw(new Set,n),nextSkip:n.commits.length,hasMore:n.hasMore,outgoing:n.outgoing}}function Nh(n){return Math.min(1e3,Math.max(n,200))}function ww(n,e){let t=[],r=e&&e.length>0?new Set(e):null,a=!1;for(let s=0;s<n.length;s++)!a&&r&&r.has(n[s].sha)&&(t.push({kind:"outgoing-divider"}),a=!0),t.push({kind:"commit",row:s});return t}function vw(n,e){return n.kind==="outgoing-divider"?"#outgoing-divider":e[n.row]?.sha??`row-${n.row}`}function kw(n){let e=n.trim();return e.startsWith("tag:")?"tag":e.startsWith("origin/")?"remote":"local"}function Sw(n,e){return e?"outgoing":n?"merge":"filled"}var NA="#89b4fa";function Cw(n,e){return n==="outgoing"?NA:e}function Rh(n,e=Date.now()){let t=Date.parse(n);if(Number.isNaN(t))return n;let r=Math.max(0,Math.floor((e-t)/1e3));if(r<60)return"just now";let a=Math.floor(r/60);if(a<60)return`${a}m ago`;let s=Math.floor(a/60);if(s<24)return`${s}h ago`;let o=Math.floor(s/24);if(o<30)return`${o}d ago`;let i=Math.floor(o/30);return i<12?`${i}mo ago`:`${Math.floor(i/12)}y ago`}function Lw(n){return!n||typeof n.upstream!="string"||n.upstream.length===0?null:{upstream:n.upstream,ahead:typeof n.ahead=="number"&&n.ahead>=0?n.ahead:0,behind:typeof n.behind=="number"&&n.behind>=0?n.behind:0}}function Mh(n,e){if(typeof window>"u")return e;try{let t=JSON.parse(window.localStorage.getItem(n)??"null");return typeof t=="boolean"?t:e}catch{return e}}function Th(n,e){if(!(typeof window>"u"))try{window.localStorage.setItem(n,JSON.stringify(e))}catch{}}function Ts(n,e){return typeof e=="string"&&e.length>0?{prefix:`${n}://`,name:e,title:`Source "${n}" \u2014 repository "${e}"`}:{prefix:"",name:n,title:`Repository: ${n}`}}var es=W($e(),1);var En=W($e(),1),RA=3,Iw=200,Aw=8*1024*1024,MA="200% 0px";function Sc(n){let e=(0,En.useRef)(new Map),t=(0,En.useRef)(null),[r,a]=(0,En.useState)(new Set),s=(0,En.useRef)(0),o=(0,En.useRef)([]),i=(0,En.useRef)(new Map),l=(0,En.useRef)(0),u=(0,En.useRef)(new Map),c=(0,En.useCallback)((p,m)=>{let g=e.current.get(p);g!==m&&(g&&t.current?.unobserve(g),m?(m.dataset.diffCardKey=p,e.current.set(p,m),t.current?.observe(m)):e.current.delete(p))},[]);(0,En.useEffect)(()=>{if(a(new Set),!n||typeof IntersectionObserver>"u")return;let p=new IntersectionObserver(m=>{a(g=>{let x=new Set(g);for(let w of m){let y=w.target.dataset.diffCardKey;y&&(w.isIntersecting?x.add(y):x.delete(y))}return x.size===g.size&&[...x].every(w=>g.has(w))?g:x})},{root:n,rootMargin:MA});t.current=p;for(let m of e.current.values())p.observe(m);return()=>{p.disconnect(),t.current=null}},[n]);let d=(0,En.useCallback)((p,m,g,x)=>{let w=i.current,y=w.get(p);if(y&&(w.delete(p),l.current-=y.bytes),!(g>Aw)){w.set(p,{value:m,bytes:g}),l.current+=g,x&&(u.current.delete(x),u.current.set(x,p)),u.current.size>Iw&&u.current.delete(u.current.keys().next().value);for(let[C,k]of w){if(w.size<=Iw&&l.current<=Aw)break;w.delete(C),l.current-=k.bytes}}},[]),f=(0,En.useCallback)((p,m,g)=>{if(g&&!g.fresh){let x=i.current.get(g.key);if(x)return i.current.delete(g.key),i.current.set(g.key,x),Promise.resolve(x.value)}return new Promise((x,w)=>{let y=()=>{s.current+=1;let C=()=>{s.current-=1,o.current.shift()?.()};if(!m()){C(),x(void 0);return}p().then(k=>{g&&d(g.key,k,g.bytes(k),g.family),C(),x(k)},k=>{C(),w(k)})};s.current<RA?y():o.current.push(y)})},[d]),h=(0,En.useCallback)((p,m)=>(i.current.get(p)??(m?i.current.get(u.current.get(m)??""):void 0))?.value,[]);return{register:c,visible:r,run:f,peek:h}}var gt=W($e(),1);var Oe=W(le()),kt=W($e());function Pw(n,e){var t=Object.keys(n);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(n);e&&(r=r.filter((function(a){return Object.getOwnPropertyDescriptor(n,a).enumerable}))),t.push.apply(t,r)}return t}function At(n){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?Pw(Object(t),!0).forEach((function(r){Oh(n,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(t)):Pw(Object(t)).forEach((function(r){Object.defineProperty(n,r,Object.getOwnPropertyDescriptor(t,r))}))}return n}function Oh(n,e,t){return(e=(function(r){var a=(function(s,o){if(typeof s!="object"||s===null)return s;var i=s[Symbol.toPrimitive];if(i!==void 0){var l=i.call(s,o||"default");if(typeof l!="object")return l;throw new TypeError("@@toPrimitive must return a primitive value.")}return(o==="string"?String:Number)(s)})(r,"string");return typeof a=="symbol"?a:String(a)})(e))in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}function Fs(n,e){if(n==null)return{};var t,r,a=(function(o,i){if(o==null)return{};var l,u,c={},d=Object.keys(o);for(u=0;u<d.length;u++)l=d[u],i.indexOf(l)>=0||(c[l]=o[l]);return c})(n,e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(n);for(r=0;r<s.length;r++)t=s[r],e.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(n,t)&&(a[t]=n[t])}return a}function en(n,e){return rv(n)||(function(t,r){var a=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(a!=null){var s,o,i,l,u=[],c=!0,d=!1;try{if(i=(a=a.call(t)).next,r===0){if(Object(a)!==a)return;c=!1}else for(;!(c=(s=i.call(a)).done)&&(u.push(s.value),u.length!==r);c=!0);}catch(f){d=!0,o=f}finally{try{if(!c&&a.return!=null&&(l=a.return(),Object(l)!==l))return}finally{if(d)throw o}}return u}})(n,e)||Fc(n,e)||sv()}function TA(n){return rv(n)||av(n)||Fc(n)||sv()}function Sr(n){return(function(e){if(Array.isArray(e))return _h(e)})(n)||av(n)||Fc(n)||(function(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
5
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)})()}function rv(n){if(Array.isArray(n))return n}function av(n){if(typeof Symbol<"u"&&n[Symbol.iterator]!=null||n["@@iterator"]!=null)return Array.from(n)}function Fc(n,e){if(n){if(typeof n=="string")return _h(n,e);var t=Object.prototype.toString.call(n).slice(8,-1);return t==="Object"&&n.constructor&&(t=n.constructor.name),t==="Map"||t==="Set"?Array.from(n):t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_h(n,e):void 0}}function _h(n,e){(e==null||e>n.length)&&(e=n.length);for(var t=0,r=new Array(e);t<e;t++)r[t]=n[t];return r}function sv(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
6
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Vh(n,e){var t=typeof Symbol<"u"&&n[Symbol.iterator]||n["@@iterator"];if(!t){if(Array.isArray(n)||(t=Fc(n))||e&&n&&typeof n.length=="number"){t&&(n=t);var r=0,a=function(){};return{s:a,n:function(){return r>=n.length?{done:!0}:{done:!1,value:n[r++]}},e:function(l){throw l},f:a}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
7
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s,o=!0,i=!1;return{s:function(){t=t.call(n)},n:function(){var l=t.next();return o=l.done,l},e:function(l){i=!0,s=l},f:function(){try{o||t.return==null||t.return()}finally{if(i)throw s}}}}var Cc=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Zl(n,e){return n(e={exports:{}},e.exports),e.exports}var wn=Zl((function(n){(function(){var e={}.hasOwnProperty;function t(){for(var r=[],a=0;a<arguments.length;a++){var s=arguments[a];if(s){var o=typeof s;if(o==="string"||o==="number")r.push(s);else if(Array.isArray(s)){if(s.length){var i=t.apply(null,s);i&&r.push(i)}}else if(o==="object"){if(s.toString!==Object.prototype.toString&&!s.toString.toString().includes("[native code]")){r.push(s.toString());continue}for(var l in s)e.call(s,l)&&s[l]&&r.push(l)}}}return r.join(" ")}n.exports?(t.default=t,n.exports=t):window.classNames=t})()})),or={hunkClassName:"",lineClassName:"",gutterClassName:"",codeClassName:"",monotonous:!1,gutterType:"default",viewType:"split",widgets:{},hideGutter:!1,selectedChanges:[],generateAnchorID:function(){},generateLineClassName:function(){},renderGutter:function(n){var e=n.renderDefault;return(0,n.wrapInAnchor)(e())},codeEvents:{},gutterEvents:{}},ov=(0,kt.createContext)(or),DA=ov.Provider,iv=function(){return(0,kt.useContext)(ov)},FA=Zl((function(n,e){(function(t){function r(s){var o=s.slice(11),i=null,l=null;switch(o.indexOf('"')){case-1:i=(d=o.split(" "))[0].slice(2),l=d[1].slice(2);break;case 0:var u=o.indexOf('"',2);i=o.slice(3,u);var c=o.indexOf('"',u+1);l=c<0?o.slice(u+4):o.slice(c+3,-1);break;default:var d;i=(d=o.split(" "))[0].slice(2),l=d[1].slice(3,-1)}return{oldPath:i,newPath:l}}var a={parse:function(s){for(var o,i,l,u,c,d=[],f=2,h=s.split(`
8
- `),p=h.length,m=0;m<p;){var g=h[m];if(g.indexOf("diff --git")===0){o={hunks:[],oldEndingNewLine:!0,newEndingNewLine:!0,oldPath:(c=r(g)).oldPath,newPath:c.newPath},d.push(o);var x,w=null;e:for(;x=h[++m];){var y=x.indexOf(" "),C=y>-1?x.slice(0,y):C;switch(C){case"diff":m--;break e;case"deleted":case"new":var k=x.slice(y+1);k.indexOf("file mode")===0&&(o[C==="new"?"newMode":"oldMode"]=k.slice(10));break;case"similarity":o.similarity=parseInt(x.split(" ")[2],10);break;case"index":var v=x.slice(y+1).split(" "),b=v[0].split("..");o.oldRevision=b[0],o.newRevision=b[1],v[1]&&(o.oldMode=o.newMode=v[1]);break;case"copy":case"rename":var P=x.slice(y+1);P.indexOf("from")===0?o.oldPath=P.slice(5):o.newPath=P.slice(3),w=C;break;case"---":var N=x.slice(y+1),M=h[++m].slice(4);N==="/dev/null"?(M=M.slice(2),w="add"):M==="/dev/null"?(N=N.slice(2),w="delete"):(w="modify",N=N.slice(2),M=M.slice(2)),N&&(o.oldPath=N),M&&(o.newPath=M),f=5;break e}}o.type=w||"modify"}else if(g.indexOf("Binary")===0)o.isBinary=!0,o.type=g.indexOf("/dev/null and")>=0?"add":g.indexOf("and /dev/null")>=0?"delete":"modify",f=2,o=null;else if(f===5)if(g.indexOf("@@")===0){var U=/^@@\s+-([0-9]+)(,([0-9]+))?\s+\+([0-9]+)(,([0-9]+))?/.exec(g);i={content:g,oldStart:U[1]-0,newStart:U[4]-0,oldLines:U[3]-0||1,newLines:U[6]-0||1,changes:[]},o.hunks.push(i),l=i.oldStart,u=i.newStart}else{var I=g.slice(0,1),A={content:g.slice(1)};switch(I){case"+":A.type="insert",A.isInsert=!0,A.lineNumber=u,u++;break;case"-":A.type="delete",A.isDelete=!0,A.lineNumber=l,l++;break;case" ":A.type="normal",A.isNormal=!0,A.oldLineNumber=l,A.newLineNumber=u,l++,u++;break;case"\\":var G=i.changes[i.changes.length-1];G.isDelete||(o.newEndingNewLine=!1),G.isInsert||(o.oldEndingNewLine=!1)}A.type&&i.changes.push(A)}m++}return d}};n.exports=a})()}));function Bs(n){return n.type==="insert"}function sa(n){return n.type==="delete"}function Ia(n){return n.type==="normal"}function EA(n,e){var t=e.nearbySequences==="zip"?(function(r){var a=r.reduce((function(s,o,i){var l=en(s,3),u=l[0],c=l[1],d=l[2];return c?Bs(o)&&d>=0?(u.splice(d+1,0,o),[u,o,d+2]):(u.push(o),[u,o,sa(o)&&sa(c)?d:i]):(u.push(o),[u,o,sa(o)?i:-1])}),[[],null,-1]);return en(a,1)[0]})(n.changes):n.changes;return At(At({},n),{},{isPlain:!1,changes:t})}function lv(n){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},t=(function(r){if(r.startsWith("diff --git"))return r;var a=r.indexOf(`
1
+ import{a as Vi,c as j}from"./chunks/chunk-DCANE7XH.js";var $e=Vi((FO,y0)=>{var qf=globalThis.__neuralis_shared_modules__,x0=qf&&Object.prototype.hasOwnProperty.call(qf,"react")?qf.react:void 0;if(x0===void 0)throw new Error("[neuralis-ui] shared module react is not provided by the host");y0.exports=x0});var Wn=Vi((EO,w0)=>{var $f=globalThis.__neuralis_shared_modules__,b0=$f&&Object.prototype.hasOwnProperty.call($f,"@neuralis/package-system/client")?$f["@neuralis/package-system/client"]:void 0;if(b0===void 0)throw new Error("[neuralis-ui] shared module @neuralis/package-system/client is not provided by the host");w0.exports=b0});var Zr=Vi((OO,k0)=>{var Kf=globalThis.__neuralis_shared_modules__,v0=Kf&&Object.prototype.hasOwnProperty.call(Kf,"@neuralis/agent-core/app/chat")?Kf["@neuralis/agent-core/app/chat"]:void 0;if(v0===void 0)throw new Error("[neuralis-ui] shared module @neuralis/agent-core/app/chat is not provided by the host");k0.exports=v0});var ie=Vi((qU,Tb)=>{var fh=globalThis.__neuralis_shared_modules__,Mb=fh&&Object.prototype.hasOwnProperty.call(fh,"react/jsx-runtime")?fh["react/jsx-runtime"]:void 0;if(Mb===void 0)throw new Error("[neuralis-ui] shared module react/jsx-runtime is not provided by the host");Tb.exports=Mb});var Za=Vi((a8,Ob)=>{var mh=globalThis.__neuralis_shared_modules__,Eb=mh&&Object.prototype.hasOwnProperty.call(mh,"react-dom")?mh["react-dom"]:void 0;if(Eb===void 0)throw new Error("[neuralis-ui] shared module react-dom is not provided by the host");Ob.exports=Eb});var r2=Vi((w9,n2)=>{var o0=globalThis.__neuralis_shared_modules__,t2=o0&&Object.prototype.hasOwnProperty.call(o0,"@neuralis/agent-core/app/chat/store")?o0["@neuralis/agent-core/app/chat/store"]:void 0;if(t2===void 0)throw new Error("[neuralis-ui] shared module @neuralis/agent-core/app/chat/store is not provided by the host");n2.exports=t2});var ol=j($e(),1),Gf=j(Wn(),1),b2=j(Zr(),1);var Rn=j($e(),1);var ya=j($e(),1);var S0=t=>{let e,n=new Set,r=(u,c)=>{let d=typeof u=="function"?u(e):u;if(!Object.is(d,e)){let f=e;e=c??(typeof d!="object"||d===null)?d:Object.assign({},e,d),n.forEach(h=>h(e,f))}},a=()=>e,o={setState:r,getState:a,getInitialState:()=>l,subscribe:u=>(n.add(u),()=>n.delete(u))},l=e=t(r,a,o);return o},Xf=(t=>t?S0(t):S0);var ul=j($e(),1);var B2=t=>t;function C0(t,e=B2){let n=ul.default.useSyncExternalStore(t.subscribe,ul.default.useCallback(()=>e(t.getState()),[t,e]),ul.default.useCallback(()=>e(t.getInitialState()),[t,e]));return ul.default.useDebugValue(n),n}function Jf(t,e){let n;try{n=t()}catch{return}return{getItem:a=>{var s;let i=l=>l===null?null:JSON.parse(l,e?.reviver),o=(s=n.getItem(a))!=null?s:null;return o instanceof Promise?o.then(i):i(o)},setItem:(a,s)=>n.setItem(a,JSON.stringify(s,e?.replacer)),removeItem:a=>n.removeItem(a)}}var Yf=t=>e=>{try{let n=t(e);return n instanceof Promise?n:{then(r){return Yf(r)(n)},catch(r){return this}}}catch(n){return{then(r){return this},catch(r){return Yf(r)(n)}}}},_2=(t,e)=>(n,r,a)=>{let s={storage:Jf(()=>window.localStorage),partialize:m=>m,version:0,merge:(m,x)=>({...x,...m}),...e},i=!1,o=0,l=new Set,u=new Set,c=s.storage;if(!c)return t((...m)=>{console.warn(`[zustand persist middleware] Unable to update item '${s.name}', the given storage is currently unavailable.`),n(...m)},r,a);let d=()=>{let m=s.partialize({...r()});return c.setItem(s.name,{state:m,version:s.version})},f=a.setState;a.setState=(m,x)=>(f(m,x),d());let h=t((...m)=>(n(...m),d()),r,a);a.getInitialState=()=>h;let p,g=()=>{var m,x;if(!c)return;let y=++o;i=!1,l.forEach(C=>{var L;return C((L=r())!=null?L:h)});let b=((x=s.onRehydrateStorage)==null?void 0:x.call(s,(m=r())!=null?m:h))||void 0;return Yf(c.getItem.bind(c))(s.name).then(C=>{if(C)if(typeof C.version=="number"&&C.version!==s.version){if(s.migrate){let L=s.migrate(C.state,C.version);return L instanceof Promise?L.then(P=>[!0,P]):[!0,L]}console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}else return[!1,C.state];return[!1,void 0]}).then(C=>{var L;if(y!==o)return;let[P,w]=C;if(p=s.merge(w,(L=r())!=null?L:h),n(p,!0),P)return d()}).then(()=>{y===o&&(b?.(r(),void 0),p=r(),i=!0,u.forEach(C=>C(p)))}).catch(C=>{y===o&&b?.(void 0,C)})};return a.persist={setOptions:m=>{s={...s,...m},m.storage&&(c=m.storage)},clearStorage:()=>{++o,c?.removeItem(s.name)},getOptions:()=>s,rehydrate:()=>g(),hasHydrated:()=>i,onHydrate:m=>(l.add(m),()=>{l.delete(m)}),onFinishHydration:m=>(u.add(m),()=>{u.delete(m)})},s.skipHydration||g(),p||h},I0=_2;var Sx=j(Wn(),1);var L0=j(Wn(),1);async function qi(t,e,n,r){let a={agentId:t};return e&&(a.projectId=e),n?.uri&&(a.uri=n.uri),typeof n?.recursive=="boolean"&&(a.recursive=n.recursive),n?.include&&(a.include=n.include),typeof n?.summary_chars=="number"&&(a.summary_chars=n.summary_chars),typeof n?.include_metadata=="boolean"&&(a.include_metadata=n.include_metadata),typeof n?.only_indexed=="boolean"&&(a.only_indexed=n.only_indexed),typeof n?.sources_only=="boolean"&&(a.sources_only=n.sources_only),typeof n?.include_counts=="boolean"&&(a.include_counts=n.include_counts),typeof n?.limit=="number"&&(a.limit=n.limit),r.post("list",a)}async function A0(t,e,n,r){return(await qi(t,e,{uri:`${n}://`,recursive:!1,include:"folders",include_counts:!0,limit:1},r)).sources?.[0]??null}async function $i(t,e){return(e??await(0,L0.tryGetPackageApiImperativeAsync)("brain-core")).post("read",t)}async function P0(t,e){let n={agentId:t.agentId};return t.projectId&&(n.projectId=t.projectId),t.scope&&(n.scope=t.scope),t.observed&&(n.observed="1"),e.get("sources",n)}async function Zf(t,e){return e.patch("sources",{agentId:t.agentId,...t.projectId?{projectId:t.projectId}:{},...t.config})}async function N0(t,e){return e.post("sources/sync",t)}async function R0(t,e){let n={agentId:t.agentId};return t.projectId&&(n.projectId=t.projectId),t.source&&(n.source=t.source),e.get("sources/sync-status",n)}async function M0(t,e){return e.post("sources/enabled",{agentId:t.agentId,...t.projectId?{projectId:t.projectId}:{},source:t.source,enabled:t.enabled})}async function ic(t,e){let n=new URLSearchParams;return n.set("agentId",t.agentId),t.projectId&&n.set("projectId",t.projectId),e.get("sources/discoverable",Object.fromEntries(n))}function ps(t){return t?{repo:t}:{}}function xr(t){return t?{repo:t}:{}}async function Ki(t,e){let n={agentId:t.agentId,source:t.source};return t.projectId&&(n.projectId=t.projectId),e.get("git/repos",n)}async function oc(t,e){let n={agentId:t.agentId,source:t.source,...ps(t.repo)};return t.projectId&&(n.projectId=t.projectId),e.get("git/status",n)}async function T0(t,e){let n={agentId:t.agentId,source:t.source,...ps(t.repo)};return t.projectId&&(n.projectId=t.projectId),e.get("git/branch",n)}async function lc(t,e){let n={agentId:t.agentId,source:t.source,...ps(t.repo),path:t.path};return typeof t.commit=="string"&&(n.commit=t.commit),typeof t.base=="string"&&(n.base=t.base),typeof t.head=="string"&&(n.head=t.head),typeof t.staged=="boolean"&&(n.staged=t.staged?"1":"0"),t.projectId&&(n.projectId=t.projectId),e.get("git/diff",n)}async function uc(t,e){let n={agentId:t.agentId,source:t.source,...ps(t.repo)};return t.projectId&&(n.projectId=t.projectId),typeof t.maxCount=="number"&&(n.maxCount=String(t.maxCount)),typeof t.skip=="number"&&(n.skip=String(t.skip)),t.ref&&(n.ref=t.ref),e.get("git/log",n)}async function D0(t,e){let n={agentId:t.agentId,source:t.source,...ps(t.repo)};return t.projectId&&(n.projectId=t.projectId),typeof t.maxCount=="number"&&(n.maxCount=String(t.maxCount)),typeof t.skip=="number"&&(n.skip=String(t.skip)),t.ref&&(n.ref=t.ref),e.get("git/log-stats",n)}async function cc(t,e){let n={agentId:t.agentId,source:t.source,...ps(t.repo),sha:t.sha};return t.projectId&&(n.projectId=t.projectId),e.get("git/commit",n)}async function cl(t,e){let n={agentId:t.agentId,source:t.source,...ps(t.repo)};return t.projectId&&(n.projectId=t.projectId),e.get("git/outgoing",n)}async function F0(t,e){let n={agentId:t.agentId,source:t.source,...ps(t.repo),path:t.path,rev:t.rev};return t.projectId&&(n.projectId=t.projectId),e.get("git/show",n)}async function E0(t,e){return e.post("git/stage",{source:t.source,...xr(t.repo),paths:t.paths,...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function O0(t,e){return e.post("git/unstage",{source:t.source,...xr(t.repo),paths:t.paths,...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function B0(t,e){return e.post("git/stage",{source:t.source,...xr(t.repo),hunk:t.hunk,...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function _0(t,e){return e.post("git/unstage",{source:t.source,...xr(t.repo),hunk:t.hunk,...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function H0(t,e){return e.post("git/discard",{source:t.source,...xr(t.repo),paths:t.paths,...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function U0(t,e){return e.post("git/commit",{source:t.source,...xr(t.repo),message:t.message,...t.amend?{amend:!0}:{},...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function G0(t,e){return e.post("git/branch",{source:t.source,...xr(t.repo),action:"create",name:t.name,...t.startPoint?{startPoint:t.startPoint}:{},...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function W0(t,e){return e.post("git/branch",{source:t.source,...xr(t.repo),action:"delete",name:t.name,...t.force?{force:!0}:{},...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function z0(t,e){return e.post("git/restore",{source:t.source,...xr(t.repo),rescue:t.rescue,...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function Qf(t,e){return e.post("git/checkout",{source:t.source,...xr(t.repo),ref:t.ref,...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function j0(t,e){return e.post("git/fetch",{source:t.source,...xr(t.repo),...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function V0(t,e){return e.post("git/pull",{source:t.source,...xr(t.repo),...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function q0(t,e){return e.post("git/push",{source:t.source,...xr(t.repo),...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function $0(t,e){return e.post("search",t)}async function dc(t,e){let n=new FormData;return n.append("agentId",t.agentId),t.projectId&&n.append("projectId",t.projectId),n.append("file",t.file),t.uri&&n.append("uri",t.uri),t.tags?.length&&n.append("tags",t.tags.join(",")),e.upload("upload",n)}async function yr(t,e){return e.post("write",t)}function ga(t,e){return t?.code==="destination_exists"?"Something is already there \u2014 nothing was overwritten. Pick another name.":t?.message||t?.error||e}async function fc(t,e){return e.post("approve",t)}async function Xi(t,e){return(await e.post("pending",{...t,action:"preview"})).preview}async function K0(t,e){let n=await e.post("pending",t);return{ok:n?.ok!==!1,changes:Array.isArray(n?.changes)?n.changes:[],orphanIds:Array.isArray(n?.orphanIds)?n.orphanIds:[]}}async function X0(t,e){let n={agentId:t.agentId,count_only:"1"};t.projectId&&(n.projectId=t.projectId);let r=await e.get("pending",n);return typeof r?.count=="number"?r.count:0}async function Y0(t,e){return e.post("pending",{...t,action:"revert"})}async function J0(t,e){return e.post("pending",{...t,action:"discard"})}async function Z0(t,e){return e.post("pending",{...t,action:"dismiss"})}async function Q0(t,e){let n=await e.post("pending",{...t,action:"discard-orphans"});return{ok:n?.ok!==!1,discarded:typeof n?.discarded=="number"?n.discarded:0}}function ex(t,e,n){let r=new URLSearchParams({agentId:t,uri:e});return n&&r.set("projectId",n),`/api/packages/brain-core/raw?${r.toString()}`}async function tx(t,e){return e.post("health",t)}async function nx(t,e){return e.post("health/scan",t)}async function rx(t,e){return e.post("health/gc",t)}async function ax(t,e){return e.post("sources",t)}async function sx(t,e){let n=new URLSearchParams({agentId:t.agentId});return t.projectId&&n.set("projectId",t.projectId),t.purgeVectors&&n.set("purge","1"),e.del(`sources/${encodeURIComponent(t.source)}?${n.toString()}`)}async function ix(t,e){return e.post("sources/reset",t)}async function ox(t,e){return e.post("sources/reindex",t)}async function lx(t,e){return e.post("sources/purge",t)}function Zs(t){return typeof t=="number"&&Number.isFinite(t)?t:null}function H2(t){let e=t&&typeof t=="object"?t:null,n=e?.estimate&&typeof e.estimate=="object"?e.estimate:null,r=Zs(n?.points),a=Zs(n?.tokens);if(!e||!n||r===null||a===null)return null;let s=Zs(n.relStdErr),i=Zs(n.usd);return{documents:Zs(e.documents),truncated:e.truncated===!0,points:r,tokens:a,tokensMargin:s!==null?Math.round(a*s):null,usd:i,usdMargin:s!==null&&i!==null?i*s:null,durationSeconds:Zs(n.seconds)}}var ux=t=>t==="pending"?{embeddingOnly:!0}:{force:!0};async function cx(t,e,n){return H2(await n.post("sources/reindex",{...t,...ux(e),estimate:!0}))}async function hc(t,e,n){let r=await n.post("sources/reindex",{...t,...ux(e)}),a=r?.job&&typeof r.job=="object"?r.job:null;return{documents:Zs(r?.documents),truncated:r?.truncated===!0,job:a}}async function dx(t,e){return e.post("sources/cancel",t)}async function fx(t,e){let n={agentId:t.agentId};return t.projectId&&(n.projectId=t.projectId),e.get("sources/health",n)}async function eh(t,e){let n={path:t.path,agentId:t.agentId};return t.projectId&&(n.projectId=t.projectId),e.get("sources/browse",n)}async function hx(t){return t.get("sources/kinds",{})}function qe(t){let e=t.indexOf("://");return e>0?t.slice(0,e):"brain"}function sr(t){let e=t.indexOf("://");return e>0?t.slice(0,e+3):`${t}://`}function et(t){let e=t.indexOf("://");if(e<1)return t;let n=t.slice(0,e+3),r=t.lastIndexOf("/");return r<=e+2?n:t.slice(0,r)}function xa(t){let e=t.indexOf("://");if(e<1)return[];let r=`${t.slice(0,e)}://`,a=t.slice(e+3);if(!a)return[];let s=a.split("/").filter(Boolean);if(s.length===0)return[];let i=[r],o=r;for(let l=0;l<s.length-1;l++)o=o.endsWith("/")?`${o}${s[l]}`:`${o}/${s[l]}`,i.push(o);return i}function gt(t){let e=t.indexOf("://"),n=e>=0?t.slice(e+3):t,r=n.lastIndexOf("/");return r>=0?n.slice(r+1):n}var px=t=>t;function Va(t){return t.uri}function U2(t,e,n){for(let r of e){if(t[r]?.type==="folder")continue;let a=r.endsWith("://")?r.slice(0,r.indexOf("://")):r.split("/").pop()||"",s=et(r),i=t[r];t[r]={...i||{},storeKey:r,name:a,uri:r,type:"folder",parentUri:s===r?void 0:s,lastUpdated:n}}}function Qs(t,e,n){U2(t,xa(e),n)}function dl(t){if(typeof t=="string")return t;if(Array.isArray(t)){let e=t.map(n=>{if(n){if(typeof n=="string")return n;if(typeof n=="object"){let r=typeof n.text=="string"?n.text:void 0,a=typeof n.content=="string"?n.content:void 0;return r??a}}}).filter(n=>!!(n&&n.trim()));if(e.length>0)return e.join(`
2
+ `)}if(t&&typeof t=="object"){let e=t;if(typeof e.text=="string")return e.text;if(typeof e.content=="string")return e.content;if(Array.isArray(e.content)){let n=dl(e.content);if(n)return n}try{return JSON.stringify(t,null,2)}catch{return}}}function Yi(t){return Array.isArray(t?.files)?t.files:Array.isArray(t?.widget?.files)?t.widget.files:Array.isArray(t?.state?.files)?t.state.files:Array.isArray(t?.data?.files)?t.data.files:[]}function Ji(t){return dl(t?.text)??dl(t?.content)??dl(t?.file_content)??dl(t?.fileContent)??""}function pc(t){if(!t||typeof t!="object")return;let e=t;if(e.content!=null)return{content:typeof e.content=="string"?e.content:JSON.stringify(e.content,null,2),updatedAt:typeof e.updatedAt=="string"?e.updatedAt:"",...typeof e.uri=="string"?{uri:e.uri}:{},...typeof e.status=="string"?{status:e.status}:{},...typeof e.sourceVersion=="string"?{sourceVersion:e.sourceVersion}:{},...e.metadata&&typeof e.metadata=="object"?{metadata:e.metadata}:{}}}function mc(t,e){return typeof t.fileErrorByPath[e]=="string"||typeof t.fileBaseContentByPath[e]=="string"}function ei(t,e,n){return`${t??""}::${e??""}::${n}`}var th={glob:"",category:"",status:"",tags:"",createdAfter:"",createdBefore:"",scopeToFolder:!1},mx={searchQuery:"",searchMode:"keyword",searchFilters:th,searchResults:[],searchLoading:!1,searchError:void 0,searchEffect:{}};function nh(t,e,n){let r=typeof t=="string"&&t.includes("://")?t:null;if(n&&r)return r.startsWith("brain://")?null:r;let a=r?sr(r):null;return a&&!a.startsWith("brain://")?a:(e??[]).find(i=>i.source_kind!=="brain"&&typeof i.uri_root=="string")?.uri_root??null}function gx(t,e){let n=0;return{setSearchQuery:r=>t(()=>({searchQuery:r})),setSearchMode:r=>t(()=>({searchMode:r})),setSearchFilters:r=>t(a=>({searchFilters:{...a.searchFilters,...r}})),clearSearch:()=>t(()=>({searchQuery:"",searchFilters:th,searchResults:[],searchLoading:!1,searchError:void 0,searchEffect:{}})),async runSearch({agentId:r,projectId:a}){let{searchQuery:s,searchMode:i,searchFilters:o,activeFolderPath:l,sources:u}=e(),c=(s??"").trim(),d=o??th,f=d.glob.trim(),h=i==="keyword"?c.length>=2||f.length>=2:c.length>=2;if(!r||!h){t(()=>({searchResults:[],searchLoading:!1,searchError:void 0,searchEffect:{}}));return}let p=typeof l=="string"&&l.includes("://")?l:void 0,g=i==="grep"?nh(l,u,d.scopeToFolder):d.scopeToFolder?p:void 0;if(i==="grep"&&!g){t(()=>({searchResults:[],searchLoading:!1,searchError:"Grep needs a non-brain folder scope \u2014 select a folder in a disk-backed source.",searchEffect:{}}));return}let m=d.tags.split(",").map(y=>y.trim()).filter(y=>y.length>0),x=++n;t(()=>({searchLoading:!0,searchError:void 0}));try{let y=await $0({agentId:r,...a?{projectId:a}:{},search_mode:i==="keyword"?"filter":i,...c?{query:c}:{},...g?{folder_uri:g}:{},...f?{glob:f}:{},...i!=="grep"&&d.category.trim()?{category:d.category.trim()}:{},...i!=="grep"&&d.status.trim()?{status:d.status.trim()}:{},...i!=="grep"&&m.length>0?{tags:m}:{},...i!=="grep"&&d.createdAfter.trim()?{created_after:d.createdAfter.trim()}:{},...i!=="grep"&&d.createdBefore.trim()?{created_before:d.createdBefore.trim()}:{},limit:i==="semantic"?30:50},e().client);if(x!==n)return;let b=y.results||[],C=b.find(P=>typeof P.error=="string"&&P.error.length>0),L=b.filter(P=>typeof P.uri=="string"&&P.uri.includes("://")&&!P.error).map(P=>({id:P.id||`fs:${P.uri}:${P.chunk_start??""}`,uri:P.uri,filename:P.filename||String(P.uri).split("/").pop(),content_preview:P.content_preview,snippet:P.snippet,chunk_start:P.chunk_start,chunk_end:P.chunk_end,match_type:P.match_type,score:P.score,...typeof P.embedding_status=="string"?{embedding_status:P.embedding_status}:{}}));t(()=>({searchResults:L,searchLoading:!1,searchError:C?String(C.error):void 0,searchEffect:{...y.requested_mode?{requestedMode:y.requested_mode}:{},...y.effective_mode?{effectiveMode:y.effective_mode}:{},...y.embedding_degraded?{embeddingDegraded:y.embedding_degraded}:{},...y.warning?{warning:y.warning}:{}}}))}catch(y){if(x!==n)return;t(()=>({searchResults:[],searchLoading:!1,searchError:y instanceof Error?y.message:"Search failed",searchEffect:{}}))}}}}function Zi(){return{files:{},folderBadges:{},fileContentByPath:{},fileBaseContentByPath:{},fileErrorByPath:{},filePrevByPath:{},openFiles:[],activeFile:null,tabMeta:{},pendingReviewPaths:new Set,pendingCount:0,expandedFolders:new Set,sidebarView:"tree",activeWorkspaceTab:"file",workspacePanels:{upload:!1,sources:!1,packages:!1,pending:!1},pendingSourceSuggestion:null,vectorHealthOpen:!1,searchQuery:"",searchResults:[],searchLoading:!1,searchError:void 0,searchEffect:{},gitStatus:null,gitTotals:null,gitOutgoingStat:null,gitBranches:[],gitLoading:!1,gitError:void 0,gitDiffTarget:null,gitCommitTarget:null,sources:[],sourcesLoading:!0,activeSource:null,activeRepoRel:"",loadedFolders:{},hydrationState:{},dirtySources:{},sourceChangeRevision:{},organizeError:null,pendingPanelFilter:{},activeFolderPath:"brain://docs",snapshotError:void 0}}var G2=200;function gc(t,e=G2){let n=[...t],r=[],a=!0;for(;n.length>e&&a;){a=!1;for(let s=0;s<n.length&&n.length>e;){let i=n[s],o=`${i}/`;if(i.endsWith("://")||n.some(l=>l.startsWith(o))){s+=1;continue}n.splice(s,1),r.push(i),a=!0}}return{kept:n,evicted:r}}var W2=Object.keys(Zi());function z2(t){let e={};for(let n of W2)e[n]=t[n];return e}function xc(t){let e=t.expandedFolders;return{openFiles:Array.isArray(t.openFiles)?t.openFiles:[],activeFile:typeof t.activeFile=="string"?t.activeFile:null,tabMeta:t.tabMeta??{},expandedFolders:e instanceof Set?gc(Array.from(e)).kept:[],sidebarView:t.sidebarView??"tree",activeWorkspaceTab:t.activeWorkspaceTab??"file",workspacePanels:t.workspacePanels??{upload:!1,sources:!1,packages:!1,pending:!1},activeFolderPath:t.activeFolderPath??"brain://docs"}}function xx(t){let e=Zi();return t?{...e,openFiles:Array.isArray(t.openFiles)?t.openFiles:[],activeFile:typeof t.activeFile=="string"?t.activeFile:null,tabMeta:t.tabMeta??{},expandedFolders:new Set(Array.isArray(t.expandedFolders)?gc(t.expandedFolders).kept:[]),sidebarView:t.sidebarView??e.sidebarView,activeWorkspaceTab:t.activeWorkspaceTab??e.activeWorkspaceTab,workspacePanels:t.workspacePanels??e.workspacePanels,activeFolderPath:t.activeFolderPath??e.activeFolderPath}:e}function yx(t,e){let n=new Map;return{async loadList({agentId:r,projectId:a,userId:s,withCounts:i}){if(!r)return;let o=`${r}:${a||""}:${i?"c":""}`,l=n.get(o);if(l){await l;return}let u="brain://",c=e(),d=s===void 0?c.activeUserId:s,f=c.activeUserId!==null&&c.activeUserId!==d,h=c.activeAgentId!==r||c.activeProjectId!==a||f,p;if(h?(e().fenceInFlightWriters(),t(m=>{let x={...m.contextStateByKey};m.activeAgentId&&(x[ei(m.activeUserId,m.activeProjectId,m.activeAgentId)]=z2(m));let y=ei(d,a,r);return p=x[y],delete x[y],{activeUserId:d,activeAgentId:r,activeProjectId:a,...Zi(),...p??{},contextStateByKey:x}})):t(()=>({activeUserId:d,activeAgentId:r,activeProjectId:a,sourcesLoading:!0})),p){let m=p.loadedFolders??{},x=new Set;for(let[y,b]of Object.entries(m)){if(!b)continue;let C=qe(y);C&&x.add(C)}for(let y of x)e().reconcileSourceFolders({agentId:r,projectId:a,source:y})}e().rehydrateActiveTab();let g=(async()=>{let m;try{m=await qi(r,a??void 0,{sources_only:!0,recursive:!1,...i?{include_counts:!0}:{}},e().client)}catch{t(()=>({snapshotError:"Filesystem service unavailable",sourcesLoading:!1}));return}let x=Array.isArray(m.folders)?m.folders:[],y=Array.isArray(m.files)?m.files:[],b=Array.isArray(m.sources)?m.sources:[];t(C=>{let L=C.activeAgentId===r&&C.activeProjectId===a,P=L?{...C.files}:{},w=Date.now();P[u]||(P[u]={storeKey:u,name:"brain",uri:u,type:"folder",lastUpdated:w,presence:"brain"});for(let M of x){let R=typeof M=="string"?M:typeof M?.uri=="string"?M.uri:"";if(!R)continue;let U=typeof M?.name=="string"?M.name:R.split("/").pop()||"folder",v=M?.presence??(qe(R)==="brain"?"brain":"stale_indexed");Qs(P,`${R}/placeholder`,w),P[R]={storeKey:R,name:U,uri:R,type:"folder",parentUri:R.endsWith("://")?void 0:et(R),lastUpdated:w,presence:v,git:typeof M.git=="string"?String(M.git):void 0}}for(let M of y){let R=typeof M?.uri=="string"?String(M.uri):"";if(!R)continue;let U=typeof M?.id=="string"?String(M.id):void 0,v=typeof M.status=="string"?String(M.status):void 0,T=Array.isArray(M.tags)&&M.tags.length>0?M.tags:void 0,V=typeof M.category=="string"?String(M.category):void 0,Y=M.version&&typeof M.version=="object"?M.version:void 0,N=typeof M.agent_id=="string"?String(M.agent_id):void 0,A=typeof M.project_id=="string"?String(M.project_id):void 0,B=M?.presence??(qe(R)==="brain"?"brain":"stale_indexed"),K=typeof M.git=="string"?String(M.git):void 0;Qs(P,R,w),P[R]={storeKey:R,id:U,name:String(M.filename||M.name||gt(R)),uri:R,os_uri:typeof M.os_uri=="string"?String(M.os_uri):void 0,type:"file",status:v,parentUri:et(R),lastUpdated:w,category:V,tags:T,metadata:M.metadata&&typeof M.metadata=="object"?M.metadata:void 0,createdAt:typeof M.createdAt=="string"?String(M.createdAt):void 0,updatedAt:typeof M.updatedAt=="string"?String(M.updatedAt):void 0,version:Y,sourceAgentId:N,sourceProjectId:A,presence:B,git:K};let te=et(R),ne=P[te];ne&&ne.type==="folder"&&(P[te]={...ne,sourceAgentId:N??ne.sourceAgentId,sourceProjectId:A??ne.sourceProjectId,lastUpdated:w})}let k=L?{...C.loadedFolders||{}}:{},_=L?{...C.hydrationState||{}}:{};for(let M of b)!k[M.uri_root]&&!_[M.uri_root]&&(_[M.uri_root]="idle");return{files:P,sources:b,sourcesLoading:!1,snapshotError:void 0,loadedFolders:k,hydrationState:_}})})();n.set(o,g);try{await g}finally{n.delete(o)}},async refresh({agentId:r,projectId:a,withCounts:s}){await e().loadList({agentId:r,projectId:a,withCounts:s})}}}var wx={gitStatus:null,gitTotals:null,gitOutgoingStat:null,gitBranches:[],gitLoading:!1,gitError:void 0,gitViewMode:"list",gitDiffTarget:null,gitCommitTarget:null,gitLogNonce:0};function rh(t,e){let n=t??(typeof e=="string"?e:"");return n?n.includes("://")?qe(n):n:""}function bx(t,e){return typeof t=="string"?t:typeof e=="string"?e:""}function vx(t,e){let n=0,r=0;return{setGitViewMode:a=>t(()=>({gitViewMode:a})),setGitDiffTarget:a=>t(()=>({gitDiffTarget:a})),setGitCommitTarget:a=>t(s=>({gitCommitTarget:a,...a===null&&s.activeWorkspaceTab==="git-commit"?{activeWorkspaceTab:"file"}:{}})),notifyGitLogChanged:a=>{if(!a)return;let s=rh(void 0,e().activeSource);a===s&&t(i=>({gitLogNonce:(typeof i.gitLogNonce=="number"?i.gitLogNonce:0)+1}))},clearGit:()=>t(a=>({gitStatus:null,gitBranches:[],gitLoading:!1,gitError:void 0,gitDiffTarget:null,gitCommitTarget:null,...a.activeWorkspaceTab==="git-commit"?{activeWorkspaceTab:"file"}:{}})),setGitOutgoingStat(a){t(()=>({gitOutgoingStat:a}))},async loadGitStatus({agentId:a,projectId:s,source:i,repo:o}){let l=rh(i,e().activeSource),u=bx(o,e().activeRepoRel);if(!a||!l){t(()=>({gitStatus:null,gitTotals:null,gitLoading:!1,gitError:void 0}));return}let c=++n;t(()=>({gitLoading:!0,gitError:void 0}));try{let d=await oc({agentId:a,...s?{projectId:s}:{},source:l,...u?{repo:u}:{}},e().client);if(c!==n)return;t(()=>({gitStatus:d?.status??null,gitTotals:d?.totals??null,gitLoading:!1,gitError:void 0}))}catch(d){if(c!==n)return;t(()=>({gitStatus:null,gitTotals:null,gitLoading:!1,gitError:d instanceof Error?d.message:"Git status failed"}))}},async loadGitBranches({agentId:a,projectId:s,source:i,repo:o}){let l=rh(i,e().activeSource),u=bx(o,e().activeRepoRel);if(!a||!l){t(()=>({gitBranches:[]}));return}let c=++r;try{let d=await T0({agentId:a,...s?{projectId:s}:{},source:l,...u?{repo:u}:{}},e().client);if(c!==r)return;t(()=>({gitBranches:Array.isArray(d?.branches)?d.branches:[]}))}catch(d){if(c!==r)return;t(()=>({gitBranches:[],gitError:d instanceof Error?d.message:"Git branches failed"}))}}}}var ah=5e4,j2=3;function V2(){return{resetEpoch:0,pendingCountSeq:0,rehydrateInFlight:new Set,liveFolderLoadInFlight:new Map,reconcileJobs:new Map,folderGeneration:new Map}}function oh(t,e){let n=(t.folderGeneration.get(e)??0)+1;return t.folderGeneration.set(e,n),n}function Cx(t,e,n){return t.folderGeneration.get(e)===n}function sh(t){return{storeKey:t,uri:t,name:gt(t),type:"file",parentUri:et(t)}}function kx(t,e,n){let r=et(e);if(r===e||n.parentUri===r)return n;let a={...n,parentUri:r};return t[e]=a,a}function Ix(t,e,n,r){let a=r?.issuedAt??n,s=r?.pending;for(let i of e.folders||[]){let o=typeof i=="string"?i:typeof i?.uri=="string"?i.uri:"";if(!o)continue;let l=typeof i?.name=="string"?i.name:o.split("/").pop()||"folder",u=i?.presence??"unindexed",c=typeof i?.git=="string"?String(i.git):void 0,d=typeof i?.status=="string"?i.status:void 0,f=t[o];if(!f){t[o]={storeKey:o,name:l,uri:o,type:"folder",parentUri:o.endsWith("://")?void 0:et(o),lastUpdated:n,presence:u,git:c,status:d};continue}f=kx(t,o,f),!((f.lastUpdated??0)>=a)&&(f.git!==c||f.presence!==u||f.name!==l||f.status!==d)&&(t[o]={...f,name:l,presence:u,git:c,status:d})}for(let i of e.files||[]){let o=typeof i?.uri=="string"?String(i.uri):"";if(!o)continue;Qs(t,o,n);let l=typeof i.git=="string"?String(i.git):void 0,u=typeof i.status=="string"?i.status:void 0,c=i.presence??"unindexed",d=typeof i.os_uri=="string"?i.os_uri:void 0,f=t[o];if(!f){t[o]={storeKey:o,name:gt(o),uri:o,type:"file",id:typeof i.id=="string"?i.id:void 0,os_uri:d,status:u,parentUri:et(o),lastUpdated:n,category:typeof i.category=="string"?i.category:void 0,presence:c,pinned:i.pinned===!0,git:l},s&&u==="pending_review"&&s.add.add(o);continue}if(f=kx(t,o,f),(f.lastUpdated??0)>=a)continue;let h={...f,name:gt(o)||f.name,presence:c,status:u,os_uri:d,git:l};typeof i.id=="string"&&(h.id=i.id),"category"in i&&(h.category=typeof i.category=="string"?i.category:void 0),"version"in i&&(h.version=i.version),"pinned"in i&&(h.pinned=i.pinned===!0),t[o]=h,s&&f.status!==u&&(u==="pending_review"?s.add.add(o):f.status==="pending_review"&&s.remove.add(o))}}function lh(t,e,n){if(n.add.size===0&&n.remove.size===0)return t;let r=new Set(e);for(let a of n.add)r.add(a);for(let a of n.remove)r.delete(a);return t.pendingReviewPaths=r,t}var q2=4;function $2(t,e){if(t.endsWith("://"))return!0;if(!e.has(t))return!1;for(let n of xa(t))if(!n.endsWith("://")&&!e.has(n))return!1;return!0}function Lx(t,e){return e.some(n=>t===n||t.startsWith(n.endsWith("://")?n:`${n}/`))}function Ax(t,e){let n=t;for(let[r,a]of Object.entries(t))a!==!0||!Lx(r,e)||(n===t&&(n={...t}),n[r]=!1);return n}function yc(t,e){let n=new Set(e),r=Array.from(t.expandedFolders).filter(l=>!n.has(l));r.push(...n);let{kept:a,evicted:s}=gc(r);if(s.length===0)return{expandedFolders:new Set(a)};let i=t.loadedFolders||{},o=Ax(i,s);return o===i?{expandedFolders:new Set(a)}:{expandedFolders:new Set(a),loadedFolders:o}}async function K2(t,e,n){if(t.length===0)return[];let r=Math.max(1,Math.min(e,t.length)),a=new Array(t.length),s=0;return await Promise.all(Array.from({length:r},async()=>{for(;;){let i=s++;if(i>=t.length)return;a[i]=await n(t[i])}})),a}async function X2(t,e){let{agentId:n,projectId:r,source:a,extraTargets:s,wide:i}=e,o=t.fences.resetEpoch,l=t.get(),u=l.loadedFolders||{},c=new Set;if(i)for(let p of Object.keys(u))qe(p)===a&&$2(p,l.expandedFolders)&&c.add(p);for(let p of s)qe(p)===a&&u[p]!==void 0&&c.add(p);let d=p=>{let g=p.indexOf("://"),m=(g>=0?p.slice(g+3):p).replace(/\/+$/,"");return m?m.split("/").length:0},f=Array.from(c).sort((p,g)=>d(g)-d(p));if(f.length===0)return;let h=await K2(f,q2,async p=>{let g=oh(t.fences,p),m=Date.now();try{let x=await qi(n,r??void 0,{uri:p,recursive:!1},t.client);return Cx(t.fences,p,g)?{folderKey:p,res:x,issuedAt:m,ok:!0}:{folderKey:p,res:null,issuedAt:m,ok:!1}}catch{return{folderKey:p,res:null,issuedAt:m,ok:!1}}});t.set(p=>{if(o!==t.fences.resetEpoch)return p;let g={...p.files},m=Date.now(),x={add:new Set,remove:new Set},y=[],b=!1,C=!1;for(let M of h){if(!M.ok||!M.res){C=!0;continue}Ix(g,M.res,m,{issuedAt:M.issuedAt,pending:x}),M.res.truncated?C=!0:b=!0}let L=C===!!p.dirtySources[a]?p.dirtySources:(()=>{let M={...p.dirtySources};return C?M[a]=!0:delete M[a],M})(),P=p.loadedFolders;for(let M of h)!M.ok||!M.res||P?.[M.folderKey]!==!1||(P===p.loadedFolders&&(P={...P}),P[M.folderKey]=!0);if(!b)return lh({files:uh(g,p.expandedFolders,p.openFiles),dirtySources:L,loadedFolders:P},p.pendingReviewPaths,x);let w=new Map;for(let M of Object.keys(g)){let R=g[M]?.parentUri;if(!R)continue;let U=w.get(R);U?U.push(M):w.set(R,[M])}for(let M of h){if(!M.ok||!M.res)continue;let R=M.res;if(R.truncated)continue;let U=new Set;for(let v of R.files||[]){let T=typeof v?.uri=="string"?v.uri:"";T&&U.add(T)}for(let v of R.folders||[]){let T=typeof v=="string"?v:typeof v?.uri=="string"?v.uri:"";T&&U.add(T)}for(let v of w.get(M.folderKey)||[]){let T=g[v];if(T&&!U.has(v)&&!((T.lastUpdated??0)>=M.issuedAt)){if(T.type==="folder"){let Y=(w.get(v)||[]).filter(A=>g[A]!==void 0);if(Y.filter(A=>g[A].status!=="deleted").length>0)continue;Y.length===0?delete g[v]:T.status!=="deleted"&&(g[v]={...T,status:"deleted",lastUpdated:m});continue}T.presence==="unindexed"?(delete g[v],y.push(v),T.status==="pending_review"&&x.remove.add(v)):T.status!=="deleted"&&(g[v]={...T,status:"deleted",lastUpdated:m},T.status==="pending_review"&&x.remove.add(v))}}}let _={files:uh(g,p.expandedFolders,p.openFiles),dirtySources:L,loadedFolders:P};if(y.length){let M=new Set(y),R=p.openFiles.filter(N=>!M.has(N));_.openFiles=R;let U={...p.tabMeta};for(let N of y)delete U[N];_.tabMeta=U,_.activeFile=p.activeFile&&M.has(p.activeFile)?R.length?R[R.length-1]:null:p.activeFile;let v={...p.fileContentByPath},T={...p.fileBaseContentByPath},V={...p.fileErrorByPath},Y={...p.filePrevByPath};for(let N of y)delete v[N],delete T[N],delete V[N],delete Y[N];_.fileContentByPath=v,_.fileBaseContentByPath=T,_.fileErrorByPath=V,_.filePrevByPath=Y}return lh(_,p.pendingReviewPaths,x)})}async function bc(t,e){let{agentId:n,projectId:r,source:a,targets:s}=e,i=e.wide!==!1;if(!n||!a)return;let o=t.fences.reconcileJobs.get(a);if(o){if(o.rerun=!0,i&&(o.wide=!0),s)for(let u of s)o.extra.add(u);await o.promise;return}let l={rerun:!1,wide:i,extra:new Set(s??[]),promise:Promise.resolve()};t.fences.reconcileJobs.set(a,l),l.promise=(async()=>{try{for(let u=0;u<j2;u++){l.rerun=!1;let c=l.wide;l.wide=!1;let d=Array.from(l.extra);if(l.extra.clear(),await X2(t,{agentId:n,projectId:r,source:a,extraTargets:d,wide:c}),!l.rerun)break}}finally{t.fences.reconcileJobs.delete(a)}})(),await l.promise}function wc(t,e){let n=`${e}/`,r=Object.keys(t.get().files).filter(a=>a===e||a.startsWith(n));r.length!==0&&t.set(a=>{let s={...a.files};for(let h of r)delete s[h];let i=new Set(r),o=a.openFiles.filter(h=>!i.has(h)),l={...a.tabMeta},u={...a.fileContentByPath},c={...a.fileBaseContentByPath},d={...a.fileErrorByPath},f={...a.filePrevByPath};for(let h of r)delete l[h],delete u[h],delete c[h],delete d[h],delete f[h];return{files:s,openFiles:o,activeFile:a.activeFile&&i.has(a.activeFile)?o.length?o[o.length-1]:null:a.activeFile,tabMeta:l,fileContentByPath:u,fileBaseContentByPath:c,fileErrorByPath:d,filePrevByPath:f}})}var Y2=30;function uh(t,e,n){let r=Object.keys(t);if(r.length<=ah)return t;let a=new Set;for(let u of e){a.add(u);let c=u;for(;c;){a.add(c);let d=et(c);if(!d||d===c)break;c=d}}for(let u of n){a.add(u);let c=et(u);for(;c;){a.add(c);let d=et(c);if(!d||d===c)break;c=d}}for(let u of r)u.endsWith("://")&&a.add(u);let s=r.filter(u=>{if(a.has(u))return!1;let c=t[u].parentUri;return!(c&&e.has(c))}).map(u=>({key:u,ts:t[u].lastUpdated??0})).sort((u,c)=>u.ts-c.ts),i=r.length-ah;if(i<=0||s.length===0)return t;let o={...t},l=Math.min(i,s.length);for(let u=0;u<l;u++)delete o[s[u].key];return console.warn("[Filesystem] cold-row eviction",{total:r.length,cap:ah,removed:l,protected:r.length-s.length}),o}var Px="filesystem",fl=120,ih=240,Nx="neuralis.filesystem.sidebarWidth";function J2(){if(typeof window>"u")return ih;try{let t=window.localStorage.getItem(Nx),e=t?Number(t):NaN;return Number.isFinite(e)&&e>=fl?e:ih}catch{return ih}}function Z2(t){let e=V2(),n=t.client;return Xf()((r,a)=>({windowId:t.windowId??null,client:n,files:{},folderBadges:{},fileContentByPath:{},fileBaseContentByPath:{},fileErrorByPath:{},filePrevByPath:{},openFiles:[],activeFile:null,tabMeta:{},activeUserId:t.userId??null,contextStateByKey:{},previewEditorsEnabled:t.previewEditorsEnabled??!1,expandedFolders:new Set,sidebarOpen:!0,sidebarWidth:J2(),sidebarView:"tree",activeAgentId:t.agentId??null,activeProjectId:t.projectId??null,sources:[],sourcesLoading:!0,activeSource:null,activeRepoRel:"",activeFolderPath:"brain://docs",uploading:!1,workspacePanels:{upload:!1,sources:!1,packages:!1,pending:!1},activeWorkspaceTab:"file",pendingSourceSuggestion:null,vectorHealthOpen:!1,diffViewMode:t.diffViewMode??"auto",pendingPanelFilter:{},loadedFolders:{},hydrationState:{},dirtySources:{},sourceChangeRevision:{},organizeError:null,snapshotError:void 0,pendingReviewPaths:new Set,pendingCount:0,...mx,...gx(r,a),...yx(r,a),...wx,...vx(r,a),toggleSidebar:()=>r(s=>({sidebarOpen:!s.sidebarOpen})),setSidebarView:s=>r(()=>({sidebarView:s})),setSidebarWidth:s=>r(()=>{let i=Math.max(fl,Math.round(s));if(typeof window<"u")try{window.localStorage.setItem(Nx,String(i))}catch{}return{sidebarWidth:i}}),setActiveFolderPath:s=>r(()=>({activeFolderPath:s?String(s):null})),setActiveSource:(s,i)=>r(()=>({activeSource:s,activeRepoRel:typeof i=="string"?i:"",gitOutgoingStat:null})),setWorkspacePanelOpen:(s,i)=>r(o=>{let l={upload:!1,sources:!1,packages:!1,pending:!1};i?l[s]=!0:(l.upload=o.workspacePanels.upload,l.sources=o.workspacePanels.sources,l.packages=o.workspacePanels.packages,l.pending=o.workspacePanels.pending,l[s]=!1);let u=i?s:o.activeWorkspaceTab===s?"file":o.activeWorkspaceTab;return{workspacePanels:l,activeWorkspaceTab:u}}),setPendingSourceSuggestion:s=>r(()=>({pendingSourceSuggestion:s})),setVectorHealthOpen:s=>r(()=>({vectorHealthOpen:s})),setActiveWorkspaceTab:s=>r(()=>({activeWorkspaceTab:s})),setDiffViewMode:s=>r(()=>({diffViewMode:s})),setPreviewEditorsEnabled:s=>r(()=>({previewEditorsEnabled:s})),reorderOpenFiles:(s,i)=>r(o=>{if(s===i)return o;let l=[...o.openFiles],u=l.indexOf(s),c=l.indexOf(i);if(u<0||c<0)return o;let[d]=l.splice(u,1);return l.splice(c,0,d),{openFiles:l}}),toggleTabPin:s=>r(i=>{let o=i.tabMeta[s]||{};return{tabMeta:{...i.tabMeta,[s]:{...o,pinned:!o.pinned,preview:!1}}}}),promoteTab:s=>r(i=>{let o=i.tabMeta[s];return!o||!o.preview?i:{tabMeta:{...i.tabMeta,[s]:{...o,preview:!1}}}}),closeAllFiles:()=>r(s=>{let i=s.openFiles.filter(l=>s.tabMeta[l]?.pinned),o=s.activeFile&&i.includes(s.activeFile)?s.activeFile:i[i.length-1]??null;return{openFiles:i,activeFile:o}}),closeSavedFiles:()=>r(s=>{let i=u=>{let c=s.fileBaseContentByPath[u],d=s.fileContentByPath[u];return typeof c=="string"&&c!==d},o=s.openFiles.filter(u=>s.tabMeta[u]?.pinned||i(u)||s.files[u]?.status==="pending_review"),l=s.activeFile&&o.includes(s.activeFile)?s.activeFile:o[o.length-1]??null;return{openFiles:o,activeFile:l}}),closeOtherFiles:s=>r(i=>{let o=i.openFiles.filter(l=>l===s||i.tabMeta[l]?.pinned);return{openFiles:o,activeFile:o.includes(s)?s:o[o.length-1]??null}}),setPendingPanelFilter:s=>r(()=>({pendingPanelFilter:s})),toggleFolder:s=>r(i=>{if(i.expandedFolders.has(s)){let u=new Set(Array.from(i.expandedFolders).filter(f=>!Lx(f,[s]))),c=i.loadedFolders||{},d=Ax(c,[s]);return d===c?{expandedFolders:u}:{expandedFolders:u,loadedFolders:d}}let o=!!i.folderBadges[s],l=o?{...i.folderBadges}:i.folderBadges;return o&&delete l[s],{...yc(i,[s]),folderBadges:l}}),async ensureFolderLoaded({agentId:s,projectId:i,uri:o,force:l}){if(!s||!o)return;let u=a().loadedFolders?.[o];if(!l&&u)return;if(!l&&u===!1){await bc({get:a,set:r,fences:e,client:n},{agentId:s,projectId:i,source:qe(o),targets:[o],wide:!1});return}let c=e.liveFolderLoadInFlight.get(o);if(c){await c;return}r(f=>({hydrationState:{...f.hydrationState||{},[o]:"loading"}}));let d=(async()=>{let f=oh(e,o),h=Date.now();try{let p=await qi(s,i??void 0,{uri:o,recursive:!1},n);if(!Cx(e,o,f)){r(g=>({hydrationState:{...g.hydrationState||{},[o]:g.loadedFolders?.[o]?"ready":"idle"}}));return}r(g=>{let m={...g.files},x={add:new Set,remove:new Set};return Ix(m,p,Date.now(),{issuedAt:h,pending:x}),lh({files:uh(m,g.expandedFolders,g.openFiles),loadedFolders:{...g.loadedFolders||{},[o]:!0},hydrationState:{...g.hydrationState||{},[o]:"ready"}},g.pendingReviewPaths,x)})}catch(p){console.error("[Filesystem] subfolder load failed",p),r(g=>({hydrationState:{...g.hydrationState||{},[o]:"error"}}))}})();e.liveFolderLoadInFlight.set(o,d);try{await d}finally{e.liveFolderLoadInFlight.delete(o)}},clearOrganizeError:()=>r(()=>({organizeError:null})),clearSnapshotError:()=>r(()=>({snapshotError:void 0})),setSourceDirty:(s,i)=>r(o=>{if(!!o.dirtySources[s]===i)return o;let u={...o.dirtySources};return i?u[s]=!0:delete u[s],{dirtySources:u}}),async reconcileSourceFolders({agentId:s,projectId:i,source:o}){await bc({get:a,set:r,fences:e,client:n},{agentId:s,projectId:i,source:o})},fenceInFlightWriters(){e.resetEpoch+=1;for(let s of Array.from(e.folderGeneration.keys()))oh(e,s);e.liveFolderLoadInFlight.clear(),e.rehydrateInFlight.clear()},resetClientState(s){let i=a();if(!i.activeProjectId||s.projectId!==i.activeProjectId||s.level!=="project"&&s.agentId!==i.activeAgentId||(s.level==="widget"||s.level==="instance")&&(s.widgetType!==Px||s.instanceId!==i.windowId))return;a().fenceInFlightWriters();let o=`${i.activeUserId??""}::${i.activeProjectId}::`,l=ei(i.activeUserId,i.activeProjectId,i.activeAgentId??""),u={};for(let[c,d]of Object.entries(i.contextStateByKey))(s.level==="project"?c.startsWith(o):c===l)||(u[c]=d);r(()=>({...Zi(),contextStateByKey:u}))},async reconcileFolders({agentId:s,projectId:i,folders:o}){if(!s||!Array.isArray(o)||o.length===0)return;let l=new Map,u=a().loadedFolders||{};for(let c of o){if(!c)continue;let d=qe(c);if(!d||u[c]===!1)continue;if(!u[c]){a().setSourceDirty(d,!0);continue}let f=l.get(d);f?f.push(c):l.set(d,[c])}l.size!==0&&await Promise.all(Array.from(l.entries()).map(([c,d])=>bc({get:a,set:r,fences:e,client:n},{agentId:s,projectId:i,source:c,targets:d})))},async refreshTree({agentId:s,projectId:i}){if(!s)return;await a().loadList({agentId:s,projectId:i});let o=a(),l=new Set;for(let[u,c]of Object.entries(o.loadedFolders||{})){if(!c)continue;let d=qe(u);d&&l.add(d)}await Promise.all(Array.from(l).map(u=>bc({get:a,set:r,fences:e,client:n},{agentId:s,projectId:i,source:u})))},setActiveFile:s=>{r({activeFile:s,activeWorkspaceTab:"file"}),a().rehydrateActiveTab()},async rehydrateActiveTab(){let s=a(),i=s.activeFile,o=s.activeAgentId;if(!(!i||!o)&&!mc(s,i)&&!e.rehydrateInFlight.has(i)){e.rehydrateInFlight.add(i);try{let l=s.tabMeta[i]?.sourceAgentId,u=l&&l!==o&&!/^__.*__$/.test(l)?l:void 0;await s.openFile({agentId:o,projectId:s.activeProjectId,uri:i,readAgentId:u,revealPane:!1})}finally{e.rehydrateInFlight.delete(i)}}},closeFile:s=>r(i=>{let o=i.openFiles.filter(c=>c!==s),l=i.activeFile===s?o.length?o[o.length-1]:null:i.activeFile,u={...i.tabMeta};return delete u[s],{openFiles:o,activeFile:l,tabMeta:u}}),replaceFilePath:(s,i)=>r(o=>{if(!s||!i||s===i)return o;let l=o.files[s],u={...o.files};l&&(delete u[s],u[i]={...l,storeKey:i,uri:i,name:gt(i)||l.name,parentUri:et(i),lastUpdated:Date.now()});let c={...o.fileContentByPath},d={...o.fileBaseContentByPath},f={...o.fileErrorByPath},h={...o.filePrevByPath};Object.prototype.hasOwnProperty.call(c,s)&&(c[i]=c[s],delete c[s]),Object.prototype.hasOwnProperty.call(d,s)&&(d[i]=d[s],delete d[s]),Object.prototype.hasOwnProperty.call(f,s)&&(f[i]=f[s],delete f[s]),Object.prototype.hasOwnProperty.call(h,s)&&(h[i]=h[s],delete h[s]);let p=[];for(let g of o.openFiles){let m=g===s?i:g;p.includes(m)||p.push(m)}return{files:u,fileContentByPath:c,fileBaseContentByPath:d,fileErrorByPath:f,filePrevByPath:h,openFiles:p,activeFile:o.activeFile===s?i:o.activeFile}}),patchFileNode:(s,i)=>r(o=>{let l=o.files[s];return l?{files:{...o.files,[s]:{...l,...i,lastUpdated:Date.now()}}}:o}),clearFilePrev:s=>r(i=>{if(!i.filePrevByPath[s])return i;let o={...i.filePrevByPath};return delete o[s],{filePrevByPath:o}}),upsertFileNodeFromEvent:({id:s,uri:i,folder_ancestors:o,status:l,sourceAgentId:u,sourceProjectId:c})=>r(d=>{if(!i||!d.files[i]&&l==="deleted")return d;let f=Date.now(),h={...d.files},p=o||xa(i);Qs(h,i,f);let g=et(i),m=h[g];m&&m.type==="folder"&&(h[g]={...m,sourceAgentId:u??m.sourceAgentId,sourceProjectId:c??m.sourceProjectId});let x=h[i],y=qe(i)==="brain";h[i]={...x||sh(i),id:s??x?.id,name:gt(i)||x?.name||"file",type:"file",uri:i,status:l??x?.status,parentUri:g,sourceAgentId:u??x?.sourceAgentId,sourceProjectId:c??x?.sourceProjectId,lastUpdated:f,presence:x?.presence??(y?"brain":"synced"),git:x?.git};let b=new Set(d.pendingReviewPaths);if(l==="pending_review"?b.add(i):x?.status==="pending_review"&&l&&l!=="pending_review"&&b.delete(i),l==="active"&&x?.status==="pending_review"&&d.filePrevByPath[i]){let L={...d.filePrevByPath};return delete L[i],{files:h,filePrevByPath:L,pendingReviewPaths:b}}return{files:h,pendingReviewPaths:b}}),removeFilePath:s=>r(i=>{if(!s||!i.files[s]&&!i.openFiles.includes(s)&&!i.tabMeta[s])return i;let o={...i.files};delete o[s];let l=i.openFiles.filter(g=>g!==s),u=i.activeFile===s?l.length?l[l.length-1]:null:i.activeFile,c={...i.fileContentByPath},d={...i.fileBaseContentByPath},f={...i.fileErrorByPath},h={...i.filePrevByPath};delete c[s],delete d[s],delete f[s],delete h[s];let p={...i.tabMeta};return delete p[s],{files:o,openFiles:l,activeFile:u,tabMeta:p,fileContentByPath:c,fileBaseContentByPath:d,fileErrorByPath:f,filePrevByPath:h}}),incrementFolderBadges:s=>r(i=>{if(!Array.isArray(s)||s.length===0)return i;let o={...i.folderBadges};for(let l of s)l&&(i.expandedFolders.has(l)||(o[l]=(o[l]||0)+1));return{folderBadges:o}}),clearFolderBadge:s=>r(i=>{if(!s||!i.folderBadges[s])return i;let o={...i.folderBadges};return delete o[s],{folderBadges:o}}),autoExpandToFile:s=>r(i=>yc(i,[sr(s),...xa(s)])),updateFileContent:(s,i)=>r(o=>({fileContentByPath:{...o.fileContentByPath,[s]:i},fileErrorByPath:{...o.fileErrorByPath,[s]:void 0}})),async saveFileInPlace({agentId:s,projectId:i,readAgentId:o,node:l,targetUri:u,content:c,currentContent:d}){let f=l.uri,h=!!u&&u!==f,p=c!==d;if(!h&&!p)return{uri:f,moved:!1,contentChanged:!1};let g=e.resetEpoch,m=()=>g!==e.resetEpoch,x=f;if(h){let y=await yr({agentId:s,...i?{projectId:i}:{},id:l.id,uri:f,move:u},n);if(!y||y.ok!==!0)throw new Error(ga(y,"Move failed"));if(x=u,m())return{uri:x,moved:h,contentChanged:!1};a().replaceFilePath(l.storeKey||f,u)}if(p){let y=await yr({agentId:s,...i?{projectId:i}:{},id:l.id,uri:x,overwrite:{content:c}},n);if(!y||y.ok!==!0)throw new Error(ga(y,"Save failed"));if(m())return{uri:x,moved:h,contentChanged:p};let b=h?x:l.storeKey||f;a().updateFileContent(b,c),a().patchFileNode(b,{status:"pending_review"})}return await a().reconcileFolders({agentId:s,projectId:i,folders:Array.from(new Set([et(f),et(x)]))}),m()?{uri:x,moved:h,contentChanged:p}:(await a().openFile({agentId:s,projectId:i,uri:x,readAgentId:o,force:!0}),{uri:x,moved:h,contentChanged:p})},async refreshPendingCount({agentId:s,projectId:i}){if(!s)return;let o=++e.pendingCountSeq,l;try{l=await X0({agentId:s,...i?{projectId:i}:{}},n)}catch{return}if(o!==e.pendingCountSeq)return;let u=a();u.activeAgentId!==s||u.activeProjectId!==i||r(()=>({pendingCount:l}))},async markFileDeleted({agentId:s,projectId:i,node:o}){let l=e.resetEpoch,u=await yr({agentId:s,...i?{projectId:i}:{},id:o.id,uri:o.uri,delete:!0},n);if(!u||u.ok!==!0)throw new Error(ga(u,"Delete failed"));l===e.resetEpoch&&await a().reconcileFolders({agentId:s,projectId:i,folders:[et(o.uri)]})},async moveFileToFolder({agentId:s,projectId:i,fromUri:o,toFolderUri:l,id:u}){if(!s||!o||!l)return;let c=gt(o);if(!c)return;let d=l.endsWith("://")?`${l}${c}`:`${l}/${c}`;if(d===o)return;let f=et(o),h=a().files[o]?.type==="folder",p;try{p=await yr({agentId:s,...i?{projectId:i}:{},id:u,uri:o,move:d},n)}catch(m){console.error("[Filesystem] move failed",o,m),r(()=>({organizeError:"Move failed"}));return}if(p&&p.ok===!1){console.error("[Filesystem] move rejected",o,p.code,p.error),r(()=>({organizeError:ga(p,"Move rejected")})),await a().reconcileFolders({agentId:s,projectId:i,folders:[f,l]});return}let g=p?.warning==="moved_with_source_retained";g&&r(()=>({organizeError:"Copied to the destination, but the original could not be removed \u2014 both copies exist."})),h?(g||wc({get:a,set:r,fences:e,client:n},o),await a().ensureFolderLoaded({agentId:s,projectId:i,uri:l,force:!0})):(r(m=>{let x=m.openFiles.map(y=>y===o?d:y);return{activeFolderPath:l,openFiles:Array.from(new Set(x)),activeFile:m.activeFile===o?d:m.activeFile}}),g||a().replaceFilePath(o,d)),await a().reconcileFolders({agentId:s,projectId:i,folders:[f,l]})},async renameNode({agentId:s,projectId:i,uri:o,id:l,newName:u}){let c=(u??"").trim();if(!s||!o||!c||c===gt(o))return;let d=et(o),f=d.endsWith("://")?`${d}${c}`:`${d}/${c}`;if(f===o)return;let h=a().files[o]?.type==="folder",p;try{p=await yr({agentId:s,...i?{projectId:i}:{},id:l,uri:o,move:h?f:c},n)}catch(g){console.error("[Filesystem] rename failed",o,g),r(()=>({organizeError:"Rename failed"}));return}if(p&&p.ok===!1){console.error("[Filesystem] rename rejected",o,p.code,p.error),r(()=>({organizeError:ga(p,"Rename rejected")})),await a().reconcileFolders({agentId:s,projectId:i,folders:[d]});return}h?(wc({get:a,set:r,fences:e,client:n},o),await a().ensureFolderLoaded({agentId:s,projectId:i,uri:d,force:!0})):a().replaceFilePath(o,f),await a().reconcileFolders({agentId:s,projectId:i,folders:[d]})},async createNode({agentId:s,projectId:i,parentUri:o,name:l,kind:u}){let c=(l??"").trim();if(!s||!o||!c)return;let d=o.endsWith("://")?`${o}${c}`:`${o}/${c}`,f=e.resetEpoch;try{if(u==="folder"){let h=await yr({agentId:s,...i?{projectId:i}:{},uri:d,mkdir:!0},n);h?.ok&&f===e.resetEpoch?r(p=>({...yc(p,[o]),files:{...p.files,[d]:{storeKey:d,name:c,uri:d,type:"folder",parentUri:o,presence:"unindexed",lastUpdated:Date.now()}}})):h&&h.ok===!1&&(console.error("[Filesystem] create folder rejected",d,h.code,h.error),r(()=>({organizeError:ga(h,"Could not create folder")})))}else await dc({agentId:s,...i?{projectId:i}:{},file:new File([""],c),uri:o,tags:[]},n)}catch(h){console.error("[Filesystem] create failed",u,d,h),r(()=>({organizeError:`Could not create ${u==="folder"?"folder":"file"}`}))}await a().reconcileFolders({agentId:s,projectId:i,folders:[o]})},async pasteNodes({agentId:s,projectId:i,targetFolderUri:o,op:l,uris:u}){if(!s||!o||!Array.isArray(u)||u.length===0)return;let c=new Set([o]),d=[];for(let f of u){if(!f)continue;let h=gt(f);if(!h)continue;let p=o.endsWith("://")?`${o}${h}`:`${o}/${h}`;if(p!==f){c.add(et(f));try{if(l==="copy"){let g=await yr({agentId:s,...i?{projectId:i}:{},uri:f,copy:p},n);g&&g.ok===!1&&d.push(h)}else{let g=await yr({agentId:s,...i?{projectId:i}:{},uri:f,move:p},n);g&&g.ok===!1?d.push(h):g?.warning==="moved_with_source_retained"?d.push(`${h} (original retained)`):a().files[f]?.type==="folder"&&wc({get:a,set:r,fences:e,client:n},f)}}catch(g){console.error("[Filesystem] paste failed",l,f,g),d.push(h)}}}d.length&&r(()=>({organizeError:`${l==="copy"?"Copy":"Move"} incomplete: ${d.join(", ")}`})),await a().reconcileFolders({agentId:s,projectId:i,folders:Array.from(c)})},async deleteNodes({agentId:s,projectId:i,targets:o}){if(!s||!Array.isArray(o)||o.length===0)return;let l=new Set,u=[],c=null;for(let d of o){if(!d?.uri)continue;l.add(et(d.uri));let f=a().files[d.uri]?.type==="folder";try{let h=await yr({agentId:s,...i?{projectId:i}:{},id:d.id,uri:d.uri,delete:!0},n);if(h&&h.ok===!1){console.error("[Filesystem] delete rejected",d.uri,h.code,h.error),u.push(gt(d.uri)||d.uri),(typeof h.affected=="number"||h.failed?.length)&&(c={affected:h.affected,failed:h.failed});continue}f?wc({get:a,set:r,fences:e,client:n},d.uri):a().patchFileNode(d.uri,{status:"deleted"})}catch(h){console.error("[Filesystem] delete failed",d.uri,h),u.push(gt(d.uri)||d.uri)}}if(u.length){let d=c?.failed?.length?` \u2014 ${c.affected??0} removed, could not remove: ${c.failed.slice(0,5).join(", ")}${c.failed.length>5?"\u2026":""}`:"";r(()=>({organizeError:`Delete failed: ${u.join(", ")}${d}`}))}await a().reconcileFolders({agentId:s,projectId:i,folders:Array.from(l)})},async openFile({agentId:s,projectId:i,uri:o,readAgentId:l,force:u,revealPane:c=!0}){if(!s||!o)return;r(p=>{let g=p.openFiles.includes(o),m=p.previewEditorsEnabled&&!g&&!p.tabMeta[o]?.pinned,x=p.openFiles,y=p.tabMeta;if(m){let C=p.openFiles.find(L=>L!==o&&p.tabMeta[L]?.preview&&!p.tabMeta[L]?.pinned);C&&(x=x.filter(L=>L!==C),y={...y},delete y[C]),y={...y,[o]:{...y[o]||{},preview:!0}}}let b=x.includes(o)?x:[...x,o];if(b.length>Y2){let C=b.findIndex(L=>L!==o&&!p.tabMeta[L]?.pinned);C>=0&&(b=b.filter((L,P)=>P!==C))}return{openFiles:b,activeFile:o,activeAgentId:s,activeProjectId:i,...c?{activeWorkspaceTab:"file"}:{},tabMeta:y}}),a().autoExpandToFile(o);{let p=new Set([sr(o),...xa(o)]);for(let g of p)!g||g===o||a().ensureFolderLoaded({agentId:s,projectId:i,uri:g})}let d=a(),f=typeof d.fileBaseContentByPath[o]=="string"||typeof d.fileContentByPath[o]=="string"&&(d.fileContentByPath[o]?.length||0)>0;if(!u&&f)return;let h=e.resetEpoch;try{let p=await $i({agentId:l||s,...i?{projectId:i}:{},files:[o]},n);if(h!==e.resetEpoch)return;let g=Yi(p);if(g.length>0){let m=g[0],x=Ji(m),y=typeof m.error=="string"?m.error:void 0,b=typeof m.code=="string"&&m.code==="not_found";if(y&&b){a().removeFilePath(o);return}let C=typeof m.status=="string"?String(m.status):void 0,L=typeof m.category=="string"?m.category:void 0,P=Array.isArray(m.tags)?m.tags:void 0,w=m.metadata&&typeof m.metadata=="object"?m.metadata:void 0,k=typeof m.createdAt=="string"?m.createdAt:void 0,_=typeof m.updatedAt=="string"?m.updatedAt:void 0,M=m.version&&typeof m.version=="object"?m.version:void 0,R=typeof m.readSource=="string"?m.readSource:void 0,U=typeof m.id=="string"?m.id:void 0,v=typeof m.uri=="string"?String(m.uri):o,T=typeof m.agent_id=="string"?String(m.agent_id):l||s,V=typeof m.project_id=="string"?String(m.project_id):i||void 0,Y=qe(v)==="brain",N=M?.sync?.status,A=pc(M?.baseline);r(B=>{let K=B.files[v],te=B.fileContentByPath[v],ne=B.fileBaseContentByPath[v],pe=y&&typeof te=="string"?te:x,Se=y&&typeof ne=="string"?ne:x,le={...B.files},re=!!U||!!C||!!M,he=Y?"brain":K?.presence??(re?"synced":R==="live"?"unindexed":"synced");Qs(le,v,Date.now());let Ne=B.openFiles.includes(v)?B.openFiles:B.openFiles.map(Ee=>Ee===o?v:Ee);return{files:{...le,[v]:{...K||sh(v),id:U??K?.id,name:String(m.filename||K?.name||gt(v)),type:"file",uri:v,parentUri:et(v),status:C??K?.status,sourceAgentId:T,sourceProjectId:V??K?.sourceProjectId,lastUpdated:K?.lastUpdated??Date.now(),category:L??K?.category,tags:P??K?.tags,metadata:w??K?.metadata,createdAt:k??K?.createdAt,updatedAt:_??K?.updatedAt,version:M??K?.version,presence:he,readSource:R??K?.readSource}},fileContentByPath:{...B.fileContentByPath,[v]:pe},fileBaseContentByPath:{...B.fileBaseContentByPath,[v]:Se},fileErrorByPath:{...B.fileErrorByPath,[v]:y},filePrevByPath:{...B.filePrevByPath,[v]:A},openFiles:Array.from(new Set(Ne)),activeFile:v,tabMeta:{...B.tabMeta,[v]:{...B.tabMeta[v]||B.tabMeta[o]||{},name:String(m.filename||K?.name||gt(v)),status:C??K?.status,sourceAgentId:T}}}})}}catch(p){let g=p instanceof Error?p.message:"Read failed";if(console.error("[Filesystem] read failed",p),h!==e.resetEpoch)return;r(m=>({files:{...m.files,[o]:{...m.files[o]||sh(o),sourceAgentId:l||s,sourceProjectId:i||void 0,lastUpdated:m.files[o]?.lastUpdated??Date.now()}},fileErrorByPath:{...m.fileErrorByPath,[o]:g}}))}},async applyNav({agentId:s,projectId:i,nav:o,readAgentId:l,force:u}){if(!s||!o||o.kind!=="filesystem")return;let c=String(o.action||""),d=o.uri;if((c==="read"||c==="open"||c==="modify"||c==="save")&&d){await a().openFile({agentId:s,projectId:i,uri:d,readAgentId:l,force:u});return}if(c==="open-pending"){r(()=>({activeAgentId:s,activeProjectId:i})),a().setPendingPanelFilter(o.filter??{}),a().setWorkspacePanelOpen("pending",!0);return}if(c==="open-sources"||c==="open-vector-health"){r(()=>({activeAgentId:s,activeProjectId:i,...c==="open-vector-health"?{vectorHealthOpen:!0}:{}})),a().setWorkspacePanelOpen("sources",!0);return}c==="list"&&d&&r(f=>{let h=sr(d),p=f.expandedFolders.has(d)&&f.expandedFolders.has(h),g=f.activeAgentId===s,m=f.activeProjectId===i;return p&&g&&m?f:{...yc(f,[h,d]),activeAgentId:s,activeProjectId:i}})},async upload({agentId:s,projectId:i,file:o,uri:l}){if(!s)return;let u=l||"brain://docs";r(()=>({uploading:!0}));try{await dc({agentId:s,...i?{projectId:i}:{},file:o,uri:u,tags:["upload"]},n),await a().reconcileFolders({agentId:s,projectId:i,folders:[u]})}finally{r(()=>({uploading:!1}))}},async uploadMany({agentId:s,projectId:i,files:o,uri:l}){if(!s)return;let u=Array.isArray(o)?o.filter(Boolean):[];if(u.length===0)return;let c=l||"brain://docs";r(()=>({uploading:!0}));try{for(let d of u)await dc({agentId:s,...i?{projectId:i}:{},file:d,uri:c,tags:["upload"]},n);await a().reconcileFolders({agentId:s,projectId:i,folders:[c]})}finally{r(()=>({uploading:!1}))}},...t.projection?xx(t.projection):{}}))}var Qi=Xf()(I0(()=>({previewEditorsEnabled:!1,diffViewMode:"auto",activeUserId:null,activeAgentId:null,activeProjectId:null,contexts:{}}),{name:"neuralis.filesystem.tabs",version:2,migrate:(t,e)=>{if(e>=2)return t;let n=t??{},r=n.activeAgentId?ei(null,n.activeProjectId??null,n.activeAgentId):null;return{previewEditorsEnabled:n.previewEditorsEnabled??!1,diffViewMode:n.diffViewMode??"auto",activeUserId:null,activeAgentId:n.activeAgentId??null,activeProjectId:n.activeProjectId??null,contexts:r?{[r]:xc({...Zi(),openFiles:n.openFiles??[],activeFile:n.activeFile??null,tabMeta:n.tabMeta??{}})}:{}}},merge:(t,e)=>{let n=t;return n?{previewEditorsEnabled:n.previewEditorsEnabled??e.previewEditorsEnabled,diffViewMode:n.diffViewMode??e.diffViewMode,activeUserId:n.activeUserId??null,activeAgentId:n.activeAgentId??null,activeProjectId:n.activeProjectId??null,contexts:n.contexts??{},...n.windows?{windows:n.windows}:{}}:e},storage:Jf(()=>typeof window<"u"&&window.localStorage?window.localStorage:{getItem:()=>null,setItem:()=>{},removeItem:()=>{}}),partialize:t=>({previewEditorsEnabled:t.previewEditorsEnabled,diffViewMode:t.diffViewMode,activeUserId:t.activeUserId,activeAgentId:t.activeAgentId,activeProjectId:t.activeProjectId,contexts:t.contexts,...t.windows?{windows:t.windows}:{}})}));function Q2(t,e){return t.userId===e.userId&&t.projectId===e.projectId&&t.agentId===e.agentId}function eA(t){let{userId:e,projectId:n,agentId:r,...a}=t;return a}function tA(t){let e=Qi.getState(),n=e.windows?.[t.windowId],r=n&&Q2(n,t)?eA(n):void 0;return Z2({client:(0,Sx.createPackageApi)({slug:"brain-core",getProjectId:()=>t.projectId,getAgentId:()=>t.agentId}),windowId:t.windowId,userId:t.userId,projectId:t.projectId,agentId:t.agentId,previewEditorsEnabled:e.previewEditorsEnabled,diffViewMode:e.diffViewMode,...r?{projection:r}:{}})}var nA=["openFiles","activeFile","tabMeta","expandedFolders","sidebarView","activeWorkspaceTab","workspacePanels","activeFolderPath"];function rA(t,e){let n=JSON.stringify(xc(t.getState()));return t.subscribe((r,a)=>{if(r.previewEditorsEnabled!==a.previewEditorsEnabled||r.diffViewMode!==a.diffViewMode){let o=Qi.getState();(o.previewEditorsEnabled!==r.previewEditorsEnabled||o.diffViewMode!==r.diffViewMode)&&Qi.setState({previewEditorsEnabled:r.previewEditorsEnabled,diffViewMode:r.diffViewMode})}if(!nA.some(o=>r[o]!==a[o])||r.activeUserId!==e.userId||r.activeProjectId!==e.projectId||r.activeAgentId!==e.agentId)return;let s=xc(r),i=JSON.stringify(s);i!==n&&(n=i,Qi.setState(o=>({windows:{...o.windows??{},[e.windowId]:{userId:e.userId,projectId:e.projectId,agentId:e.agentId,...s}}})))})}var ch=new Set,Rx=null;function Mx(t){Rx=t}function aA(t,e){let n={identity:e,store:t};ch.add(n);let r=rA(t,e);return()=>{r(),ch.delete(n),t.getState().fenceInFlightWriters()}}function sA(t,e){return t.projectId!==e.projectId?!1:t.level==="project"?!0:t.agentId!==e.agentId?!1:t.level==="agent"||t.instanceId===e.windowId}function iA(t,e){if((t.level==="instance"||t.level==="widget")&&t.widgetType!==Px)return;let n=Qi.getState(),r=(o,l)=>l.projectId!==t.projectId?!1:t.level==="instance"||t.level==="widget"?o===t.instanceId&&l.agentId===t.agentId:e===null||l.userId!==e?!1:t.level==="project"||l.agentId===t.agentId,a=o=>t.level==="instance"?!1:t.level==="project"?o.startsWith(`${e??""}::${t.projectId}::`):o===ei(e,t.projectId,t.agentId),s=n.windows;for(let[o,l]of Object.entries(n.windows??{}))r(o,l)&&(s===n.windows&&(s={...n.windows}),delete s[o]);let i=n.contexts;for(let o of Object.keys(n.contexts))a(o)&&(i===n.contexts&&(i={...n.contexts}),delete i[o]);s===n.windows&&i===n.contexts||Qi.setState({contexts:i,...s?{windows:s}:{}})}function Tx(t){for(let e of ch)sA(t,e.identity)&&e.store.getState().resetClientState(t);iA(t,Rx)}function Dx(t,e,n,r){let a=(0,ya.useMemo)(()=>{if(!t||!e||!n||!r)return null;let s={windowId:t,userId:e,projectId:n,agentId:r};return{identity:s,store:tA(s)}},[t,e,n,r]);return(0,ya.useLayoutEffect)(()=>a?aA(a.store,a.identity):void 0,[a]),a?.store??null}var Fx=(0,ya.createContext)(null);function Ex({store:t,children:e}){return(0,ya.createElement)(Fx.Provider,{value:t},e)}function ti(){let t=(0,ya.useContext)(Fx);if(!t)throw new Error("useFilesystemStore must be used inside a Files window (FilesystemStoreProvider)");return t}function H(t){return C0(ti(),t)}var Vl=j(Wn(),1);var vc=j($e(),1);var Ox=t=>t?.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();function Bx(t,e,n=[]){if(e==null)throw new Error("[lucide]: iconNode is required when icon name is used");return{name:Ox(t),size:24,node:e,...n.length>0?{aliases:n}:{}}}var _x=t=>{let e="",n=!1;for(let r of t){if(r==="-"||r==="_"||r<=" "){n=e.length>0;continue}e.length===0?e+=r.toLowerCase():e+=n?r.toUpperCase():r,n=!1}return e};var Hx=t=>{let e=_x(t);return e.charAt(0).toUpperCase()+e.slice(1)};var pl=j($e(),1);var hl=(...t)=>t.filter((e,n,r)=>!!e&&e.trim()!==""&&r.indexOf(e)===n).join(" ").trim();var ms={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":2,"stroke-linecap":"round","stroke-linejoin":"round"};function dh(t){return t!=null}function Ux(t,e={}){let n=e.attributeNames??{},r=f=>n[f]??f,a=t.size??t.width??ms.width,s=t.size??t.height??ms.height,i=t.aliases?.filter(f=>typeof f=="string"&&f.trim()!=="").map(f=>`lucide-${f}`)??[],o=[...t.name?[`lucide-${t.name}`]:[],...i],l=e.className?.split(" ").filter(Boolean)??[],u=e.includeDefaultClasses===!1?hl(...l):hl("lucide",...o,...l),c=e.absoluteStrokeWidth?Number(e.strokeWidth??ms["stroke-width"])*Number(t.size??t.width??ms.width)/Number(e.size??e.width??ms.width):e.strokeWidth??ms["stroke-width"];return["svg",{...Object.entries(ms).reduce((f,[h,p])=>(f[r(h)]=p,f),{}),..."color"in e&&e.color&&{[r("stroke")]:e.color},..."size"in e&&dh(e.size)&&{[r("width")]:e.size,[r("height")]:e.size},..."width"in e&&dh(e.width)&&{[r("width")]:e.width},..."height"in e&&dh(e.height)&&{[r("height")]:e.height},[r("stroke-width")]:c,...u&&{[r("class")]:u},[r("viewBox")]:`0 0 ${a} ${s}`,...e.hasA11yProp===!1?{[r("aria-hidden")]:"true"}:{},..."attributes"in e&&e.attributes},t.node.map(f=>{let[h,p,g]=f,m=e.nonScalingStroke?{[r("vector-effect")]:"non-scaling-stroke",...p}:p;return g?[h,m,g]:[h,m]})]}function Gx(t,e={}){return Ux(t,{...e,attributeNames:{...e.attributeNames,class:"className","stroke-width":"strokeWidth","stroke-linecap":"strokeLinecap","stroke-linejoin":"strokeLinejoin","vector-effect":"vectorEffect"}})}var Wx=t=>{for(let e in t)if(e.startsWith("aria-")||e==="role"||e==="title")return!0;return!1};var eo=j($e(),1);var oA=(0,eo.createContext)({});var zx=()=>(0,eo.useContext)(oA);var jx=(0,pl.forwardRef)(({color:t,size:e,width:n,height:r,strokeWidth:a,absoluteStrokeWidth:s,nonScalingStroke:i,className:o="",children:l,iconNode:u=[],icon:c={node:u,aliases:[],size:24},...d},f)=>{let{size:h=24,strokeWidth:p=2,absoluteStrokeWidth:g=!1,nonScalingStroke:m=!1,color:x="currentColor",className:y=""}=zx()??{},b=!!l||Wx(d),[C,L,P=[]]=Gx(c,{color:t??x,width:n??e??h,height:r??e??h,strokeWidth:a??p,absoluteStrokeWidth:s??g,nonScalingStroke:i??m,className:hl(y,o),hasA11yProp:b,attributes:d});return(0,pl.createElement)(C,{ref:f,...L},[...P.map(([w,k])=>(0,pl.createElement)(w,k)),...Array.isArray(l)?l:[l]])});function W(t,e=[],n=[]){let r=typeof t=="string"?Bx(t,e,n):t,a=(0,vc.forwardRef)(({className:s,...i},o)=>(0,vc.createElement)(jx,{ref:o,icon:r,className:s,...i}));return r.name&&(a.displayName=Hx(r.name)),a}var Vx={name:"archive",size:24,node:[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]]};Vx.node;var to=W(Vx);var qx={name:"arrow-down",size:24,node:[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]};qx.node;var ml=W(qx);var $x={name:"arrow-right",size:24,node:[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]};$x.node;var no=W($x);var Kx={name:"arrow-up-down",size:24,node:[["path",{d:"m21 16-4 4-4-4",key:"f6ql7i"}],["path",{d:"M17 20V4",key:"1ejh1v"}],["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}]]};Kx.node;var gl=W(Kx);var Xx={name:"arrow-up",size:24,node:[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]};Xx.node;var xl=W(Xx);var Yx={name:"bot",size:24,node:[["path",{d:"M12 8V4H8",key:"hb8ula"}],["rect",{width:"16",height:"12",x:"4",y:"8",rx:"2",key:"enze0r"}],["path",{d:"M2 14h2",key:"vft8re"}],["path",{d:"M20 14h2",key:"4cs60a"}],["path",{d:"M15 13v2",key:"1xurst"}],["path",{d:"M9 13v2",key:"rq6x2g"}]]};Yx.node;var yl=W(Yx);var Jx={name:"braces",size:24,node:[["path",{d:"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1",key:"ezmyqa"}],["path",{d:"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1",key:"e1hn23"}]],aliases:["curly-braces"]};Jx.node;var ba=W(Jx);var Zx={name:"check-check",size:24,node:[["path",{d:"M18 6 7 17l-5-5",key:"116fxf"}],["path",{d:"m22 10-7.5 7.5L13 16",key:"ke71qq"}]]};Zx.node;var gs=W(Zx);var Qx={name:"check",size:24,node:[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]};Qx.node;var Dn=W(Qx);var ey={name:"chevron-down",size:24,node:[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]};ey.node;var Et=W(ey);var ty={name:"chevron-left",size:24,node:[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]]};ty.node;var bl=W(ty);var ny={name:"chevron-right",size:24,node:[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]};ny.node;var un=W(ny);var ry={name:"chevron-up",size:24,node:[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]]};ry.node;var qa=W(ry);var ay={name:"circle-alert",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]],aliases:["alert-circle"]};ay.node;var xs=W(ay);var sy={name:"circle-check",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m16 9-5.5 5.5L8 12",key:"xofnsj"}]],aliases:["check-circle-2"]};sy.node;var Qr=W(sy);var iy={name:"circle-question-mark",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3",key:"1u773s"}],["path",{d:"M12 17h.01",key:"p32p05"}]],aliases:["help-circle","circle-help"]};iy.node;var ea=W(iy);var oy={name:"circle-x",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]],aliases:["x-circle"]};oy.node;var ta=W(oy);var ly={name:"clipboard-paste",size:24,node:[["path",{d:"M11 14h10",key:"1w8e9d"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v1.344",key:"1e62lh"}],["path",{d:"m17 18 4-4-4-4",key:"z2g111"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 1.793-1.113",key:"bjbb7m"}],["rect",{x:"8",y:"2",width:"8",height:"4",rx:"1",key:"ublpy"}]]};ly.node;var wl=W(ly);var uy={name:"clock-3",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 6v6h4",key:"135r8i"}]]};uy.node;var wa=W(uy);var cy={name:"cloud",size:24,node:[["path",{d:"M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z",key:"p7xjir"}]]};cy.node;var vl=W(cy);var dy={name:"cloud-upload",size:24,node:[["path",{d:"M12 13v8",key:"1l5pq0"}],["path",{d:"M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242",key:"1pljnt"}],["path",{d:"m8 17 4-4 4 4",key:"1quai1"}]],aliases:["upload-cloud"]};dy.node;var Mr=W(dy);var fy={name:"columns-2",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M12 3v18",key:"108xh3"}]],aliases:["columns"]};fy.node;var ys=W(fy);var hy={name:"copy",size:24,node:[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]};hy.node;var na=W(hy);var py={name:"corner-up-right",size:24,node:[["path",{d:"m15 14 5-5-5-5",key:"12vg1m"}],["path",{d:"M4 20v-7a4 4 0 0 1 4-4h12",key:"1lu4f8"}]]};py.node;var kl=W(py);var my={name:"database",size:24,node:[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]]};my.node;var ir=W(my);var gy={name:"ellipsis",size:24,node:[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]],aliases:["more-horizontal"]};gy.node;var bs=W(gy);var xy={name:"eye",size:24,node:[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]};xy.node;var Sl=W(xy);var yy={name:"file-code",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 12.5 8 15l2 2.5",key:"1tg20x"}],["path",{d:"m14 12.5 2 2.5-2 2.5",key:"yinavb"}]]};yy.node;var Cl=W(yy);var by={name:"file-code-corner",size:24,node:[["path",{d:"M4 12.15V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2h-3.35",key:"1wthlu"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"m5 16-3 3 3 3",key:"331omg"}],["path",{d:"m9 22 3-3-3-3",key:"lsp7cz"}]],aliases:["file-code-2"]};by.node;var $a=W(by);var wy={name:"file-diff",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M9 10h6",key:"9gxzsh"}],["path",{d:"M12 13V7",key:"h0r20n"}],["path",{d:"M9 17h6",key:"r8uit2"}]]};wy.node;var Ka=W(wy);var vy={name:"file-exclamation-point",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]],aliases:["file-warning"]};vy.node;var ws=W(vy);var ky={name:"file-image",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["circle",{cx:"10",cy:"12",r:"2",key:"737tya"}],["path",{d:"m20 17-1.296-1.296a2.41 2.41 0 0 0-3.408 0L9 22",key:"wt3hpn"}]]};ky.node;var Il=W(ky);var Sy={name:"file-pen",size:24,node:[["path",{d:"M12.659 22H18a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v9.34",key:"o6klzx"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10.378 12.622a1 1 0 0 1 3 3.003L8.36 20.637a2 2 0 0 1-.854.506l-2.867.837a.5.5 0 0 1-.62-.62l.836-2.869a2 2 0 0 1 .506-.853z",key:"zhnas1"}]],aliases:["file-edit"]};Sy.node;var vs=W(Sy);var Cy={name:"file-play",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M15.033 13.44a.647.647 0 0 1 0 1.12l-4.065 2.352a.645.645 0 0 1-.968-.56v-4.704a.645.645 0 0 1 .967-.56z",key:"1tzo1f"}]],aliases:["file-video"]};Cy.node;var ks=W(Cy);var Iy={name:"file-plus-corner",size:24,node:[["path",{d:"M11.35 22H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v5.35",key:"17jvcc"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M14 19h6",key:"bvotb8"}],["path",{d:"M17 16v6",key:"18yu1i"}]],aliases:["file-plus-2"]};Iy.node;var Ss=W(Iy);var Ly={name:"file-plus",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M9 15h6",key:"cctwl0"}],["path",{d:"M12 18v-6",key:"17g6i2"}]]};Ly.node;var Cs=W(Ly);var Ay={name:"file-text",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]]};Ay.node;var va=W(Ay);var Py={name:"file",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}]]};Py.node;var Ll=W(Py);var Ny={name:"folder-open",size:24,node:[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]]};Ny.node;var Is=W(Ny);var Ry={name:"folder-plus",size:24,node:[["path",{d:"M12 10v6",key:"1bos4e"}],["path",{d:"M9 13h6",key:"1uhe8q"}],["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]};Ry.node;var br=W(Ry);var My={name:"folder-tree",size:24,node:[["path",{d:"M20 10a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1h-2.5a1 1 0 0 1-.8-.4l-.9-1.2A1 1 0 0 0 15 3h-2a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z",key:"hod4my"}],["path",{d:"M20 21a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1h-2.9a1 1 0 0 1-.88-.55l-.42-.85a1 1 0 0 0-.92-.6H13a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z",key:"w4yl2u"}],["path",{d:"M3 5a2 2 0 0 0 2 2h3",key:"f2jnh7"}],["path",{d:"M3 3v13a2 2 0 0 0 2 2h3",key:"k8epm1"}]]};My.node;var Al=W(My);var Ty={name:"folder",size:24,node:[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]};Ty.node;var Tr=W(Ty);var Dy={name:"git-branch",size:24,node:[["path",{d:"M15 6a9 9 0 0 0-9 9V3",key:"1cii5b"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}]]};Dy.node;var Cn=W(Dy);var Fy={name:"git-commit-horizontal",size:24,node:[["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}],["line",{x1:"3",x2:"9",y1:"12",y2:"12",key:"1dyftd"}],["line",{x1:"15",x2:"21",y1:"12",y2:"12",key:"oup4p8"}]],aliases:["git-commit"]};Fy.node;var Dr=W(Fy);var Ey={name:"git-compare-arrows",size:24,node:[["circle",{cx:"5",cy:"6",r:"3",key:"1qnov2"}],["path",{d:"M12 6h5a2 2 0 0 1 2 2v7",key:"1yj91y"}],["path",{d:"m15 9-3-3 3-3",key:"1lwv8l"}],["circle",{cx:"19",cy:"18",r:"3",key:"1qljk2"}],["path",{d:"M12 18H7a2 2 0 0 1-2-2V9",key:"16sdep"}],["path",{d:"m9 15 3 3-3 3",key:"1m3kbl"}]]};Ey.node;var or=W(Ey);var Oy={name:"git-compare",size:24,node:[["circle",{cx:"18",cy:"18",r:"3",key:"1xkwt0"}],["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M13 6h3a2 2 0 0 1 2 2v7",key:"1yeb86"}],["path",{d:"M11 18H8a2 2 0 0 1-2-2V9",key:"19pyzm"}]]};Oy.node;var ro=W(Oy);var By={name:"hard-drive",size:24,node:[["path",{d:"M10 16h.01",key:"1bzywj"}],["path",{d:"M2.212 11.577a2 2 0 0 0-.212.896V18a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-5.527a2 2 0 0 0-.212-.896L18.55 5.11A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"18tbho"}],["path",{d:"M21.946 12.013H2.054",key:"zqlbp7"}],["path",{d:"M6 16h.01",key:"1pmjb7"}]]};By.node;var zn=W(By);var _y={name:"info",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]]};_y.node;var Pl=W(_y);var Hy={name:"link-2",size:24,node:[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]]};Hy.node;var Nl=W(Hy);var Uy={name:"link-2-off",size:24,node:[["path",{d:"M9 17H7A5 5 0 0 1 7 7",key:"10o201"}],["path",{d:"M15 7h2a5 5 0 0 1 4 8",key:"1d3206"}],["line",{x1:"8",x2:"12",y1:"12",y2:"12",key:"rvw6j4"}],["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}]]};Uy.node;var Rl=W(Uy);var Gy={name:"list",size:24,node:[["path",{d:"M3 5h.01",key:"18ugdj"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 19h.01",key:"noohij"}],["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 19h13",key:"m83p4d"}]]};Gy.node;var ni=W(Gy);var Wy={name:"loader-circle",size:24,node:[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],aliases:["loader-2"]};Wy.node;var We=W(Wy);var zy={name:"lock",size:24,node:[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 10 0v4",key:"fwvmzm"}]]};zy.node;var ri=W(zy);var jy={name:"minus",size:24,node:[["path",{d:"M5 12h14",key:"1ays0h"}]]};jy.node;var ai=W(jy);var Vy={name:"mouse-pointer-click",size:24,node:[["path",{d:"M14 4.1 12 6",key:"ita8i4"}],["path",{d:"m5.1 8-2.9-.8",key:"1go3kf"}],["path",{d:"m6 12-1.9 2",key:"mnht97"}],["path",{d:"M7.2 2.2 8 5.1",key:"1cfko1"}],["path",{d:"M9.037 9.69a.498.498 0 0 1 .653-.653l11 4.5a.5.5 0 0 1-.074.949l-4.349 1.041a1 1 0 0 0-.74.739l-1.04 4.35a.5.5 0 0 1-.95.074z",key:"s0h3yz"}]]};Vy.node;var Ml=W(Vy);var qy={name:"move-right",size:24,node:[["path",{d:"M18 8L22 12L18 16",key:"1r0oui"}],["path",{d:"M2 12H22",key:"1m8cig"}]]};qy.node;var Tl=W(qy);var $y={name:"music-4",size:24,node:[["path",{d:"M9 18V5l12-2v13",key:"1jmyc2"}],["path",{d:"m9 9 12-2",key:"1e64n2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["circle",{cx:"18",cy:"16",r:"3",key:"1hluhg"}]]};$y.node;var Dl=W($y);var Ky={name:"network",size:24,node:[["rect",{x:"16",y:"16",width:"6",height:"6",rx:"1",key:"4q2zg0"}],["rect",{x:"2",y:"16",width:"6",height:"6",rx:"1",key:"8cvhb9"}],["rect",{x:"9",y:"2",width:"6",height:"6",rx:"1",key:"1egb70"}],["path",{d:"M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3",key:"1jsf9p"}],["path",{d:"M12 12V8",key:"2874zd"}]]};Ky.node;var Fl=W(Ky);var Xy={name:"package",size:24,node:[["path",{d:"M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z",key:"1a0edw"}],["path",{d:"M12 22V12",key:"d0xqtd"}],["polyline",{points:"3.29 7 12 12 20.71 7",key:"ousv84"}],["path",{d:"m7.5 4.27 9 5.15",key:"1c824w"}]]};Xy.node;var wr=W(Xy);var Yy={name:"panel-left",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}]],aliases:["sidebar"]};Yy.node;var Ls=W(Yy);var Jy={name:"pen-line",size:24,node:[["path",{d:"M13 21h8",key:"1jsn5i"}],["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}]],aliases:["edit-3"]};Jy.node;var As=W(Jy);var Zy={name:"pencil",size:24,node:[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]};Zy.node;var si=W(Zy);var Qy={name:"pin",size:24,node:[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]]};Qy.node;var ii=W(Qy);var eb={name:"play",size:24,node:[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z",key:"10ikf1"}]]};eb.node;var El=W(eb);var tb={name:"plus",size:24,node:[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]};tb.node;var Fn=W(tb);var nb={name:"radio",size:24,node:[["path",{d:"M16.247 7.761a6 6 0 0 1 0 8.478",key:"1fwjs5"}],["path",{d:"M19.075 4.933a10 10 0 0 1 0 14.134",key:"ehdyv1"}],["path",{d:"M4.925 19.067a10 10 0 0 1 0-14.134",key:"1q22gi"}],["path",{d:"M7.753 16.239a6 6 0 0 1 0-8.478",key:"r2q7qm"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]]};nb.node;var Xa=W(nb);var rb={name:"refresh-ccw",size:24,node:[["path",{d:"M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"14sxne"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16",key:"1hlbsb"}],["path",{d:"M16 16h5v5",key:"ccwih5"}]]};rb.node;var ka=W(rb);var ab={name:"refresh-cw",size:24,node:[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]};ab.node;var _t=W(ab);var sb={name:"rotate-ccw",size:24,node:[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]]};sb.node;var oi=W(sb);var ib={name:"save",size:24,node:[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]]};ib.node;var li=W(ib);var ob={name:"scan-search",size:24,node:[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2",key:"aa7l1z"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2",key:"4qcy5o"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2",key:"6vwrx8"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2",key:"ioqczr"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}],["path",{d:"m16 16-1.9-1.9",key:"1dq9hf"}]]};ob.node;var Ya=W(ob);var lb={name:"scissors",size:24,node:[["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M8.12 8.12 12 12",key:"1alkpv"}],["path",{d:"M20 4 8.12 15.88",key:"xgtan2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M14.8 14.8 20 20",key:"ptml3r"}]]};lb.node;var Ol=W(lb);var ub={name:"search",size:24,node:[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]]};ub.node;var Bl=W(ub);var cb={name:"settings",size:24,node:[["path",{d:"M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915",key:"1i5ecw"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]};cb.node;var ao=W(cb);var db={name:"shield-alert",size:24,node:[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]]};db.node;var Sa=W(db);var fb={name:"shield-check",size:24,node:[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]};fb.node;var so=W(fb);var hb={name:"shield-off",size:24,node:[["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71",key:"1jlk70"}],["path",{d:"M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264",key:"18rp1v"}]]};hb.node;var _l=W(hb);var pb={name:"shield",size:24,node:[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]]};pb.node;var Ps=W(pb);var mb={name:"sigma",size:24,node:[["path",{d:"M18 7V5a1 1 0 0 0-1-1H6.5a.5.5 0 0 0-.4.8l4.5 6a2 2 0 0 1 0 2.4l-4.5 6a.5.5 0 0 0 .4.8H17a1 1 0 0 0 1-1v-2",key:"wuwx1p"}]]};mb.node;var Hl=W(mb);var gb={name:"sliders-horizontal",size:24,node:[["path",{d:"M10 5H3",key:"1qgfaw"}],["path",{d:"M12 19H3",key:"yhmn1j"}],["path",{d:"M14 3v4",key:"1sua03"}],["path",{d:"M16 17v4",key:"1q0r14"}],["path",{d:"M21 12h-9",key:"1o4lsq"}],["path",{d:"M21 19h-5",key:"1rlt1p"}],["path",{d:"M21 5h-7",key:"1oszz2"}],["path",{d:"M8 10v4",key:"tgpxqk"}],["path",{d:"M8 12H3",key:"a7s4jb"}]]};gb.node;var ui=W(gb);var xb={name:"square",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]};xb.node;var Ul=W(xb);var yb={name:"tag",size:24,node:[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]]};yb.node;var Gl=W(yb);var bb={name:"terminal",size:24,node:[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]]};bb.node;var io=W(bb);var wb={name:"text-align-justify",size:24,node:[["path",{d:"M3 5h18",key:"1u36vt"}],["path",{d:"M3 12h18",key:"1i2n21"}],["path",{d:"M3 19h18",key:"awlh7x"}]],aliases:["align-justify"]};wb.node;var Ns=W(wb);var vb={name:"trash",size:24,node:[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]],aliases:["trash-2"]};vb.node;var Nt=W(vb);var kb={name:"triangle-alert",size:24,node:[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]],aliases:["alert-triangle"]};kb.node;var ot=W(kb);var Sb={name:"undo-2",size:24,node:[["path",{d:"M9 14 4 9l5-5",key:"102s5s"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11",key:"f3b9sd"}]]};Sb.node;var Ca=W(Sb);var Cb={name:"unfold-vertical",size:24,node:[["path",{d:"M12 22v-6",key:"6o8u61"}],["path",{d:"M12 8V2",key:"1wkif3"}],["path",{d:"M4 12H2",key:"rhcxmi"}],["path",{d:"M10 12H8",key:"s88cx1"}],["path",{d:"M16 12h-2",key:"10asgb"}],["path",{d:"M22 12h-2",key:"14jgyd"}],["path",{d:"m15 19-3 3-3-3",key:"11eu04"}],["path",{d:"m15 5-3-3-3 3",key:"itvq4r"}]]};Cb.node;var Wl=W(Cb);var Ib={name:"unlink",size:24,node:[["path",{d:"m18.84 12.25 1.72-1.71h-.02a5.004 5.004 0 0 0-.12-7.07 5.006 5.006 0 0 0-6.95 0l-1.72 1.71",key:"yqzxt4"}],["path",{d:"m5.17 11.75-1.71 1.71a5.004 5.004 0 0 0 .12 7.07 5.006 5.006 0 0 0 6.95 0l1.71-1.71",key:"4qinb0"}],["line",{x1:"8",x2:"8",y1:"2",y2:"5",key:"1041cp"}],["line",{x1:"2",x2:"5",y1:"8",y2:"8",key:"14m1p5"}],["line",{x1:"16",x2:"16",y1:"19",y2:"22",key:"rzdirn"}],["line",{x1:"19",x2:"22",y1:"16",y2:"16",key:"ox905f"}]]};Ib.node;var zl=W(Ib);var Lb={name:"upload",size:24,node:[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]]};Lb.node;var Ia=W(Lb);var Ab={name:"wand-sparkles",size:24,node:[["path",{d:"m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72",key:"ul74o6"}],["path",{d:"m14 7 3 3",key:"1r5n42"}],["path",{d:"M5 6v4",key:"ilb8ba"}],["path",{d:"M19 14v4",key:"blhpug"}],["path",{d:"M10 2v2",key:"7u0qdc"}],["path",{d:"M7 8H3",key:"zfb6yr"}],["path",{d:"M21 16h-4",key:"1cnmox"}],["path",{d:"M11 3H9",key:"1obp7u"}]],aliases:["wand-2"]};Ab.node;var Rs=W(Ab);var Pb={name:"wrench",size:24,node:[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z",key:"1ngwbx"}]]};Pb.node;var ci=W(Pb);var Nb={name:"x",size:24,node:[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]};Nb.node;var Ht=W(Nb);var Rb={name:"zap",size:24,node:[["path",{d:"M15.914 4a1.5 1.5 0 00-2.474-1.561l-9 9A1.5 1.5 0 005.5 14h4.002a.5.5 0 01.471.666L8.086 20a1.5 1.5 0 002.475 1.56l9-9A1.5 1.5 0 0018.5 10h-3.997a.5.5 0 01-.472-.667z",key:"1v7up4"}]]};Rb.node;var jl=W(Rb);var Xt=j(ie(),1);function hh(t){let{agentId:e,agentName:n,agentIcon:r,agentAccent:a,supportsSources:s=!0}=t,i=(0,Vl.resolveAgentIcon)(r),o=H(m=>m.toggleSidebar),l=H(m=>m.sidebarOpen),u=H(m=>m.refreshTree),c=H(m=>m.activeProjectId),d=H(m=>m.uploading),f=H(m=>m.workspacePanels),h=H(m=>m.setWorkspacePanelOpen),p=H(m=>m.activeWorkspaceTab),g=H(m=>m.pendingCount);return(0,Xt.jsxs)("div",{className:"h-10 flex items-center px-3 shrink-0 gap-2.5",style:{backgroundColor:"transparent",borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[(0,Xt.jsx)("div",{className:"flex items-center gap-1",children:(0,Xt.jsx)("button",{onClick:o,className:`p-1.5 rounded-lg transition-colors ${l?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white"}`,title:"Toggle Sidebar",children:(0,Xt.jsx)(Ls,{className:"w-4 h-4"})})}),(0,Xt.jsx)("div",{className:"h-4 w-[1px] bg-white/10"}),(0,Xt.jsx)("span",{className:"inline-flex h-6 w-6 shrink-0 items-center justify-center",style:{color:a||"var(--icon-muted)"},title:n||"Agent","aria-label":n||"Agent",children:(0,Xt.jsx)(i,{className:"h-4 w-4"})}),(0,Xt.jsxs)("div",{className:"flex items-center gap-1",children:[(0,Xt.jsx)("button",{onClick:()=>u({agentId:e,projectId:c??null}),className:"p-1.5 rounded-lg text-white/50 hover:bg-white/5 hover:text-white transition-colors",title:"Refresh",children:(0,Xt.jsx)(_t,{className:"w-4 h-4"})}),(0,Xt.jsx)("button",{className:"p-1.5 rounded-lg text-white/50 hover:bg-white/5 hover:text-white transition-colors disabled:opacity-50 disabled:cursor-not-allowed",title:"Upload files",disabled:d,onClick:()=>{if(f.upload&&p==="upload"){h("upload",!1);return}h("upload",!0)},children:d?(0,Xt.jsx)(We,{className:"w-4 h-4 animate-spin"}):(0,Xt.jsx)(Ia,{className:"w-4 h-4"})}),s?(0,Xt.jsx)("button",{className:`p-1.5 rounded-lg transition-colors ${f.sources&&p==="sources"?"bg-cyan-500/15 text-cyan-400":"text-white/50 hover:bg-white/5 hover:text-cyan-300"}`,title:"Data Sources & Sync",onClick:()=>{if(f.sources&&p==="sources"){h("sources",!1);return}h("sources",!0)},children:(0,Xt.jsx)(ir,{className:"w-4 h-4"})}):null,s?(0,Xt.jsx)(Vl.SkillLauncher,{variant:"icon",size:"sm",skill:"sync",packageId:"@neuralis/brain-core",label:"Sync sources with the agent",icon:"brain"}):null,(0,Xt.jsx)(Vl.SkillLauncher,{variant:"icon",size:"sm",skill:"manage-files",packageId:"@neuralis/brain-core",scripts:["scripts/mkdir.sh","scripts/copy.sh","scripts/modify.sh","scripts/search.sh"],label:"Create, copy, edit or search files with the agent",icon:"Folder"}),(0,Xt.jsx)("button",{className:`p-1.5 rounded-lg transition-colors ${f.packages&&p==="packages"?"bg-violet-500/15 text-violet-300":"text-white/50 hover:bg-white/5 hover:text-violet-200"}`,title:"Packages \u2014 trust & build",onClick:()=>{if(f.packages&&p==="packages"){h("packages",!1);return}h("packages",!0)},children:(0,Xt.jsx)(wr,{className:"w-4 h-4"})}),(0,Xt.jsxs)("button",{className:`relative p-1.5 rounded-lg transition-colors ${f.pending&&p==="pending"?"bg-amber-500/15 text-amber-300":"text-white/50 hover:bg-white/5 hover:text-amber-200"}`,title:g>0?`Pending changes \u2014 ${g} to review`:"Pending changes \u2014 review, approve & revert",onClick:()=>{if(f.pending&&p==="pending"){h("pending",!1);return}h("pending",!0)},children:[(0,Xt.jsx)(Ka,{className:"w-4 h-4"}),g>0?(0,Xt.jsx)("span",{"data-testid":"pending-count-badge",className:"absolute -top-1 -right-1 min-w-[14px] rounded-full px-1 text-center text-[9px] leading-[14px] font-semibold bg-amber-500/15 text-amber-300",children:g>=1e3?"1000+":g}):null]})]})]})}var _e=j($e(),1),F1=j(Wn(),1);function Ja(t,e){let n=t.grantedFeatures;return n?n.includes("*")||n.includes(e):!1}function oo(t,e){let n=e?.features;return!n||n.length===0?!0:n.every(r=>Ja(t,r))}var ph={owner:1,admin:2,manager:10,member:20,viewer:30};var lA=ph.member,Db=Number.MAX_SAFE_INTEGER;var ra=j($e(),1),Vb=j(Za(),1);function Bb(t){return typeof t=="object"?t.key:t}function _b(t,e){let n=t.length;return new Proxy(t,{get(r,a,s){if(typeof a=="string"){let i=a.charCodeAt(0);if(i>=48&&i<=57){let o=+a;if(Number.isInteger(o)&&o>=0&&o<n){let l=r[o];if(typeof l!="object"){let u=e[o*2];l=r[o]={index:o,key:l,start:u,size:e[o*2+1],end:u+e[o*2+1],lane:0}}return l}}if(a==="length")return n}return Reflect.get(r,a,s)}})}function di(t,e,n){let r=n.initialDeps??[],a,s=!0;function i(){var o;let u=0,c=t();if(!(c.length!==r.length||c.some((h,p)=>r[p]!==h)))return a;r=c;let f=0;return a=e(...c),n?.onChange&&!(s&&n.skipInitialOnChange)&&n.onChange(a),s=!1,a}return i.updateDeps=o=>{r=o},i}function gh(t,e){if(t===void 0)throw new Error(`Unexpected undefined${e?`: ${e}`:""}`);return t}var xh=(t,e)=>Math.abs(t-e)<1.01,Hb=(t,e,n)=>{let r;return Object.assign(function(...a){t.clearTimeout(r),r=t.setTimeout(()=>e.apply(this,a),n)},{cancel:()=>{t.clearTimeout(r)}})};var ql,yh=()=>{if(ql!==void 0)return ql;if(typeof navigator>"u")return ql=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return ql=!0;let t=navigator.maxTouchPoints;return ql=navigator.platform==="MacIntel"&&t!==void 0&&t>0};var Ub=t=>{let{offsetWidth:e,offsetHeight:n}=t;return{width:e,height:n}},mA=t=>t,gA=t=>{let e=Math.max(t.startIndex-t.overscan,0),r=Math.min(t.endIndex+t.overscan,t.count-1)-e+1,a=new Array(r);for(let s=0;s<r;s++)a[s]=e+s;return a},Gb=(t,e)=>{let n=t.scrollElement;if(!n)return;let r=t.targetWindow;if(!r)return;let a=i=>{let{width:o,height:l}=i;e({width:Math.round(o),height:Math.round(l)})};if(a(Ub(n)),!r.ResizeObserver)return()=>{};let s=new r.ResizeObserver(i=>{let o=()=>{let l=i[0];if(l?.borderBoxSize){let u=l.borderBoxSize[0];if(u){a({width:u.inlineSize,height:u.blockSize});return}}a(Ub(n))};t.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(o):o()});return s.observe(n,{box:"border-box"}),()=>{s.unobserve(n)}},kc={passive:!0};var xA=typeof window>"u"?!0:"onscrollend"in window,yA=(t,e,n)=>{let r=t.scrollElement;if(!r)return;let a=t.targetWindow;if(!a)return;let s=t.options.useScrollendEvent&&xA,i=0,o=s?null:Hb(a,()=>e(n(r),!1),t.options.isScrollingResetDelay),l=d=>()=>{i=n(r),o?.(),e(i,d)},u=l(!0),c=l(!1);return r.addEventListener("scroll",u,kc),s&&r.addEventListener("scrollend",c,kc),()=>{r.removeEventListener("scroll",u),s&&r.removeEventListener("scrollend",c),o?.cancel()}},Wb=(t,e)=>yA(t,e,n=>{let{horizontal:r,isRtl:a}=t.options;return r?n.scrollLeft*(a&&-1||1):n.scrollTop});var bA=(t,e,n)=>{if(n.options.useCachedMeasurements){let r=n.indexFromElement(t),a=n.options.getItemKey(r);return n.itemSizeCache.get(a)??n.options.estimateSize(r)}if(e?.borderBoxSize){let r=e.borderBoxSize[0];if(r)return Math.round(r[n.options.horizontal?"inlineSize":"blockSize"])}if(!e){let r=n.indexFromElement(t),a=n.options.getItemKey(r),s=n.itemSizeCache.get(a);if(s!==void 0)return s}return t[n.options.horizontal?"offsetWidth":"offsetHeight"]},wA=(t,{adjustments:e=0,behavior:n},r)=>{var a,s;(s=(a=r.scrollElement)==null?void 0:a.scrollTo)==null||s.call(a,{[r.options.horizontal?"left":"top"]:t+e,behavior:n})};var zb=wA;function vA(t,e,n,r){if(e===0)return!1;let a=r(0),s=new Set,i=0;for(;i<t;){let l=n(i);if(l===a)break;s.add(l),i++}let o=t-i;if(o===0||o>=e)return!1;for(let l=0;l<o;l++)if(r(l)!==n(i+l))return!1;for(let l=o;l<e;l++)if(s.has(r(l)))return!1;return!0}var Sc=class{constructor(e){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache=new Map,this.itemSizeCacheVersion=0,this.laneAssignments=new Map,this.pendingMin=null,this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.pendingScrollAnchor=null,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._intendedScrollOffset=null,this._clampedAdjustment=null,this.elementsCache=new Map,this.now=()=>{var n,r,a;return((a=(r=(n=this.targetWindow)==null?void 0:n.performance)==null?void 0:r.now)==null?void 0:a.call(r))??Date.now()},this.observer=(()=>{let n=null,r=()=>n||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:n=new this.targetWindow.ResizeObserver(a=>{a.forEach(s=>{let i=()=>{let o=s.target,l=this.indexFromElement(o);if(!o.isConnected){this.observer.unobserve(o);for(let[u,c]of this.elementsCache)if(c===o){this.elementsCache.delete(u);break}return}this.isIndexInRange(l)&&this.shouldMeasureDuringScroll(l)&&this.resizeItem(l,this.options.measureElement(o,s,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(i):i()})}));return{disconnect:()=>{var a;(a=r())==null||a.disconnect(),n=null},observe:a=>{var s;return(s=r())==null?void 0:s.observe(a,{box:"border-box"})},unobserve:a=>{var s;return(s=r())==null?void 0:s.unobserve(a)}}})(),this.range=null,this.setOptions=n=>{var r;let a={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:mA,rangeExtractor:gA,onChange:()=>{},measureElement:bA,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,anchorTo:"start",followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:"estimate",useCachedMeasurements:!1};for(let d in n){let f=n[d];f!==void 0&&(a[d]=f)}let s=this.options,i=null,o=null,l=!1;if(s!==void 0&&s.enabled&&a.enabled&&a.anchorTo==="end"&&this.scrollElement!==null){let d=s.count,f=a.count,h=this.getMeasurements(),p=((r=this._singleLaneMeasurements)==null?void 0:r.items)??h,g=C=>Bb(p[C]),m=d>0?g(0):null,x=d>0?g(d-1):null;if(f!==d||d>0&&f>0&&(a.getItemKey(0)!==m||a.getItemKey(f-1)!==x)){l=!0;let C=d>0?this.getVirtualItemForOffset(this.getScrollOffset())??h[0]:null;C&&(i=[C.key,this.getScrollOffset()-C.start]);let L=a.followOnAppend===!0?"auto":a.followOnAppend||null;L&&f>0&&this.isAtEnd(s.scrollEndThreshold)&&(d===0||a.getItemKey(f-1)!==x)&&(f>d||vA(d,f,g,a.getItemKey))&&(o=L)}}this.options=a,l&&(this.pendingMin=0,this.itemSizeCacheVersion++);let u=!1,c=0;if(i&&this.scrollOffset!==null){let[d,f]=i,h=this.getMeasurements(),{count:p,getItemKey:g}=this.options,m=0;for(;m<p&&g(m)!==d;)m++;if(m<p){let x=h[m];if(x){let y=Math.max(0,x.start+f);!o&&y!==this.scrollOffset&&(c=y-this.scrollOffset,this.scrollOffset=y,u=!0)}}}(u||o)&&(this.pendingScrollAnchor=[u?i[0]:null,u?i[1]:0,o,c])},this.notify=n=>{var r,a;(a=(r=this.options).onChange)==null||a.call(r,this,n)},this.maybeNotify=di(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),n=>{this.notify(n)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(n=>n()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.isScrolling=!1,this.scrollDirection=null,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._clampedAdjustment=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var n,r;let a=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==a){if(this.cleanup(),!a){this.maybeNotify();return}if(this.scrollElement=a,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((n=this.scrollElement)==null?void 0:n.window)??null,this.elementsCache.forEach(i=>{this.observer.observe(i)}),this.unsubs.push(this.options.observeElementRect(this,i=>{this.scrollRect=i,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(i,o)=>{if(o&&this._intendedScrollOffset===null&&i===this.scrollOffset)return;this._intendedScrollOffset!==null&&Math.abs(i-this._intendedScrollOffset)<1.5&&(i=this._intendedScrollOffset),this._intendedScrollOffset=null,this._clampedAdjustment!==null&&Math.abs(i-this._clampedAdjustment.maxAtWrite)>=1.5&&(this._clampedAdjustment=null),this.scrollAdjustments=0;let l=this.getScrollOffset();this.scrollDirection=o?l===i?this.scrollDirection:l<i?"forward":"backward":null,this.scrollOffset=i,this.isScrolling=o,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),"addEventListener"in this.scrollElement){let i=this.scrollElement,o=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},l=()=>{this._iosTouching=!1,!(!yh()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};i.addEventListener("touchstart",o,kc),i.addEventListener("touchend",l,kc),this.unsubs.push(()=>{i.removeEventListener("touchstart",o),i.removeEventListener("touchend",l),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}let s=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,s&&this.scrollElement&&this.options.enabled){let[i,o,l,u]=s;i!==null&&!l&&(yh()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?u!==0&&(this._iosDeferredAdjustment+=u):((r=this.scrollState)==null?void 0:r.behavior)==="smooth"&&!xh(this.getScrollOffset()-u,this.scrollState.lastTargetOffset)||this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),l&&this.scrollToEnd({behavior:l})}this._retryClampedAdjustment()},this._retryClampedAdjustment=()=>{if(this._clampedAdjustment===null||!this.scrollElement||!this.options.enabled)return;let{target:n,maxAtWrite:r}=this._clampedAdjustment,a=this.getMaxScrollOffset();a>r+.5&&(this._clampedAdjustment=n>a+.5?{target:n,maxAtWrite:a}:null,this._scrollToOffset(n,{adjustments:void 0,behavior:void 0}))},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;let n=this.getScrollOffset(),r=this.getMaxScrollOffset();if(n<0||n>r)return;if(this._iosDeferredAdjustment<0&&n>=r-1){this._iosDeferredAdjustment=0;return}let a=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(n,{adjustments:this.scrollAdjustments+=a,behavior:void 0})},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getMeasurementOptions=di(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode,this.options.gap],(n,r,a,s,i,o,l,u)=>(this.prevLanes!==void 0&&this.prevLanes!==o&&(this.lanesChangedFlag=!0),this.prevLanes=o,this.pendingMin=null,{count:n,paddingStart:r,scrollMargin:a,getItemKey:s,enabled:i,lanes:o,laneAssignmentMode:l,gap:u}),{key:!1}),this.isIndexInRange=n=>n>=0&&n<this.options.count,this.getMeasurements=di(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:n,paddingStart:r,scrollMargin:a,getItemKey:s,enabled:i,lanes:o,laneAssignmentMode:l,gap:u},c)=>{var d;let f=this.itemSizeCache;if(!i)return this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>n)for(let y of this.laneAssignments.keys())y>=n&&this.laneAssignments.delete(y);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(y=>{this.itemSizeCache.set(y.key,y.size)}));let h=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===n&&(this.lanesSettling=!1),o===1){let y=n*2,b=(d=this._singleLaneMeasurements)==null?void 0:d.flat;if(!b||b.length<y){let w=new Float64Array(y);b&&h>0&&w.set(b.subarray(0,h*2)),b=w}let C=h===0?new Array(n):this._singleLaneMeasurements.items.slice(),L;if(h===0)L=r+a;else{let w=h-1;L=b[w*2]+b[w*2+1]+u}for(let w=h;w<n;w++){let k=s(w);C[w]=k;let _=f.get(k),M=typeof _=="number"?_:this.options.estimateSize(w);b[w*2]=L,b[w*2+1]=M,L+=M+u}this._singleLaneMeasurements={flat:b,items:C};let P=_b(C,b);return this.measurementsCache=P,P}let p=this.measurementsCache.slice(0,h),g=new Array(o).fill(void 0),m=new Float64Array(o),x=0;for(let y=0;y<h;y++){let b=p[y];b&&(g[b.lane]===void 0&&x++,g[b.lane]=y,m[b.lane]=b.end)}for(let y=h;y<n;y++){let b=s(y),C=this.laneAssignments.get(y),L,P,w=l==="estimate"||f.has(b);if(C!==void 0&&this.options.lanes>1){L=C;let R=g[L],U=R!==void 0?p[R]:void 0;P=U?U.end+u:r+a}else if(x===o){let R=0,U=m[0],v=g[0];for(let T=1;T<o;T++){let V=m[T];(V<U||V===U&&g[T]<v)&&(R=T,U=V,v=g[T])}L=R,P=U+u,w&&this.laneAssignments.set(y,L)}else L=y%this.options.lanes,P=r+a,w&&this.laneAssignments.set(y,L);let k=f.get(b),_=typeof k=="number"?k:this.options.estimateSize(y),M=P+_;p[y]={index:y,start:P,size:_,end:M,key:b,lane:L},g[L]===void 0&&x++,g[L]=y,m[L]=M}return this.measurementsCache=p,p},{key:!1,debug:()=>this.options.debug}),this.calculateRange=di(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(n,r,a,s)=>n.length===0||r===0?(this.range=null,null):(this.range=SA(n,r,a,s,s===1&&this._singleLaneMeasurements!==null?this._singleLaneMeasurements.flat:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=di(()=>{let n=null,r=null,a=this.calculateRange();return a&&(n=a.startIndex,r=a.endIndex),this.maybeNotify.updateDeps([this.isScrolling,n,r]),[this.options.rangeExtractor,this.options.overscan,this.options.count,n,r]},(n,r,a,s,i)=>s===null||i===null?[]:n({startIndex:s,endIndex:i,overscan:r,count:a}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=n=>{let r=this.options.indexAttribute,a=n.getAttribute(r);return a?parseInt(a,10):(console.warn(`Missing attribute name '${r}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=n=>{var r;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;let a=this.scrollState.index??((r=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:r.index);if(a!==void 0&&this.range){let s=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),i=Math.max(0,a-s),o=Math.min(this.options.count-1,a+s);return n>=i&&n<=o}return!0},this.measureElement=n=>{if(!n){this.elementsCache.forEach((i,o)=>{i.isConnected||(this.observer.unobserve(i),this.elementsCache.delete(o))});return}let r=this.indexFromElement(n);if(!this.isIndexInRange(r))return;let a=this.options.getItemKey(r),s=this.elementsCache.get(a);s!==n&&(s&&this.observer.unobserve(s),this.observer.observe(n),this.elementsCache.set(a,n)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(r)&&this.resizeItem(r,this.options.measureElement(n,void 0,this))},this.resizeItem=(n,r)=>{var a,s,i;if(!this.isIndexInRange(n))return;let o,l,u,c=(a=this._singleLaneMeasurements)==null?void 0:a.flat;if(this.options.lanes===1&&c!=null)u=this.options.getItemKey(n),l=c[n*2],o=c[n*2+1];else{let h=this.measurementsCache[n];if(!h)return;u=h.key,l=h.start,o=h.size}let d=this.itemSizeCache.get(u)??o,f=r-d;if(f!==0){let h=this.options.anchorTo==="end"&&((s=this.scrollState)==null?void 0:s.behavior)!=="smooth"&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,p=h?this.getTotalSize():0,g=this.getScrollOffset()+this.scrollAdjustments,x=!this.itemSizeCache.has(u)?l<g:l+d<=g&&this.scrollDirection!=="backward",y=((i=this.scrollState)==null?void 0:i.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[n]??{index:n,key:u,start:l,size:o,end:l+o,lane:0},f,this):x);(this.pendingMin===null||n<this.pendingMin)&&(this.pendingMin=n),this.itemSizeCache.set(u,r),this.itemSizeCacheVersion++;let b=!1;h?b=this.applyScrollAdjustment(this.getTotalSize()-p):y&&(b=this.applyScrollAdjustment(f)),this.notify(b),this._retryClampedAdjustment()}},this.getVirtualItems=di(()=>[this.getVirtualIndexes(),this.getMeasurements()],(n,r)=>{let a=[];for(let s=0,i=n.length;s<i;s++){let o=n[s],l=r[o];a.push(l)}return a},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=n=>{var r;let a=this.getMeasurements();if(a.length===0)return;let s=(r=this._singleLaneMeasurements)==null?void 0:r.flat,i=this.options.lanes===1&&s!=null,o=jb(0,a.length-1,i?l=>s[l*2]:l=>gh(a[l]).start,n);return gh(a[o])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{let n=this.scrollElement.document.documentElement;return this.options.horizontal?n.scrollWidth-this.scrollElement.innerWidth:n.scrollHeight-this.scrollElement.innerHeight}},this.getVirtualDistanceFromEnd=()=>Math.max(this.getTotalSize()-this.getSize()-this.getScrollOffset(),0),this.getDistanceFromEnd=()=>Math.max(this.getMaxScrollOffset()-this.getScrollOffset(),0),this.isAtEnd=(n=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=n,this.getOffsetForAlignment=(n,r,a=0)=>{if(!this.scrollElement)return 0;let s=this.getSize(),i=this.getScrollOffset();r==="auto"&&(r=n>=i+s?"end":"start"),r==="center"?n+=(a-s)/2:r==="end"&&(n-=s);let o=this.getMaxScrollOffset();return Math.max(Math.min(o,n),0)},this.getOffsetForIndex=(n,r="auto")=>{n=Math.max(0,Math.min(n,this.options.count-1));let a=this.getSize(),s=this.getScrollOffset(),i=this.measurementsCache[n];if(!i)return;if(r==="auto")if(i.end>=s+a-this.options.scrollPaddingEnd)r="end";else if(i.start<=s+this.options.scrollPaddingStart)r="start";else return[s,r];if(r==="end"&&n===this.options.count-1)return[this.getMaxScrollOffset(),r];let o=r==="end"?i.end+this.options.scrollPaddingEnd:i.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(o,r,i.size),r]},this.scrollToOffset=(n,{align:r="start",behavior:a="auto"}={})=>{this._iosDeferredAdjustment=0;let s=this.getOffsetForAlignment(n,r),i=this.now();this.scrollState={index:null,align:r,behavior:a,startedAt:i,lastTargetOffset:s,stableFrames:0},this._scrollToOffset(s,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollToIndex=(n,{align:r="auto",behavior:a="auto"}={})=>{this._iosDeferredAdjustment=0,n=Math.max(0,Math.min(n,this.options.count-1));let s=this.getOffsetForIndex(n,r);if(!s)return;let[i,o]=s,l=this.now();this.scrollState={index:n,align:o,behavior:a,startedAt:l,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollBy=(n,{behavior:r="auto"}={})=>{let a=this.getScrollOffset()+n,s=this.now();this.scrollState={index:null,align:"start",behavior:r,startedAt:s,lastTargetOffset:a,stableFrames:0},this._scrollToOffset(a,{adjustments:void 0,behavior:r}),this.scheduleScrollReconcile()},this.scrollToEnd=({behavior:n="auto"}={})=>{if(this.options.count>0){this.scrollToIndex(this.options.count-1,{align:"end",behavior:n});return}this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:n})},this.getTotalSize=()=>{var n,r;let a=this.getMeasurements(),s;if(a.length===0)s=this.options.paddingStart;else if(this.options.lanes===1){let i=a.length-1,o=(n=this._singleLaneMeasurements)==null?void 0:n.flat;o!=null?s=o[i*2]+o[i*2+1]:s=((r=a[i])==null?void 0:r.end)??0}else{let i=Array(this.options.lanes).fill(null),o=a.length-1;for(;o>=0&&i.some(l=>l===null);){let l=a[o];i[l.lane]===null&&(i[l.lane]=l.end),o--}s=Math.max(...i.filter(l=>l!==null))}return Math.max(s-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{let n=[];if(this.itemSizeCache.size===0)return n;let r=this.getMeasurements();for(let a of r)a&&this.itemSizeCache.has(a.key)&&n.push({index:a.index,key:a.key,start:a.start,size:a.size,end:a.end,lane:a.lane});return n},this._scrollToOffset=(n,{adjustments:r,behavior:a})=>{this._intendedScrollOffset=n+(r??0),this.options.scrollToFn(n,{behavior:a,adjustments:r},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(e)}applyScrollAdjustment(e,n){if(e===0)return!1;if(yh()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded))return this._iosDeferredAdjustment+=e,!1;{let r=this.getScrollOffset()+this.scrollAdjustments+e,a=this.scrollElement,s=a!==null&&("scrollHeight"in a||"document"in a)?this.getMaxScrollOffset():null;return this._clampedAdjustment=s!==null&&r>s+.5?{target:r,maxAtWrite:s}:null,this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=e,behavior:n}),this.scrollOffset!==null&&(this.scrollOffset+=this.scrollAdjustments,this.scrollOffset<0&&(this.scrollOffset=0),this.scrollAdjustments=0),!0}}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}let r=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,a=r?r[0]:this.scrollState.lastTargetOffset,s=1,i=a!==this.scrollState.lastTargetOffset;if(!i&&xh(a,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=s){this.getScrollOffset()!==a&&this._scrollToOffset(a,{adjustments:void 0,behavior:"auto"}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,i){let o=this.getSize()||600,l=Math.abs(a-this.getScrollOffset()),u=this.scrollState.behavior==="smooth"&&l>o;this.scrollState.lastTargetOffset=a,u||(this.scrollState.behavior="auto"),this._scrollToOffset(a,{adjustments:void 0,behavior:u?"smooth":"auto"})}this.scheduleScrollReconcile()}},jb=(t,e,n,r)=>{for(;t<=e;){let a=(t+e)/2|0,s=n(a);if(s<r)t=a+1;else if(s>r)e=a-1;else return a}return t>0?t-1:0};function kA(t,e,n){let r=0;for(;r<=e;){let a=(r+e)/2|0,s=t[a*2];if(s<n)r=a+1;else if(s>n)e=a-1;else return a}return r>0?r-1:0}function SA(t,e,n,r,a){let s=t.length-1;if(t.length<=r)return{startIndex:0,endIndex:s};if(r===1&&a!==null){let u=kA(a,s,n),c=u,d=n+e;for(;c<s&&a[c*2]+a[c*2+1]<d;)c++;return{startIndex:u,endIndex:c}}let o=jb(0,s,u=>t[u].start,n),l=o;if(r===1)for(;l<s&&t[l].end<n+e;)l++;else if(r>1){let u=Array(r).fill(0);for(;l<s&&u.some(d=>d<n+e);){let d=t[l];u[d.lane]=d.end,l++}let c=Array(r).fill(n+e);for(;o>=0&&c.some(d=>d>=n);){let d=t[o];c[d.lane]=d.start,o--}o=Math.max(0,o-o%r),l=Math.min(s,l+(r-1-l%r))}return{startIndex:o,endIndex:l}}var bh=typeof document<"u"?ra.useLayoutEffect:ra.useEffect;function CA({useFlushSync:t=!0,directDomUpdates:e=!1,directDomUpdatesMode:n="transform",...r}){let a=ra.useReducer(d=>d+1,0)[1],s=ra.useRef({enabled:e,mode:n,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});s.current.enabled=e,s.current.mode=n;let i=ra.useRef(!1),o=d=>{let f=s.current;if(!f.enabled||!f.container)return;let h=d.getTotalSize();if(h!==f.lastSize){f.lastSize=h;let p=d.options.horizontal?"width":"height";f.container.style[p]=`${h}px`}},l=d=>{let f=s.current;if(!f.enabled||!f.container)return;o(d);let h=!!d.options.horizontal,p=f.mode==="transform",g=h?"left":"top",m=d.options.scrollMargin,x=d.getVirtualItems();for(let y of x){let b=y.start-m,C=d.elementsCache.get(y.key);C&&f.lastPositions.get(C)!==b&&(f.lastPositions.set(C,b),p?C.style.transform=h?`translate3d(${b}px, 0, 0)`:`translate3d(0, ${b}px, 0)`:C.style[g]=`${b}px`)}},u={...r,onChange:(d,f)=>{var h;let p=s.current,g=!0;if(p.enabled){l(d);let m=d.range,x=p.prevRange;g=!x||x.isScrolling!==d.isScrolling||x.startIndex!==m?.startIndex||x.endIndex!==m?.endIndex,g&&(p.prevRange=m?{startIndex:m.startIndex,endIndex:m.endIndex,isScrolling:d.isScrolling}:null)}g&&(t&&f&&!i.current?(0,Vb.flushSync)(a):a()),(h=r.onChange)==null||h.call(r,d,f)}},[c]=ra.useState(()=>{let d=new Sc(u),f=d.measureElement;return d.measureElement=h=>{i.current=!0;try{f(h)}finally{i.current=!1}},Object.assign(d,{containerRef:h=>{let p=s.current;if(p.container=h,p.lastSize=null,h&&p.enabled){let g=d.getTotalSize();p.lastSize=g;let m=d.options.horizontal?"width":"height";h.style[m]=`${g}px`}}})});return c.setOptions(u),bh(()=>c._didMount(),[]),bh(()=>(o(c),c._willUpdate())),bh(()=>{l(c)}),c}function lo(t){return CA({observeElementRect:Gb,observeElementOffset:Wb,scrollToFn:zb,...t})}var Qa=j($e(),1);function qb(t){let e=H(u=>u.client),{agentId:n,projectId:r,enabled:a}=t,[s,i]=(0,Qa.useState)([]),o=(0,Qa.useRef)(!0);(0,Qa.useEffect)(()=>(o.current=!0,()=>{o.current=!1}),[]);let l=(0,Qa.useRef)(!1);return(0,Qa.useEffect)(()=>{l.current=!1,i([])},[n,r]),(0,Qa.useEffect)(()=>{!n||!a||l.current||(l.current=!0,ic({agentId:n,...r?{projectId:r}:{}},e).then(u=>{o.current&&i(u.suggestions??[])}).catch(()=>{o.current&&i([])}))},[n,r,a,e]),s}var Lc=j($e(),1);var lr=j(Wn(),1);var La=j(ie(),1);function IA({className:t}){return(0,La.jsxs)("svg",{viewBox:"0 0 64 64",className:t,"aria-hidden":"true",children:[(0,La.jsx)("path",{d:"M10 52L24 28L36 36L52 12",fill:"none",stroke:"currentColor",strokeWidth:"3.5",strokeLinecap:"round",strokeLinejoin:"round"}),(0,La.jsx)("circle",{cx:"10",cy:"52",r:"5.2",fill:"#fb923c",stroke:"currentColor",strokeWidth:"2.4"}),(0,La.jsx)("circle",{cx:"24",cy:"28",r:"5.2",fill:"#fb923c",stroke:"currentColor",strokeWidth:"2.4"}),(0,La.jsx)("circle",{cx:"36",cy:"36",r:"5.2",fill:"#fb923c",stroke:"currentColor",strokeWidth:"2.4"}),(0,La.jsx)("circle",{cx:"52",cy:"12",r:"5.2",fill:"#fb923c",stroke:"currentColor",strokeWidth:"2.4"})]})}function LA(t){if(!t)return"aged";let e=Date.parse(t);if(!Number.isFinite(e))return"aged";let n=Math.max(0,(Date.now()-e)/6e4);return n<=15?"fresh":n<=180?"recent":n<=1440?"aged":"stale"}function fi(t){switch(LA(t)){case"fresh":return{pillClassName:"border-emerald-400/25 bg-emerald-500/14 text-emerald-100",iconClassName:"text-emerald-300/85",label:"Changed just now"};case"recent":return{pillClassName:"border-amber-400/22 bg-amber-500/10 text-amber-100/92",iconClassName:"text-amber-300/76",label:"Changed recently"};case"aged":return{pillClassName:"border-white/10 bg-white/[0.05] text-white/60",iconClassName:"text-white/40",label:"Older change"};default:return{pillClassName:"border-rose-400/18 bg-rose-500/10 text-rose-100/80",iconClassName:"text-rose-300/70",label:"Older indexed change"}}}function $l(t){let e=t.status==="deleted",n=t.status==="pending_review",r=t.status==="pinned";return e?{tone:"text-red-100/70",iconTone:"text-red-300/70",secondaryTone:"text-red-200/60",highlightTone:"bg-red-500/12",icon:xs,label:"Deleted",title:"Marked as deleted",ghosted:!0}:n?{tone:"text-amber-50/95",iconTone:"text-amber-300/85",secondaryTone:"text-amber-200/75",highlightTone:"bg-amber-500/10",icon:ot,label:"Review pending",title:"Pending review before approval"}:t.presence==="brain"?{tone:"text-violet-50/92",iconTone:"text-violet-300/80",secondaryTone:"text-violet-200/68",highlightTone:"bg-violet-500/10",icon:ir,label:"Brain node",title:"Stored in brain index"}:t.presence==="stale_indexed"?{tone:"text-rose-100/78",iconTone:"text-rose-300/75",secondaryTone:"text-rose-200/65",highlightTone:"bg-rose-500/8",icon:Ya,label:"Missing from disk",title:"Indexed but not found in live source",ghosted:!0}:t.presence==="unindexed"?{tone:"text-white/55",iconTone:"text-white/70",secondaryTone:"text-white/45",highlightTone:"bg-white/[0.04]",icon:Xa,label:"Unindexed",title:"Connector entry not vector-indexed yet"}:r?{tone:"text-white/82",iconTone:"text-amber-200/80",secondaryTone:"text-amber-100/65",highlightTone:"bg-amber-500/8",icon:ii,label:"Pinned",title:"Pinned item"}:t.presence==="synced"?{tone:"text-white",iconTone:"text-sky-300/80",secondaryTone:"text-white/82",highlightTone:"bg-sky-500/10",icon:IA,label:"Synced",title:"Indexed and present on the connector"}:{tone:"text-white/72",iconTone:"text-white/48",secondaryTone:"text-white/48",highlightTone:"bg-white/[0.04]",icon:wa,label:"Neutral",title:"File entry"}}function $b(t){return t?Is:Tr}function Kb(t){let n=[$l(t).label];return t.version?.changedAt&&n.push(fi(t.version.changedAt).label),t.status==="pinned"&&n.push("Pinned"),n}function Cc(t){return{iconClassName:"text-white/35",labelClassName:"text-white/45",detailClassName:"text-white/30",containerClassName:"opacity-55",title:t==="disabled"?"Source disabled in this scope \u2014 toggle in the Sources panel.":"Source discovered but not yet attached \u2014 click to add."}}function Ic(t){let e=t.enabled===!1,n=t.enabled==="auto"&&t.enabled_effective===!1;return e||n?{iconClassName:"text-white/35",labelClassName:"text-white/45",detailClassName:"text-white/30"}:t.live===!1?{iconClassName:"text-white/35",labelClassName:"text-white/45",detailClassName:"text-white/30"}:t.sync_status==="error"?{iconClassName:"text-rose-300/80",labelClassName:"text-rose-50/92",detailClassName:"text-rose-200/65"}:t.sync_status==="paused"?{iconClassName:"text-amber-300/80",labelClassName:"text-amber-50/90",detailClassName:"text-amber-200/65"}:t.sync_status==="active"?{iconClassName:"text-sky-300/80",labelClassName:"text-sky-50/90",detailClassName:"text-sky-200/62"}:t.source_kind==="brain"?{iconClassName:"text-violet-300/85",labelClassName:"text-violet-50/92",detailClassName:"text-violet-200/60"}:{iconClassName:"text-white/80",labelClassName:"text-white/90",detailClassName:"text-white/55"}}var AA={runtime_offline:"Machine offline \u2014 container not running",fs_unreachable:"Filesystem unreachable \u2014 mount missing",fs_permission:"Filesystem unreadable \u2014 permission denied",store_unreachable:"Store offline \u2014 backing service unreachable"};function wh(t){return(t?AA[t]:void 0)??"Disconnected \u2014 connector cannot reach its backing filesystem"}function Xb(t){return t.enabled===!1?"Source disabled":t.enabled==="auto"&&t.enabled_effective===!1?"Source auto \u2014 currently stopped":t.live===!1?wh(t.live_reason):t.sync_status==="error"?t.last_error??"Sync error":t.sync_status==="paused"?"Sync paused":t.sync_status==="active"?"Sync active":null}function vh(t){if(!t)return null;let e=Date.parse(t);if(!Number.isFinite(e))return null;let n=Math.max(0,Math.round((Date.now()-e)/6e4));if(n<1)return"now";if(n<60)return`${n}m`;let r=Math.round(n/60);return r<24?`${r}h`:`${Math.round(r/24)}d`}function Yb({className:t,title:e}){return(0,La.jsx)("span",{title:e,className:"inline-flex",children:(0,La.jsx)(or,{className:t})})}function $(...t){return t.filter(Boolean).join(" ")}var Qn=j(ie(),1),PA=5,Jb=28;function Zb({suggestions:t,expanded:e,onToggleExpanded:n,onPick:r,overlay:a}){return t.length===0?null:(0,Qn.jsxs)("div",{className:$("group/discover shrink-0 border-t border-white/[0.06] bg-[#0b0b0f]/95",a?"absolute inset-x-0 bottom-0 z-20 shadow-[0_-8px_24px_rgba(0,0,0,0.45)]":""),"data-testid":"discover-dock",children:[(0,Qn.jsxs)("div",{className:"flex items-center justify-between px-2 pt-1.5 pb-1",children:[(0,Qn.jsx)("span",{className:"text-[10px] font-bold uppercase tracking-wider text-white/40",children:"Discover"}),(0,Qn.jsx)("button",{type:"button",onClick:n,className:"inline-flex h-4 w-4 items-center justify-center rounded text-white/40 opacity-0 transition-opacity hover:text-white/70 focus-visible:opacity-100 group-hover/discover:opacity-60",title:e?"Collapse discoverable sources":"Show all discoverable sources","aria-label":e?"Collapse discoverable sources":"Show all discoverable sources","aria-expanded":e,children:e?(0,Qn.jsx)(Et,{className:"h-3 w-3"}):(0,Qn.jsx)(qa,{className:"h-3 w-3"})})]}),(0,Qn.jsx)("ul",{className:"overlay-scroll overflow-y-auto pb-1",style:{maxHeight:e?"60vh":PA*Jb},children:t.map(s=>(0,Qn.jsx)(NA,{suggestion:s,onPick:r},s.id))})]})}var NA=Lc.default.memo(function({suggestion:e,onPick:n}){let r=Cc("unattached"),a=(0,lr.resolveLucideIcon)(e.icon??null)??zn,s=(0,Lc.useCallback)(()=>n(e),[n,e]),i=[e.description,e.root].filter(Boolean).join(`
3
+ `);return(0,Qn.jsx)("li",{children:(0,Qn.jsxs)("button",{type:"button",onClick:s,title:i||r.title,style:{height:Jb},className:$("flex w-full items-center gap-2 px-2 text-left transition-colors hover:bg-white/[0.05]",r.containerClassName),children:[(0,Qn.jsx)(a,{className:$("h-4 w-4 shrink-0",r.iconClassName)}),(0,Qn.jsx)("span",{className:$("truncate text-xs font-medium",r.labelClassName),children:e.label}),(0,Qn.jsxs)("span",{className:$("shrink-0 font-mono text-[9px]",r.detailClassName),children:[e.suggestedScheme,"://"]})]})})});var uo=j($e(),1),nw=j(ie(),1),Qb=(0,uo.createContext)(null),kh=null;function hn(){let t=(0,uo.useContext)(Qb);if(!t)throw new Error("useFilesystemHost must be used within a FilesystemHostProvider");return t}function ew(){return kh}function tw({value:t,children:e}){return kh=t,(0,uo.useEffect)(()=>{kh=t},[t]),(0,nw.jsx)(Qb.Provider,{value:t,children:e})}var aw=j(Wn(),1);function rw(t){return String(t||"").trim().toLowerCase().replace(/[\s_]+/g,"-")}function Ms(t){let e=new Map,n=new Map,r=new Map;return t.ids.forEach((a,s)=>{let i=t.byId[a];if(!i)return;e.set(a,i);let o=i.slug?rw(i.slug):"";o&&n.set(o,i);let l=i.name?rw(i.name):"";l&&n.set(l,i);let u=i.config?.appearance?.color,c=(0,aw.resolveAgentColor)(u,s);r.set(a,c)}),{byId:e,bySlug:n,accentById:r}}function co(t,e){if(t)return e.accentById.get(t)}var vr=j($e(),1);var sw=j(Zr(),1);var TA=j(ie(),1);function fo(t){let e=gt(t)||t.split("/").pop()||"",n=RA(e);return MA(e.toLowerCase(),n)}function RA(t){return t.includes(".")?t.split(".").pop().toLowerCase():""}function MA(t,e){if(t==="dockerfile")return to;if(t==="package.json")return ba;if(t===".gitignore"||t===".env"||t.startsWith(".env."))return va;if(t==="tsconfig.json"||t==="tsconfig.base.json")return ba;if(t.endsWith(".d.ts"))return $a;let n=new Set(["ts","tsx","js","jsx","py","java","kt","php","go","rs","cpp","c","hpp","cs","swift","sh","bash","zsh","ps1","prisma"]),r=new Set(["md","mdx","txt","yml","yaml","xml","ini","toml","css","scss","html","csv","xls","xlsx"]),a=new Set(["png","jpg","jpeg","gif","webp","svg"]),s=new Set(["mp4","mov","webm"]),i=new Set(["mp3","wav"]),o=new Set(["zip","gz","tar","rar","lock"]);return e==="json"||e==="jsonl"?ba:n.has(e)?$a:r.has(e)?va:a.has(e)?Il:s.has(e)?ks:i.has(e)?Dl:o.has(e)?to:Ll}var Ch=j(ie(),1),DA={M:"text-amber-400",A:"text-emerald-400",D:"text-rose-400",R:"text-sky-400",C:"text-sky-400",U:"text-rose-400","?":"text-emerald-400"},FA={M:"bg-amber-400",A:"bg-emerald-400",D:"bg-rose-400",R:"bg-sky-400",C:"bg-sky-400",U:"bg-rose-400","?":"bg-emerald-400"},Sh={M:"Modified",A:"Added",D:"Deleted",R:"Renamed",C:"Copied",U:"Unmerged","?":"Untracked"};function EA(t){let e=t[0]??" ",n=t[1]??" ";if(e==="?"||n==="?")return"?";let r=n!==" "?n:e;return r===" "?null:r}function Ac({code:t,dot:e=!1}){let n=EA(t);if(!n)return null;let r=t[0]!==" "&&t[0]!=="?",a=t[1]!==" "&&t[1]!=="?",s=(Sh[n]??"Changed")+(r&&a?" (staged + unstaged)":r?" (staged)":"");if(e)return(0,Ch.jsx)("span",{className:$("shrink-0 w-1.5 h-1.5 rounded-full",FA[n]??"bg-white/60"),title:`Git: contains ${(Sh[n]??"changes").toLowerCase()}`,"aria-label":`Git: folder contains changes (${Sh[n]??"changed"})`});let i=n==="?"?"U":n;return(0,Ch.jsx)("span",{className:$("shrink-0 text-[10px] font-bold leading-none tabular-nums",DA[n]??"text-white/60"),title:`Git: ${s}`,"aria-label":`Git status: ${s}`,children:i})}var rn=j(ie(),1),Kl="application/x-neuralis-fs-node";function OA({uri:t,tone:e,title:n}){let r=fo(t);return(0,rn.jsx)("span",{className:$("inline-flex items-center justify-center shrink-0",e),title:n,children:(0,rn.jsx)(r,{className:"w-4 h-4"})})}var iw=vr.default.memo(function({node:e,depth:n=0,agentId:r,projectId:a,isActive:s,isExpanded:i,badgeCount:o,isDrop:l,isSelectedFolder:u,mark:c,agentIndex:d,fallbackAgent:f,uploading:h,packageIconBySlug:p,onToggleFolder:g,onOpenFile:m,onClearFileMark:x,onSetDropTarget:y,onUploadMany:b,onMoveFileToFolder:C,pendingReviewCount:L,isSelected:P,isCut:w,renaming:k,onNodeClick:_,onNodeContextMenu:M,onRenameCommit:R,onRenameCancel:U}){let v=e.type==="folder",T=e.status==="deleted",V=e.status==="pending_review",Y=!v&&e.version?.diff?e.version.diff:void 0,N=e.storeKey||Va(e),A=(0,vr.useRef)(null),B=e.sourceAgentId?d.byId.get(e.sourceAgentId)??null:f,K=co(B?.id,d),te=(0,vr.useMemo)(()=>$l(e),[e]),ne=!!(Y&&(Y.added>0||Y.removed>0)),pe=!!(v&&o),Se=!!c,le=!!e.git,re=fi(e.version?.changedAt),he=(0,vr.useMemo)(()=>{if(!v||!p)return null;let Le=e.uri.match(/^(packages|data):\/\/([^/]+)\/?$/);return Le?Le[2]:null},[v,e.uri,p]),Ee=(he?p?.[he]:void 0)??$b(i),ze=Kb(e).join(" \u2022 "),ct=ne||pe||Se||V||le,it=(0,vr.useCallback)(()=>{g({key:N})},[N,g]),Qe=(0,vr.useCallback)(()=>{m({agentId:r,projectId:a??null,uri:e.uri,readAgentId:B?.id}),c&&x({agentId:r,path:e.uri})},[r,e.uri,B?.id,m,x,a,c]),Ye=(0,vr.useCallback)(Le=>{let at=Le.metaKey||Le.ctrlKey,ft=Le.shiftKey;if(at||ft){_?.({node:e,additive:at,range:ft});return}_?.({node:e,additive:!1,range:!1}),v?it():Qe()},[e,v,_,it,Qe]),Lt=(0,vr.useCallback)(Le=>{Le.preventDefault(),Le.stopPropagation(),M?.({node:e,x:Le.clientX,y:Le.clientY})},[e,M]);return(0,rn.jsxs)("div",{ref:A,className:$("group flex h-7 items-center gap-1.5 px-2 rounded-md cursor-pointer select-none transition-colors",s?"bg-white/10 text-white":"text-white/70 hover:bg-white/5 hover:text-white",u?"bg-sky-500/15 text-sky-100":"",P&&!s?"bg-sky-400/20 ring-1 ring-inset ring-sky-400/30 text-white":"",V&&!s?"bg-amber-500/[0.08] border-l-2 border-l-amber-400/60":"",T?"opacity-70":"",w?"opacity-45":"",l?"bg-white/10":""),style:{paddingLeft:`${n*12+8}px`},draggable:!k,onDragStart:Le=>{let at={kind:"filesystem",action:v?"list":"read",uri:e.uri};Le.dataTransfer.setData("application/x-neuralis-fs-ref",JSON.stringify(at)),Le.dataTransfer.setData(Kl,JSON.stringify({type:e.type,uri:e.uri,id:e.id,name:e.name})),Le.dataTransfer.setData("text/plain",`\u27E6fs:${v?"list":"read"}:${e.uri}\u27E7`),Le.dataTransfer.effectAllowed="copyMove"},onClick:Ye,onContextMenu:Lt,onDragOver:Le=>{if(!v||h)return;let at=Array.from(Le.dataTransfer.types||[]);(at.includes("Files")||at.includes(Kl))&&(Le.preventDefault(),Le.dataTransfer.dropEffect=at.includes(Kl)?"move":"copy",y(N))},onDragLeave:()=>{l&&y(null)},onDrop:async Le=>{if(!v||h)return;let at=Array.from(Le.dataTransfer.types||[]),ft=at.includes("Files"),bt=at.includes(Kl);if(!(!ft&&!bt)){if(Le.preventDefault(),y(null),bt){let At=Le.dataTransfer.getData(Kl);if(!At)return;try{let Tt=JSON.parse(At);if(!Tt.uri||Tt.uri===e.uri||e.uri===Tt.uri||e.uri.startsWith(`${Tt.uri}/`))return;await C({fromUri:Tt.uri,id:Tt.id,toFolderUri:e.uri});return}catch{return}}if(ft){let At=Array.from(Le.dataTransfer.files||[]);if(At.length===0)return;await b({agentId:r,projectId:a??null,files:At,uri:e.uri})}}},title:`${e.uri}${ze?`
4
+ ${ze}`:""}`,"aria-label":`${e.name} \u2014 ${ze}`,children:[(0,rn.jsx)("span",{className:"shrink-0 text-white/40",children:v?i?(0,rn.jsx)(Et,{className:"w-3.5 h-3.5"}):(0,rn.jsx)(un,{className:"w-3.5 h-3.5"}):(0,rn.jsx)("span",{className:"w-3.5 h-3.5 inline-block"})}),v?(0,rn.jsx)("span",{title:te.title,children:(0,rn.jsx)(Ee,{className:$("w-4 h-4 shrink-0",te.iconTone),style:{color:e.presence==="brain"&&K||void 0}})}):(0,rn.jsx)(OA,{uri:e.uri,tone:te.iconTone,title:te.title}),k?(0,rn.jsx)(BA,{initial:e.name,onCommit:Le=>R?.({node:e,newName:Le}),onCancel:()=>U?.()}):(0,rn.jsx)("span",{className:$("min-w-0 text-xs truncate flex-1 transition-colors",te.tone,te.ghosted&&"opacity-70",T&&"line-through"),children:e.name}),ct?(0,rn.jsxs)("span",{className:"ml-1 shrink-0 flex items-center justify-end gap-1",children:[V?(0,rn.jsx)("span",{title:"Pending review",className:"shrink-0 flex items-center",children:(0,rn.jsx)(sw.LivePulseDot,{className:"text-amber-400/80 shrink-0"})}):null,Se?(0,rn.jsx)("span",{className:$("w-1.5 h-1.5 rounded-full shrink-0",c?.kind==="new"?"bg-emerald-400":"bg-blue-400"),title:c?.kind==="new"?"New file":"Modified"}):null,le&&e.git?(0,rn.jsx)(Ac,{code:e.git,dot:v}):null,ne?(0,rn.jsx)(Yb,{className:$("w-3.5 h-3.5 shrink-0",re.iconClassName),title:re.label}):null,pe?(0,rn.jsx)("span",{className:$("inline-flex items-center justify-center min-w-[16px] h-4 px-1 rounded-full text-[9px] font-semibold",L?"bg-amber-500/20 text-amber-200":"bg-sky-500/15 text-sky-200"),children:o}):null]}):null]})});function BA({initial:t,onCommit:e,onCancel:n}){let r=(0,vr.useRef)(!1);return(0,rn.jsx)("input",{autoFocus:!0,defaultValue:t,spellCheck:!1,onFocus:a=>{let s=a.currentTarget.value,i=s.lastIndexOf(".");a.currentTarget.setSelectionRange(0,i>0?i:s.length)},onClick:a=>a.stopPropagation(),onMouseDown:a=>a.stopPropagation(),onKeyDown:a=>{a.stopPropagation(),a.key==="Enter"?r.current||(r.current=!0,e(a.currentTarget.value)):a.key==="Escape"&&(r.current||(r.current=!0,n()))},onBlur:a=>{r.current||(r.current=!0,e(a.currentTarget.value))},className:"min-w-0 flex-1 rounded border border-sky-400/60 bg-black/50 px-1 py-0 text-xs text-white outline-none"})}var Ds=j($e(),1),ow=j(Za(),1);var Ts=j(ie(),1),_A=[{kind:"item",action:"new-file",label:"New File\u2026",Icon:Cs},{kind:"item",action:"new-folder",label:"New Folder\u2026",Icon:br},{kind:"sep"},{kind:"item",action:"cut",label:"Cut",Icon:Ol,shortcut:"\u2318X"},{kind:"item",action:"copy",label:"Copy",Icon:na,shortcut:"\u2318C"},{kind:"item",action:"paste",label:"Paste",Icon:wl,shortcut:"\u2318V"},{kind:"sep"},{kind:"item",action:"copy-path",label:"Copy Path",Icon:Nl},{kind:"item",action:"copy-relative-path",label:"Copy Relative Path",Icon:kl},{kind:"sep"},{kind:"item",action:"reembed",label:"Re-embed\u2026",Icon:ka},{kind:"sep"},{kind:"item",action:"rename",label:"Rename",Icon:As,shortcut:"F2"},{kind:"item",action:"delete",label:"Delete",Icon:Nt,danger:!0,shortcut:"Del"}],HA=[{kind:"item",action:"new-file",label:"New File\u2026",Icon:Cs},{kind:"item",action:"new-folder",label:"New Folder\u2026",Icon:br}],UA=210;function lw({x:t,y:e,enabled:n,onAction:r,onClose:a,variant:s="node"}){let i=s==="source"?HA:_A,o=(0,Ds.useRef)(null),[l,u]=(0,Ds.useState)({top:e,left:t});return(0,Ds.useLayoutEffect)(()=>{let c=o.current;if(!c)return;let d=c.getBoundingClientRect(),f=t,h=e;f+d.width>window.innerWidth-4&&(f=Math.max(4,window.innerWidth-d.width-4)),h+d.height>window.innerHeight-4&&(h=Math.max(4,window.innerHeight-d.height-4)),u({top:h,left:f})},[t,e]),(0,Ds.useEffect)(()=>{let c=h=>{o.current?.contains(h.target)||a()},d=h=>{h.key==="Escape"&&a()},f=()=>a();return document.addEventListener("mousedown",c,!0),document.addEventListener("keydown",d,!0),window.addEventListener("resize",f),window.addEventListener("scroll",f,!0),()=>{document.removeEventListener("mousedown",c,!0),document.removeEventListener("keydown",d,!0),window.removeEventListener("resize",f),window.removeEventListener("scroll",f,!0)}},[a]),(0,ow.createPortal)((0,Ts.jsx)("div",{ref:o,role:"menu",style:{position:"fixed",top:l.top,left:l.left,width:UA},className:"z-[1000] rounded-lg border border-white/10 bg-[#14141b] py-1 text-[11px] text-white/80 shadow-[0_18px_46px_-20px_rgba(0,0,0,0.8)]",onContextMenu:c=>c.preventDefault(),children:i.map((c,d)=>{if(c.kind==="sep")return(0,Ts.jsx)("div",{className:"my-1 h-px bg-white/[0.06]"},`s${d}`);let f=n[c.action]===!0,h=c.Icon;return(0,Ts.jsxs)("button",{type:"button",role:"menuitem",disabled:!f,onClick:()=>{f&&(r(c.action),a())},className:$("flex w-full items-center gap-2 px-3 py-1.5 text-left transition",f?"hover:bg-white/[0.06]":"opacity-35 cursor-not-allowed",c.danger&&f?"text-rose-200 hover:bg-rose-500/10":""),children:[(0,Ts.jsx)(h,{className:$("w-3.5 h-3.5 shrink-0",c.danger?"text-rose-300/80":"text-white/45")}),(0,Ts.jsx)("span",{className:"flex-1 truncate",children:c.label}),c.shortcut?(0,Ts.jsx)("span",{className:"text-[9px] text-white/30 tabular-nums",children:c.shortcut}):null]},c.action)})}),document.body)}var uw=j($e(),1),cw=j(Za(),1);var bn=j(ie(),1);function dw({names:t,busy:e,onCancel:n,onConfirm:r}){(0,uw.useEffect)(()=>{let i=o=>{e||(o.key==="Escape"?(o.preventDefault(),n()):o.key==="Enter"&&(o.preventDefault(),r()))};return document.addEventListener("keydown",i,!0),()=>document.removeEventListener("keydown",i,!0)},[e,n,r]);let a=t.length>1,s=a?`Delete ${t.length} items?`:`Delete '${t[0]}'?`;return(0,cw.createPortal)((0,bn.jsx)("div",{className:"fixed inset-0 z-[1100] flex items-center justify-center bg-black/40 backdrop-blur-[1px]",onMouseDown:i=>{i.target===i.currentTarget&&!e&&n()},children:(0,bn.jsxs)("div",{className:"w-[340px] rounded-xl border border-rose-400/25 bg-[#15151d] p-4 shadow-[0_30px_80px_-24px_rgba(0,0,0,0.85)]",children:[(0,bn.jsxs)("div",{className:"flex items-start gap-2.5",children:[(0,bn.jsx)(ot,{className:"h-4 w-4 text-rose-300 shrink-0 mt-0.5"}),(0,bn.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,bn.jsx)("div",{className:"text-[12px] font-semibold text-white/90",children:s}),(0,bn.jsxs)("div",{className:"mt-1 text-[10.5px] text-white/55 leading-relaxed",children:[a?"The selected files move to Pending Changes. ":"The file moves to Pending Changes. ",(0,bn.jsx)("span",{className:"text-white/75",children:"You can restore"})," ",a?"them":"it"," from there \u2014 this is not a permanent erase."]}),a?(0,bn.jsxs)("div",{className:"mt-2 max-h-24 overflow-auto rounded-md bg-white/[0.03] px-2 py-1.5 text-[10px] font-mono text-white/50 space-y-0.5 overlay-scroll",children:[t.slice(0,12).map(i=>(0,bn.jsx)("div",{className:"truncate",children:i},i)),t.length>12?(0,bn.jsxs)("div",{className:"text-white/35",children:["+",t.length-12," more\u2026"]}):null]}):null]})]}),(0,bn.jsxs)("div",{className:"mt-4 flex items-center justify-end gap-2",children:[(0,bn.jsxs)("button",{type:"button",onClick:n,disabled:e,className:"h-7 px-2.5 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[11px] font-medium text-white/70 transition disabled:opacity-40 inline-flex items-center gap-1",children:[(0,bn.jsx)(Ht,{className:"h-3 w-3"}),"Cancel"]}),(0,bn.jsxs)("button",{type:"button",onClick:r,disabled:e,className:$("h-7 px-3 rounded-md text-[11px] font-semibold transition disabled:opacity-40 inline-flex items-center gap-1.5","bg-rose-500/20 hover:bg-rose-500/30 border border-rose-400/40 text-rose-100"),children:[e?(0,bn.jsx)(We,{className:"h-3 w-3 animate-spin"}):(0,bn.jsx)(Nt,{className:"h-3 w-3"}),"Delete"]})]})]})}),document.body)}var es=j($e(),1),fw=j(Za(),1);var xt=j(ie(),1);function GA(t){return t.usd===null?"unpriced \u2014 the active model has no price":`~$${t.usd.toFixed(2)}${t.usdMargin!==null?` \xB1 $${t.usdMargin.toFixed(2)}`:""}`}function WA(t){return t===null?"time unknown":t<90?`~${Math.round(t)} s`:t<5400?`~${Math.round(t/60)} min`:`~${(t/3600).toFixed(1)} h`}function Xl({agentId:t,projectId:e,target:n,onClose:r,onStarted:a,kind:s="reembed"}){let i=H(b=>b.client),[o,l]=(0,es.useState)(null),[u,c]=(0,es.useState)(!0),[d,f]=(0,es.useState)(!1),[h,p]=(0,es.useState)(null),[g,m]=(0,es.useState)(!1),x={agentId:t,...e?{projectId:e}:{},source:n.source,...n.folder?{folder:n.folder}:{},...n.uri?{uri:n.uri}:{}};(0,es.useEffect)(()=>{let b=!0;return c(!0),cx(x,s,i).then(C=>{b&&l(C)}).catch(C=>{b&&p(C instanceof Error?C.message:"Estimate failed")}).finally(()=>{b&&c(!1)}),()=>{b=!1}},[]),(0,es.useEffect)(()=>{let b=C=>{C.key==="Escape"&&!d&&(C.preventDefault(),r())};return document.addEventListener("keydown",b,!0),()=>document.removeEventListener("keydown",b,!0)},[d,r]);let y=async()=>{f(!0),p(null);try{if(!(await hc(x,s,i)).job){m(!0),f(!1);return}a?.(),r()}catch(b){p(b instanceof Error?b.message:"Re-embed failed"),f(!1)}};return(0,fw.createPortal)((0,xt.jsx)("div",{className:"fixed inset-0 z-[1100] flex items-center justify-center bg-black/40 backdrop-blur-[1px]",onMouseDown:b=>{b.target===b.currentTarget&&!d&&r()},children:(0,xt.jsxs)("div",{role:"dialog","aria-label":`${s==="pending"?"Embed pending files of":"Re-embed"} ${n.label}`,className:"w-[360px] rounded-xl border border-cyan-400/25 bg-[#15151d] p-4 shadow-[0_30px_80px_-24px_rgba(0,0,0,0.85)]",children:[(0,xt.jsxs)("div",{className:"flex items-start gap-2.5",children:[(0,xt.jsx)(ka,{className:"h-4 w-4 text-cyan-300 shrink-0 mt-0.5"}),(0,xt.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,xt.jsx)("div",{className:"truncate text-[12px] font-semibold text-white/90",children:s==="pending"?`Embed pending files of ${n.label}?`:`Re-embed ${n.label}?`}),(0,xt.jsx)("div",{className:"mt-1 text-[10.5px] text-white/55 leading-relaxed",children:s==="pending"?(0,xt.jsxs)(xt.Fragment,{children:["Only files whose semantic embedding is missing or stale are embedded, with the"," ",(0,xt.jsx)("span",{className:"text-white/75",children:"active"})," model. The figures below cover the whole scope \u2014 an upper bound; files already embedded are skipped. Contents and text search are not touched."]}):(0,xt.jsxs)(xt.Fragment,{children:["Every file in this scope is read again and embedded with the ",(0,xt.jsx)("span",{className:"text-white/75",children:"active"})," ","model, whether it changed or not. File contents and history are not touched \u2014 only the vectors are replaced."]})}),(0,xt.jsx)("div",{className:"mt-2 rounded-md bg-white/[0.03] px-2 py-1.5 text-[10.5px] text-white/65 space-y-0.5",children:u?(0,xt.jsxs)("div",{className:"inline-flex items-center gap-1.5 text-white/45",children:[(0,xt.jsx)(We,{className:"h-3 w-3 animate-spin"}),"Estimating from a sample\u2026"]}):o?(0,xt.jsxs)(xt.Fragment,{children:[(0,xt.jsxs)("div",{children:[o.documents!==null?`${o.documents.toLocaleString()} documents \xB7 `:null,o.points.toLocaleString()," points"]}),(0,xt.jsxs)("div",{children:["~",o.tokens.toLocaleString(),o.tokensMargin!==null?` \xB1 ${o.tokensMargin.toLocaleString()}`:""," tokens"]}),(0,xt.jsxs)("div",{children:[GA(o)," \xB7 ",WA(o.durationSeconds)]}),o.truncated?(0,xt.jsx)("div",{className:"text-amber-300/80",children:"The scope is larger than one listing \u2014 these figures cover its first part."}):null]}):h?null:(0,xt.jsx)("div",{className:"text-white/45",children:"No estimate available for this scope."})}),h?(0,xt.jsx)("div",{className:"mt-2 text-[10px] text-rose-300/90",children:h}):null,g?(0,xt.jsx)("div",{className:"mt-2 text-[10px] text-white/55",children:"Nothing readable in this scope \u2014 nothing was queued."}):null]})]}),(0,xt.jsxs)("div",{className:"mt-4 flex items-center justify-end gap-2",children:[(0,xt.jsxs)("button",{type:"button",onClick:r,disabled:d,className:"h-7 px-2.5 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[11px] font-medium text-white/70 transition disabled:opacity-40 inline-flex items-center gap-1",children:[(0,xt.jsx)(Ht,{className:"h-3 w-3"}),"Cancel"]}),(0,xt.jsxs)("button",{type:"button",onClick:()=>{y()},disabled:d||u||g,className:"h-7 px-3 rounded-md text-[11px] font-semibold transition disabled:opacity-40 inline-flex items-center gap-1.5 bg-cyan-500/20 hover:bg-cyan-500/30 border border-cyan-400/40 text-cyan-100",children:[d?(0,xt.jsx)(We,{className:"h-3 w-3 animate-spin"}):(0,xt.jsx)(ka,{className:"h-3 w-3"}),s==="pending"?"Embed pending":"Re-embed"]})]})]})}),document.body)}var ho=j($e(),1);var pw=j(Zr(),1);var In=j(ie(),1);function zA(t){if(!t)return null;if(t.isRepo&&t.repoName)return{label:t.repoName,title:`Repository: ${t.repoName}`};if(t.containsRepos&&t.repoNames&&t.repoNames.length>0){let e=t.repoNames,n=e.slice(0,2).join(", ");return{label:e.length>2?`${n} +${e.length-2}`:n,title:`Repositories: ${e.join(", ")}`}}return null}function jA({info:t}){let e=(0,lr.resolveIconWithFallback)(t.kind_icon??void 0,zn),n=t.source_kind==="brain"||t.source_kind==="local-disk",r=!!(t.git?.isRepo||t.git?.containsRepos);return(0,In.jsxs)("span",{className:"relative inline-flex items-center justify-center",children:[(0,In.jsx)(e,{className:"w-4 h-4"}),n?(0,In.jsx)(Fl,{className:"absolute -right-1.5 -bottom-1.5 w-2.5 h-2.5 text-current bg-black/80 rounded-full p-[1px] opacity-80"}):null,r?(0,In.jsx)(Cn,{className:"absolute -right-1.5 -top-1.5 w-2.5 h-2.5 text-violet-300/90 bg-black/80 rounded-full p-[1px]"}):null]})}function hw(t){return t.source_kind==="brain"?"brain":qe(t.uri_root)}var mw=ho.default.memo(function({info:e,expanded:n,onToggle:r,onContextMenu:a,onRefresh:s,hydration:i="ready",dirty:o=!1,hideChevron:l=!0,compact:u=!1}){let c=(0,ho.useCallback)(()=>r(e.uri_root),[r,e.uri_root]),d=(0,ho.useCallback)(x=>a?.(e.uri_root,x),[a,e.uri_root]),f=(0,ho.useCallback)(x=>{x.stopPropagation(),x.preventDefault(),s?.(e.uri_root)},[s,e.uri_root]),h=Ic(e),p=Xb(e),g=zA(e.git),m=i==="loading";return(0,In.jsxs)("div",{className:$("group flex w-full items-center gap-2 rounded-md select-none text-left transition-colors",u?"py-1 px-1.5":"py-1.5 px-2","hover:bg-white/5",n&&"bg-white/[0.03]"),onContextMenu:d,"aria-busy":m||void 0,children:[(0,In.jsxs)("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-2 bg-transparent text-left outline-none",onClick:c,"aria-expanded":n,title:p?`${e.uri_root} \u2014 ${p}`:e.uri_root,children:[l?null:(0,In.jsx)("span",{className:"w-0","aria-hidden":"true"}),(0,In.jsx)("span",{className:$("shrink-0",h.iconClassName,i==="idle"||i==="error"?"opacity-50":""),children:(0,In.jsx)(jA,{info:e})}),(0,In.jsx)("span",{className:$("text-xs font-medium flex-1 truncate transition-colors",h.labelClassName,i==="idle"||i==="error"?"opacity-70":""),children:hw(e)})]}),g?(0,In.jsxs)("span",{className:"ml-1 inline-flex max-w-[120px] shrink-0 items-center gap-0.5 text-[10px] text-violet-300/70",title:g.title,children:[(0,In.jsx)(Cn,{className:"h-2.5 w-2.5 shrink-0"}),(0,In.jsx)("span",{className:"truncate",children:g.label})]}):null,s?(0,In.jsx)("button",{type:"button",onClick:f,disabled:m,"aria-label":`Refresh ${hw(e)}`,title:i==="error"?"Last listing failed \u2014 click to retry":o?"This source may be out of date \u2014 click to refresh":"Refresh this source",className:$("shrink-0 inline-flex h-4 w-4 items-center justify-center rounded transition-opacity","text-white/40 hover:text-white/80 focus-visible:opacity-100",m||o||i==="error"?"opacity-100":"opacity-0 group-hover:opacity-100",o||i==="error"?"text-amber-300/80 hover:text-amber-200":""),children:m?(0,In.jsx)(pw.LiveSpinner,{className:"h-3 w-3"}):(0,In.jsx)(_t,{className:"h-3 w-3","aria-hidden":"true"})}):null]})});var mo=j($e(),1);var tt=j(ie(),1),VA=[{id:"keyword",label:"Keyword",hint:"Indexed word search (primary)"},{id:"semantic",label:"Semantic",hint:"Embedding search by meaning"},{id:"grep",label:"Grep",hint:"Literal scan of live connector content"}],po="h-6 w-full bg-transparent border border-white/[0.06] rounded px-1.5 text-[11px] text-white/80 placeholder:text-white/25 outline-none focus:border-white/20";function qA(t){return t?t.requestedMode==="semantic"&&t.effectiveMode&&t.effectiveMode!=="semantic"?`Searched as keyword \u2014 semantic search unavailable${t.embeddingDegraded?` (${t.embeddingDegraded})`:""}. Use specific words.`:t.warning??null:null}function gw({agentId:t}){let e=H(k=>k.activeProjectId),n=H(k=>k.setActiveFolderPath),r=H(k=>k.openFile),a=H(k=>k.searchQuery),s=H(k=>k.searchMode),i=H(k=>k.setSearchMode),o=H(k=>k.searchFilters),l=H(k=>k.setSearchFilters),u=H(k=>k.searchResults),c=H(k=>k.searchLoading),d=H(k=>k.searchError),f=H(k=>k.searchEffect),h=qA(f),p=H(k=>k.runSearch),g=H(k=>k.activeFolderPath),m=H(k=>k.sources),[x,y]=(0,mo.useState)(!1),b=a.trim(),C=o.glob.trim(),L=s==="keyword"?b.length>=2||C.length>=2:b.length>=2,P=(0,mo.useMemo)(()=>nh(g,m,o.scopeToFolder),[g,m,o.scopeToFolder]);(0,mo.useEffect)(()=>{if(!L)return;let k=setTimeout(()=>{p({agentId:t,projectId:e??null})},250);return()=>clearTimeout(k)},[t,e,L,s,a,o,p]);let w=(C?1:0)+(o.category.trim()?1:0)+(o.status.trim()?1:0)+(o.tags.trim()?1:0)+(o.createdAfter.trim()?1:0)+(o.createdBefore.trim()?1:0)+(o.scopeToFolder?1:0);return(0,tt.jsxs)("div",{className:"px-2 pb-2",children:[(0,tt.jsxs)("div",{className:"flex items-center gap-1 pb-1.5",children:[(0,tt.jsx)("div",{className:"flex-1 flex items-center rounded-md border border-white/[0.06] overflow-hidden",children:VA.map(k=>{let _=k.id==="grep"&&!P;return(0,tt.jsx)("button",{type:"button",disabled:_,onClick:()=>i(k.id),title:_?"Grep needs a disk-backed source (brain:// has no live text)":k.hint,className:`flex-1 h-6 text-[10px] uppercase tracking-wide transition-colors ${s===k.id?"bg-white/[0.08] text-white/85":_?"text-white/20 cursor-not-allowed":"text-white/40 hover:text-white/70"}`,"aria-pressed":s===k.id,children:k.label},k.id)})}),(0,tt.jsxs)("button",{type:"button",onClick:()=>y(k=>!k),className:`h-6 w-6 shrink-0 rounded-md inline-flex items-center justify-center transition-colors ${x||w>0?"text-white/85":"text-white/40 hover:text-white/70"}`,title:"Search filters","aria-label":"Toggle search filters","aria-pressed":x,children:[(0,tt.jsx)(ui,{className:"w-3.5 h-3.5"}),w>0?(0,tt.jsx)("span",{className:"absolute translate-x-2.5 -translate-y-2 text-[8px] text-white/70",children:w}):null]})]}),x?(0,tt.jsxs)("div",{className:"pb-2 space-y-1",children:[(0,tt.jsxs)("div",{className:"flex items-center gap-1",children:[(0,tt.jsx)("input",{type:"text",value:o.glob,onChange:k=>l({glob:k.target.value}),placeholder:"Filename\u2026",className:po}),(0,tt.jsxs)("label",{className:"flex items-center gap-1 shrink-0 text-[10px] text-white/45 select-none cursor-pointer",title:"Scope to the active folder",children:[(0,tt.jsx)("input",{type:"checkbox",checked:o.scopeToFolder,onChange:k=>l({scopeToFolder:k.target.checked}),className:"accent-white/60"}),"folder"]})]}),s!=="grep"?(0,tt.jsxs)(tt.Fragment,{children:[(0,tt.jsxs)("div",{className:"flex items-center gap-1",children:[(0,tt.jsx)("input",{type:"text",value:o.category,onChange:k=>l({category:k.target.value}),placeholder:"Category\u2026",className:po}),(0,tt.jsx)("input",{type:"text",value:o.status,onChange:k=>l({status:k.target.value}),placeholder:"Status\u2026",className:po})]}),(0,tt.jsx)("input",{type:"text",value:o.tags,onChange:k=>l({tags:k.target.value}),placeholder:"Tags (comma-separated)\u2026",className:po}),(0,tt.jsxs)("div",{className:"flex items-center gap-1",children:[(0,tt.jsx)("input",{type:"date",value:o.createdAfter,onChange:k=>l({createdAfter:k.target.value}),title:"Created after",className:po}),(0,tt.jsx)("input",{type:"date",value:o.createdBefore,onChange:k=>l({createdBefore:k.target.value}),title:"Created before",className:po})]})]}):null]}):null,L?c?(0,tt.jsx)("div",{className:"px-2 py-3 text-[11px] text-white/35",children:"Searching\u2026"}):d?(0,tt.jsx)("div",{className:"px-2 py-3 text-[11px] text-red-300/70",children:d}):u.length===0?(0,tt.jsxs)("div",{className:"px-2 py-3 text-[11px] text-white/35",children:[h?(0,tt.jsx)("div",{role:"status",className:"mb-1 text-[10px] text-amber-200/70",children:h}):null,"No matches"]}):(0,tt.jsxs)("div",{className:"space-y-1",children:[h?(0,tt.jsx)("div",{role:"status",className:"px-2 py-1 text-[10px] text-amber-200/70",children:h}):null,u.map(k=>(0,tt.jsxs)("button",{type:"button",className:"w-full text-left px-2 py-2 rounded-md hover:bg-white/5 border border-white/[0.04] transition-colors",onClick:()=>{n(et(k.uri)),r({agentId:t,projectId:e??null,uri:k.uri})},children:[(0,tt.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,tt.jsx)("span",{className:"text-[11px] text-white/80 truncate flex-1",children:k.filename}),typeof k.score=="number"?(0,tt.jsx)("span",{className:"text-[9px] text-white/30 shrink-0",children:k.score.toFixed(2)}):null,k.embedding_status==="missing"||k.embedding_status==="stale"?(0,tt.jsxs)("span",{className:"text-[9px] px-1 py-0.5 rounded bg-white/[0.06] text-white/40 shrink-0",title:"This file is text-searchable; its semantic embedding is not current",children:["embedding ",k.embedding_status]}):null,k.match_type?(0,tt.jsx)("span",{className:"text-[9px] px-1 py-0.5 rounded bg-white/[0.06] text-white/40 shrink-0",children:k.match_type==="hybrid"?"H":k.match_type==="semantic"?"S":"K"}):null]}),(0,tt.jsxs)("div",{className:"text-[10px] text-white/35 font-mono truncate",children:[k.uri,s==="grep"&&typeof k.chunk_start=="number"?`:${k.chunk_start}`:""]}),k.snippet??k.content_preview?(0,tt.jsx)("div",{className:"text-[10px] text-white/45 mt-1 line-clamp-2",children:k.snippet??k.content_preview}):null]},`${k.id}:${k.uri}:${k.chunk_start??""}`))]}):(0,tt.jsx)("div",{className:"px-2 py-3 text-[11px] text-white/35",children:s==="keyword"?"Type to search (or set a filename filter)\u2026":"Type to search\u2026"})]})}var we=j($e(),1),A1=j(Za(),1);var P1=j(Wn(),1);var nt=j($e(),1);var h1=j(Zr(),1);var hi=j(ie(),1);function $A(t){return t<1e4?String(t):t<1e6?`${Math.round(t/1e3)}k`:`${(t/1e6).toFixed(1)}M`}function Aa({added:t,removed:e,binary:n,unknown:r,compact:a,className:s}){if(n)return(0,hi.jsx)("span",{className:$("shrink-0 text-[9px] tabular-nums text-white/40",s),title:"Binary file \u2014 git reports no line count",children:"bin"});if(!(typeof t=="number"&&typeof e=="number")||t===0&&e===0&&!r)return null;let o=a?$A:String,l=r?"+":"";return(0,hi.jsxs)("span",{className:$("flex shrink-0 items-center gap-1 text-[9px] tabular-nums",s),title:r?`+${t} \u2212${e} across the counted files; ${r} more could not be measured`:`+${t} \u2212${e}`,children:[t>0?(0,hi.jsx)("span",{className:"text-emerald-400/80",children:`+${o(t)}${l}`}):null,e>0?(0,hi.jsx)("span",{className:"text-rose-400/80",children:`\u2212${o(e)}${l}`}):null,t===0&&e===0?(0,hi.jsx)("span",{className:"text-white/35",children:`0${l}`}):null]})}function KA(t){return(t.refs??[]).some(e=>e==="HEAD"||e.startsWith("HEAD ")||e.startsWith("HEAD-")||e.includes("HEAD ->"))}function xw(t){let e=[],n=[];if(!Array.isArray(t)||t.length===0)return{nodes:e,edges:n,rowSegments:[],laneCount:0};let r=[],a=new Map,s=0,i=u=>{let c=r.indexOf(u);if(c>=0)return c;let d=r.indexOf(null);return d>=0?(r[d]=u,d):(r.push(u),r.length-1)};for(let u=0;u<t.length;u++){let c=t[u],d=c.sha,f=r.indexOf(d);f<0&&(f=i(d));for(let p=0;p<r.length;p++)r[p]===d&&(r[p]=null);f>s&&(s=f),a.set(d,{row:u,lane:f});let h=Array.isArray(c.parents)?c.parents:[];if(h.length!==0){r[f]=h[0];for(let p=1;p<h.length;p++){let g=i(h[p]);g>s&&(s=g)}}e.push({commit:c,row:u,lane:f,isHead:KA(c),isMerge:h.length>=2})}let o=t.map(()=>[]),l=(u,c)=>{u>=0&&u<o.length&&o[u].push(c)};for(let u of e){let c=Array.isArray(u.commit.parents)?u.commit.parents:[];for(let d=0;d<c.length;d++){let f=a.get(c[d]);if(f){n.push({fromRow:u.row,fromLane:u.lane,toRow:f.row,toLane:f.lane,colorLane:u.lane,open:!1});let h=u.row,p=f.row,g=u.lane,m=f.lane,x=u.lane;if(p<=h)continue;if(g===m){l(h,{kind:"pass",fromLane:g,toLane:g,fromY:"center",toY:"edge",colorLane:x});for(let y=h+1;y<p;y++)l(y,{kind:"pass",fromLane:g,toLane:g,fromY:"edge",toY:"edge",colorLane:x});l(p,{kind:"pass",fromLane:g,toLane:g,fromY:"edge",toY:"center",colorLane:x})}else{let y=(g+m)/2,b=d>0?"merge":"fork";if(d>0){if(l(h,{kind:b,fromLane:g,toLane:y,fromY:"center",toY:"edge",colorLane:x}),l(h+1,{kind:b,fromLane:y,toLane:m,fromY:"edge",toY:"center",colorLane:x}),h+1<p){l(h+1,{kind:"pass",fromLane:m,toLane:m,fromY:"center",toY:"edge",colorLane:x});for(let C=h+2;C<p;C++)l(C,{kind:"pass",fromLane:m,toLane:m,fromY:"edge",toY:"edge",colorLane:x});l(p,{kind:"pass",fromLane:m,toLane:m,fromY:"edge",toY:"center",colorLane:x})}}else{if(p-1>h){l(h,{kind:"pass",fromLane:g,toLane:g,fromY:"center",toY:"edge",colorLane:x});for(let C=h+1;C<p-1;C++)l(C,{kind:"pass",fromLane:g,toLane:g,fromY:"edge",toY:"edge",colorLane:x});l(p-1,{kind:"pass",fromLane:g,toLane:g,fromY:"edge",toY:"center",colorLane:x})}l(p-1,{kind:b,fromLane:g,toLane:y,fromY:"center",toY:"edge",colorLane:x}),l(p,{kind:b,fromLane:y,toLane:m,fromY:"edge",toY:"center",colorLane:x})}}}else n.push({fromRow:u.row,fromLane:u.lane,toRow:u.row+1,toLane:u.lane,colorLane:u.lane,open:!0}),l(u.row,{kind:"stub",fromLane:u.lane,toLane:u.lane,fromY:"center",toY:"edge",colorLane:u.lane})}}return{nodes:e,edges:n,rowSegments:o,laneCount:s+1}}function yw(t,e){if(!Array.isArray(t)||e<=0||e>=t.length)return[];let n=[],r=new Set;for(let a of t[e]??[]){if(a.fromY!=="edge")continue;let s=`${a.fromLane}|${a.colorLane}`;r.has(s)||(r.add(s),n.push({kind:"pass",fromLane:a.fromLane,toLane:a.fromLane,fromY:"edge",toY:"edge",colorLane:a.colorLane}))}return n}var Ih={commits:[],nextSkip:0,hasMore:!1};function bw(t,e){let n=[];for(let r of e.commits)!r||typeof r.sha!="string"||t.has(r.sha)||(t.add(r.sha),n.push(r));return n}function ww(t,e){let n=new Set(t.commits.map(a=>a.sha)),r=bw(n,e);return{commits:r.length>0?[...t.commits,...r]:t.commits,nextSkip:t.nextSkip+e.commits.length,hasMore:e.hasMore,outgoing:t.outgoing}}function vw(t){return{commits:bw(new Set,t),nextSkip:t.commits.length,hasMore:t.hasMore,outgoing:t.outgoing}}function Lh(t){return Math.min(1e3,Math.max(t,200))}function kw(t,e){let n=[],r=e&&e.length>0?new Set(e):null,a=!1;for(let s=0;s<t.length;s++)!a&&r&&r.has(t[s].sha)&&(n.push({kind:"outgoing-divider"}),a=!0),n.push({kind:"commit",row:s});return n}function Sw(t,e){return t.kind==="outgoing-divider"?"#outgoing-divider":e[t.row]?.sha??`row-${t.row}`}function Cw(t){let e=t.trim();return e.startsWith("tag:")?"tag":e.startsWith("origin/")?"remote":"local"}function Iw(t,e){return e?"outgoing":t?"merge":"filled"}var XA="#89b4fa";function Lw(t,e){return t==="outgoing"?XA:e}function Ah(t,e=Date.now()){let n=Date.parse(t);if(Number.isNaN(n))return t;let r=Math.max(0,Math.floor((e-n)/1e3));if(r<60)return"just now";let a=Math.floor(r/60);if(a<60)return`${a}m ago`;let s=Math.floor(a/60);if(s<24)return`${s}h ago`;let i=Math.floor(s/24);if(i<30)return`${i}d ago`;let o=Math.floor(i/30);return o<12?`${o}mo ago`:`${Math.floor(o/12)}y ago`}function Aw(t){return!t||typeof t.upstream!="string"||t.upstream.length===0?null:{upstream:t.upstream,ahead:typeof t.ahead=="number"&&t.ahead>=0?t.ahead:0,behind:typeof t.behind=="number"&&t.behind>=0?t.behind:0}}function Ph(t,e){if(typeof window>"u")return e;try{let n=JSON.parse(window.localStorage.getItem(t)??"null");return typeof n=="boolean"?n:e}catch{return e}}function Nh(t,e){if(!(typeof window>"u"))try{window.localStorage.setItem(t,JSON.stringify(e))}catch{}}function Fs(t,e){return typeof e=="string"&&e.length>0?{prefix:`${t}://`,name:e,title:`Source "${t}" \u2014 repository "${e}"`}:{prefix:"",name:t,title:`Repository: ${t}`}}var ns=j($e(),1);var En=j($e(),1),YA=3,Pw=200,Nw=8*1024*1024,JA="200% 0px";function Pc(t){let e=(0,En.useRef)(new Map),n=(0,En.useRef)(null),[r,a]=(0,En.useState)(new Set),s=(0,En.useRef)(0),i=(0,En.useRef)([]),o=(0,En.useRef)(new Map),l=(0,En.useRef)(0),u=(0,En.useRef)(new Map),c=(0,En.useCallback)((p,g)=>{let m=e.current.get(p);m!==g&&(m&&n.current?.unobserve(m),g?(g.dataset.diffCardKey=p,e.current.set(p,g),n.current?.observe(g)):e.current.delete(p))},[]);(0,En.useEffect)(()=>{if(a(new Set),!t||typeof IntersectionObserver>"u")return;let p=new IntersectionObserver(g=>{a(m=>{let x=new Set(m);for(let y of g){let b=y.target.dataset.diffCardKey;b&&(y.isIntersecting?x.add(b):x.delete(b))}return x.size===m.size&&[...x].every(y=>m.has(y))?m:x})},{root:t,rootMargin:JA});n.current=p;for(let g of e.current.values())p.observe(g);return()=>{p.disconnect(),n.current=null}},[t]);let d=(0,En.useCallback)((p,g,m,x)=>{let y=o.current,b=y.get(p);if(b&&(y.delete(p),l.current-=b.bytes),!(m>Nw)){y.set(p,{value:g,bytes:m}),l.current+=m,x&&(u.current.delete(x),u.current.set(x,p)),u.current.size>Pw&&u.current.delete(u.current.keys().next().value);for(let[C,L]of y){if(y.size<=Pw&&l.current<=Nw)break;y.delete(C),l.current-=L.bytes}}},[]),f=(0,En.useCallback)((p,g,m)=>{if(m&&!m.fresh){let x=o.current.get(m.key);if(x)return o.current.delete(m.key),o.current.set(m.key,x),Promise.resolve(x.value)}return new Promise((x,y)=>{let b=()=>{s.current+=1;let C=()=>{s.current-=1,i.current.shift()?.()};if(!g()){C(),x(void 0);return}p().then(L=>{m&&d(m.key,L,m.bytes(L),m.family),C(),x(L)},L=>{C(),y(L)})};s.current<YA?b():i.current.push(b)})},[d]),h=(0,En.useCallback)((p,g)=>(o.current.get(p)??(g?o.current.get(u.current.get(g)??""):void 0))?.value,[]);return{register:c,visible:r,run:f,peek:h}}var ht=j($e(),1);var Be=j(ie()),St=j($e());function Rw(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(a){return Object.getOwnPropertyDescriptor(t,a).enumerable}))),n.push.apply(n,r)}return n}function Rt(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?Rw(Object(n),!0).forEach((function(r){Fh(t,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Rw(Object(n)).forEach((function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))}))}return t}function Fh(t,e,n){return(e=(function(r){var a=(function(s,i){if(typeof s!="object"||s===null)return s;var o=s[Symbol.toPrimitive];if(o!==void 0){var l=o.call(s,i||"default");if(typeof l!="object")return l;throw new TypeError("@@toPrimitive must return a primitive value.")}return(i==="string"?String:Number)(s)})(r,"string");return typeof a=="symbol"?a:String(a)})(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Os(t,e){if(t==null)return{};var n,r,a=(function(i,o){if(i==null)return{};var l,u,c={},d=Object.keys(i);for(u=0;u<d.length;u++)l=d[u],o.indexOf(l)>=0||(c[l]=i[l]);return c})(t,e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);for(r=0;r<s.length;r++)n=s[r],e.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(t,n)&&(a[n]=t[n])}return a}function en(t,e){return sv(t)||(function(n,r){var a=n==null?null:typeof Symbol<"u"&&n[Symbol.iterator]||n["@@iterator"];if(a!=null){var s,i,o,l,u=[],c=!0,d=!1;try{if(o=(a=a.call(n)).next,r===0){if(Object(a)!==a)return;c=!1}else for(;!(c=(s=o.call(a)).done)&&(u.push(s.value),u.length!==r);c=!0);}catch(f){d=!0,i=f}finally{try{if(!c&&a.return!=null&&(l=a.return(),Object(l)!==l))return}finally{if(d)throw i}}return u}})(t,e)||Hc(t,e)||ov()}function ZA(t){return sv(t)||iv(t)||Hc(t)||ov()}function kr(t){return(function(e){if(Array.isArray(e))return Eh(e)})(t)||iv(t)||Hc(t)||(function(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
5
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)})()}function sv(t){if(Array.isArray(t))return t}function iv(t){if(typeof Symbol<"u"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function Hc(t,e){if(t){if(typeof t=="string")return Eh(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return n==="Object"&&t.constructor&&(n=t.constructor.name),n==="Map"||n==="Set"?Array.from(t):n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Eh(t,e):void 0}}function Eh(t,e){(e==null||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function ov(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
6
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function zh(t,e){var n=typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=Hc(t))||e&&t&&typeof t.length=="number"){n&&(t=n);var r=0,a=function(){};return{s:a,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(l){throw l},f:a}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
7
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s,i=!0,o=!1;return{s:function(){n=n.call(t)},n:function(){var l=n.next();return i=l.done,l},e:function(l){o=!0,s=l},f:function(){try{i||n.return==null||n.return()}finally{if(o)throw s}}}}var Nc=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function nu(t,e){return t(e={exports:{}},e.exports),e.exports}var wn=nu((function(t){(function(){var e={}.hasOwnProperty;function n(){for(var r=[],a=0;a<arguments.length;a++){var s=arguments[a];if(s){var i=typeof s;if(i==="string"||i==="number")r.push(s);else if(Array.isArray(s)){if(s.length){var o=n.apply(null,s);o&&r.push(o)}}else if(i==="object"){if(s.toString!==Object.prototype.toString&&!s.toString.toString().includes("[native code]")){r.push(s.toString());continue}for(var l in s)e.call(s,l)&&s[l]&&r.push(l)}}}return r.join(" ")}t.exports?(n.default=n,t.exports=n):window.classNames=n})()})),ur={hunkClassName:"",lineClassName:"",gutterClassName:"",codeClassName:"",monotonous:!1,gutterType:"default",viewType:"split",widgets:{},hideGutter:!1,selectedChanges:[],generateAnchorID:function(){},generateLineClassName:function(){},renderGutter:function(t){var e=t.renderDefault;return(0,t.wrapInAnchor)(e())},codeEvents:{},gutterEvents:{}},lv=(0,St.createContext)(ur),QA=lv.Provider,uv=function(){return(0,St.useContext)(lv)},eP=nu((function(t,e){(function(n){function r(s){var i=s.slice(11),o=null,l=null;switch(i.indexOf('"')){case-1:o=(d=i.split(" "))[0].slice(2),l=d[1].slice(2);break;case 0:var u=i.indexOf('"',2);o=i.slice(3,u);var c=i.indexOf('"',u+1);l=c<0?i.slice(u+4):i.slice(c+3,-1);break;default:var d;o=(d=i.split(" "))[0].slice(2),l=d[1].slice(3,-1)}return{oldPath:o,newPath:l}}var a={parse:function(s){for(var i,o,l,u,c,d=[],f=2,h=s.split(`
8
+ `),p=h.length,g=0;g<p;){var m=h[g];if(m.indexOf("diff --git")===0){i={hunks:[],oldEndingNewLine:!0,newEndingNewLine:!0,oldPath:(c=r(m)).oldPath,newPath:c.newPath},d.push(i);var x,y=null;e:for(;x=h[++g];){var b=x.indexOf(" "),C=b>-1?x.slice(0,b):C;switch(C){case"diff":g--;break e;case"deleted":case"new":var L=x.slice(b+1);L.indexOf("file mode")===0&&(i[C==="new"?"newMode":"oldMode"]=L.slice(10));break;case"similarity":i.similarity=parseInt(x.split(" ")[2],10);break;case"index":var P=x.slice(b+1).split(" "),w=P[0].split("..");i.oldRevision=w[0],i.newRevision=w[1],P[1]&&(i.oldMode=i.newMode=P[1]);break;case"copy":case"rename":var k=x.slice(b+1);k.indexOf("from")===0?i.oldPath=k.slice(5):i.newPath=k.slice(3),y=C;break;case"---":var _=x.slice(b+1),M=h[++g].slice(4);_==="/dev/null"?(M=M.slice(2),y="add"):M==="/dev/null"?(_=_.slice(2),y="delete"):(y="modify",_=_.slice(2),M=M.slice(2)),_&&(i.oldPath=_),M&&(i.newPath=M),f=5;break e}}i.type=y||"modify"}else if(m.indexOf("Binary")===0)i.isBinary=!0,i.type=m.indexOf("/dev/null and")>=0?"add":m.indexOf("and /dev/null")>=0?"delete":"modify",f=2,i=null;else if(f===5)if(m.indexOf("@@")===0){var R=/^@@\s+-([0-9]+)(,([0-9]+))?\s+\+([0-9]+)(,([0-9]+))?/.exec(m);o={content:m,oldStart:R[1]-0,newStart:R[4]-0,oldLines:R[3]-0||1,newLines:R[6]-0||1,changes:[]},i.hunks.push(o),l=o.oldStart,u=o.newStart}else{var U=m.slice(0,1),v={content:m.slice(1)};switch(U){case"+":v.type="insert",v.isInsert=!0,v.lineNumber=u,u++;break;case"-":v.type="delete",v.isDelete=!0,v.lineNumber=l,l++;break;case" ":v.type="normal",v.isNormal=!0,v.oldLineNumber=l,v.newLineNumber=u,l++,u++;break;case"\\":var T=o.changes[o.changes.length-1];T.isDelete||(i.newEndingNewLine=!1),T.isInsert||(i.oldEndingNewLine=!1)}v.type&&o.changes.push(v)}g++}return d}};t.exports=a})()}));function _s(t){return t.type==="insert"}function aa(t){return t.type==="delete"}function Pa(t){return t.type==="normal"}function tP(t,e){var n=e.nearbySequences==="zip"?(function(r){var a=r.reduce((function(s,i,o){var l=en(s,3),u=l[0],c=l[1],d=l[2];return c?_s(i)&&d>=0?(u.splice(d+1,0,i),[u,i,d+2]):(u.push(i),[u,i,aa(i)&&aa(c)?d:o]):(u.push(i),[u,i,aa(i)?o:-1])}),[[],null,-1]);return en(a,1)[0]})(t.changes):t.changes;return Rt(Rt({},t),{},{isPlain:!1,changes:n})}function cv(t){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},n=(function(r){if(r.startsWith("diff --git"))return r;var a=r.indexOf(`
9
9
  `),s=r.indexOf(`
10
- `,a+1),o=r.slice(0,a),i=r.slice(a+1,s),l=o.split(" ").slice(1,-3).join(" "),u=i.split(" ").slice(1,-3).join(" ");return["diff --git a/".concat(l," b/").concat(u),"index 1111111..2222222 100644","--- a/".concat(l),"+++ b/".concat(u),r.slice(s+1)].join(`
11
- `)})(n.trimStart());return FA.parse(t).map((function(r){return(function(a,s){var o=a.hunks.map((function(i){return EA(i,s)}));return At(At({},a),{},{hunks:o})})(r,e)}))}function uv(n){return n[0]}function cv(n){return n[n.length-1]}function Hh(n){return["".concat(n,"Start"),"".concat(n,"Lines")]}function Es(n){return n==="old"?function(e){return Bs(e)?-1:Ia(e)?e.oldLineNumber:e.lineNumber}:function(e){return sa(e)?-1:Ia(e)?e.newLineNumber:e.lineNumber}}function $h(n,e){return function(t,r){var a=t[n],s=a+t[e];return r>=a&&r<s}}function dv(n,e){return function(t,r,a){var s=t[n]+t[e],o=r[n];return a>=s&&a<o}}function fv(n){var e=Es(n),t=(function(r){var a=en(Hh(r),2),s=$h(a[0],a[1]);return function(o,i){return o.find((function(l){return s(l,i)}))}})(n);return function(r,a){var s=t(r,a);if(s)return s.changes.find((function(o){return e(o)===a}))}}function Kh(n){var e=n==="old"?"new":"old",t=en(Hh(n),2),r=t[0],a=t[1],s=en(Hh(e),2),o=s[0],i=s[1],l=Es(n),u=Es(e),c=$h(r,a),d=dv(r,a);return function(f,h){var p=uv(f);if(h<p[r]){var m=p[r]-h;return p[o]-m}var g=cv(f);if(g[r]+g[a]<=h){var x=h-g[r]-g[a];return g[o]+g[i]+x}for(var w=0;w<f.length;w++){var y=f[w],C=f[w+1];if(c(y,h)){var k=y.changes.findIndex((function(U){return l(U)===h})),v=y.changes[k];if(Ia(v))return u(v);var b=sa(v)?k+1:k-1,P=y.changes[b];if(!P)return-1;var N=Bs(v)?"delete":"insert";return P.type===N?u(P):-1}if(d(y,C,h)){var M=h-y[r]-y[a];return y[o]+y[i]+M}}throw new Error("Unexpected line position ".concat(h))}}var BA=function(n,e,t,r){for(var a=n.length,s=t+(r?1:-1);r?s--:++s<a;)if(e(n[s],s,n))return s;return-1},OA=function(){this.__data__=[],this.size=0},hv=function(n,e){return n===e||n!=n&&e!=e},Ec=function(n,e){for(var t=n.length;t--;)if(hv(n[t][0],e))return t;return-1},_A=Array.prototype.splice,HA=function(n){var e=this.__data__,t=Ec(e,n);return!(t<0)&&(t==e.length-1?e.pop():_A.call(e,t,1),--this.size,!0)},UA=function(n){var e=this.__data__,t=Ec(e,n);return t<0?void 0:e[t][1]},GA=function(n){return Ec(this.__data__,n)>-1},zA=function(n,e){var t=this.__data__,r=Ec(t,n);return r<0?(++this.size,t.push([n,e])):t[r][1]=e,this};function pi(n){var e=-1,t=n==null?0:n.length;for(this.clear();++e<t;){var r=n[e];this.set(r[0],r[1])}}pi.prototype.clear=OA,pi.prototype.delete=HA,pi.prototype.get=UA,pi.prototype.has=GA,pi.prototype.set=zA;var Bc=pi,WA=function(){this.__data__=new Bc,this.size=0},jA=function(n){var e=this.__data__,t=e.delete(n);return this.size=e.size,t},qA=function(n){return this.__data__.get(n)},VA=function(n){return this.__data__.has(n)},pv=typeof Cc=="object"&&Cc&&Cc.Object===Object&&Cc,$A=typeof self=="object"&&self&&self.Object===Object&&self,Qa=pv||$A||Function("return this")(),Aa=Qa.Symbol,mv=Object.prototype,KA=mv.hasOwnProperty,XA=mv.toString,Vl=Aa?Aa.toStringTag:void 0,YA=function(n){var e=KA.call(n,Vl),t=n[Vl];try{n[Vl]=void 0;var r=!0}catch{}var a=XA.call(n);return r&&(e?n[Vl]=t:delete n[Vl]),a},JA=Object.prototype.toString,ZA=function(n){return JA.call(n)},Nw=Aa?Aa.toStringTag:void 0,bi=function(n){return n==null?n===void 0?"[object Undefined]":"[object Null]":Nw&&Nw in Object(n)?YA(n):ZA(n)},Kl=function(n){var e=typeof n;return n!=null&&(e=="object"||e=="function")},gv=function(n){if(!Kl(n))return!1;var e=bi(n);return e=="[object Function]"||e=="[object GeneratorFunction]"||e=="[object AsyncFunction]"||e=="[object Proxy]"},Dh=Qa["__core-js_shared__"],Rw=(function(){var n=/[^.]+$/.exec(Dh&&Dh.keys&&Dh.keys.IE_PROTO||"");return n?"Symbol(src)_1."+n:""})(),QA=function(n){return!!Rw&&Rw in n},eP=Function.prototype.toString,mo=function(n){if(n!=null){try{return eP.call(n)}catch{}try{return n+""}catch{}}return""},tP=/^\[object .+?Constructor\]$/,nP=Function.prototype,rP=Object.prototype,aP=nP.toString,sP=rP.hasOwnProperty,oP=RegExp("^"+aP.call(sP).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),iP=function(n){return!(!Kl(n)||QA(n))&&(gv(n)?oP:tP).test(mo(n))},lP=function(n,e){return n?.[e]},go=function(n,e){var t=lP(n,e);return iP(t)?t:void 0},Xl=go(Qa,"Map"),Yl=go(Object,"create"),uP=function(){this.__data__=Yl?Yl(null):{},this.size=0},cP=function(n){var e=this.has(n)&&delete this.__data__[n];return this.size-=e?1:0,e},dP=Object.prototype.hasOwnProperty,fP=function(n){var e=this.__data__;if(Yl){var t=e[n];return t==="__lodash_hash_undefined__"?void 0:t}return dP.call(e,n)?e[n]:void 0},hP=Object.prototype.hasOwnProperty,pP=function(n){var e=this.__data__;return Yl?e[n]!==void 0:hP.call(e,n)},mP=function(n,e){var t=this.__data__;return this.size+=this.has(n)?0:1,t[n]=Yl&&e===void 0?"__lodash_hash_undefined__":e,this};function mi(n){var e=-1,t=n==null?0:n.length;for(this.clear();++e<t;){var r=n[e];this.set(r[0],r[1])}}mi.prototype.clear=uP,mi.prototype.delete=cP,mi.prototype.get=fP,mi.prototype.has=pP,mi.prototype.set=mP;var Mw=mi,gP=function(){this.size=0,this.__data__={hash:new Mw,map:new(Xl||Bc),string:new Mw}},xP=function(n){var e=typeof n;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?n!=="__proto__":n===null},Oc=function(n,e){var t=n.__data__;return xP(e)?t[typeof e=="string"?"string":"hash"]:t.map},yP=function(n){var e=Oc(this,n).delete(n);return this.size-=e?1:0,e},bP=function(n){return Oc(this,n).get(n)},wP=function(n){return Oc(this,n).has(n)},vP=function(n,e){var t=Oc(this,n),r=t.size;return t.set(n,e),this.size+=t.size==r?0:1,this};function gi(n){var e=-1,t=n==null?0:n.length;for(this.clear();++e<t;){var r=n[e];this.set(r[0],r[1])}}gi.prototype.clear=gP,gi.prototype.delete=yP,gi.prototype.get=bP,gi.prototype.has=wP,gi.prototype.set=vP;var _c=gi,kP=function(n,e){var t=this.__data__;if(t instanceof Bc){var r=t.__data__;if(!Xl||r.length<199)return r.push([n,e]),this.size=++t.size,this;t=this.__data__=new _c(r)}return t.set(n,e),this.size=t.size,this};function xi(n){var e=this.__data__=new Bc(n);this.size=e.size}xi.prototype.clear=WA,xi.prototype.delete=jA,xi.prototype.get=qA,xi.prototype.has=VA,xi.prototype.set=kP;var Rc=xi,SP=function(n){return this.__data__.set(n,"__lodash_hash_undefined__"),this},CP=function(n){return this.__data__.has(n)};function Mc(n){var e=-1,t=n==null?0:n.length;for(this.__data__=new _c;++e<t;)this.add(n[e])}Mc.prototype.add=Mc.prototype.push=SP,Mc.prototype.has=CP;var LP=Mc,IP=function(n,e){for(var t=-1,r=n==null?0:n.length;++t<r;)if(e(n[t],t,n))return!0;return!1},AP=function(n,e){return n.has(e)},xv=function(n,e,t,r,a,s){var o=1&t,i=n.length,l=e.length;if(i!=l&&!(o&&l>i))return!1;var u=s.get(n),c=s.get(e);if(u&&c)return u==e&&c==n;var d=-1,f=!0,h=2&t?new LP:void 0;for(s.set(n,e),s.set(e,n);++d<i;){var p=n[d],m=e[d];if(r)var g=o?r(m,p,d,e,n,s):r(p,m,d,n,e,s);if(g!==void 0){if(g)continue;f=!1;break}if(h){if(!IP(e,(function(x,w){if(!AP(h,w)&&(p===x||a(p,x,t,r,s)))return h.push(w)}))){f=!1;break}}else if(p!==m&&!a(p,m,t,r,s)){f=!1;break}}return s.delete(n),s.delete(e),f},Tw=Qa.Uint8Array,PP=function(n){var e=-1,t=Array(n.size);return n.forEach((function(r,a){t[++e]=[a,r]})),t},NP=function(n){var e=-1,t=Array(n.size);return n.forEach((function(r){t[++e]=r})),t},Dw=Aa?Aa.prototype:void 0,Fh=Dw?Dw.valueOf:void 0,RP=function(n,e,t,r,a,s,o){switch(t){case"[object DataView]":if(n.byteLength!=e.byteLength||n.byteOffset!=e.byteOffset)return!1;n=n.buffer,e=e.buffer;case"[object ArrayBuffer]":return!(n.byteLength!=e.byteLength||!s(new Tw(n),new Tw(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return hv(+n,+e);case"[object Error]":return n.name==e.name&&n.message==e.message;case"[object RegExp]":case"[object String]":return n==e+"";case"[object Map]":var i=PP;case"[object Set]":var l=1&r;if(i||(i=NP),n.size!=e.size&&!l)return!1;var u=o.get(n);if(u)return u==e;r|=2,o.set(n,e);var c=xv(i(n),i(e),r,a,s,o);return o.delete(n),c;case"[object Symbol]":if(Fh)return Fh.call(n)==Fh.call(e)}return!1},yv=function(n,e){for(var t=-1,r=e.length,a=n.length;++t<r;)n[a+t]=e[t];return n},_r=Array.isArray,MP=function(n,e,t){var r=e(n);return _r(n)?r:yv(r,t(n))},TP=function(n,e){for(var t=-1,r=n==null?0:n.length,a=0,s=[];++t<r;){var o=n[t];e(o,t,n)&&(s[a++]=o)}return s},DP=function(){return[]},FP=Object.prototype.propertyIsEnumerable,Fw=Object.getOwnPropertySymbols,EP=Fw?function(n){return n==null?[]:(n=Object(n),TP(Fw(n),(function(e){return FP.call(n,e)})))}:DP,BP=function(n,e){for(var t=-1,r=Array(n);++t<n;)r[t]=e(t);return r},yi=function(n){return n!=null&&typeof n=="object"},Ew=function(n){return yi(n)&&bi(n)=="[object Arguments]"},bv=Object.prototype,OP=bv.hasOwnProperty,_P=bv.propertyIsEnumerable,Xh=Ew((function(){return arguments})())?Ew:function(n){return yi(n)&&OP.call(n,"callee")&&!_P.call(n,"callee")},HP=function(){return!1},Uh=Zl((function(n,e){var t=e&&!e.nodeType&&e,r=t&&n&&!n.nodeType&&n,a=r&&r.exports===t?Qa.Buffer:void 0,s=(a?a.isBuffer:void 0)||HP;n.exports=s})),UP=/^(?:0|[1-9]\d*)$/,wv=function(n,e){var t=typeof n;return!!(e=e??9007199254740991)&&(t=="number"||t!="symbol"&&UP.test(n))&&n>-1&&n%1==0&&n<e},Yh=function(n){return typeof n=="number"&&n>-1&&n%1==0&&n<=9007199254740991},Vt={};Vt["[object Float32Array]"]=Vt["[object Float64Array]"]=Vt["[object Int8Array]"]=Vt["[object Int16Array]"]=Vt["[object Int32Array]"]=Vt["[object Uint8Array]"]=Vt["[object Uint8ClampedArray]"]=Vt["[object Uint16Array]"]=Vt["[object Uint32Array]"]=!0,Vt["[object Arguments]"]=Vt["[object Array]"]=Vt["[object ArrayBuffer]"]=Vt["[object Boolean]"]=Vt["[object DataView]"]=Vt["[object Date]"]=Vt["[object Error]"]=Vt["[object Function]"]=Vt["[object Map]"]=Vt["[object Number]"]=Vt["[object Object]"]=Vt["[object RegExp]"]=Vt["[object Set]"]=Vt["[object String]"]=Vt["[object WeakMap]"]=!1;var GP=function(n){return yi(n)&&Yh(n.length)&&!!Vt[bi(n)]},zP=function(n){return function(e){return n(e)}},Bw=Zl((function(n,e){var t=e&&!e.nodeType&&e,r=t&&n&&!n.nodeType&&n,a=r&&r.exports===t&&pv.process,s=(function(){try{var o=r&&r.require&&r.require("util").types;return o||a&&a.binding&&a.binding("util")}catch{}})();n.exports=s})),Ow=Bw&&Bw.isTypedArray,vv=Ow?zP(Ow):GP,WP=Object.prototype.hasOwnProperty,jP=function(n,e){var t=_r(n),r=!t&&Xh(n),a=!t&&!r&&Uh(n),s=!t&&!r&&!a&&vv(n),o=t||r||a||s,i=o?BP(n.length,String):[],l=i.length;for(var u in n)!e&&!WP.call(n,u)||o&&(u=="length"||a&&(u=="offset"||u=="parent")||s&&(u=="buffer"||u=="byteLength"||u=="byteOffset")||wv(u,l))||i.push(u);return i},qP=Object.prototype,VP=function(n){var e=n&&n.constructor;return n===(typeof e=="function"&&e.prototype||qP)},$P=(function(n,e){return function(t){return n(e(t))}})(Object.keys,Object),KP=Object.prototype.hasOwnProperty,XP=function(n){if(!VP(n))return $P(n);var e=[];for(var t in Object(n))KP.call(n,t)&&t!="constructor"&&e.push(t);return e},Jh=function(n){return n!=null&&Yh(n.length)&&!gv(n)},Zh=function(n){return Jh(n)?jP(n):XP(n)},_w=function(n){return MP(n,Zh,EP)},YP=Object.prototype.hasOwnProperty,JP=function(n,e,t,r,a,s){var o=1&t,i=_w(n),l=i.length;if(l!=_w(e).length&&!o)return!1;for(var u=l;u--;){var c=i[u];if(!(o?c in e:YP.call(e,c)))return!1}var d=s.get(n),f=s.get(e);if(d&&f)return d==e&&f==n;var h=!0;s.set(n,e),s.set(e,n);for(var p=o;++u<l;){var m=n[c=i[u]],g=e[c];if(r)var x=o?r(g,m,c,e,n,s):r(m,g,c,n,e,s);if(!(x===void 0?m===g||a(m,g,t,r,s):x)){h=!1;break}p||(p=c=="constructor")}if(h&&!p){var w=n.constructor,y=e.constructor;w==y||!("constructor"in n)||!("constructor"in e)||typeof w=="function"&&w instanceof w&&typeof y=="function"&&y instanceof y||(h=!1)}return s.delete(n),s.delete(e),h},Gh=go(Qa,"DataView"),zh=go(Qa,"Promise"),Wh=go(Qa,"Set"),jh=go(Qa,"WeakMap"),ZP=mo(Gh),QP=mo(Xl),eN=mo(zh),tN=mo(Wh),nN=mo(jh),po=bi;(Gh&&po(new Gh(new ArrayBuffer(1)))!="[object DataView]"||Xl&&po(new Xl)!="[object Map]"||zh&&po(zh.resolve())!="[object Promise]"||Wh&&po(new Wh)!="[object Set]"||jh&&po(new jh)!="[object WeakMap]")&&(po=function(n){var e=bi(n),t=e=="[object Object]"?n.constructor:void 0,r=t?mo(t):"";if(r)switch(r){case ZP:return"[object DataView]";case QP:return"[object Map]";case eN:return"[object Promise]";case tN:return"[object Set]";case nN:return"[object WeakMap]"}return e});var Hw=po,Lc="[object Object]",Uw=Object.prototype.hasOwnProperty,rN=function(n,e,t,r,a,s){var o=_r(n),i=_r(e),l=o?"[object Array]":Hw(n),u=i?"[object Array]":Hw(e),c=(l=l=="[object Arguments]"?Lc:l)==Lc,d=(u=u=="[object Arguments]"?Lc:u)==Lc,f=l==u;if(f&&Uh(n)){if(!Uh(e))return!1;o=!0,c=!1}if(f&&!c)return s||(s=new Rc),o||vv(n)?xv(n,e,t,r,a,s):RP(n,e,l,t,r,a,s);if(!(1&t)){var h=c&&Uw.call(n,"__wrapped__"),p=d&&Uw.call(e,"__wrapped__");if(h||p){var m=h?n.value():n,g=p?e.value():e;return s||(s=new Rc),a(m,g,t,r,s)}}return!!f&&(s||(s=new Rc),JP(n,e,t,r,a,s))},Hc=function n(e,t,r,a,s){return e===t||(e==null||t==null||!yi(e)&&!yi(t)?e!=e&&t!=t:rN(e,t,r,a,n,s))},aN=function(n,e,t,r){var a=t.length,s=a,o=!r;if(n==null)return!s;for(n=Object(n);a--;){var i=t[a];if(o&&i[2]?i[1]!==n[i[0]]:!(i[0]in n))return!1}for(;++a<s;){var l=(i=t[a])[0],u=n[l],c=i[1];if(o&&i[2]){if(u===void 0&&!(l in n))return!1}else{var d=new Rc;if(r)var f=r(u,c,l,n,e,d);if(!(f===void 0?Hc(c,u,3,r,d):f))return!1}}return!0},kv=function(n){return n==n&&!Kl(n)},sN=function(n){for(var e=Zh(n),t=e.length;t--;){var r=e[t],a=n[r];e[t]=[r,a,kv(a)]}return e},Sv=function(n,e){return function(t){return t!=null&&t[n]===e&&(e!==void 0||n in Object(t))}},oN=function(n){var e=sN(n);return e.length==1&&e[0][2]?Sv(e[0][0],e[0][1]):function(t){return t===n||aN(t,n,e)}},Uc=function(n){return typeof n=="symbol"||yi(n)&&bi(n)=="[object Symbol]"},iN=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,lN=/^\w*$/,Qh=function(n,e){if(_r(n))return!1;var t=typeof n;return!(t!="number"&&t!="symbol"&&t!="boolean"&&n!=null&&!Uc(n))||lN.test(n)||!iN.test(n)||e!=null&&n in Object(e)};function ep(n,e){if(typeof n!="function"||e!=null&&typeof e!="function")throw new TypeError("Expected a function");var t=function(){var r=arguments,a=e?e.apply(this,r):r[0],s=t.cache;if(s.has(a))return s.get(a);var o=n.apply(this,r);return t.cache=s.set(a,o)||s,o};return t.cache=new(ep.Cache||_c),t}ep.Cache=_c;var uN=ep,cN=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,dN=/\\(\\)?/g,fN=(function(n){var e=uN(n,(function(r){return t.size===500&&t.clear(),r})),t=e.cache;return e})((function(n){var e=[];return n.charCodeAt(0)===46&&e.push(""),n.replace(cN,(function(t,r,a,s){e.push(a?s.replace(dN,"$1"):r||t)})),e})),Cv=function(n,e){for(var t=-1,r=n==null?0:n.length,a=Array(r);++t<r;)a[t]=e(n[t],t,n);return a},Gw=Aa?Aa.prototype:void 0,zw=Gw?Gw.toString:void 0,hN=function n(e){if(typeof e=="string")return e;if(_r(e))return Cv(e,n)+"";if(Uc(e))return zw?zw.call(e):"";var t=e+"";return t=="0"&&1/e==-1/0?"-0":t},pN=function(n){return n==null?"":hN(n)},Lv=function(n,e){return _r(n)?n:Qh(n,e)?[n]:fN(pN(n))},Gc=function(n){if(typeof n=="string"||Uc(n))return n;var e=n+"";return e=="0"&&1/n==-1/0?"-0":e},Iv=function(n,e){for(var t=0,r=(e=Lv(e,n)).length;n!=null&&t<r;)n=n[Gc(e[t++])];return t&&t==r?n:void 0},mN=function(n,e,t){var r=n==null?void 0:Iv(n,e);return r===void 0?t:r},gN=function(n,e){return n!=null&&e in Object(n)},xN=function(n,e,t){for(var r=-1,a=(e=Lv(e,n)).length,s=!1;++r<a;){var o=Gc(e[r]);if(!(s=n!=null&&t(n,o)))break;n=n[o]}return s||++r!=a?s:!!(a=n==null?0:n.length)&&Yh(a)&&wv(o,a)&&(_r(n)||Xh(n))},yN=function(n,e){return n!=null&&xN(n,e,gN)},bN=function(n,e){return Qh(n)&&kv(e)?Sv(Gc(n),e):function(t){var r=mN(t,n);return r===void 0&&r===e?yN(t,n):Hc(e,r,3)}},wN=function(n){return n},vN=function(n){return function(e){return e?.[n]}},kN=function(n){return function(e){return Iv(e,n)}},SN=function(n){return Qh(n)?vN(Gc(n)):kN(n)},zc=function(n){return typeof n=="function"?n:n==null?wN:typeof n=="object"?_r(n)?bN(n[0],n[1]):oN(n):SN(n)},CN=/\s/,LN=function(n){for(var e=n.length;e--&&CN.test(n.charAt(e)););return e},IN=/^\s+/,AN=function(n){return n&&n.slice(0,LN(n)+1).replace(IN,"")},PN=/^[-+]0x[0-9a-f]+$/i,NN=/^0b[01]+$/i,RN=/^0o[0-7]+$/i,MN=parseInt,TN=function(n){if(typeof n=="number")return n;if(Uc(n))return NaN;if(Kl(n)){var e=typeof n.valueOf=="function"?n.valueOf():n;n=Kl(e)?e+"":e}if(typeof n!="string")return n===0?n:+n;n=AN(n);var t=NN.test(n);return t||RN.test(n)?MN(n.slice(2),t?2:8):PN.test(n)?NaN:+n},DN=function(n){return n?(n=TN(n))===1/0||n===-1/0?17976931348623157e292*(n<0?-1:1):n==n?n:0:n===0?n:0},FN=function(n){var e=DN(n),t=e%1;return e==e?t?e-t:e:0},EN=Math.max,BN=Math.min,Ww=function(n,e,t){var r=n==null?0:n.length;if(!r)return-1;var a=r-1;return t!==void 0&&(a=FN(t),a=t<0?EN(r+a,0):BN(a,r-1)),BA(n,zc(e),a,!0)},Jl=Es("old"),ON=Es("new");function jw(n){var e=n.oldStart;return[e,e+n.oldLines-1]}function Tc(n){if(!n.length)return null;var e=n.reduce((function(o,i){return Ia(i)||(o.isPlain=!1),Bs(i)||(o.oldLines=o.oldLines+1,o.oldStart===-1&&(o.oldStart=Jl(i))),sa(i)||(o.newLines=o.newLines+1,o.newStart===-1&&(o.newStart=ON(i))),o}),{isPlain:!0,content:"",oldStart:-1,oldLines:0,newStart:-1,newLines:0}),t=e.oldStart,r=e.oldLines,a=e.newStart,s=e.newLines;return At(At({},e),{},{content:"@@ -".concat(t,",").concat(r," +").concat(a,",").concat(s),changes:n})}function _N(n,e,t){return Tc(n.map((function(r,a){return{type:"normal",isNormal:!0,oldLineNumber:e+a,newLineNumber:t+a,content:""+r}})))}function Ic(n,e,t){var r=n.changes,a=r.findIndex((function(i){return Jl(i)>=e}));if(a===-1)return null;var s=(function(){if(a===0)return a;var i=Ww(r,(function(l){return!Bs(l)}),a-1);return i===-1?a:i+1})();if(t===void 0)return Tc(r.slice(s));var o=Ww(r,(function(i){return Jl(i)<=t}));return Tc(r.slice(s,o===-1?void 0:o))}function $l(n,e){if(!n)return e;if(!e)return n;var t=en(jw(n),2),r=t[0],a=t[1],s=en(jw(e),2),o=s[0],i=s[1];if(a+1===o)return Tc([].concat(Sr(n.changes),Sr(e.changes)));if(r<=o&&a>=i){if(n.isPlain&&!e.isPlain){var l=Ic(n,r,o),u=Ic(n,i+1);return $l($l(l,e),u)}return n}return n.isPlain?$l(Ic(n,r,o),e):$l(n,Ic(e,a+1))}function HN(n,e){var t=cv(n);if(!t)return[e];if(t.oldStart+t.oldLines<e.oldStart)return n.concat(e);var r=$l(t,e);return r?[].concat(Sr(n.slice(0,-1)),[r]):n}function UN(n,e){var t=Jl(e.changes[0]),r=n.findIndex((function(a){var s=a.changes;return!!s.length&&Jl(s[0])>=t}));return(r===-1?n.concat(e):[].concat(Sr(n.slice(0,r)),[e],Sr(n.slice(r)))).reduce(HN,[])}function Ds(n){if(!n)throw new Error("change is not provided");if(Ia(n))return"N".concat(n.oldLineNumber);var e=Bs(n)?"I":"D";return"".concat(e).concat(n.lineNumber)}var GN=Kh("old"),Eh=Es("old"),qw=$h("oldStart","oldLines"),zN=dv("oldStart","oldLines");function qh(n,e,t){var r=(function(h,p){if(!h.length)return-1;var m=uv(h);if(p<m.oldStart||qw(m,p))return 0;for(var g=1;g<h.length;g++){var x=h[g];if(qw(x,p))return g;var w=h[g-1];if(zN(w,x,p))return g}return-1})(n,e);if(r===-1)return[[e,t]];var a=n[r];if(e<a.oldStart){var s=a.changes.findIndex((function(h){return!Ia(h)})),o=a.oldStart+Math.max(s,0);return o>=t?[[e,t]]:[[e,o]].concat(Sr(qh(n,o+1,t)))}var i=a.changes,l=(function(h,p){var m=h.changes,g=m.findIndex((function(w){return Eh(w)===p}));if(g<0)return-1;for(var x=g;x<m.length;x++)if(Ia(m[x]))return x;return-1})(a,e);if(l===-1)return[];var u=i[l],c=Eh(u),d=i.slice(l+1).findIndex((function(h){return!Ia(h)})),f=Eh(u)+Math.max(d,0);return f>=t?[[c,t]]:[[c,f]].concat(Sr(qh(n,f+1,t)))}function Av(n,e,t,r){return qh(n,t,r).reduce((function(a,s){return(function(o,i,l){var u=en(l,2),c=u[0],d=u[1],f=(typeof i=="string"?i.split(`
12
- `):i).slice(Math.max(c,1)-1,d-1);if(!f.length)return o;var h=_N(f,c,GN(o,c));return h?UN(o,h):o})(a,e,s)}),n)}function Pv(n,e){if(!n)return e.oldStart-1;var t=n.oldStart+n.oldLines;return e.oldStart-t}var Wc=Es("old"),jc=Es("new"),YG=fv("old"),JG=fv("new"),ZG=Kh("new"),QG=Kh("old"),Vw=(function(){try{var n=go(Object,"defineProperty");return n({},"",{}),n}catch{}})(),tp=function(n,e,t){e=="__proto__"&&Vw?Vw(n,e,{configurable:!0,enumerable:!0,value:t,writable:!0}):n[e]=t},WN=function(n){return function(e,t,r){for(var a=-1,s=Object(e),o=r(e),i=o.length;i--;){var l=o[n?i:++a];if(t(s[l],l,s)===!1)break}return e}},jN=WN(),Nv=function(n,e){return n&&jN(n,e,Zh)},Rv=function(n,e){var t={};return e=zc(e),Nv(n,(function(r,a,s){tp(t,a,e(r,a,s))})),t},qN=["changeKey","text","tokens","renderToken"],$w=function n(e,t){var r=e.type,a=e.value,s=e.markType,o=e.properties,i=e.className,l=e.children,u=function(d){return(0,Oe.jsx)("span",{className:d,children:a||l&&l.map(n)},t)};switch(r){case"text":return a;case"mark":return u("diff-code-mark diff-code-mark-".concat(s));case"edit":return u("diff-code-edit");default:var c=o&&o.className;return u(wn(i||c))}};function VN(n){if(!Array.isArray(n))return!0;if(n.length>1)return!1;if(n.length===1){var e=en(n,1)[0];return e.type==="text"&&!e.value}return!0}function $N(n){var e=n.changeKey,t=n.text,r=n.tokens,a=n.renderToken,s=Fs(n,qN),o=a?function(i,l){return a(i,$w,l)}:$w;return(0,Oe.jsx)("td",At(At({},s),{},{"data-change-key":e,children:r?VN(r)?" ":r.map(o):t||" "}))}var Mv=(0,kt.memo)($N);function Tv(n,e){return function(){var t=e==="old"?Wc(n):jc(n);return t===-1?void 0:t}}function Dv(n,e){return function(t){return n&&t?(0,Oe.jsx)("a",{href:e?"#"+e:void 0,children:t}):t}}function Dc(n,e){return e?function(t){n(),e(t)}:n}function Kw(n,e,t,r){return(0,kt.useMemo)((function(){var a=Rv(n,(function(s){return function(o){return s&&s(e,o)}}));return a.onMouseEnter=Dc(t,a.onMouseEnter),a.onMouseLeave=Dc(r,a.onMouseLeave),a}),[n,t,r,e])}function Xw(n,e,t,r,a,s,o,i,l){var u={change:e,side:r,inHoverState:i,renderDefault:Tv(e,r),wrapInAnchor:Dv(a,s)};return(0,Oe.jsx)("td",At(At({className:n},o),{},{"data-change-key":t,children:l(u)}))}function KN(n){var e,t,r,a=n.change,s=n.selected,o=n.tokens,i=n.className,l=n.generateLineClassName,u=n.gutterClassName,c=n.codeClassName,d=n.gutterEvents,f=n.codeEvents,h=n.hideGutter,p=n.gutterAnchor,m=n.generateAnchorID,g=n.renderToken,x=n.renderGutter,w=a.type,y=a.content,C=Ds(a),k=(e=en((0,kt.useState)(!1),2),t=e[0],r=e[1],[t,(0,kt.useCallback)((function(){return r(!0)}),[]),(0,kt.useCallback)((function(){return r(!1)}),[])]),v=en(k,3),b=v[0],P=v[1],N=v[2],M=(0,kt.useMemo)((function(){return{change:a}}),[a]),U=Kw(d,M,P,N),I=Kw(f,M,P,N),A=m(a),G=l({changes:[a],defaultGenerate:function(){return i}}),V=wn("diff-gutter","diff-gutter-".concat(w),u,{"diff-gutter-selected":s}),K=wn("diff-code","diff-code-".concat(w),c,{"diff-code-selected":s});return(0,Oe.jsxs)("tr",{id:A,className:wn("diff-line",G),children:[!h&&Xw(V,a,C,"old",p,A,U,b,x),!h&&Xw(V,a,C,"new",p,A,U,b,x),(0,Oe.jsx)(Mv,At({className:K,changeKey:C,text:y,tokens:o,renderToken:g},I))]})}var XN=(0,kt.memo)(KN);function YN(n){var e=n.hideGutter,t=n.element;return(0,Oe.jsx)("tr",{className:"diff-widget",children:(0,Oe.jsx)("td",{colSpan:e?1:3,className:"diff-widget-content",children:t})})}var JN=["hideGutter","selectedChanges","tokens","lineClassName"],ZN=["hunk","widgets","className"];function QN(n){var e=n.hunk,t=n.widgets,r=n.className,a=Fs(n,ZN),s=(function(o,i){return o.reduce((function(l,u){var c=Ds(u);l.push(["change",c,u]);var d=i[c];return d&&l.push(["widget",c,d]),l}),[])})(e.changes,t);return(0,Oe.jsx)("tbody",{className:wn("diff-hunk",r),children:s.map((function(o){return(function(i,l){var u=en(i,3),c=u[0],d=u[1],f=u[2],h=l.hideGutter,p=l.selectedChanges,m=l.tokens,g=l.lineClassName,x=Fs(l,JN);if(c==="change"){var w=sa(f)?"old":"new",y=sa(f)?Wc(f):jc(f),C=m?m[w][y-1]:null;return(0,Oe.jsx)(XN,At({className:g,change:f,hideGutter:h,selected:p.includes(d),tokens:C},x),"change".concat(d))}return c==="widget"?(0,Oe.jsx)(YN,{hideGutter:h,element:f},"widget".concat(d)):null})(o,a)}))})}var Fv=0;function Ac(n,e,t,r){var a=(0,kt.useCallback)((function(){return e(n)}),[n,e]),s=(0,kt.useCallback)((function(){return e("")}),[e]);return(0,kt.useMemo)((function(){var o=Rv(r,(function(i){return function(l){return i&&i({side:n,change:t},l)}}));return o.onMouseEnter=Dc(a,o.onMouseEnter),o.onMouseLeave=Dc(s,o.onMouseLeave),o}),[t,r,a,n,s])}function Bh(n){var e=n.change,t=n.side,r=n.selected,a=n.tokens,s=n.gutterClassName,o=n.codeClassName,i=n.gutterEvents,l=n.codeEvents,u=n.anchorID,c=n.gutterAnchor,d=n.gutterAnchorTarget,f=n.hideGutter,h=n.hover,p=n.renderToken,m=n.renderGutter;if(!e){var g=wn("diff-gutter","diff-gutter-omit",s),x=wn("diff-code","diff-code-omit",o);return[!f&&(0,Oe.jsx)("td",{className:g},"gutter"),(0,Oe.jsx)("td",{className:x},"code")]}var w=e.type,y=e.content,C=Ds(e),k=t===Fv?"old":"new",v=At({id:u||void 0,className:wn("diff-gutter","diff-gutter-".concat(w),Oh({"diff-gutter-selected":r},"diff-line-hover-"+k,h),s),children:m({change:e,side:k,inHoverState:h,renderDefault:Tv(e,k),wrapInAnchor:Dv(c,d)})},i),b=wn("diff-code","diff-code-".concat(w),Oh({"diff-code-selected":r},"diff-line-hover-"+k,h),o);return[!f&&(0,Oe.jsx)("td",At(At({},v),{},{"data-change-key":C}),"gutter"),(0,Oe.jsx)(Mv,At({className:b,changeKey:C,text:y,tokens:a,renderToken:p},l),"code")]}function eR(n){var e=n.className,t=n.oldChange,r=n.newChange,a=n.oldSelected,s=n.newSelected,o=n.oldTokens,i=n.newTokens,l=n.monotonous,u=n.gutterClassName,c=n.codeClassName,d=n.gutterEvents,f=n.codeEvents,h=n.hideGutter,p=n.generateAnchorID,m=n.generateLineClassName,g=n.gutterAnchor,x=n.renderToken,w=n.renderGutter,y=en((0,kt.useState)(""),2),C=y[0],k=y[1],v=Ac("old",k,t,d),b=Ac("new",k,r,d),P=Ac("old",k,t,f),N=Ac("new",k,r,f),M=t&&p(t),U=r&&p(r),I=m({changes:[t,r],defaultGenerate:function(){return e}}),A={monotonous:l,hideGutter:h,gutterClassName:u,codeClassName:c,gutterEvents:d,codeEvents:f,renderToken:x,renderGutter:w},G=At(At({},A),{},{change:t,side:Fv,selected:a,tokens:o,gutterEvents:v,codeEvents:P,anchorID:M,gutterAnchor:g,gutterAnchorTarget:M,hover:C==="old"}),V=At(At({},A),{},{change:r,side:1,selected:s,tokens:i,gutterEvents:b,codeEvents:N,anchorID:t===r?null:U,gutterAnchor:g,gutterAnchorTarget:t===r?M:U,hover:C==="new"});if(l)return(0,Oe.jsx)("tr",{className:wn("diff-line",I),children:Bh(t?G:V)});var K=(function(L,R){return L&&!R?"diff-line-old-only":!L&&R?"diff-line-new-only":L===R?"diff-line-normal":"diff-line-compare"})(t,r);return(0,Oe.jsxs)("tr",{className:wn("diff-line",K,I),children:[Bh(G),Bh(V)]})}var tR=(0,kt.memo)(eR);function nR(n){var e=n.hideGutter,t=n.oldElement,r=n.newElement;return n.monotonous?(0,Oe.jsx)("tr",{className:"diff-widget",children:(0,Oe.jsx)("td",{colSpan:e?1:2,className:"diff-widget-content",children:t||r})}):t===r?(0,Oe.jsx)("tr",{className:"diff-widget",children:(0,Oe.jsx)("td",{colSpan:e?2:4,className:"diff-widget-content",children:t})}):(0,Oe.jsxs)("tr",{className:"diff-widget",children:[(0,Oe.jsx)("td",{colSpan:e?1:2,className:"diff-widget-content",children:t}),(0,Oe.jsx)("td",{colSpan:e?1:2,className:"diff-widget-content",children:r})]})}var rR=["selectedChanges","monotonous","hideGutter","tokens","lineClassName"],aR=["hunk","widgets","className"];function Pc(n,e){return(n?Ds(n):"00")+(e?Ds(e):"00")}function sR(n){var e=n.hunk,t=n.widgets,r=n.className,a=Fs(n,aR),s=(function(o,i){for(var l=function(x){if(!x)return null;var w=Ds(x);return i[w]||null},u=[],c=0;c<o.length;c++){var d=o[c];if(Ia(d))u.push(["change",Pc(d,d),d,d]);else if(sa(d)){var f=o[c+1];f&&Bs(f)?(c+=1,u.push(["change",Pc(d,f),d,f])):u.push(["change",Pc(d,null),d,null])}else u.push(["change",Pc(null,d),null,d]);var h=u[u.length-1],p=l(h[2]),m=l(h[3]);if(p||m){var g=h[1];u.push(["widget",g,p,m])}}return u})(e.changes,t);return(0,Oe.jsx)("tbody",{className:wn("diff-hunk",r),children:s.map((function(o){return(function(i,l){var u=en(i,4),c=u[0],d=u[1],f=u[2],h=u[3],p=l.selectedChanges,m=l.monotonous,g=l.hideGutter,x=l.tokens,w=l.lineClassName,y=Fs(l,rR);if(c==="change"){var C=!!f&&p.includes(Ds(f)),k=!!h&&p.includes(Ds(h)),v=f&&x?x.old[Wc(f)-1]:null,b=h&&x?x.new[jc(h)-1]:null;return(0,Oe.jsx)(tR,At({className:w,oldChange:f,newChange:h,monotonous:m,hideGutter:g,oldSelected:C,newSelected:k,oldTokens:v,newTokens:b},y),"change".concat(d))}return c==="widget"?(0,Oe.jsx)(nR,{monotonous:m,hideGutter:g,oldElement:f,newElement:h},"widget".concat(d)):null})(o,a)}))})}var oR=["gutterType","hunkClassName"];function np(n){var e=n.hunk,t=iv(),r=t.gutterType,a=t.hunkClassName,s=Fs(t,oR),o=r==="none",i=r==="anchor",l=s.viewType==="unified"?QN:sR;return(0,Oe.jsx)(l,At(At({},s),{},{hunk:e,hideGutter:o,gutterAnchor:i,className:a}))}function iR(){}function Yw(n,e){var t=e?"auto":"none";n instanceof HTMLElement&&n.style.userSelect!==t&&(n.style.userSelect=t)}function lR(n){return n.map((function(e){return(0,Oe.jsx)(np,{hunk:e},(function(t){return"-".concat(t.oldStart,",").concat(t.oldLines," +").concat(t.newStart,",").concat(t.newLines)})(e))}))}function uR(n){var e=n.diffType,t=n.hunks,r=n.optimizeSelection,a=n.className,s=n.hunkClassName,o=s===void 0?or.hunkClassName:s,i=n.lineClassName,l=i===void 0?or.lineClassName:i,u=n.generateLineClassName,c=u===void 0?or.generateLineClassName:u,d=n.gutterClassName,f=d===void 0?or.gutterClassName:d,h=n.codeClassName,p=h===void 0?or.codeClassName:h,m=n.gutterType,g=m===void 0?or.gutterType:m,x=n.viewType,w=x===void 0?or.viewType:x,y=n.gutterEvents,C=y===void 0?or.gutterEvents:y,k=n.codeEvents,v=k===void 0?or.codeEvents:k,b=n.generateAnchorID,P=b===void 0?or.generateAnchorID:b,N=n.selectedChanges,M=N===void 0?or.selectedChanges:N,U=n.widgets,I=U===void 0?or.widgets:U,A=n.renderGutter,G=A===void 0?or.renderGutter:A,V=n.tokens,K=n.renderToken,L=n.children,R=L===void 0?lR:L,z=(0,kt.useRef)(null),J=(0,kt.useCallback)((function(ue){var He=ue.target;if(ue.button===0){var De=(function(Pt,Ye){for(var Ne=Pt;Ne&&Ne!==document.documentElement&&!Ne.classList.contains(Ye);)Ne=Ne.parentElement;return Ne===document.documentElement?null:Ne})(He,"diff-code");if(De&&De.parentElement){var je=window.getSelection();je&&je.removeAllRanges();var et=Sr(De.parentElement.children).indexOf(De);if(et===1||et===3){var Dt,at=Vh(z.current?z.current.querySelectorAll(".diff-line"):[]);try{for(at.s();!(Dt=at.n()).done;){var vt=Dt.value.children;Yw(vt[1],et===1),Yw(vt[3],et===3)}}catch(Pt){at.e(Pt)}finally{at.f()}}}}}),[]),Q=g==="none",re=e==="add"||e==="delete",pe=w==="split"&&!re&&r?J:iR,ee=(0,kt.useMemo)((function(){return(0,Oe.jsxs)("colgroup",w==="unified"?{children:[!Q&&(0,Oe.jsx)("col",{className:"diff-gutter-col"}),!Q&&(0,Oe.jsx)("col",{className:"diff-gutter-col"}),(0,Oe.jsx)("col",{})]}:re?{children:[!Q&&(0,Oe.jsx)("col",{className:"diff-gutter-col"}),(0,Oe.jsx)("col",{})]}:{children:[!Q&&(0,Oe.jsx)("col",{className:"diff-gutter-col"}),(0,Oe.jsx)("col",{}),!Q&&(0,Oe.jsx)("col",{className:"diff-gutter-col"}),(0,Oe.jsx)("col",{})]})}),[w,re,Q]),ce=(0,kt.useMemo)((function(){return{hunkClassName:o,lineClassName:l,generateLineClassName:c,gutterClassName:f,codeClassName:p,monotonous:re,hideGutter:Q,viewType:w,gutterType:g,codeEvents:v,gutterEvents:C,generateAnchorID:P,selectedChanges:M,widgets:I,renderGutter:G,tokens:V,renderToken:K}}),[p,v,P,f,C,g,Q,o,l,c,re,G,K,M,V,w,I]);return(0,Oe.jsx)(DA,{value:ce,children:(0,Oe.jsxs)("table",{ref:z,className:wn("diff","diff-".concat(w),a),onMouseDown:pe,children:[ee,R(t)]})})}var Ev=(0,kt.memo)(uR),cR=function(){};var Jw=cR;function dR(n){var e=n.hideGutter,t=n.monotonous,r=n.className,a=n.gutterClassName,s=n.contentClassName,o=n.children,i=wn("diff-decoration",r),l=wn("diff-decoration-gutter",a),u=wn("diff-decoration-content",s),c=(e?2:4)/(t?2:1),d=c-(e?0:1);if(kt.Children.count(o)===1)return(0,Oe.jsx)("tbody",{className:i,children:(0,Oe.jsx)("tr",{children:(0,Oe.jsx)("td",{colSpan:c,className:u,children:o})})});var f=en(o,2),h=f[0],p=f[1];return(0,Oe.jsx)("tbody",{className:i,children:(0,Oe.jsxs)("tr",{children:[!e&&(0,Oe.jsx)("td",{className:l,children:h}),(0,Oe.jsx)("td",{colSpan:d,className:u,children:p})]})})}function fR(n){var e=n.hideGutter,t=n.className,r=n.gutterClassName,a=n.contentClassName,s=n.children,o=wn("diff-decoration",t),i=wn("diff-decoration-gutter",r),l=wn("diff-decoration-content",a);if(kt.Children.count(s)===1)return(0,Oe.jsx)("tbody",{className:o,children:(0,Oe.jsx)("tr",{children:(0,Oe.jsx)("td",{colSpan:e?1:3,className:l,children:s})})});var u=en(s,2),c=u[0],d=u[1];return(0,Oe.jsx)("tbody",{className:o,children:(0,Oe.jsxs)("tr",{children:[!e&&(0,Oe.jsx)("td",{colSpan:2,className:i,children:c}),(0,Oe.jsx)("td",{className:l,children:d})]})})}function qc(n){var e=n.className,t=e===void 0?"":e,r=n.gutterClassName,a=r===void 0?"":r,s=n.contentClassName,o=s===void 0?"":s,i=n.children,l=iv(),u=l.viewType,c=l.gutterType,d=l.monotonous,f=u==="split"?dR:fR,h=kt.Children.count(i),p=c==="none";return Jw(h<=2,"Decoration only accepts a maxium of 2 children"),Jw(h<2||!p,"Gutter element in decoration will not be rendered since hideGutter prop is set to true"),(0,Oe.jsx)(f,{hideGutter:p,monotonous:d,className:t,gutterClassName:a,contentClassName:o,children:i})}var hR=function(n,e,t,r){for(var a=-1,s=n==null?0:n.length;++a<s;){var o=n[a];e(r,o,t(o),n)}return r},pR=function(n,e){return function(t,r){if(t==null)return t;if(!Jh(t))return n(t,r);for(var a=t.length,s=e?a:-1,o=Object(t);(e?s--:++s<a)&&r(o[s],s,o)!==!1;);return t}},Bv=pR(Nv),mR=function(n,e,t,r){return Bv(n,(function(a,s,o){e(r,a,t(a),o)})),r},Ov=function(n,e){return function(t,r){var a=_r(t)?hR:mR,s=e?e():{};return a(t,n,zc(r),s)}},gR=Ov((function(n,e,t){tp(n,t,e)})),Zw=Aa?Aa.isConcatSpreadable:void 0,xR=function(n){return _r(n)||Xh(n)||!!(Zw&&n&&n[Zw])},yR=function n(e,t,r,a,s){var o=-1,i=e.length;for(r||(r=xR),s||(s=[]);++o<i;){var l=e[o];t>0&&r(l)?t>1?n(l,t-1,r,a,s):yv(s,l):a||(s[s.length]=l)}return s},bR=function(n,e){var t=-1,r=Jh(n)?Array(n.length):[];return Bv(n,(function(a,s,o){r[++t]=e(a,s,o)})),r},wR=function(n,e){return(_r(n)?Cv:bR)(n,zc(e))},vR=function(n,e){return yR(wR(n,e),1)};function kR(n,e){var t=e.newStart,r=e.changes.reduce((function(a,s){var o=en(a,2),i=o[0],l=o[1];return sa(s)?(i.splice(l,1),[i,l]):(Bs(s)&&i.splice(l,0,s.content),[i,l+1])}),[n,t-1]);return en(r,1)[0]}function Qw(n,e,t){if(!n.length)return[];var r=e==="old"?Wc:jc,a=gR(n,r),s=r(n[n.length-1]);return Array.from({length:s}).map((function(o,i){return t(a[i+1])}))}function SR(n){var e=(function(o){return vR(o,(function(i){return i.changes})).reduce((function(i,l){var u=en(i,2),c=u[0],d=u[1];return Ia(l)?(c.push(l),d.push(l)):sa(l)?c.push(l):d.push(l),[c,d]}),[[],[]])})(n),t=en(e,2),r=t[0],a=t[1],s=function(o){return o?o.content:""};return[Qw(r,"old",s).join(`
13
- `),Qw(a,"new",s).join(`
14
- `)]}function Nc(n){return{type:"root",children:n}}function CR(n,e){if(e.oldSource){var t=(function(l,u){return u.reduce(kR,l.split(`
10
+ `,a+1),i=r.slice(0,a),o=r.slice(a+1,s),l=i.split(" ").slice(1,-3).join(" "),u=o.split(" ").slice(1,-3).join(" ");return["diff --git a/".concat(l," b/").concat(u),"index 1111111..2222222 100644","--- a/".concat(l),"+++ b/".concat(u),r.slice(s+1)].join(`
11
+ `)})(t.trimStart());return eP.parse(n).map((function(r){return(function(a,s){var i=a.hunks.map((function(o){return tP(o,s)}));return Rt(Rt({},a),{},{hunks:i})})(r,e)}))}function dv(t){return t[0]}function fv(t){return t[t.length-1]}function Oh(t){return["".concat(t,"Start"),"".concat(t,"Lines")]}function Bs(t){return t==="old"?function(e){return _s(e)?-1:Pa(e)?e.oldLineNumber:e.lineNumber}:function(e){return aa(e)?-1:Pa(e)?e.newLineNumber:e.lineNumber}}function jh(t,e){return function(n,r){var a=n[t],s=a+n[e];return r>=a&&r<s}}function hv(t,e){return function(n,r,a){var s=n[t]+n[e],i=r[t];return a>=s&&a<i}}function pv(t){var e=Bs(t),n=(function(r){var a=en(Oh(r),2),s=jh(a[0],a[1]);return function(i,o){return i.find((function(l){return s(l,o)}))}})(t);return function(r,a){var s=n(r,a);if(s)return s.changes.find((function(i){return e(i)===a}))}}function Vh(t){var e=t==="old"?"new":"old",n=en(Oh(t),2),r=n[0],a=n[1],s=en(Oh(e),2),i=s[0],o=s[1],l=Bs(t),u=Bs(e),c=jh(r,a),d=hv(r,a);return function(f,h){var p=dv(f);if(h<p[r]){var g=p[r]-h;return p[i]-g}var m=fv(f);if(m[r]+m[a]<=h){var x=h-m[r]-m[a];return m[i]+m[o]+x}for(var y=0;y<f.length;y++){var b=f[y],C=f[y+1];if(c(b,h)){var L=b.changes.findIndex((function(R){return l(R)===h})),P=b.changes[L];if(Pa(P))return u(P);var w=aa(P)?L+1:L-1,k=b.changes[w];if(!k)return-1;var _=_s(P)?"delete":"insert";return k.type===_?u(k):-1}if(d(b,C,h)){var M=h-b[r]-b[a];return b[i]+b[o]+M}}throw new Error("Unexpected line position ".concat(h))}}var nP=function(t,e,n,r){for(var a=t.length,s=n+(r?1:-1);r?s--:++s<a;)if(e(t[s],s,t))return s;return-1},rP=function(){this.__data__=[],this.size=0},mv=function(t,e){return t===e||t!=t&&e!=e},Uc=function(t,e){for(var n=t.length;n--;)if(mv(t[n][0],e))return n;return-1},aP=Array.prototype.splice,sP=function(t){var e=this.__data__,n=Uc(e,t);return!(n<0)&&(n==e.length-1?e.pop():aP.call(e,n,1),--this.size,!0)},iP=function(t){var e=this.__data__,n=Uc(e,t);return n<0?void 0:e[n][1]},oP=function(t){return Uc(this.__data__,t)>-1},lP=function(t,e){var n=this.__data__,r=Uc(n,t);return r<0?(++this.size,n.push([t,e])):n[r][1]=e,this};function go(t){var e=-1,n=t==null?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}go.prototype.clear=rP,go.prototype.delete=sP,go.prototype.get=iP,go.prototype.has=oP,go.prototype.set=lP;var Gc=go,uP=function(){this.__data__=new Gc,this.size=0},cP=function(t){var e=this.__data__,n=e.delete(t);return this.size=e.size,n},dP=function(t){return this.__data__.get(t)},fP=function(t){return this.__data__.has(t)},gv=typeof Nc=="object"&&Nc&&Nc.Object===Object&&Nc,hP=typeof self=="object"&&self&&self.Object===Object&&self,ts=gv||hP||Function("return this")(),Na=ts.Symbol,xv=Object.prototype,pP=xv.hasOwnProperty,mP=xv.toString,Yl=Na?Na.toStringTag:void 0,gP=function(t){var e=pP.call(t,Yl),n=t[Yl];try{t[Yl]=void 0;var r=!0}catch{}var a=mP.call(t);return r&&(e?t[Yl]=n:delete t[Yl]),a},xP=Object.prototype.toString,yP=function(t){return xP.call(t)},Mw=Na?Na.toStringTag:void 0,vo=function(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Mw&&Mw in Object(t)?gP(t):yP(t)},Zl=function(t){var e=typeof t;return t!=null&&(e=="object"||e=="function")},yv=function(t){if(!Zl(t))return!1;var e=vo(t);return e=="[object Function]"||e=="[object GeneratorFunction]"||e=="[object AsyncFunction]"||e=="[object Proxy]"},Rh=ts["__core-js_shared__"],Tw=(function(){var t=/[^.]+$/.exec(Rh&&Rh.keys&&Rh.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""})(),bP=function(t){return!!Tw&&Tw in t},wP=Function.prototype.toString,mi=function(t){if(t!=null){try{return wP.call(t)}catch{}try{return t+""}catch{}}return""},vP=/^\[object .+?Constructor\]$/,kP=Function.prototype,SP=Object.prototype,CP=kP.toString,IP=SP.hasOwnProperty,LP=RegExp("^"+CP.call(IP).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),AP=function(t){return!(!Zl(t)||bP(t))&&(yv(t)?LP:vP).test(mi(t))},PP=function(t,e){return t?.[e]},gi=function(t,e){var n=PP(t,e);return AP(n)?n:void 0},Ql=gi(ts,"Map"),eu=gi(Object,"create"),NP=function(){this.__data__=eu?eu(null):{},this.size=0},RP=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},MP=Object.prototype.hasOwnProperty,TP=function(t){var e=this.__data__;if(eu){var n=e[t];return n==="__lodash_hash_undefined__"?void 0:n}return MP.call(e,t)?e[t]:void 0},DP=Object.prototype.hasOwnProperty,FP=function(t){var e=this.__data__;return eu?e[t]!==void 0:DP.call(e,t)},EP=function(t,e){var n=this.__data__;return this.size+=this.has(t)?0:1,n[t]=eu&&e===void 0?"__lodash_hash_undefined__":e,this};function xo(t){var e=-1,n=t==null?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}xo.prototype.clear=NP,xo.prototype.delete=RP,xo.prototype.get=TP,xo.prototype.has=FP,xo.prototype.set=EP;var Dw=xo,OP=function(){this.size=0,this.__data__={hash:new Dw,map:new(Ql||Gc),string:new Dw}},BP=function(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null},Wc=function(t,e){var n=t.__data__;return BP(e)?n[typeof e=="string"?"string":"hash"]:n.map},_P=function(t){var e=Wc(this,t).delete(t);return this.size-=e?1:0,e},HP=function(t){return Wc(this,t).get(t)},UP=function(t){return Wc(this,t).has(t)},GP=function(t,e){var n=Wc(this,t),r=n.size;return n.set(t,e),this.size+=n.size==r?0:1,this};function yo(t){var e=-1,n=t==null?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}yo.prototype.clear=OP,yo.prototype.delete=_P,yo.prototype.get=HP,yo.prototype.has=UP,yo.prototype.set=GP;var zc=yo,WP=function(t,e){var n=this.__data__;if(n instanceof Gc){var r=n.__data__;if(!Ql||r.length<199)return r.push([t,e]),this.size=++n.size,this;n=this.__data__=new zc(r)}return n.set(t,e),this.size=n.size,this};function bo(t){var e=this.__data__=new Gc(t);this.size=e.size}bo.prototype.clear=uP,bo.prototype.delete=cP,bo.prototype.get=dP,bo.prototype.has=fP,bo.prototype.set=WP;var Ec=bo,zP=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},jP=function(t){return this.__data__.has(t)};function Oc(t){var e=-1,n=t==null?0:t.length;for(this.__data__=new zc;++e<n;)this.add(t[e])}Oc.prototype.add=Oc.prototype.push=zP,Oc.prototype.has=jP;var VP=Oc,qP=function(t,e){for(var n=-1,r=t==null?0:t.length;++n<r;)if(e(t[n],n,t))return!0;return!1},$P=function(t,e){return t.has(e)},bv=function(t,e,n,r,a,s){var i=1&n,o=t.length,l=e.length;if(o!=l&&!(i&&l>o))return!1;var u=s.get(t),c=s.get(e);if(u&&c)return u==e&&c==t;var d=-1,f=!0,h=2&n?new VP:void 0;for(s.set(t,e),s.set(e,t);++d<o;){var p=t[d],g=e[d];if(r)var m=i?r(g,p,d,e,t,s):r(p,g,d,t,e,s);if(m!==void 0){if(m)continue;f=!1;break}if(h){if(!qP(e,(function(x,y){if(!$P(h,y)&&(p===x||a(p,x,n,r,s)))return h.push(y)}))){f=!1;break}}else if(p!==g&&!a(p,g,n,r,s)){f=!1;break}}return s.delete(t),s.delete(e),f},Fw=ts.Uint8Array,KP=function(t){var e=-1,n=Array(t.size);return t.forEach((function(r,a){n[++e]=[a,r]})),n},XP=function(t){var e=-1,n=Array(t.size);return t.forEach((function(r){n[++e]=r})),n},Ew=Na?Na.prototype:void 0,Mh=Ew?Ew.valueOf:void 0,YP=function(t,e,n,r,a,s,i){switch(n){case"[object DataView]":if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case"[object ArrayBuffer]":return!(t.byteLength!=e.byteLength||!s(new Fw(t),new Fw(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return mv(+t,+e);case"[object Error]":return t.name==e.name&&t.message==e.message;case"[object RegExp]":case"[object String]":return t==e+"";case"[object Map]":var o=KP;case"[object Set]":var l=1&r;if(o||(o=XP),t.size!=e.size&&!l)return!1;var u=i.get(t);if(u)return u==e;r|=2,i.set(t,e);var c=bv(o(t),o(e),r,a,s,i);return i.delete(t),c;case"[object Symbol]":if(Mh)return Mh.call(t)==Mh.call(e)}return!1},wv=function(t,e){for(var n=-1,r=e.length,a=t.length;++n<r;)t[a+n]=e[n];return t},Fr=Array.isArray,JP=function(t,e,n){var r=e(t);return Fr(t)?r:wv(r,n(t))},ZP=function(t,e){for(var n=-1,r=t==null?0:t.length,a=0,s=[];++n<r;){var i=t[n];e(i,n,t)&&(s[a++]=i)}return s},QP=function(){return[]},eN=Object.prototype.propertyIsEnumerable,Ow=Object.getOwnPropertySymbols,tN=Ow?function(t){return t==null?[]:(t=Object(t),ZP(Ow(t),(function(e){return eN.call(t,e)})))}:QP,nN=function(t,e){for(var n=-1,r=Array(t);++n<t;)r[n]=e(n);return r},wo=function(t){return t!=null&&typeof t=="object"},Bw=function(t){return wo(t)&&vo(t)=="[object Arguments]"},vv=Object.prototype,rN=vv.hasOwnProperty,aN=vv.propertyIsEnumerable,qh=Bw((function(){return arguments})())?Bw:function(t){return wo(t)&&rN.call(t,"callee")&&!aN.call(t,"callee")},sN=function(){return!1},Bh=nu((function(t,e){var n=e&&!e.nodeType&&e,r=n&&t&&!t.nodeType&&t,a=r&&r.exports===n?ts.Buffer:void 0,s=(a?a.isBuffer:void 0)||sN;t.exports=s})),iN=/^(?:0|[1-9]\d*)$/,kv=function(t,e){var n=typeof t;return!!(e=e??9007199254740991)&&(n=="number"||n!="symbol"&&iN.test(t))&&t>-1&&t%1==0&&t<e},$h=function(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=9007199254740991},$t={};$t["[object Float32Array]"]=$t["[object Float64Array]"]=$t["[object Int8Array]"]=$t["[object Int16Array]"]=$t["[object Int32Array]"]=$t["[object Uint8Array]"]=$t["[object Uint8ClampedArray]"]=$t["[object Uint16Array]"]=$t["[object Uint32Array]"]=!0,$t["[object Arguments]"]=$t["[object Array]"]=$t["[object ArrayBuffer]"]=$t["[object Boolean]"]=$t["[object DataView]"]=$t["[object Date]"]=$t["[object Error]"]=$t["[object Function]"]=$t["[object Map]"]=$t["[object Number]"]=$t["[object Object]"]=$t["[object RegExp]"]=$t["[object Set]"]=$t["[object String]"]=$t["[object WeakMap]"]=!1;var oN=function(t){return wo(t)&&$h(t.length)&&!!$t[vo(t)]},lN=function(t){return function(e){return t(e)}},_w=nu((function(t,e){var n=e&&!e.nodeType&&e,r=n&&t&&!t.nodeType&&t,a=r&&r.exports===n&&gv.process,s=(function(){try{var i=r&&r.require&&r.require("util").types;return i||a&&a.binding&&a.binding("util")}catch{}})();t.exports=s})),Hw=_w&&_w.isTypedArray,Sv=Hw?lN(Hw):oN,uN=Object.prototype.hasOwnProperty,cN=function(t,e){var n=Fr(t),r=!n&&qh(t),a=!n&&!r&&Bh(t),s=!n&&!r&&!a&&Sv(t),i=n||r||a||s,o=i?nN(t.length,String):[],l=o.length;for(var u in t)!e&&!uN.call(t,u)||i&&(u=="length"||a&&(u=="offset"||u=="parent")||s&&(u=="buffer"||u=="byteLength"||u=="byteOffset")||kv(u,l))||o.push(u);return o},dN=Object.prototype,fN=function(t){var e=t&&t.constructor;return t===(typeof e=="function"&&e.prototype||dN)},hN=(function(t,e){return function(n){return t(e(n))}})(Object.keys,Object),pN=Object.prototype.hasOwnProperty,mN=function(t){if(!fN(t))return hN(t);var e=[];for(var n in Object(t))pN.call(t,n)&&n!="constructor"&&e.push(n);return e},Kh=function(t){return t!=null&&$h(t.length)&&!yv(t)},Xh=function(t){return Kh(t)?cN(t):mN(t)},Uw=function(t){return JP(t,Xh,tN)},gN=Object.prototype.hasOwnProperty,xN=function(t,e,n,r,a,s){var i=1&n,o=Uw(t),l=o.length;if(l!=Uw(e).length&&!i)return!1;for(var u=l;u--;){var c=o[u];if(!(i?c in e:gN.call(e,c)))return!1}var d=s.get(t),f=s.get(e);if(d&&f)return d==e&&f==t;var h=!0;s.set(t,e),s.set(e,t);for(var p=i;++u<l;){var g=t[c=o[u]],m=e[c];if(r)var x=i?r(m,g,c,e,t,s):r(g,m,c,t,e,s);if(!(x===void 0?g===m||a(g,m,n,r,s):x)){h=!1;break}p||(p=c=="constructor")}if(h&&!p){var y=t.constructor,b=e.constructor;y==b||!("constructor"in t)||!("constructor"in e)||typeof y=="function"&&y instanceof y&&typeof b=="function"&&b instanceof b||(h=!1)}return s.delete(t),s.delete(e),h},_h=gi(ts,"DataView"),Hh=gi(ts,"Promise"),Uh=gi(ts,"Set"),Gh=gi(ts,"WeakMap"),yN=mi(_h),bN=mi(Ql),wN=mi(Hh),vN=mi(Uh),kN=mi(Gh),pi=vo;(_h&&pi(new _h(new ArrayBuffer(1)))!="[object DataView]"||Ql&&pi(new Ql)!="[object Map]"||Hh&&pi(Hh.resolve())!="[object Promise]"||Uh&&pi(new Uh)!="[object Set]"||Gh&&pi(new Gh)!="[object WeakMap]")&&(pi=function(t){var e=vo(t),n=e=="[object Object]"?t.constructor:void 0,r=n?mi(n):"";if(r)switch(r){case yN:return"[object DataView]";case bN:return"[object Map]";case wN:return"[object Promise]";case vN:return"[object Set]";case kN:return"[object WeakMap]"}return e});var Gw=pi,Rc="[object Object]",Ww=Object.prototype.hasOwnProperty,SN=function(t,e,n,r,a,s){var i=Fr(t),o=Fr(e),l=i?"[object Array]":Gw(t),u=o?"[object Array]":Gw(e),c=(l=l=="[object Arguments]"?Rc:l)==Rc,d=(u=u=="[object Arguments]"?Rc:u)==Rc,f=l==u;if(f&&Bh(t)){if(!Bh(e))return!1;i=!0,c=!1}if(f&&!c)return s||(s=new Ec),i||Sv(t)?bv(t,e,n,r,a,s):YP(t,e,l,n,r,a,s);if(!(1&n)){var h=c&&Ww.call(t,"__wrapped__"),p=d&&Ww.call(e,"__wrapped__");if(h||p){var g=h?t.value():t,m=p?e.value():e;return s||(s=new Ec),a(g,m,n,r,s)}}return!!f&&(s||(s=new Ec),xN(t,e,n,r,a,s))},jc=function t(e,n,r,a,s){return e===n||(e==null||n==null||!wo(e)&&!wo(n)?e!=e&&n!=n:SN(e,n,r,a,t,s))},CN=function(t,e,n,r){var a=n.length,s=a,i=!r;if(t==null)return!s;for(t=Object(t);a--;){var o=n[a];if(i&&o[2]?o[1]!==t[o[0]]:!(o[0]in t))return!1}for(;++a<s;){var l=(o=n[a])[0],u=t[l],c=o[1];if(i&&o[2]){if(u===void 0&&!(l in t))return!1}else{var d=new Ec;if(r)var f=r(u,c,l,t,e,d);if(!(f===void 0?jc(c,u,3,r,d):f))return!1}}return!0},Cv=function(t){return t==t&&!Zl(t)},IN=function(t){for(var e=Xh(t),n=e.length;n--;){var r=e[n],a=t[r];e[n]=[r,a,Cv(a)]}return e},Iv=function(t,e){return function(n){return n!=null&&n[t]===e&&(e!==void 0||t in Object(n))}},LN=function(t){var e=IN(t);return e.length==1&&e[0][2]?Iv(e[0][0],e[0][1]):function(n){return n===t||CN(n,t,e)}},Vc=function(t){return typeof t=="symbol"||wo(t)&&vo(t)=="[object Symbol]"},AN=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,PN=/^\w*$/,Yh=function(t,e){if(Fr(t))return!1;var n=typeof t;return!(n!="number"&&n!="symbol"&&n!="boolean"&&t!=null&&!Vc(t))||PN.test(t)||!AN.test(t)||e!=null&&t in Object(e)};function Jh(t,e){if(typeof t!="function"||e!=null&&typeof e!="function")throw new TypeError("Expected a function");var n=function(){var r=arguments,a=e?e.apply(this,r):r[0],s=n.cache;if(s.has(a))return s.get(a);var i=t.apply(this,r);return n.cache=s.set(a,i)||s,i};return n.cache=new(Jh.Cache||zc),n}Jh.Cache=zc;var NN=Jh,RN=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,MN=/\\(\\)?/g,TN=(function(t){var e=NN(t,(function(r){return n.size===500&&n.clear(),r})),n=e.cache;return e})((function(t){var e=[];return t.charCodeAt(0)===46&&e.push(""),t.replace(RN,(function(n,r,a,s){e.push(a?s.replace(MN,"$1"):r||n)})),e})),Lv=function(t,e){for(var n=-1,r=t==null?0:t.length,a=Array(r);++n<r;)a[n]=e(t[n],n,t);return a},zw=Na?Na.prototype:void 0,jw=zw?zw.toString:void 0,DN=function t(e){if(typeof e=="string")return e;if(Fr(e))return Lv(e,t)+"";if(Vc(e))return jw?jw.call(e):"";var n=e+"";return n=="0"&&1/e==-1/0?"-0":n},FN=function(t){return t==null?"":DN(t)},Av=function(t,e){return Fr(t)?t:Yh(t,e)?[t]:TN(FN(t))},qc=function(t){if(typeof t=="string"||Vc(t))return t;var e=t+"";return e=="0"&&1/t==-1/0?"-0":e},Pv=function(t,e){for(var n=0,r=(e=Av(e,t)).length;t!=null&&n<r;)t=t[qc(e[n++])];return n&&n==r?t:void 0},EN=function(t,e,n){var r=t==null?void 0:Pv(t,e);return r===void 0?n:r},ON=function(t,e){return t!=null&&e in Object(t)},BN=function(t,e,n){for(var r=-1,a=(e=Av(e,t)).length,s=!1;++r<a;){var i=qc(e[r]);if(!(s=t!=null&&n(t,i)))break;t=t[i]}return s||++r!=a?s:!!(a=t==null?0:t.length)&&$h(a)&&kv(i,a)&&(Fr(t)||qh(t))},_N=function(t,e){return t!=null&&BN(t,e,ON)},HN=function(t,e){return Yh(t)&&Cv(e)?Iv(qc(t),e):function(n){var r=EN(n,t);return r===void 0&&r===e?_N(n,t):jc(e,r,3)}},UN=function(t){return t},GN=function(t){return function(e){return e?.[t]}},WN=function(t){return function(e){return Pv(e,t)}},zN=function(t){return Yh(t)?GN(qc(t)):WN(t)},$c=function(t){return typeof t=="function"?t:t==null?UN:typeof t=="object"?Fr(t)?HN(t[0],t[1]):LN(t):zN(t)},jN=/\s/,VN=function(t){for(var e=t.length;e--&&jN.test(t.charAt(e)););return e},qN=/^\s+/,$N=function(t){return t&&t.slice(0,VN(t)+1).replace(qN,"")},KN=/^[-+]0x[0-9a-f]+$/i,XN=/^0b[01]+$/i,YN=/^0o[0-7]+$/i,JN=parseInt,ZN=function(t){if(typeof t=="number")return t;if(Vc(t))return NaN;if(Zl(t)){var e=typeof t.valueOf=="function"?t.valueOf():t;t=Zl(e)?e+"":e}if(typeof t!="string")return t===0?t:+t;t=$N(t);var n=XN.test(t);return n||YN.test(t)?JN(t.slice(2),n?2:8):KN.test(t)?NaN:+t},QN=function(t){return t?(t=ZN(t))===1/0||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:t===0?t:0},eR=function(t){var e=QN(t),n=e%1;return e==e?n?e-n:e:0},tR=Math.max,nR=Math.min,Vw=function(t,e,n){var r=t==null?0:t.length;if(!r)return-1;var a=r-1;return n!==void 0&&(a=eR(n),a=n<0?tR(r+a,0):nR(a,r-1)),nP(t,$c(e),a,!0)},tu=Bs("old"),rR=Bs("new");function qw(t){var e=t.oldStart;return[e,e+t.oldLines-1]}function Bc(t){if(!t.length)return null;var e=t.reduce((function(i,o){return Pa(o)||(i.isPlain=!1),_s(o)||(i.oldLines=i.oldLines+1,i.oldStart===-1&&(i.oldStart=tu(o))),aa(o)||(i.newLines=i.newLines+1,i.newStart===-1&&(i.newStart=rR(o))),i}),{isPlain:!0,content:"",oldStart:-1,oldLines:0,newStart:-1,newLines:0}),n=e.oldStart,r=e.oldLines,a=e.newStart,s=e.newLines;return Rt(Rt({},e),{},{content:"@@ -".concat(n,",").concat(r," +").concat(a,",").concat(s),changes:t})}function aR(t,e,n){return Bc(t.map((function(r,a){return{type:"normal",isNormal:!0,oldLineNumber:e+a,newLineNumber:n+a,content:""+r}})))}function Mc(t,e,n){var r=t.changes,a=r.findIndex((function(o){return tu(o)>=e}));if(a===-1)return null;var s=(function(){if(a===0)return a;var o=Vw(r,(function(l){return!_s(l)}),a-1);return o===-1?a:o+1})();if(n===void 0)return Bc(r.slice(s));var i=Vw(r,(function(o){return tu(o)<=n}));return Bc(r.slice(s,i===-1?void 0:i))}function Jl(t,e){if(!t)return e;if(!e)return t;var n=en(qw(t),2),r=n[0],a=n[1],s=en(qw(e),2),i=s[0],o=s[1];if(a+1===i)return Bc([].concat(kr(t.changes),kr(e.changes)));if(r<=i&&a>=o){if(t.isPlain&&!e.isPlain){var l=Mc(t,r,i),u=Mc(t,o+1);return Jl(Jl(l,e),u)}return t}return t.isPlain?Jl(Mc(t,r,i),e):Jl(t,Mc(e,a+1))}function sR(t,e){var n=fv(t);if(!n)return[e];if(n.oldStart+n.oldLines<e.oldStart)return t.concat(e);var r=Jl(n,e);return r?[].concat(kr(t.slice(0,-1)),[r]):t}function iR(t,e){var n=tu(e.changes[0]),r=t.findIndex((function(a){var s=a.changes;return!!s.length&&tu(s[0])>=n}));return(r===-1?t.concat(e):[].concat(kr(t.slice(0,r)),[e],kr(t.slice(r)))).reduce(sR,[])}function Es(t){if(!t)throw new Error("change is not provided");if(Pa(t))return"N".concat(t.oldLineNumber);var e=_s(t)?"I":"D";return"".concat(e).concat(t.lineNumber)}var oR=Vh("old"),Th=Bs("old"),$w=jh("oldStart","oldLines"),lR=hv("oldStart","oldLines");function Wh(t,e,n){var r=(function(h,p){if(!h.length)return-1;var g=dv(h);if(p<g.oldStart||$w(g,p))return 0;for(var m=1;m<h.length;m++){var x=h[m];if($w(x,p))return m;var y=h[m-1];if(lR(y,x,p))return m}return-1})(t,e);if(r===-1)return[[e,n]];var a=t[r];if(e<a.oldStart){var s=a.changes.findIndex((function(h){return!Pa(h)})),i=a.oldStart+Math.max(s,0);return i>=n?[[e,n]]:[[e,i]].concat(kr(Wh(t,i+1,n)))}var o=a.changes,l=(function(h,p){var g=h.changes,m=g.findIndex((function(y){return Th(y)===p}));if(m<0)return-1;for(var x=m;x<g.length;x++)if(Pa(g[x]))return x;return-1})(a,e);if(l===-1)return[];var u=o[l],c=Th(u),d=o.slice(l+1).findIndex((function(h){return!Pa(h)})),f=Th(u)+Math.max(d,0);return f>=n?[[c,n]]:[[c,f]].concat(kr(Wh(t,f+1,n)))}function Nv(t,e,n,r){return Wh(t,n,r).reduce((function(a,s){return(function(i,o,l){var u=en(l,2),c=u[0],d=u[1],f=(typeof o=="string"?o.split(`
12
+ `):o).slice(Math.max(c,1)-1,d-1);if(!f.length)return i;var h=aR(f,c,oR(i,c));return h?iR(i,h):i})(a,e,s)}),t)}function Rv(t,e){if(!t)return e.oldStart-1;var n=t.oldStart+t.oldLines;return e.oldStart-n}var Kc=Bs("old"),Xc=Bs("new"),yW=pv("old"),bW=pv("new"),wW=Vh("new"),vW=Vh("old"),Kw=(function(){try{var t=gi(Object,"defineProperty");return t({},"",{}),t}catch{}})(),Zh=function(t,e,n){e=="__proto__"&&Kw?Kw(t,e,{configurable:!0,enumerable:!0,value:n,writable:!0}):t[e]=n},uR=function(t){return function(e,n,r){for(var a=-1,s=Object(e),i=r(e),o=i.length;o--;){var l=i[t?o:++a];if(n(s[l],l,s)===!1)break}return e}},cR=uR(),Mv=function(t,e){return t&&cR(t,e,Xh)},Tv=function(t,e){var n={};return e=$c(e),Mv(t,(function(r,a,s){Zh(n,a,e(r,a,s))})),n},dR=["changeKey","text","tokens","renderToken"],Xw=function t(e,n){var r=e.type,a=e.value,s=e.markType,i=e.properties,o=e.className,l=e.children,u=function(d){return(0,Be.jsx)("span",{className:d,children:a||l&&l.map(t)},n)};switch(r){case"text":return a;case"mark":return u("diff-code-mark diff-code-mark-".concat(s));case"edit":return u("diff-code-edit");default:var c=i&&i.className;return u(wn(o||c))}};function fR(t){if(!Array.isArray(t))return!0;if(t.length>1)return!1;if(t.length===1){var e=en(t,1)[0];return e.type==="text"&&!e.value}return!0}function hR(t){var e=t.changeKey,n=t.text,r=t.tokens,a=t.renderToken,s=Os(t,dR),i=a?function(o,l){return a(o,Xw,l)}:Xw;return(0,Be.jsx)("td",Rt(Rt({},s),{},{"data-change-key":e,children:r?fR(r)?" ":r.map(i):n||" "}))}var Dv=(0,St.memo)(hR);function Fv(t,e){return function(){var n=e==="old"?Kc(t):Xc(t);return n===-1?void 0:n}}function Ev(t,e){return function(n){return t&&n?(0,Be.jsx)("a",{href:e?"#"+e:void 0,children:n}):n}}function _c(t,e){return e?function(n){t(),e(n)}:t}function Yw(t,e,n,r){return(0,St.useMemo)((function(){var a=Tv(t,(function(s){return function(i){return s&&s(e,i)}}));return a.onMouseEnter=_c(n,a.onMouseEnter),a.onMouseLeave=_c(r,a.onMouseLeave),a}),[t,n,r,e])}function Jw(t,e,n,r,a,s,i,o,l){var u={change:e,side:r,inHoverState:o,renderDefault:Fv(e,r),wrapInAnchor:Ev(a,s)};return(0,Be.jsx)("td",Rt(Rt({className:t},i),{},{"data-change-key":n,children:l(u)}))}function pR(t){var e,n,r,a=t.change,s=t.selected,i=t.tokens,o=t.className,l=t.generateLineClassName,u=t.gutterClassName,c=t.codeClassName,d=t.gutterEvents,f=t.codeEvents,h=t.hideGutter,p=t.gutterAnchor,g=t.generateAnchorID,m=t.renderToken,x=t.renderGutter,y=a.type,b=a.content,C=Es(a),L=(e=en((0,St.useState)(!1),2),n=e[0],r=e[1],[n,(0,St.useCallback)((function(){return r(!0)}),[]),(0,St.useCallback)((function(){return r(!1)}),[])]),P=en(L,3),w=P[0],k=P[1],_=P[2],M=(0,St.useMemo)((function(){return{change:a}}),[a]),R=Yw(d,M,k,_),U=Yw(f,M,k,_),v=g(a),T=l({changes:[a],defaultGenerate:function(){return o}}),V=wn("diff-gutter","diff-gutter-".concat(y),u,{"diff-gutter-selected":s}),Y=wn("diff-code","diff-code-".concat(y),c,{"diff-code-selected":s});return(0,Be.jsxs)("tr",{id:v,className:wn("diff-line",T),children:[!h&&Jw(V,a,C,"old",p,v,R,w,x),!h&&Jw(V,a,C,"new",p,v,R,w,x),(0,Be.jsx)(Dv,Rt({className:Y,changeKey:C,text:b,tokens:i,renderToken:m},U))]})}var mR=(0,St.memo)(pR);function gR(t){var e=t.hideGutter,n=t.element;return(0,Be.jsx)("tr",{className:"diff-widget",children:(0,Be.jsx)("td",{colSpan:e?1:3,className:"diff-widget-content",children:n})})}var xR=["hideGutter","selectedChanges","tokens","lineClassName"],yR=["hunk","widgets","className"];function bR(t){var e=t.hunk,n=t.widgets,r=t.className,a=Os(t,yR),s=(function(i,o){return i.reduce((function(l,u){var c=Es(u);l.push(["change",c,u]);var d=o[c];return d&&l.push(["widget",c,d]),l}),[])})(e.changes,n);return(0,Be.jsx)("tbody",{className:wn("diff-hunk",r),children:s.map((function(i){return(function(o,l){var u=en(o,3),c=u[0],d=u[1],f=u[2],h=l.hideGutter,p=l.selectedChanges,g=l.tokens,m=l.lineClassName,x=Os(l,xR);if(c==="change"){var y=aa(f)?"old":"new",b=aa(f)?Kc(f):Xc(f),C=g?g[y][b-1]:null;return(0,Be.jsx)(mR,Rt({className:m,change:f,hideGutter:h,selected:p.includes(d),tokens:C},x),"change".concat(d))}return c==="widget"?(0,Be.jsx)(gR,{hideGutter:h,element:f},"widget".concat(d)):null})(i,a)}))})}var Ov=0;function Tc(t,e,n,r){var a=(0,St.useCallback)((function(){return e(t)}),[t,e]),s=(0,St.useCallback)((function(){return e("")}),[e]);return(0,St.useMemo)((function(){var i=Tv(r,(function(o){return function(l){return o&&o({side:t,change:n},l)}}));return i.onMouseEnter=_c(a,i.onMouseEnter),i.onMouseLeave=_c(s,i.onMouseLeave),i}),[n,r,a,t,s])}function Dh(t){var e=t.change,n=t.side,r=t.selected,a=t.tokens,s=t.gutterClassName,i=t.codeClassName,o=t.gutterEvents,l=t.codeEvents,u=t.anchorID,c=t.gutterAnchor,d=t.gutterAnchorTarget,f=t.hideGutter,h=t.hover,p=t.renderToken,g=t.renderGutter;if(!e){var m=wn("diff-gutter","diff-gutter-omit",s),x=wn("diff-code","diff-code-omit",i);return[!f&&(0,Be.jsx)("td",{className:m},"gutter"),(0,Be.jsx)("td",{className:x},"code")]}var y=e.type,b=e.content,C=Es(e),L=n===Ov?"old":"new",P=Rt({id:u||void 0,className:wn("diff-gutter","diff-gutter-".concat(y),Fh({"diff-gutter-selected":r},"diff-line-hover-"+L,h),s),children:g({change:e,side:L,inHoverState:h,renderDefault:Fv(e,L),wrapInAnchor:Ev(c,d)})},o),w=wn("diff-code","diff-code-".concat(y),Fh({"diff-code-selected":r},"diff-line-hover-"+L,h),i);return[!f&&(0,Be.jsx)("td",Rt(Rt({},P),{},{"data-change-key":C}),"gutter"),(0,Be.jsx)(Dv,Rt({className:w,changeKey:C,text:b,tokens:a,renderToken:p},l),"code")]}function wR(t){var e=t.className,n=t.oldChange,r=t.newChange,a=t.oldSelected,s=t.newSelected,i=t.oldTokens,o=t.newTokens,l=t.monotonous,u=t.gutterClassName,c=t.codeClassName,d=t.gutterEvents,f=t.codeEvents,h=t.hideGutter,p=t.generateAnchorID,g=t.generateLineClassName,m=t.gutterAnchor,x=t.renderToken,y=t.renderGutter,b=en((0,St.useState)(""),2),C=b[0],L=b[1],P=Tc("old",L,n,d),w=Tc("new",L,r,d),k=Tc("old",L,n,f),_=Tc("new",L,r,f),M=n&&p(n),R=r&&p(r),U=g({changes:[n,r],defaultGenerate:function(){return e}}),v={monotonous:l,hideGutter:h,gutterClassName:u,codeClassName:c,gutterEvents:d,codeEvents:f,renderToken:x,renderGutter:y},T=Rt(Rt({},v),{},{change:n,side:Ov,selected:a,tokens:i,gutterEvents:P,codeEvents:k,anchorID:M,gutterAnchor:m,gutterAnchorTarget:M,hover:C==="old"}),V=Rt(Rt({},v),{},{change:r,side:1,selected:s,tokens:o,gutterEvents:w,codeEvents:_,anchorID:n===r?null:R,gutterAnchor:m,gutterAnchorTarget:n===r?M:R,hover:C==="new"});if(l)return(0,Be.jsx)("tr",{className:wn("diff-line",U),children:Dh(n?T:V)});var Y=(function(N,A){return N&&!A?"diff-line-old-only":!N&&A?"diff-line-new-only":N===A?"diff-line-normal":"diff-line-compare"})(n,r);return(0,Be.jsxs)("tr",{className:wn("diff-line",Y,U),children:[Dh(T),Dh(V)]})}var vR=(0,St.memo)(wR);function kR(t){var e=t.hideGutter,n=t.oldElement,r=t.newElement;return t.monotonous?(0,Be.jsx)("tr",{className:"diff-widget",children:(0,Be.jsx)("td",{colSpan:e?1:2,className:"diff-widget-content",children:n||r})}):n===r?(0,Be.jsx)("tr",{className:"diff-widget",children:(0,Be.jsx)("td",{colSpan:e?2:4,className:"diff-widget-content",children:n})}):(0,Be.jsxs)("tr",{className:"diff-widget",children:[(0,Be.jsx)("td",{colSpan:e?1:2,className:"diff-widget-content",children:n}),(0,Be.jsx)("td",{colSpan:e?1:2,className:"diff-widget-content",children:r})]})}var SR=["selectedChanges","monotonous","hideGutter","tokens","lineClassName"],CR=["hunk","widgets","className"];function Dc(t,e){return(t?Es(t):"00")+(e?Es(e):"00")}function IR(t){var e=t.hunk,n=t.widgets,r=t.className,a=Os(t,CR),s=(function(i,o){for(var l=function(x){if(!x)return null;var y=Es(x);return o[y]||null},u=[],c=0;c<i.length;c++){var d=i[c];if(Pa(d))u.push(["change",Dc(d,d),d,d]);else if(aa(d)){var f=i[c+1];f&&_s(f)?(c+=1,u.push(["change",Dc(d,f),d,f])):u.push(["change",Dc(d,null),d,null])}else u.push(["change",Dc(null,d),null,d]);var h=u[u.length-1],p=l(h[2]),g=l(h[3]);if(p||g){var m=h[1];u.push(["widget",m,p,g])}}return u})(e.changes,n);return(0,Be.jsx)("tbody",{className:wn("diff-hunk",r),children:s.map((function(i){return(function(o,l){var u=en(o,4),c=u[0],d=u[1],f=u[2],h=u[3],p=l.selectedChanges,g=l.monotonous,m=l.hideGutter,x=l.tokens,y=l.lineClassName,b=Os(l,SR);if(c==="change"){var C=!!f&&p.includes(Es(f)),L=!!h&&p.includes(Es(h)),P=f&&x?x.old[Kc(f)-1]:null,w=h&&x?x.new[Xc(h)-1]:null;return(0,Be.jsx)(vR,Rt({className:y,oldChange:f,newChange:h,monotonous:g,hideGutter:m,oldSelected:C,newSelected:L,oldTokens:P,newTokens:w},b),"change".concat(d))}return c==="widget"?(0,Be.jsx)(kR,{monotonous:g,hideGutter:m,oldElement:f,newElement:h},"widget".concat(d)):null})(i,a)}))})}var LR=["gutterType","hunkClassName"];function Qh(t){var e=t.hunk,n=uv(),r=n.gutterType,a=n.hunkClassName,s=Os(n,LR),i=r==="none",o=r==="anchor",l=s.viewType==="unified"?bR:IR;return(0,Be.jsx)(l,Rt(Rt({},s),{},{hunk:e,hideGutter:i,gutterAnchor:o,className:a}))}function AR(){}function Zw(t,e){var n=e?"auto":"none";t instanceof HTMLElement&&t.style.userSelect!==n&&(t.style.userSelect=n)}function PR(t){return t.map((function(e){return(0,Be.jsx)(Qh,{hunk:e},(function(n){return"-".concat(n.oldStart,",").concat(n.oldLines," +").concat(n.newStart,",").concat(n.newLines)})(e))}))}function NR(t){var e=t.diffType,n=t.hunks,r=t.optimizeSelection,a=t.className,s=t.hunkClassName,i=s===void 0?ur.hunkClassName:s,o=t.lineClassName,l=o===void 0?ur.lineClassName:o,u=t.generateLineClassName,c=u===void 0?ur.generateLineClassName:u,d=t.gutterClassName,f=d===void 0?ur.gutterClassName:d,h=t.codeClassName,p=h===void 0?ur.codeClassName:h,g=t.gutterType,m=g===void 0?ur.gutterType:g,x=t.viewType,y=x===void 0?ur.viewType:x,b=t.gutterEvents,C=b===void 0?ur.gutterEvents:b,L=t.codeEvents,P=L===void 0?ur.codeEvents:L,w=t.generateAnchorID,k=w===void 0?ur.generateAnchorID:w,_=t.selectedChanges,M=_===void 0?ur.selectedChanges:_,R=t.widgets,U=R===void 0?ur.widgets:R,v=t.renderGutter,T=v===void 0?ur.renderGutter:v,V=t.tokens,Y=t.renderToken,N=t.children,A=N===void 0?PR:N,B=(0,St.useRef)(null),K=(0,St.useCallback)((function(re){var he=re.target;if(re.button===0){var Ne=(function(Ye,Lt){for(var Le=Ye;Le&&Le!==document.documentElement&&!Le.classList.contains(Lt);)Le=Le.parentElement;return Le===document.documentElement?null:Le})(he,"diff-code");if(Ne&&Ne.parentElement){var Ee=window.getSelection();Ee&&Ee.removeAllRanges();var ze=kr(Ne.parentElement.children).indexOf(Ne);if(ze===1||ze===3){var ct,it=zh(B.current?B.current.querySelectorAll(".diff-line"):[]);try{for(it.s();!(ct=it.n()).done;){var Qe=ct.value.children;Zw(Qe[1],ze===1),Zw(Qe[3],ze===3)}}catch(Ye){it.e(Ye)}finally{it.f()}}}}}),[]),te=m==="none",ne=e==="add"||e==="delete",pe=y==="split"&&!ne&&r?K:AR,Se=(0,St.useMemo)((function(){return(0,Be.jsxs)("colgroup",y==="unified"?{children:[!te&&(0,Be.jsx)("col",{className:"diff-gutter-col"}),!te&&(0,Be.jsx)("col",{className:"diff-gutter-col"}),(0,Be.jsx)("col",{})]}:ne?{children:[!te&&(0,Be.jsx)("col",{className:"diff-gutter-col"}),(0,Be.jsx)("col",{})]}:{children:[!te&&(0,Be.jsx)("col",{className:"diff-gutter-col"}),(0,Be.jsx)("col",{}),!te&&(0,Be.jsx)("col",{className:"diff-gutter-col"}),(0,Be.jsx)("col",{})]})}),[y,ne,te]),le=(0,St.useMemo)((function(){return{hunkClassName:i,lineClassName:l,generateLineClassName:c,gutterClassName:f,codeClassName:p,monotonous:ne,hideGutter:te,viewType:y,gutterType:m,codeEvents:P,gutterEvents:C,generateAnchorID:k,selectedChanges:M,widgets:U,renderGutter:T,tokens:V,renderToken:Y}}),[p,P,k,f,C,m,te,i,l,c,ne,T,Y,M,V,y,U]);return(0,Be.jsx)(QA,{value:le,children:(0,Be.jsxs)("table",{ref:B,className:wn("diff","diff-".concat(y),a),onMouseDown:pe,children:[Se,A(n)]})})}var Bv=(0,St.memo)(NR),RR=function(){};var Qw=RR;function MR(t){var e=t.hideGutter,n=t.monotonous,r=t.className,a=t.gutterClassName,s=t.contentClassName,i=t.children,o=wn("diff-decoration",r),l=wn("diff-decoration-gutter",a),u=wn("diff-decoration-content",s),c=(e?2:4)/(n?2:1),d=c-(e?0:1);if(St.Children.count(i)===1)return(0,Be.jsx)("tbody",{className:o,children:(0,Be.jsx)("tr",{children:(0,Be.jsx)("td",{colSpan:c,className:u,children:i})})});var f=en(i,2),h=f[0],p=f[1];return(0,Be.jsx)("tbody",{className:o,children:(0,Be.jsxs)("tr",{children:[!e&&(0,Be.jsx)("td",{className:l,children:h}),(0,Be.jsx)("td",{colSpan:d,className:u,children:p})]})})}function TR(t){var e=t.hideGutter,n=t.className,r=t.gutterClassName,a=t.contentClassName,s=t.children,i=wn("diff-decoration",n),o=wn("diff-decoration-gutter",r),l=wn("diff-decoration-content",a);if(St.Children.count(s)===1)return(0,Be.jsx)("tbody",{className:i,children:(0,Be.jsx)("tr",{children:(0,Be.jsx)("td",{colSpan:e?1:3,className:l,children:s})})});var u=en(s,2),c=u[0],d=u[1];return(0,Be.jsx)("tbody",{className:i,children:(0,Be.jsxs)("tr",{children:[!e&&(0,Be.jsx)("td",{colSpan:2,className:o,children:c}),(0,Be.jsx)("td",{className:l,children:d})]})})}function Yc(t){var e=t.className,n=e===void 0?"":e,r=t.gutterClassName,a=r===void 0?"":r,s=t.contentClassName,i=s===void 0?"":s,o=t.children,l=uv(),u=l.viewType,c=l.gutterType,d=l.monotonous,f=u==="split"?MR:TR,h=St.Children.count(o),p=c==="none";return Qw(h<=2,"Decoration only accepts a maxium of 2 children"),Qw(h<2||!p,"Gutter element in decoration will not be rendered since hideGutter prop is set to true"),(0,Be.jsx)(f,{hideGutter:p,monotonous:d,className:n,gutterClassName:a,contentClassName:i,children:o})}var DR=function(t,e,n,r){for(var a=-1,s=t==null?0:t.length;++a<s;){var i=t[a];e(r,i,n(i),t)}return r},FR=function(t,e){return function(n,r){if(n==null)return n;if(!Kh(n))return t(n,r);for(var a=n.length,s=e?a:-1,i=Object(n);(e?s--:++s<a)&&r(i[s],s,i)!==!1;);return n}},_v=FR(Mv),ER=function(t,e,n,r){return _v(t,(function(a,s,i){e(r,a,n(a),i)})),r},Hv=function(t,e){return function(n,r){var a=Fr(n)?DR:ER,s=e?e():{};return a(n,t,$c(r),s)}},OR=Hv((function(t,e,n){Zh(t,n,e)})),ev=Na?Na.isConcatSpreadable:void 0,BR=function(t){return Fr(t)||qh(t)||!!(ev&&t&&t[ev])},_R=function t(e,n,r,a,s){var i=-1,o=e.length;for(r||(r=BR),s||(s=[]);++i<o;){var l=e[i];n>0&&r(l)?n>1?t(l,n-1,r,a,s):wv(s,l):a||(s[s.length]=l)}return s},HR=function(t,e){var n=-1,r=Kh(t)?Array(t.length):[];return _v(t,(function(a,s,i){r[++n]=e(a,s,i)})),r},UR=function(t,e){return(Fr(t)?Lv:HR)(t,$c(e))},GR=function(t,e){return _R(UR(t,e),1)};function WR(t,e){var n=e.newStart,r=e.changes.reduce((function(a,s){var i=en(a,2),o=i[0],l=i[1];return aa(s)?(o.splice(l,1),[o,l]):(_s(s)&&o.splice(l,0,s.content),[o,l+1])}),[t,n-1]);return en(r,1)[0]}function tv(t,e,n){if(!t.length)return[];var r=e==="old"?Kc:Xc,a=OR(t,r),s=r(t[t.length-1]);return Array.from({length:s}).map((function(i,o){return n(a[o+1])}))}function zR(t){var e=(function(i){return GR(i,(function(o){return o.changes})).reduce((function(o,l){var u=en(o,2),c=u[0],d=u[1];return Pa(l)?(c.push(l),d.push(l)):aa(l)?c.push(l):d.push(l),[c,d]}),[[],[]])})(t),n=en(e,2),r=n[0],a=n[1],s=function(i){return i?i.content:""};return[tv(r,"old",s).join(`
13
+ `),tv(a,"new",s).join(`
14
+ `)]}function Fc(t){return{type:"root",children:t}}function jR(t,e){if(e.oldSource){var n=(function(l,u){return u.reduce(WR,l.split(`
15
15
  `)).join(`
16
- `)})(e.oldSource,n),r=e.highlight?function(l){return e.refractor.highlight(l,e.language)}:function(l){return[{type:"text",value:l}]};return[Nc(r(e.oldSource)),Nc(r(t))]}var a=en(SR(n),2),s=a[0],o=a[1],i=e.highlight?function(l){return Nc(e.refractor.highlight(l,e.language))}:function(l){return Nc([{type:"text",value:l}])};return[i(s),i(o)]}function _v(n){return n.map((function(e){return At({},e)}))}function LR(n,e){return[].concat(Sr(_v(n.slice(0,-1))),[e])}function IR(n){return n.type==="text"}function AR(n){var e=n[n.length-1];if(IR(e))return e;throw new Error("Invalid token path with leaf of type ".concat(e.type))}var PR=["children"];function Hv(n){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:[],t=arguments.length>2&&arguments[2]!==void 0?arguments[2]:[];if(n.children){var r=n.children,a=Fs(n,PR);t.push(a);var s,o=Vh(r);try{for(o.s();!(s=o.n()).done;)Hv(s.value,e,t)}catch(i){o.e(i)}finally{o.f()}t.pop()}else e.push(_v([].concat(Sr(t.slice(1)),[n])));return e}function NR(n){return n.reduce((function(e,t){var r=e[e.length-1],a=(function(l){var u=AR(l);return u.value.includes(`
16
+ `)})(e.oldSource,t),r=e.highlight?function(l){return e.refractor.highlight(l,e.language)}:function(l){return[{type:"text",value:l}]};return[Fc(r(e.oldSource)),Fc(r(n))]}var a=en(zR(t),2),s=a[0],i=a[1],o=e.highlight?function(l){return Fc(e.refractor.highlight(l,e.language))}:function(l){return Fc([{type:"text",value:l}])};return[o(s),o(i)]}function Uv(t){return t.map((function(e){return Rt({},e)}))}function VR(t,e){return[].concat(kr(Uv(t.slice(0,-1))),[e])}function qR(t){return t.type==="text"}function $R(t){var e=t[t.length-1];if(qR(e))return e;throw new Error("Invalid token path with leaf of type ".concat(e.type))}var KR=["children"];function Gv(t){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:[],n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:[];if(t.children){var r=t.children,a=Os(t,KR);n.push(a);var s,i=zh(r);try{for(i.s();!(s=i.n()).done;)Gv(s.value,e,n)}catch(o){i.e(o)}finally{i.f()}n.pop()}else e.push(Uv([].concat(kr(n.slice(1)),[t])));return e}function XR(t){return t.reduce((function(e,n){var r=e[e.length-1],a=(function(l){var u=$R(l);return u.value.includes(`
17
17
  `)?u.value.split(`
18
- `).map((function(c){return LR(l,At(At({},u),{},{value:c}))})):[l]})(t),s=TA(a),o=s[0],i=s.slice(1);return[].concat(Sr(e.slice(0,-1)),[[].concat(Sr(r),[o])],Sr(i.map((function(l){return[l]}))))}),[[]])}function ev(n){return NR(Hv(n))}var RR=function(n,e,t){var r=(t=typeof t=="function"?t:void 0)?t(n,e):void 0;return r===void 0?Hc(n,e,void 0,t):!!r},MR=function(n,e){return Hc(n,e)},TR=function(n){var e=n==null?0:n.length;return e?n[e-1]:void 0};function DR(n,e){if(!n.children)throw new Error("parent node missing children property");var t,r,a=TR(n.children);return a&&(r=e,(t=a).type===r.type&&(t.type==="text"||t.children&&r.children&&RR(t,r,(function(s,o,i){return i==="chlidren"||MR(s,o)}))))?n.children[n.children.length-1]=(function(s,o){return"value"in s&&"value"in o?At(At({},s),{},{value:"".concat(s.value).concat(o.value)}):s})(a,e):n.children.push(e),n.children[n.children.length-1]}function tv(n){var e,t={type:"root",children:[]},r=Vh(n);try{var a=function(){var s=e.value;s.reduce((function(o,i,l){return DR(o,l===s.length-1?At({},i):At(At({},i),{},{children:[]}))}),t)};for(r.s();!(e=r.n()).done;)a()}catch(s){r.e(s)}finally{r.f()}return t}var FR=Object.prototype.hasOwnProperty,ez=Ov((function(n,e,t){FR.call(n,t)?n[t].push(e):tp(n,t,[e])}));var rp=Zl((function(n){var e=function(){this.Diff_Timeout=1,this.Diff_EditCost=4,this.Match_Threshold=.5,this.Match_Distance=1e3,this.Patch_DeleteThreshold=.5,this.Patch_Margin=4,this.Match_MaxBits=32};e.Diff=function(t,r){return[t,r]},e.prototype.diff_main=function(t,r,a,s){s===void 0&&(s=this.Diff_Timeout<=0?Number.MAX_VALUE:new Date().getTime()+1e3*this.Diff_Timeout);var o=s;if(t==null||r==null)throw new Error("Null input. (diff_main)");if(t==r)return t?[new e.Diff(0,t)]:[];a===void 0&&(a=!0);var i=a,l=this.diff_commonPrefix(t,r),u=t.substring(0,l);t=t.substring(l),r=r.substring(l),l=this.diff_commonSuffix(t,r);var c=t.substring(t.length-l);t=t.substring(0,t.length-l),r=r.substring(0,r.length-l);var d=this.diff_compute_(t,r,i,o);return u&&d.unshift(new e.Diff(0,u)),c&&d.push(new e.Diff(0,c)),this.diff_cleanupMerge(d),d},e.prototype.diff_compute_=function(t,r,a,s){var o;if(!t)return[new e.Diff(1,r)];if(!r)return[new e.Diff(-1,t)];var i=t.length>r.length?t:r,l=t.length>r.length?r:t,u=i.indexOf(l);if(u!=-1)return o=[new e.Diff(1,i.substring(0,u)),new e.Diff(0,l),new e.Diff(1,i.substring(u+l.length))],t.length>r.length&&(o[0][0]=o[2][0]=-1),o;if(l.length==1)return[new e.Diff(-1,t),new e.Diff(1,r)];var c=this.diff_halfMatch_(t,r);if(c){var d=c[0],f=c[1],h=c[2],p=c[3],m=c[4],g=this.diff_main(d,h,a,s),x=this.diff_main(f,p,a,s);return g.concat([new e.Diff(0,m)],x)}return a&&t.length>100&&r.length>100?this.diff_lineMode_(t,r,s):this.diff_bisect_(t,r,s)},e.prototype.diff_lineMode_=function(t,r,a){var s=this.diff_linesToChars_(t,r);t=s.chars1,r=s.chars2;var o=s.lineArray,i=this.diff_main(t,r,!1,a);this.diff_charsToLines_(i,o),this.diff_cleanupSemantic(i),i.push(new e.Diff(0,""));for(var l=0,u=0,c=0,d="",f="";l<i.length;){switch(i[l][0]){case 1:c++,f+=i[l][1];break;case-1:u++,d+=i[l][1];break;case 0:if(u>=1&&c>=1){i.splice(l-u-c,u+c),l=l-u-c;for(var h=this.diff_main(d,f,!1,a),p=h.length-1;p>=0;p--)i.splice(l,0,h[p]);l+=h.length}c=0,u=0,d="",f=""}l++}return i.pop(),i},e.prototype.diff_bisect_=function(t,r,a){for(var s=t.length,o=r.length,i=Math.ceil((s+o)/2),l=i,u=2*i,c=new Array(u),d=new Array(u),f=0;f<u;f++)c[f]=-1,d[f]=-1;c[l+1]=0,d[l+1]=0;for(var h=s-o,p=h%2!=0,m=0,g=0,x=0,w=0,y=0;y<i&&!(new Date().getTime()>a);y++){for(var C=-y+m;C<=y-g;C+=2){for(var k=l+C,v=(U=C==-y||C!=y&&c[k-1]<c[k+1]?c[k+1]:c[k-1]+1)-C;U<s&&v<o&&t.charAt(U)==r.charAt(v);)U++,v++;if(c[k]=U,U>s)g+=2;else if(v>o)m+=2;else if(p&&(N=l+h-C)>=0&&N<u&&d[N]!=-1&&U>=(P=s-d[N]))return this.diff_bisectSplit_(t,r,U,v,a)}for(var b=-y+x;b<=y-w;b+=2){for(var P,N=l+b,M=(P=b==-y||b!=y&&d[N-1]<d[N+1]?d[N+1]:d[N-1]+1)-b;P<s&&M<o&&t.charAt(s-P-1)==r.charAt(o-M-1);)P++,M++;if(d[N]=P,P>s)w+=2;else if(M>o)x+=2;else if(!p&&(k=l+h-b)>=0&&k<u&&c[k]!=-1){var U;if(v=l+(U=c[k])-k,U>=(P=s-P))return this.diff_bisectSplit_(t,r,U,v,a)}}}return[new e.Diff(-1,t),new e.Diff(1,r)]},e.prototype.diff_bisectSplit_=function(t,r,a,s,o){var i=t.substring(0,a),l=r.substring(0,s),u=t.substring(a),c=r.substring(s),d=this.diff_main(i,l,!1,o),f=this.diff_main(u,c,!1,o);return d.concat(f)},e.prototype.diff_linesToChars_=function(t,r){var a=[],s={};function o(u){for(var c="",d=0,f=-1,h=a.length;f<u.length-1;){(f=u.indexOf(`
19
- `,d))==-1&&(f=u.length-1);var p=u.substring(d,f+1);(s.hasOwnProperty?s.hasOwnProperty(p):s[p]!==void 0)?c+=String.fromCharCode(s[p]):(h==i&&(p=u.substring(d),f=u.length),c+=String.fromCharCode(h),s[p]=h,a[h++]=p),d=f+1}return c}a[0]="";var i=4e4,l=o(t);return i=65535,{chars1:l,chars2:o(r),lineArray:a}},e.prototype.diff_charsToLines_=function(t,r){for(var a=0;a<t.length;a++){for(var s=t[a][1],o=[],i=0;i<s.length;i++)o[i]=r[s.charCodeAt(i)];t[a][1]=o.join("")}},e.prototype.diff_commonPrefix=function(t,r){if(!t||!r||t.charAt(0)!=r.charAt(0))return 0;for(var a=0,s=Math.min(t.length,r.length),o=s,i=0;a<o;)t.substring(i,o)==r.substring(i,o)?i=a=o:s=o,o=Math.floor((s-a)/2+a);return o},e.prototype.diff_commonSuffix=function(t,r){if(!t||!r||t.charAt(t.length-1)!=r.charAt(r.length-1))return 0;for(var a=0,s=Math.min(t.length,r.length),o=s,i=0;a<o;)t.substring(t.length-o,t.length-i)==r.substring(r.length-o,r.length-i)?i=a=o:s=o,o=Math.floor((s-a)/2+a);return o},e.prototype.diff_commonOverlap_=function(t,r){var a=t.length,s=r.length;if(a==0||s==0)return 0;a>s?t=t.substring(a-s):a<s&&(r=r.substring(0,a));var o=Math.min(a,s);if(t==r)return o;for(var i=0,l=1;;){var u=t.substring(o-l),c=r.indexOf(u);if(c==-1)return i;l+=c,c!=0&&t.substring(o-l)!=r.substring(0,l)||(i=l,l++)}},e.prototype.diff_halfMatch_=function(t,r){if(this.Diff_Timeout<=0)return null;var a=t.length>r.length?t:r,s=t.length>r.length?r:t;if(a.length<4||2*s.length<a.length)return null;var o=this;function i(m,g,x){for(var w,y,C,k,v=m.substring(x,x+Math.floor(m.length/4)),b=-1,P="";(b=g.indexOf(v,b+1))!=-1;){var N=o.diff_commonPrefix(m.substring(x),g.substring(b)),M=o.diff_commonSuffix(m.substring(0,x),g.substring(0,b));P.length<M+N&&(P=g.substring(b-M,b)+g.substring(b,b+N),w=m.substring(0,x-M),y=m.substring(x+N),C=g.substring(0,b-M),k=g.substring(b+N))}return 2*P.length>=m.length?[w,y,C,k,P]:null}var l,u,c,d,f,h=i(a,s,Math.ceil(a.length/4)),p=i(a,s,Math.ceil(a.length/2));return h||p?(l=p?h&&h[4].length>p[4].length?h:p:h,t.length>r.length?(u=l[0],c=l[1],d=l[2],f=l[3]):(d=l[0],f=l[1],u=l[2],c=l[3]),[u,c,d,f,l[4]]):null},e.prototype.diff_cleanupSemantic=function(t){for(var r=!1,a=[],s=0,o=null,i=0,l=0,u=0,c=0,d=0;i<t.length;)t[i][0]==0?(a[s++]=i,l=c,u=d,c=0,d=0,o=t[i][1]):(t[i][0]==1?c+=t[i][1].length:d+=t[i][1].length,o&&o.length<=Math.max(l,u)&&o.length<=Math.max(c,d)&&(t.splice(a[s-1],0,new e.Diff(-1,o)),t[a[s-1]+1][0]=1,s--,i=--s>0?a[s-1]:-1,l=0,u=0,c=0,d=0,o=null,r=!0)),i++;for(r&&this.diff_cleanupMerge(t),this.diff_cleanupSemanticLossless(t),i=1;i<t.length;){if(t[i-1][0]==-1&&t[i][0]==1){var f=t[i-1][1],h=t[i][1],p=this.diff_commonOverlap_(f,h),m=this.diff_commonOverlap_(h,f);p>=m?(p>=f.length/2||p>=h.length/2)&&(t.splice(i,0,new e.Diff(0,h.substring(0,p))),t[i-1][1]=f.substring(0,f.length-p),t[i+1][1]=h.substring(p),i++):(m>=f.length/2||m>=h.length/2)&&(t.splice(i,0,new e.Diff(0,f.substring(0,m))),t[i-1][0]=1,t[i-1][1]=h.substring(0,h.length-m),t[i+1][0]=-1,t[i+1][1]=f.substring(m),i++),i++}i++}},e.prototype.diff_cleanupSemanticLossless=function(t){function r(m,g){if(!m||!g)return 6;var x=m.charAt(m.length-1),w=g.charAt(0),y=x.match(e.nonAlphaNumericRegex_),C=w.match(e.nonAlphaNumericRegex_),k=y&&x.match(e.whitespaceRegex_),v=C&&w.match(e.whitespaceRegex_),b=k&&x.match(e.linebreakRegex_),P=v&&w.match(e.linebreakRegex_),N=b&&m.match(e.blanklineEndRegex_),M=P&&g.match(e.blanklineStartRegex_);return N||M?5:b||P?4:y&&!k&&v?3:k||v?2:y||C?1:0}for(var a=1;a<t.length-1;){if(t[a-1][0]==0&&t[a+1][0]==0){var s=t[a-1][1],o=t[a][1],i=t[a+1][1],l=this.diff_commonSuffix(s,o);if(l){var u=o.substring(o.length-l);s=s.substring(0,s.length-l),o=u+o.substring(0,o.length-l),i=u+i}for(var c=s,d=o,f=i,h=r(s,o)+r(o,i);o.charAt(0)===i.charAt(0);){s+=o.charAt(0),o=o.substring(1)+i.charAt(0),i=i.substring(1);var p=r(s,o)+r(o,i);p>=h&&(h=p,c=s,d=o,f=i)}t[a-1][1]!=c&&(c?t[a-1][1]=c:(t.splice(a-1,1),a--),t[a][1]=d,f?t[a+1][1]=f:(t.splice(a+1,1),a--))}a++}},e.nonAlphaNumericRegex_=/[^a-zA-Z0-9]/,e.whitespaceRegex_=/\s/,e.linebreakRegex_=/[\r\n]/,e.blanklineEndRegex_=/\n\r?\n$/,e.blanklineStartRegex_=/^\r?\n\r?\n/,e.prototype.diff_cleanupEfficiency=function(t){for(var r=!1,a=[],s=0,o=null,i=0,l=!1,u=!1,c=!1,d=!1;i<t.length;)t[i][0]==0?(t[i][1].length<this.Diff_EditCost&&(c||d)?(a[s++]=i,l=c,u=d,o=t[i][1]):(s=0,o=null),c=d=!1):(t[i][0]==-1?d=!0:c=!0,o&&(l&&u&&c&&d||o.length<this.Diff_EditCost/2&&l+u+c+d==3)&&(t.splice(a[s-1],0,new e.Diff(-1,o)),t[a[s-1]+1][0]=1,s--,o=null,l&&u?(c=d=!0,s=0):(i=--s>0?a[s-1]:-1,c=d=!1),r=!0)),i++;r&&this.diff_cleanupMerge(t)},e.prototype.diff_cleanupMerge=function(t){t.push(new e.Diff(0,""));for(var r,a=0,s=0,o=0,i="",l="";a<t.length;)switch(t[a][0]){case 1:o++,l+=t[a][1],a++;break;case-1:s++,i+=t[a][1],a++;break;case 0:s+o>1?(s!==0&&o!==0&&((r=this.diff_commonPrefix(l,i))!==0&&(a-s-o>0&&t[a-s-o-1][0]==0?t[a-s-o-1][1]+=l.substring(0,r):(t.splice(0,0,new e.Diff(0,l.substring(0,r))),a++),l=l.substring(r),i=i.substring(r)),(r=this.diff_commonSuffix(l,i))!==0&&(t[a][1]=l.substring(l.length-r)+t[a][1],l=l.substring(0,l.length-r),i=i.substring(0,i.length-r))),a-=s+o,t.splice(a,s+o),i.length&&(t.splice(a,0,new e.Diff(-1,i)),a++),l.length&&(t.splice(a,0,new e.Diff(1,l)),a++),a++):a!==0&&t[a-1][0]==0?(t[a-1][1]+=t[a][1],t.splice(a,1)):a++,o=0,s=0,i="",l=""}t[t.length-1][1]===""&&t.pop();var u=!1;for(a=1;a<t.length-1;)t[a-1][0]==0&&t[a+1][0]==0&&(t[a][1].substring(t[a][1].length-t[a-1][1].length)==t[a-1][1]?(t[a][1]=t[a-1][1]+t[a][1].substring(0,t[a][1].length-t[a-1][1].length),t[a+1][1]=t[a-1][1]+t[a+1][1],t.splice(a-1,1),u=!0):t[a][1].substring(0,t[a+1][1].length)==t[a+1][1]&&(t[a-1][1]+=t[a+1][1],t[a][1]=t[a][1].substring(t[a+1][1].length)+t[a+1][1],t.splice(a+1,1),u=!0)),a++;u&&this.diff_cleanupMerge(t)},e.prototype.diff_xIndex=function(t,r){var a,s=0,o=0,i=0,l=0;for(a=0;a<t.length&&(t[a][0]!==1&&(s+=t[a][1].length),t[a][0]!==-1&&(o+=t[a][1].length),!(s>r));a++)i=s,l=o;return t.length!=a&&t[a][0]===-1?l:l+(r-i)},e.prototype.diff_prettyHtml=function(t){for(var r=[],a=/&/g,s=/</g,o=/>/g,i=/\n/g,l=0;l<t.length;l++){var u=t[l][0],c=t[l][1].replace(a,"&amp;").replace(s,"&lt;").replace(o,"&gt;").replace(i,"&para;<br>");switch(u){case 1:r[l]='<ins style="background:#e6ffe6;">'+c+"</ins>";break;case-1:r[l]='<del style="background:#ffe6e6;">'+c+"</del>";break;case 0:r[l]="<span>"+c+"</span>"}}return r.join("")},e.prototype.diff_text1=function(t){for(var r=[],a=0;a<t.length;a++)t[a][0]!==1&&(r[a]=t[a][1]);return r.join("")},e.prototype.diff_text2=function(t){for(var r=[],a=0;a<t.length;a++)t[a][0]!==-1&&(r[a]=t[a][1]);return r.join("")},e.prototype.diff_levenshtein=function(t){for(var r=0,a=0,s=0,o=0;o<t.length;o++){var i=t[o][0],l=t[o][1];switch(i){case 1:a+=l.length;break;case-1:s+=l.length;break;case 0:r+=Math.max(a,s),a=0,s=0}}return r+=Math.max(a,s)},e.prototype.diff_toDelta=function(t){for(var r=[],a=0;a<t.length;a++)switch(t[a][0]){case 1:r[a]="+"+encodeURI(t[a][1]);break;case-1:r[a]="-"+t[a][1].length;break;case 0:r[a]="="+t[a][1].length}return r.join(" ").replace(/%20/g," ")},e.prototype.diff_fromDelta=function(t,r){for(var a=[],s=0,o=0,i=r.split(/\t/g),l=0;l<i.length;l++){var u=i[l].substring(1);switch(i[l].charAt(0)){case"+":try{a[s++]=new e.Diff(1,decodeURI(u))}catch{throw new Error("Illegal escape in diff_fromDelta: "+u)}break;case"-":case"=":var c=parseInt(u,10);if(isNaN(c)||c<0)throw new Error("Invalid number in diff_fromDelta: "+u);var d=t.substring(o,o+=c);i[l].charAt(0)=="="?a[s++]=new e.Diff(0,d):a[s++]=new e.Diff(-1,d);break;default:if(i[l])throw new Error("Invalid diff operation in diff_fromDelta: "+i[l])}}if(o!=t.length)throw new Error("Delta length ("+o+") does not equal source text length ("+t.length+").");return a},e.prototype.match_main=function(t,r,a){if(t==null||r==null||a==null)throw new Error("Null input. (match_main)");return a=Math.max(0,Math.min(a,t.length)),t==r?0:t.length?t.substring(a,a+r.length)==r?a:this.match_bitap_(t,r,a):-1},e.prototype.match_bitap_=function(t,r,a){if(r.length>this.Match_MaxBits)throw new Error("Pattern too long for this browser.");var s=this.match_alphabet_(r),o=this;function i(v,b){var P=v/r.length,N=Math.abs(a-b);return o.Match_Distance?P+N/o.Match_Distance:N?1:P}var l=this.Match_Threshold,u=t.indexOf(r,a);u!=-1&&(l=Math.min(i(0,u),l),(u=t.lastIndexOf(r,a+r.length))!=-1&&(l=Math.min(i(0,u),l)));var c,d,f=1<<r.length-1;u=-1;for(var h,p=r.length+t.length,m=0;m<r.length;m++){for(c=0,d=p;c<d;)i(m,a+d)<=l?c=d:p=d,d=Math.floor((p-c)/2+c);p=d;var g=Math.max(1,a-d+1),x=Math.min(a+d,t.length)+r.length,w=Array(x+2);w[x+1]=(1<<m)-1;for(var y=x;y>=g;y--){var C=s[t.charAt(y-1)];if(w[y]=m===0?(w[y+1]<<1|1)&C:(w[y+1]<<1|1)&C|(h[y+1]|h[y])<<1|1|h[y+1],w[y]&f){var k=i(m,y-1);if(k<=l){if(l=k,!((u=y-1)>a))break;g=Math.max(1,2*a-u)}}}if(i(m+1,a)>l)break;h=w}return u},e.prototype.match_alphabet_=function(t){for(var r={},a=0;a<t.length;a++)r[t.charAt(a)]=0;for(a=0;a<t.length;a++)r[t.charAt(a)]|=1<<t.length-a-1;return r},e.prototype.patch_addContext_=function(t,r){if(r.length!=0){if(t.start2===null)throw Error("patch not initialized");for(var a=r.substring(t.start2,t.start2+t.length1),s=0;r.indexOf(a)!=r.lastIndexOf(a)&&a.length<this.Match_MaxBits-this.Patch_Margin-this.Patch_Margin;)s+=this.Patch_Margin,a=r.substring(t.start2-s,t.start2+t.length1+s);s+=this.Patch_Margin;var o=r.substring(t.start2-s,t.start2);o&&t.diffs.unshift(new e.Diff(0,o));var i=r.substring(t.start2+t.length1,t.start2+t.length1+s);i&&t.diffs.push(new e.Diff(0,i)),t.start1-=o.length,t.start2-=o.length,t.length1+=o.length+i.length,t.length2+=o.length+i.length}},e.prototype.patch_make=function(t,r,a){var s,o;if(typeof t=="string"&&typeof r=="string"&&a===void 0)s=t,(o=this.diff_main(s,r,!0)).length>2&&(this.diff_cleanupSemantic(o),this.diff_cleanupEfficiency(o));else if(t&&typeof t=="object"&&r===void 0&&a===void 0)o=t,s=this.diff_text1(o);else if(typeof t=="string"&&r&&typeof r=="object"&&a===void 0)s=t,o=r;else{if(typeof t!="string"||typeof r!="string"||!a||typeof a!="object")throw new Error("Unknown call format to patch_make.");s=t,o=a}if(o.length===0)return[];for(var i=[],l=new e.patch_obj,u=0,c=0,d=0,f=s,h=s,p=0;p<o.length;p++){var m=o[p][0],g=o[p][1];switch(u||m===0||(l.start1=c,l.start2=d),m){case 1:l.diffs[u++]=o[p],l.length2+=g.length,h=h.substring(0,d)+g+h.substring(d);break;case-1:l.length1+=g.length,l.diffs[u++]=o[p],h=h.substring(0,d)+h.substring(d+g.length);break;case 0:g.length<=2*this.Patch_Margin&&u&&o.length!=p+1?(l.diffs[u++]=o[p],l.length1+=g.length,l.length2+=g.length):g.length>=2*this.Patch_Margin&&u&&(this.patch_addContext_(l,f),i.push(l),l=new e.patch_obj,u=0,f=h,c=d)}m!==1&&(c+=g.length),m!==-1&&(d+=g.length)}return u&&(this.patch_addContext_(l,f),i.push(l)),i},e.prototype.patch_deepCopy=function(t){for(var r=[],a=0;a<t.length;a++){var s=t[a],o=new e.patch_obj;o.diffs=[];for(var i=0;i<s.diffs.length;i++)o.diffs[i]=new e.Diff(s.diffs[i][0],s.diffs[i][1]);o.start1=s.start1,o.start2=s.start2,o.length1=s.length1,o.length2=s.length2,r[a]=o}return r},e.prototype.patch_apply=function(t,r){if(t.length==0)return[r,[]];t=this.patch_deepCopy(t);var a=this.patch_addPadding(t);r=a+r+a,this.patch_splitMax(t);for(var s=0,o=[],i=0;i<t.length;i++){var l,u,c=t[i].start2+s,d=this.diff_text1(t[i].diffs),f=-1;if(d.length>this.Match_MaxBits?(l=this.match_main(r,d.substring(0,this.Match_MaxBits),c))!=-1&&((f=this.match_main(r,d.substring(d.length-this.Match_MaxBits),c+d.length-this.Match_MaxBits))==-1||l>=f)&&(l=-1):l=this.match_main(r,d,c),l==-1)o[i]=!1,s-=t[i].length2-t[i].length1;else if(o[i]=!0,s=l-c,d==(u=f==-1?r.substring(l,l+d.length):r.substring(l,f+this.Match_MaxBits)))r=r.substring(0,l)+this.diff_text2(t[i].diffs)+r.substring(l+d.length);else{var h=this.diff_main(d,u,!1);if(d.length>this.Match_MaxBits&&this.diff_levenshtein(h)/d.length>this.Patch_DeleteThreshold)o[i]=!1;else{this.diff_cleanupSemanticLossless(h);for(var p,m=0,g=0;g<t[i].diffs.length;g++){var x=t[i].diffs[g];x[0]!==0&&(p=this.diff_xIndex(h,m)),x[0]===1?r=r.substring(0,l+p)+x[1]+r.substring(l+p):x[0]===-1&&(r=r.substring(0,l+p)+r.substring(l+this.diff_xIndex(h,m+x[1].length))),x[0]!==-1&&(m+=x[1].length)}}}}return[r=r.substring(a.length,r.length-a.length),o]},e.prototype.patch_addPadding=function(t){for(var r=this.Patch_Margin,a="",s=1;s<=r;s++)a+=String.fromCharCode(s);for(s=0;s<t.length;s++)t[s].start1+=r,t[s].start2+=r;var o=t[0],i=o.diffs;if(i.length==0||i[0][0]!=0)i.unshift(new e.Diff(0,a)),o.start1-=r,o.start2-=r,o.length1+=r,o.length2+=r;else if(r>i[0][1].length){var l=r-i[0][1].length;i[0][1]=a.substring(i[0][1].length)+i[0][1],o.start1-=l,o.start2-=l,o.length1+=l,o.length2+=l}return(i=(o=t[t.length-1]).diffs).length==0||i[i.length-1][0]!=0?(i.push(new e.Diff(0,a)),o.length1+=r,o.length2+=r):r>i[i.length-1][1].length&&(l=r-i[i.length-1][1].length,i[i.length-1][1]+=a.substring(0,l),o.length1+=l,o.length2+=l),a},e.prototype.patch_splitMax=function(t){for(var r=this.Match_MaxBits,a=0;a<t.length;a++)if(!(t[a].length1<=r)){var s=t[a];t.splice(a--,1);for(var o=s.start1,i=s.start2,l="";s.diffs.length!==0;){var u=new e.patch_obj,c=!0;for(u.start1=o-l.length,u.start2=i-l.length,l!==""&&(u.length1=u.length2=l.length,u.diffs.push(new e.Diff(0,l)));s.diffs.length!==0&&u.length1<r-this.Patch_Margin;){var d=s.diffs[0][0],f=s.diffs[0][1];d===1?(u.length2+=f.length,i+=f.length,u.diffs.push(s.diffs.shift()),c=!1):d===-1&&u.diffs.length==1&&u.diffs[0][0]==0&&f.length>2*r?(u.length1+=f.length,o+=f.length,c=!1,u.diffs.push(new e.Diff(d,f)),s.diffs.shift()):(f=f.substring(0,r-u.length1-this.Patch_Margin),u.length1+=f.length,o+=f.length,d===0?(u.length2+=f.length,i+=f.length):c=!1,u.diffs.push(new e.Diff(d,f)),f==s.diffs[0][1]?s.diffs.shift():s.diffs[0][1]=s.diffs[0][1].substring(f.length))}l=(l=this.diff_text2(u.diffs)).substring(l.length-this.Patch_Margin);var h=this.diff_text1(s.diffs).substring(0,this.Patch_Margin);h!==""&&(u.length1+=h.length,u.length2+=h.length,u.diffs.length!==0&&u.diffs[u.diffs.length-1][0]===0?u.diffs[u.diffs.length-1][1]+=h:u.diffs.push(new e.Diff(0,h))),c||t.splice(++a,0,u)}}},e.prototype.patch_toText=function(t){for(var r=[],a=0;a<t.length;a++)r[a]=t[a];return r.join("")},e.prototype.patch_fromText=function(t){var r=[];if(!t)return r;for(var a=t.split(`
20
- `),s=0,o=/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;s<a.length;){var i=a[s].match(o);if(!i)throw new Error("Invalid patch string: "+a[s]);var l=new e.patch_obj;for(r.push(l),l.start1=parseInt(i[1],10),i[2]===""?(l.start1--,l.length1=1):i[2]=="0"?l.length1=0:(l.start1--,l.length1=parseInt(i[2],10)),l.start2=parseInt(i[3],10),i[4]===""?(l.start2--,l.length2=1):i[4]=="0"?l.length2=0:(l.start2--,l.length2=parseInt(i[4],10)),s++;s<a.length;){var u=a[s].charAt(0);try{var c=decodeURI(a[s].substring(1))}catch{throw new Error("Illegal escape in patch_fromText: "+c)}if(u=="-")l.diffs.push(new e.Diff(-1,c));else if(u=="+")l.diffs.push(new e.Diff(1,c));else if(u==" ")l.diffs.push(new e.Diff(0,c));else{if(u=="@")break;if(u!=="")throw new Error('Invalid patch mode "'+u+'" in: '+c)}s++}}return r},(e.patch_obj=function(){this.diffs=[],this.start1=null,this.start2=null,this.length1=0,this.length2=0}).prototype.toString=function(){for(var t,r=["@@ -"+(this.length1===0?this.start1+",0":this.length1==1?this.start1+1:this.start1+1+","+this.length1)+" +"+(this.length2===0?this.start2+",0":this.length2==1?this.start2+1:this.start2+1+","+this.length2)+` @@
21
- `],a=0;a<this.diffs.length;a++){switch(this.diffs[a][0]){case 1:t="+";break;case-1:t="-";break;case 0:t=" "}r[a+1]=t+encodeURI(this.diffs[a][1])+`
22
- `}return r.join("").replace(/%20/g," ")},n.exports=e,n.exports.diff_match_patch=e,n.exports.DIFF_DELETE=-1,n.exports.DIFF_INSERT=1,n.exports.DIFF_EQUAL=0})),tz=rp.DIFF_EQUAL,nz=rp.DIFF_DELETE,rz=rp.DIFF_INSERT;var ER=["enhancers"],Uv=function(n){var e,t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r=t.enhancers,a=r===void 0?[]:r,s=en(CR(n,Fs(t,ER)),2),o=s[0],i=s[1],l=[ev(o),ev(i)],u=(e=[l[0],l[1]],a.reduce((function(m,g){return g(m)}),e)),c=en(u,2),d=c[0],f=c[1],h=[d.map(tv),f.map(tv)],p=h[1];return{old:h[0].map((function(m){var g;return(g=m.children)!==null&&g!==void 0?g:[]})),new:p.map((function(m){var g;return(g=m.children)!==null&&g!==void 0?g:[]}))}};var nv;var az=(nv=0,function(){return nv+=1});var op=W(Qr(),1);function Gv(n){let e=n.split(`
23
- `),t=[],r=0;for(;r<e.length&&!e[r].startsWith("@@");)t.push(e[r]),r++;let a=[],s=null;for(;r<e.length;r++){let o=e[r];o.startsWith("@@")?(s&&a.push(s.join(`
24
- `)),s=[o]):s&&s.push(o)}return s&&a.push(s.join(`
25
- `)),{header:t.join(`
26
- `),hunks:a}}function zv(n,e){let t=n.replace(/\n+$/,"");if(!t.trim())return null;let r=`${t}
18
+ `).map((function(c){return VR(l,Rt(Rt({},u),{},{value:c}))})):[l]})(n),s=ZA(a),i=s[0],o=s.slice(1);return[].concat(kr(e.slice(0,-1)),[[].concat(kr(r),[i])],kr(o.map((function(l){return[l]}))))}),[[]])}function nv(t){return XR(Gv(t))}var YR=function(t,e,n){var r=(n=typeof n=="function"?n:void 0)?n(t,e):void 0;return r===void 0?jc(t,e,void 0,n):!!r},JR=function(t,e){return jc(t,e)},ZR=function(t){var e=t==null?0:t.length;return e?t[e-1]:void 0};function QR(t,e){if(!t.children)throw new Error("parent node missing children property");var n,r,a=ZR(t.children);return a&&(r=e,(n=a).type===r.type&&(n.type==="text"||n.children&&r.children&&YR(n,r,(function(s,i,o){return o==="chlidren"||JR(s,i)}))))?t.children[t.children.length-1]=(function(s,i){return"value"in s&&"value"in i?Rt(Rt({},s),{},{value:"".concat(s.value).concat(i.value)}):s})(a,e):t.children.push(e),t.children[t.children.length-1]}function rv(t){var e,n={type:"root",children:[]},r=zh(t);try{var a=function(){var s=e.value;s.reduce((function(i,o,l){return QR(i,l===s.length-1?Rt({},o):Rt(Rt({},o),{},{children:[]}))}),n)};for(r.s();!(e=r.n()).done;)a()}catch(s){r.e(s)}finally{r.f()}return n}var eM=Object.prototype.hasOwnProperty,kW=Hv((function(t,e,n){eM.call(t,n)?t[n].push(e):Zh(t,n,[e])}));var ep=nu((function(t){var e=function(){this.Diff_Timeout=1,this.Diff_EditCost=4,this.Match_Threshold=.5,this.Match_Distance=1e3,this.Patch_DeleteThreshold=.5,this.Patch_Margin=4,this.Match_MaxBits=32};e.Diff=function(n,r){return[n,r]},e.prototype.diff_main=function(n,r,a,s){s===void 0&&(s=this.Diff_Timeout<=0?Number.MAX_VALUE:new Date().getTime()+1e3*this.Diff_Timeout);var i=s;if(n==null||r==null)throw new Error("Null input. (diff_main)");if(n==r)return n?[new e.Diff(0,n)]:[];a===void 0&&(a=!0);var o=a,l=this.diff_commonPrefix(n,r),u=n.substring(0,l);n=n.substring(l),r=r.substring(l),l=this.diff_commonSuffix(n,r);var c=n.substring(n.length-l);n=n.substring(0,n.length-l),r=r.substring(0,r.length-l);var d=this.diff_compute_(n,r,o,i);return u&&d.unshift(new e.Diff(0,u)),c&&d.push(new e.Diff(0,c)),this.diff_cleanupMerge(d),d},e.prototype.diff_compute_=function(n,r,a,s){var i;if(!n)return[new e.Diff(1,r)];if(!r)return[new e.Diff(-1,n)];var o=n.length>r.length?n:r,l=n.length>r.length?r:n,u=o.indexOf(l);if(u!=-1)return i=[new e.Diff(1,o.substring(0,u)),new e.Diff(0,l),new e.Diff(1,o.substring(u+l.length))],n.length>r.length&&(i[0][0]=i[2][0]=-1),i;if(l.length==1)return[new e.Diff(-1,n),new e.Diff(1,r)];var c=this.diff_halfMatch_(n,r);if(c){var d=c[0],f=c[1],h=c[2],p=c[3],g=c[4],m=this.diff_main(d,h,a,s),x=this.diff_main(f,p,a,s);return m.concat([new e.Diff(0,g)],x)}return a&&n.length>100&&r.length>100?this.diff_lineMode_(n,r,s):this.diff_bisect_(n,r,s)},e.prototype.diff_lineMode_=function(n,r,a){var s=this.diff_linesToChars_(n,r);n=s.chars1,r=s.chars2;var i=s.lineArray,o=this.diff_main(n,r,!1,a);this.diff_charsToLines_(o,i),this.diff_cleanupSemantic(o),o.push(new e.Diff(0,""));for(var l=0,u=0,c=0,d="",f="";l<o.length;){switch(o[l][0]){case 1:c++,f+=o[l][1];break;case-1:u++,d+=o[l][1];break;case 0:if(u>=1&&c>=1){o.splice(l-u-c,u+c),l=l-u-c;for(var h=this.diff_main(d,f,!1,a),p=h.length-1;p>=0;p--)o.splice(l,0,h[p]);l+=h.length}c=0,u=0,d="",f=""}l++}return o.pop(),o},e.prototype.diff_bisect_=function(n,r,a){for(var s=n.length,i=r.length,o=Math.ceil((s+i)/2),l=o,u=2*o,c=new Array(u),d=new Array(u),f=0;f<u;f++)c[f]=-1,d[f]=-1;c[l+1]=0,d[l+1]=0;for(var h=s-i,p=h%2!=0,g=0,m=0,x=0,y=0,b=0;b<o&&!(new Date().getTime()>a);b++){for(var C=-b+g;C<=b-m;C+=2){for(var L=l+C,P=(R=C==-b||C!=b&&c[L-1]<c[L+1]?c[L+1]:c[L-1]+1)-C;R<s&&P<i&&n.charAt(R)==r.charAt(P);)R++,P++;if(c[L]=R,R>s)m+=2;else if(P>i)g+=2;else if(p&&(_=l+h-C)>=0&&_<u&&d[_]!=-1&&R>=(k=s-d[_]))return this.diff_bisectSplit_(n,r,R,P,a)}for(var w=-b+x;w<=b-y;w+=2){for(var k,_=l+w,M=(k=w==-b||w!=b&&d[_-1]<d[_+1]?d[_+1]:d[_-1]+1)-w;k<s&&M<i&&n.charAt(s-k-1)==r.charAt(i-M-1);)k++,M++;if(d[_]=k,k>s)y+=2;else if(M>i)x+=2;else if(!p&&(L=l+h-w)>=0&&L<u&&c[L]!=-1){var R;if(P=l+(R=c[L])-L,R>=(k=s-k))return this.diff_bisectSplit_(n,r,R,P,a)}}}return[new e.Diff(-1,n),new e.Diff(1,r)]},e.prototype.diff_bisectSplit_=function(n,r,a,s,i){var o=n.substring(0,a),l=r.substring(0,s),u=n.substring(a),c=r.substring(s),d=this.diff_main(o,l,!1,i),f=this.diff_main(u,c,!1,i);return d.concat(f)},e.prototype.diff_linesToChars_=function(n,r){var a=[],s={};function i(u){for(var c="",d=0,f=-1,h=a.length;f<u.length-1;){(f=u.indexOf(`
19
+ `,d))==-1&&(f=u.length-1);var p=u.substring(d,f+1);(s.hasOwnProperty?s.hasOwnProperty(p):s[p]!==void 0)?c+=String.fromCharCode(s[p]):(h==o&&(p=u.substring(d),f=u.length),c+=String.fromCharCode(h),s[p]=h,a[h++]=p),d=f+1}return c}a[0]="";var o=4e4,l=i(n);return o=65535,{chars1:l,chars2:i(r),lineArray:a}},e.prototype.diff_charsToLines_=function(n,r){for(var a=0;a<n.length;a++){for(var s=n[a][1],i=[],o=0;o<s.length;o++)i[o]=r[s.charCodeAt(o)];n[a][1]=i.join("")}},e.prototype.diff_commonPrefix=function(n,r){if(!n||!r||n.charAt(0)!=r.charAt(0))return 0;for(var a=0,s=Math.min(n.length,r.length),i=s,o=0;a<i;)n.substring(o,i)==r.substring(o,i)?o=a=i:s=i,i=Math.floor((s-a)/2+a);return i},e.prototype.diff_commonSuffix=function(n,r){if(!n||!r||n.charAt(n.length-1)!=r.charAt(r.length-1))return 0;for(var a=0,s=Math.min(n.length,r.length),i=s,o=0;a<i;)n.substring(n.length-i,n.length-o)==r.substring(r.length-i,r.length-o)?o=a=i:s=i,i=Math.floor((s-a)/2+a);return i},e.prototype.diff_commonOverlap_=function(n,r){var a=n.length,s=r.length;if(a==0||s==0)return 0;a>s?n=n.substring(a-s):a<s&&(r=r.substring(0,a));var i=Math.min(a,s);if(n==r)return i;for(var o=0,l=1;;){var u=n.substring(i-l),c=r.indexOf(u);if(c==-1)return o;l+=c,c!=0&&n.substring(i-l)!=r.substring(0,l)||(o=l,l++)}},e.prototype.diff_halfMatch_=function(n,r){if(this.Diff_Timeout<=0)return null;var a=n.length>r.length?n:r,s=n.length>r.length?r:n;if(a.length<4||2*s.length<a.length)return null;var i=this;function o(g,m,x){for(var y,b,C,L,P=g.substring(x,x+Math.floor(g.length/4)),w=-1,k="";(w=m.indexOf(P,w+1))!=-1;){var _=i.diff_commonPrefix(g.substring(x),m.substring(w)),M=i.diff_commonSuffix(g.substring(0,x),m.substring(0,w));k.length<M+_&&(k=m.substring(w-M,w)+m.substring(w,w+_),y=g.substring(0,x-M),b=g.substring(x+_),C=m.substring(0,w-M),L=m.substring(w+_))}return 2*k.length>=g.length?[y,b,C,L,k]:null}var l,u,c,d,f,h=o(a,s,Math.ceil(a.length/4)),p=o(a,s,Math.ceil(a.length/2));return h||p?(l=p?h&&h[4].length>p[4].length?h:p:h,n.length>r.length?(u=l[0],c=l[1],d=l[2],f=l[3]):(d=l[0],f=l[1],u=l[2],c=l[3]),[u,c,d,f,l[4]]):null},e.prototype.diff_cleanupSemantic=function(n){for(var r=!1,a=[],s=0,i=null,o=0,l=0,u=0,c=0,d=0;o<n.length;)n[o][0]==0?(a[s++]=o,l=c,u=d,c=0,d=0,i=n[o][1]):(n[o][0]==1?c+=n[o][1].length:d+=n[o][1].length,i&&i.length<=Math.max(l,u)&&i.length<=Math.max(c,d)&&(n.splice(a[s-1],0,new e.Diff(-1,i)),n[a[s-1]+1][0]=1,s--,o=--s>0?a[s-1]:-1,l=0,u=0,c=0,d=0,i=null,r=!0)),o++;for(r&&this.diff_cleanupMerge(n),this.diff_cleanupSemanticLossless(n),o=1;o<n.length;){if(n[o-1][0]==-1&&n[o][0]==1){var f=n[o-1][1],h=n[o][1],p=this.diff_commonOverlap_(f,h),g=this.diff_commonOverlap_(h,f);p>=g?(p>=f.length/2||p>=h.length/2)&&(n.splice(o,0,new e.Diff(0,h.substring(0,p))),n[o-1][1]=f.substring(0,f.length-p),n[o+1][1]=h.substring(p),o++):(g>=f.length/2||g>=h.length/2)&&(n.splice(o,0,new e.Diff(0,f.substring(0,g))),n[o-1][0]=1,n[o-1][1]=h.substring(0,h.length-g),n[o+1][0]=-1,n[o+1][1]=f.substring(g),o++),o++}o++}},e.prototype.diff_cleanupSemanticLossless=function(n){function r(g,m){if(!g||!m)return 6;var x=g.charAt(g.length-1),y=m.charAt(0),b=x.match(e.nonAlphaNumericRegex_),C=y.match(e.nonAlphaNumericRegex_),L=b&&x.match(e.whitespaceRegex_),P=C&&y.match(e.whitespaceRegex_),w=L&&x.match(e.linebreakRegex_),k=P&&y.match(e.linebreakRegex_),_=w&&g.match(e.blanklineEndRegex_),M=k&&m.match(e.blanklineStartRegex_);return _||M?5:w||k?4:b&&!L&&P?3:L||P?2:b||C?1:0}for(var a=1;a<n.length-1;){if(n[a-1][0]==0&&n[a+1][0]==0){var s=n[a-1][1],i=n[a][1],o=n[a+1][1],l=this.diff_commonSuffix(s,i);if(l){var u=i.substring(i.length-l);s=s.substring(0,s.length-l),i=u+i.substring(0,i.length-l),o=u+o}for(var c=s,d=i,f=o,h=r(s,i)+r(i,o);i.charAt(0)===o.charAt(0);){s+=i.charAt(0),i=i.substring(1)+o.charAt(0),o=o.substring(1);var p=r(s,i)+r(i,o);p>=h&&(h=p,c=s,d=i,f=o)}n[a-1][1]!=c&&(c?n[a-1][1]=c:(n.splice(a-1,1),a--),n[a][1]=d,f?n[a+1][1]=f:(n.splice(a+1,1),a--))}a++}},e.nonAlphaNumericRegex_=/[^a-zA-Z0-9]/,e.whitespaceRegex_=/\s/,e.linebreakRegex_=/[\r\n]/,e.blanklineEndRegex_=/\n\r?\n$/,e.blanklineStartRegex_=/^\r?\n\r?\n/,e.prototype.diff_cleanupEfficiency=function(n){for(var r=!1,a=[],s=0,i=null,o=0,l=!1,u=!1,c=!1,d=!1;o<n.length;)n[o][0]==0?(n[o][1].length<this.Diff_EditCost&&(c||d)?(a[s++]=o,l=c,u=d,i=n[o][1]):(s=0,i=null),c=d=!1):(n[o][0]==-1?d=!0:c=!0,i&&(l&&u&&c&&d||i.length<this.Diff_EditCost/2&&l+u+c+d==3)&&(n.splice(a[s-1],0,new e.Diff(-1,i)),n[a[s-1]+1][0]=1,s--,i=null,l&&u?(c=d=!0,s=0):(o=--s>0?a[s-1]:-1,c=d=!1),r=!0)),o++;r&&this.diff_cleanupMerge(n)},e.prototype.diff_cleanupMerge=function(n){n.push(new e.Diff(0,""));for(var r,a=0,s=0,i=0,o="",l="";a<n.length;)switch(n[a][0]){case 1:i++,l+=n[a][1],a++;break;case-1:s++,o+=n[a][1],a++;break;case 0:s+i>1?(s!==0&&i!==0&&((r=this.diff_commonPrefix(l,o))!==0&&(a-s-i>0&&n[a-s-i-1][0]==0?n[a-s-i-1][1]+=l.substring(0,r):(n.splice(0,0,new e.Diff(0,l.substring(0,r))),a++),l=l.substring(r),o=o.substring(r)),(r=this.diff_commonSuffix(l,o))!==0&&(n[a][1]=l.substring(l.length-r)+n[a][1],l=l.substring(0,l.length-r),o=o.substring(0,o.length-r))),a-=s+i,n.splice(a,s+i),o.length&&(n.splice(a,0,new e.Diff(-1,o)),a++),l.length&&(n.splice(a,0,new e.Diff(1,l)),a++),a++):a!==0&&n[a-1][0]==0?(n[a-1][1]+=n[a][1],n.splice(a,1)):a++,i=0,s=0,o="",l=""}n[n.length-1][1]===""&&n.pop();var u=!1;for(a=1;a<n.length-1;)n[a-1][0]==0&&n[a+1][0]==0&&(n[a][1].substring(n[a][1].length-n[a-1][1].length)==n[a-1][1]?(n[a][1]=n[a-1][1]+n[a][1].substring(0,n[a][1].length-n[a-1][1].length),n[a+1][1]=n[a-1][1]+n[a+1][1],n.splice(a-1,1),u=!0):n[a][1].substring(0,n[a+1][1].length)==n[a+1][1]&&(n[a-1][1]+=n[a+1][1],n[a][1]=n[a][1].substring(n[a+1][1].length)+n[a+1][1],n.splice(a+1,1),u=!0)),a++;u&&this.diff_cleanupMerge(n)},e.prototype.diff_xIndex=function(n,r){var a,s=0,i=0,o=0,l=0;for(a=0;a<n.length&&(n[a][0]!==1&&(s+=n[a][1].length),n[a][0]!==-1&&(i+=n[a][1].length),!(s>r));a++)o=s,l=i;return n.length!=a&&n[a][0]===-1?l:l+(r-o)},e.prototype.diff_prettyHtml=function(n){for(var r=[],a=/&/g,s=/</g,i=/>/g,o=/\n/g,l=0;l<n.length;l++){var u=n[l][0],c=n[l][1].replace(a,"&amp;").replace(s,"&lt;").replace(i,"&gt;").replace(o,"&para;<br>");switch(u){case 1:r[l]='<ins style="background:#e6ffe6;">'+c+"</ins>";break;case-1:r[l]='<del style="background:#ffe6e6;">'+c+"</del>";break;case 0:r[l]="<span>"+c+"</span>"}}return r.join("")},e.prototype.diff_text1=function(n){for(var r=[],a=0;a<n.length;a++)n[a][0]!==1&&(r[a]=n[a][1]);return r.join("")},e.prototype.diff_text2=function(n){for(var r=[],a=0;a<n.length;a++)n[a][0]!==-1&&(r[a]=n[a][1]);return r.join("")},e.prototype.diff_levenshtein=function(n){for(var r=0,a=0,s=0,i=0;i<n.length;i++){var o=n[i][0],l=n[i][1];switch(o){case 1:a+=l.length;break;case-1:s+=l.length;break;case 0:r+=Math.max(a,s),a=0,s=0}}return r+=Math.max(a,s)},e.prototype.diff_toDelta=function(n){for(var r=[],a=0;a<n.length;a++)switch(n[a][0]){case 1:r[a]="+"+encodeURI(n[a][1]);break;case-1:r[a]="-"+n[a][1].length;break;case 0:r[a]="="+n[a][1].length}return r.join(" ").replace(/%20/g," ")},e.prototype.diff_fromDelta=function(n,r){for(var a=[],s=0,i=0,o=r.split(/\t/g),l=0;l<o.length;l++){var u=o[l].substring(1);switch(o[l].charAt(0)){case"+":try{a[s++]=new e.Diff(1,decodeURI(u))}catch{throw new Error("Illegal escape in diff_fromDelta: "+u)}break;case"-":case"=":var c=parseInt(u,10);if(isNaN(c)||c<0)throw new Error("Invalid number in diff_fromDelta: "+u);var d=n.substring(i,i+=c);o[l].charAt(0)=="="?a[s++]=new e.Diff(0,d):a[s++]=new e.Diff(-1,d);break;default:if(o[l])throw new Error("Invalid diff operation in diff_fromDelta: "+o[l])}}if(i!=n.length)throw new Error("Delta length ("+i+") does not equal source text length ("+n.length+").");return a},e.prototype.match_main=function(n,r,a){if(n==null||r==null||a==null)throw new Error("Null input. (match_main)");return a=Math.max(0,Math.min(a,n.length)),n==r?0:n.length?n.substring(a,a+r.length)==r?a:this.match_bitap_(n,r,a):-1},e.prototype.match_bitap_=function(n,r,a){if(r.length>this.Match_MaxBits)throw new Error("Pattern too long for this browser.");var s=this.match_alphabet_(r),i=this;function o(P,w){var k=P/r.length,_=Math.abs(a-w);return i.Match_Distance?k+_/i.Match_Distance:_?1:k}var l=this.Match_Threshold,u=n.indexOf(r,a);u!=-1&&(l=Math.min(o(0,u),l),(u=n.lastIndexOf(r,a+r.length))!=-1&&(l=Math.min(o(0,u),l)));var c,d,f=1<<r.length-1;u=-1;for(var h,p=r.length+n.length,g=0;g<r.length;g++){for(c=0,d=p;c<d;)o(g,a+d)<=l?c=d:p=d,d=Math.floor((p-c)/2+c);p=d;var m=Math.max(1,a-d+1),x=Math.min(a+d,n.length)+r.length,y=Array(x+2);y[x+1]=(1<<g)-1;for(var b=x;b>=m;b--){var C=s[n.charAt(b-1)];if(y[b]=g===0?(y[b+1]<<1|1)&C:(y[b+1]<<1|1)&C|(h[b+1]|h[b])<<1|1|h[b+1],y[b]&f){var L=o(g,b-1);if(L<=l){if(l=L,!((u=b-1)>a))break;m=Math.max(1,2*a-u)}}}if(o(g+1,a)>l)break;h=y}return u},e.prototype.match_alphabet_=function(n){for(var r={},a=0;a<n.length;a++)r[n.charAt(a)]=0;for(a=0;a<n.length;a++)r[n.charAt(a)]|=1<<n.length-a-1;return r},e.prototype.patch_addContext_=function(n,r){if(r.length!=0){if(n.start2===null)throw Error("patch not initialized");for(var a=r.substring(n.start2,n.start2+n.length1),s=0;r.indexOf(a)!=r.lastIndexOf(a)&&a.length<this.Match_MaxBits-this.Patch_Margin-this.Patch_Margin;)s+=this.Patch_Margin,a=r.substring(n.start2-s,n.start2+n.length1+s);s+=this.Patch_Margin;var i=r.substring(n.start2-s,n.start2);i&&n.diffs.unshift(new e.Diff(0,i));var o=r.substring(n.start2+n.length1,n.start2+n.length1+s);o&&n.diffs.push(new e.Diff(0,o)),n.start1-=i.length,n.start2-=i.length,n.length1+=i.length+o.length,n.length2+=i.length+o.length}},e.prototype.patch_make=function(n,r,a){var s,i;if(typeof n=="string"&&typeof r=="string"&&a===void 0)s=n,(i=this.diff_main(s,r,!0)).length>2&&(this.diff_cleanupSemantic(i),this.diff_cleanupEfficiency(i));else if(n&&typeof n=="object"&&r===void 0&&a===void 0)i=n,s=this.diff_text1(i);else if(typeof n=="string"&&r&&typeof r=="object"&&a===void 0)s=n,i=r;else{if(typeof n!="string"||typeof r!="string"||!a||typeof a!="object")throw new Error("Unknown call format to patch_make.");s=n,i=a}if(i.length===0)return[];for(var o=[],l=new e.patch_obj,u=0,c=0,d=0,f=s,h=s,p=0;p<i.length;p++){var g=i[p][0],m=i[p][1];switch(u||g===0||(l.start1=c,l.start2=d),g){case 1:l.diffs[u++]=i[p],l.length2+=m.length,h=h.substring(0,d)+m+h.substring(d);break;case-1:l.length1+=m.length,l.diffs[u++]=i[p],h=h.substring(0,d)+h.substring(d+m.length);break;case 0:m.length<=2*this.Patch_Margin&&u&&i.length!=p+1?(l.diffs[u++]=i[p],l.length1+=m.length,l.length2+=m.length):m.length>=2*this.Patch_Margin&&u&&(this.patch_addContext_(l,f),o.push(l),l=new e.patch_obj,u=0,f=h,c=d)}g!==1&&(c+=m.length),g!==-1&&(d+=m.length)}return u&&(this.patch_addContext_(l,f),o.push(l)),o},e.prototype.patch_deepCopy=function(n){for(var r=[],a=0;a<n.length;a++){var s=n[a],i=new e.patch_obj;i.diffs=[];for(var o=0;o<s.diffs.length;o++)i.diffs[o]=new e.Diff(s.diffs[o][0],s.diffs[o][1]);i.start1=s.start1,i.start2=s.start2,i.length1=s.length1,i.length2=s.length2,r[a]=i}return r},e.prototype.patch_apply=function(n,r){if(n.length==0)return[r,[]];n=this.patch_deepCopy(n);var a=this.patch_addPadding(n);r=a+r+a,this.patch_splitMax(n);for(var s=0,i=[],o=0;o<n.length;o++){var l,u,c=n[o].start2+s,d=this.diff_text1(n[o].diffs),f=-1;if(d.length>this.Match_MaxBits?(l=this.match_main(r,d.substring(0,this.Match_MaxBits),c))!=-1&&((f=this.match_main(r,d.substring(d.length-this.Match_MaxBits),c+d.length-this.Match_MaxBits))==-1||l>=f)&&(l=-1):l=this.match_main(r,d,c),l==-1)i[o]=!1,s-=n[o].length2-n[o].length1;else if(i[o]=!0,s=l-c,d==(u=f==-1?r.substring(l,l+d.length):r.substring(l,f+this.Match_MaxBits)))r=r.substring(0,l)+this.diff_text2(n[o].diffs)+r.substring(l+d.length);else{var h=this.diff_main(d,u,!1);if(d.length>this.Match_MaxBits&&this.diff_levenshtein(h)/d.length>this.Patch_DeleteThreshold)i[o]=!1;else{this.diff_cleanupSemanticLossless(h);for(var p,g=0,m=0;m<n[o].diffs.length;m++){var x=n[o].diffs[m];x[0]!==0&&(p=this.diff_xIndex(h,g)),x[0]===1?r=r.substring(0,l+p)+x[1]+r.substring(l+p):x[0]===-1&&(r=r.substring(0,l+p)+r.substring(l+this.diff_xIndex(h,g+x[1].length))),x[0]!==-1&&(g+=x[1].length)}}}}return[r=r.substring(a.length,r.length-a.length),i]},e.prototype.patch_addPadding=function(n){for(var r=this.Patch_Margin,a="",s=1;s<=r;s++)a+=String.fromCharCode(s);for(s=0;s<n.length;s++)n[s].start1+=r,n[s].start2+=r;var i=n[0],o=i.diffs;if(o.length==0||o[0][0]!=0)o.unshift(new e.Diff(0,a)),i.start1-=r,i.start2-=r,i.length1+=r,i.length2+=r;else if(r>o[0][1].length){var l=r-o[0][1].length;o[0][1]=a.substring(o[0][1].length)+o[0][1],i.start1-=l,i.start2-=l,i.length1+=l,i.length2+=l}return(o=(i=n[n.length-1]).diffs).length==0||o[o.length-1][0]!=0?(o.push(new e.Diff(0,a)),i.length1+=r,i.length2+=r):r>o[o.length-1][1].length&&(l=r-o[o.length-1][1].length,o[o.length-1][1]+=a.substring(0,l),i.length1+=l,i.length2+=l),a},e.prototype.patch_splitMax=function(n){for(var r=this.Match_MaxBits,a=0;a<n.length;a++)if(!(n[a].length1<=r)){var s=n[a];n.splice(a--,1);for(var i=s.start1,o=s.start2,l="";s.diffs.length!==0;){var u=new e.patch_obj,c=!0;for(u.start1=i-l.length,u.start2=o-l.length,l!==""&&(u.length1=u.length2=l.length,u.diffs.push(new e.Diff(0,l)));s.diffs.length!==0&&u.length1<r-this.Patch_Margin;){var d=s.diffs[0][0],f=s.diffs[0][1];d===1?(u.length2+=f.length,o+=f.length,u.diffs.push(s.diffs.shift()),c=!1):d===-1&&u.diffs.length==1&&u.diffs[0][0]==0&&f.length>2*r?(u.length1+=f.length,i+=f.length,c=!1,u.diffs.push(new e.Diff(d,f)),s.diffs.shift()):(f=f.substring(0,r-u.length1-this.Patch_Margin),u.length1+=f.length,i+=f.length,d===0?(u.length2+=f.length,o+=f.length):c=!1,u.diffs.push(new e.Diff(d,f)),f==s.diffs[0][1]?s.diffs.shift():s.diffs[0][1]=s.diffs[0][1].substring(f.length))}l=(l=this.diff_text2(u.diffs)).substring(l.length-this.Patch_Margin);var h=this.diff_text1(s.diffs).substring(0,this.Patch_Margin);h!==""&&(u.length1+=h.length,u.length2+=h.length,u.diffs.length!==0&&u.diffs[u.diffs.length-1][0]===0?u.diffs[u.diffs.length-1][1]+=h:u.diffs.push(new e.Diff(0,h))),c||n.splice(++a,0,u)}}},e.prototype.patch_toText=function(n){for(var r=[],a=0;a<n.length;a++)r[a]=n[a];return r.join("")},e.prototype.patch_fromText=function(n){var r=[];if(!n)return r;for(var a=n.split(`
20
+ `),s=0,i=/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;s<a.length;){var o=a[s].match(i);if(!o)throw new Error("Invalid patch string: "+a[s]);var l=new e.patch_obj;for(r.push(l),l.start1=parseInt(o[1],10),o[2]===""?(l.start1--,l.length1=1):o[2]=="0"?l.length1=0:(l.start1--,l.length1=parseInt(o[2],10)),l.start2=parseInt(o[3],10),o[4]===""?(l.start2--,l.length2=1):o[4]=="0"?l.length2=0:(l.start2--,l.length2=parseInt(o[4],10)),s++;s<a.length;){var u=a[s].charAt(0);try{var c=decodeURI(a[s].substring(1))}catch{throw new Error("Illegal escape in patch_fromText: "+c)}if(u=="-")l.diffs.push(new e.Diff(-1,c));else if(u=="+")l.diffs.push(new e.Diff(1,c));else if(u==" ")l.diffs.push(new e.Diff(0,c));else{if(u=="@")break;if(u!=="")throw new Error('Invalid patch mode "'+u+'" in: '+c)}s++}}return r},(e.patch_obj=function(){this.diffs=[],this.start1=null,this.start2=null,this.length1=0,this.length2=0}).prototype.toString=function(){for(var n,r=["@@ -"+(this.length1===0?this.start1+",0":this.length1==1?this.start1+1:this.start1+1+","+this.length1)+" +"+(this.length2===0?this.start2+",0":this.length2==1?this.start2+1:this.start2+1+","+this.length2)+` @@
21
+ `],a=0;a<this.diffs.length;a++){switch(this.diffs[a][0]){case 1:n="+";break;case-1:n="-";break;case 0:n=" "}r[a+1]=n+encodeURI(this.diffs[a][1])+`
22
+ `}return r.join("").replace(/%20/g," ")},t.exports=e,t.exports.diff_match_patch=e,t.exports.DIFF_DELETE=-1,t.exports.DIFF_INSERT=1,t.exports.DIFF_EQUAL=0})),SW=ep.DIFF_EQUAL,CW=ep.DIFF_DELETE,IW=ep.DIFF_INSERT;var tM=["enhancers"],Wv=function(t){var e,n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r=n.enhancers,a=r===void 0?[]:r,s=en(jR(t,Os(n,tM)),2),i=s[0],o=s[1],l=[nv(i),nv(o)],u=(e=[l[0],l[1]],a.reduce((function(g,m){return m(g)}),e)),c=en(u,2),d=c[0],f=c[1],h=[d.map(rv),f.map(rv)],p=h[1];return{old:h[0].map((function(g){var m;return(m=g.children)!==null&&m!==void 0?m:[]})),new:p.map((function(g){var m;return(m=g.children)!==null&&m!==void 0?m:[]}))}};var av;var LW=(av=0,function(){return av+=1});var rp=j(Zr(),1);function zv(t){let e=t.split(`
23
+ `),n=[],r=0;for(;r<e.length&&!e[r].startsWith("@@");)n.push(e[r]),r++;let a=[],s=null;for(;r<e.length;r++){let i=e[r];i.startsWith("@@")?(s&&a.push(s.join(`
24
+ `)),s=[i]):s&&s.push(i)}return s&&a.push(s.join(`
25
+ `)),{header:n.join(`
26
+ `),hunks:a}}function jv(t,e){let n=t.replace(/\n+$/,"");if(!n.trim())return null;let r=`${n}
27
27
  ${e}`;return r.endsWith(`
28
28
  `)?r:`${r}
29
- `}function Wv(n,e){if(!n)return{files:[],truncated:e,hunkPatches:null};let t=[];try{t=lv(n)}catch{t=[]}return{files:t,truncated:e,hunkPatches:Gv(n)}}function Vc(n,e){let t=Pv(n,e);return t<=0?null:{start:n?n.oldStart+n.oldLines:1,end:e.oldStart,lines:t}}function Ql(n,e){if(!n)return null;let t=n.oldStart+n.oldLines;if(e===null)return{start:t,end:t,lines:null};let r=e-t+1;return r<=0?null:{start:t,end:e+1,lines:r}}function jv(n,e){let t=[];for(let a=0;a<n.length;a++){let s=Vc(a===0?null:n[a-1],n[a]);s&&t.push({start:s.start,end:s.end})}let r=Ql(n[n.length-1]??null,e);return r&&r.lines!==null&&t.push({start:r.start,end:r.end}),t}function BR(n){let e=n.split(`
30
- `);return e.length>1&&e[e.length-1]===""&&e.pop(),e}function $c(n,e){let t=BR(e);if(n.length===0)return t.slice();let r=n[n.length-1],a=Math.max(r.oldStart+r.oldLines,1),s=Math.max(r.newStart+r.newLines,1),o=Math.max(t.length-s+1,0),i=Math.max(a-1+o,0),l=new Array(i).fill(""),u=1,c=1,d=f=>{for(let h=u,p=c;h<f;h++,p++)l[h-1]=t[p-1]??""};for(let f of n)d(f.oldStart),u=Math.max(f.oldStart+f.oldLines,1),c=Math.max(f.newStart+f.newLines,1);return d(i+1),l}function qv(n,e,t){return t.reduce((r,a)=>Av(r,e,a.start,a.end),n)}function Vv(n,e){let t=n.oldStart,r=n.oldStart+n.oldLines,a=[];for(let s=0;s<e.length;s++){let o=e[s];o.oldStart>=t&&o.oldStart+o.oldLines<=r&&a.push(s)}return a}function $v(n){return"commit"in n?{kind:"commit",sha:n.commit}:"base"in n?{kind:"range",base:n.base,head:n.head}:{kind:"working",staged:n.staged}}function Kv(n){return n.kind==="working"?{staged:n.staged}:n.kind==="commit"?{commit:n.sha}:{base:n.base,head:n.head}}function Xv(n){return n.kind==="working"?n.staged?{type:"show",rev:"index"}:{type:"worktree"}:n.kind==="commit"?{type:"show",rev:n.sha}:{type:"show",rev:n.head}}function tn(n){return n.slice(0,7)}function Yv(n){return n.kind==="working"?n.staged?"Index \u2194 HEAD":"Working \u2194 Index":n.kind==="commit"?`${tn(n.sha)}^ \u2194 ${tn(n.sha)}`:`${tn(n.base)} \u2194 ${tn(n.head)}`}function Jv(n){return n.kind==="working"?n.staged?"No staged changes for this file.":"No working-tree changes for this file.":n.kind==="commit"?"No changes for this file in this commit.":"No changes for this file in this range."}function Zv(n){return"commit"in n?`commit ${tn(n.commit)}`:"base"in n?`${tn(n.base)}..${tn(n.head)}`:n.staged?"staged":"working tree"}function xo(n,e){return n?`${n} \xB7 ${e}`:e}function Qv(n){return!!n&&/uri.?policy.?denied/i.test(n)}var r1=W($e(),1);var ap={typescript:()=>import("./chunks/typescript-LWO362OA.js"),tsx:()=>import("./chunks/tsx-WPR2WRZD.js"),javascript:()=>import("./chunks/javascript-4JJTQGEL.js"),jsx:()=>import("./chunks/jsx-KQKSLAAH.js"),json:()=>import("./chunks/json-VLQ6D3JH.js"),markdown:()=>import("./chunks/markdown-46IKUAIB.js"),python:()=>import("./chunks/python-KXMCSAFQ.js"),bash:()=>import("./chunks/bash-M45GHPBQ.js"),yaml:()=>import("./chunks/yaml-MXHSIJCI.js"),html:()=>import("./chunks/html-UF3LFLNA.js"),css:()=>import("./chunks/css-2ZVPHE25.js"),go:()=>import("./chunks/go-6DGG5UTP.js"),rust:()=>import("./chunks/rust-J3BC3P6V.js"),sql:()=>import("./chunks/sql-DTZHNUZP.js"),toml:()=>import("./chunks/toml-UV7JK7K7.js"),c:()=>import("./chunks/c-X3REOAWD.js"),cpp:()=>import("./chunks/cpp-VOWI743W.js"),csharp:()=>import("./chunks/csharp-E7VIFITL.js"),java:()=>import("./chunks/java-PNTAU4L3.js"),kotlin:()=>import("./chunks/kotlin-44WS3JHE.js"),ruby:()=>import("./chunks/ruby-RLOWMVPO.js"),php:()=>import("./chunks/php-QJX57PA6.js"),swift:()=>import("./chunks/swift-QPHHCQD3.js"),scala:()=>import("./chunks/scala-AYIIHBJK.js"),r:()=>import("./chunks/r-QEZB45SR.js"),powershell:()=>import("./chunks/powershell-L4KJJ6DK.js"),ini:()=>import("./chunks/ini-VHVQ5TPB.js"),xml:()=>import("./chunks/xml-A5H72RTS.js"),scss:()=>import("./chunks/scss-B5CAI3HR.js"),less:()=>import("./chunks/less-5WZ3KLAK.js"),graphql:()=>import("./chunks/graphql-7V2NP54C.js"),lua:()=>import("./chunks/lua-UFPYUJ2O.js"),dart:()=>import("./chunks/dart-6Y3X27SZ.js"),elm:()=>import("./chunks/elm-7BG6QAIK.js"),latex:()=>import("./chunks/latex-ZWK7SXB6.js"),clojure:()=>import("./chunks/clojure-OC6KPSJO.js"),elixir:()=>import("./chunks/elixir-M36XROA6.js"),haskell:()=>import("./chunks/haskell-KK36PMMM.js"),nix:()=>import("./chunks/nix-Q6FYQZLX.js"),perl:()=>import("./chunks/perl-PBUAXXK6.js"),proto:()=>import("./chunks/proto-AYCDOTJO.js"),docker:()=>import("./chunks/docker-N33HOW54.js"),mdx:()=>import("./chunks/mdx-DGLHDAO7.js"),vue:()=>import("./chunks/vue-JOW62MHD.js"),svelte:()=>import("./chunks/svelte-GT3D4C44.js"),astro:()=>import("./chunks/astro-LRAFGXNX.js"),diff:()=>import("./chunks/diff-TR2NPA64.js"),make:()=>import("./chunks/make-X7RXMVW7.js"),nginx:()=>import("./chunks/nginx-2L6VRV3A.js"),prisma:()=>import("./chunks/prisma-IKS4LVH2.js")},OR=["typescript","tsx","javascript","jsx","json","markdown","python","bash","yaml","html","css","go","rust","sql","toml"];function vi(n){if(!n)return;let e=n.toLowerCase(),r={js:"javascript",ts:"typescript","c++":"cpp","c#":"csharp",cs:"csharp",shell:"bash",sh:"bash",zsh:"bash",yml:"yaml",protobuf:"proto",dockerfile:"docker",md:"markdown",htm:"html",py:"python",rs:"rust",kt:"kotlin",rb:"ruby"}[e]??e;return r in ap?r:void 0}var Kc=null,yo=null,e1=new Map;function eu(){return Kc||(Kc=Promise.all([import("./chunks/core-KGE7TQJ3.js"),import("./chunks/dist-T32U2VVR.js"),import("./chunks/dark-plus-BOSCZXE4.js"),import("./chunks/light-plus-HGGBC43G.js"),Promise.all(OR.map(n=>ap[n]()))]).then(([n,e,t,r,a])=>n.createHighlighterCore({themes:[t.default,r.default],langs:a.map(s=>s.default),engine:e.createJavaScriptRegexEngine()})).then(n=>(yo=n,n),n=>{throw Kc=null,n})),Kc}function Xc(n,e){return n.getLoadedLanguages().includes(e)}function Yc(n){return!!yo&&Xc(yo,n)}function t1(n){return yo&&Xc(yo,n)?yo:null}async function Jc(n){let e=await eu();if(Xc(e,n))return!0;let t=ap[n];if(!t)return!1;let r=e1.get(n);return r||(r=t().then(a=>e.loadLanguage(a.default)).then(()=>!0).catch(()=>!1),e1.set(n,r)),r}var wi=null;function n1(n,e,t){let r=yo;if(!r||!Xc(r,e))return null;if(wi&&wi.text===n&&wi.lang===e&&wi.theme===t)return wi.lines;try{let a=r.codeToTokensBase(n,{lang:e,theme:t,includeExplanation:!1});return wi={text:n,lang:e,theme:t,lines:a},a}catch{return null}}function _R(n){return{highlight(e,t){let r=n1(e,t,n);if(!r)return[{type:"text",value:e}];let a=[];return r.forEach((s,o)=>{for(let i of s){if(!i.content)continue;let l={type:"element",tagName:"span",properties:{},color:i.color,children:[{type:"text",value:i.content}]};a.push(l)}o<r.length-1&&a.push({type:"text",value:`
31
- `})}),a}}}function a1(n,e,t="dark-plus"){let r=vi(e);if(r&&Yc(r))try{return Uv(n,{highlight:!0,refractor:_R(t),language:r})}catch{return}}var s1=(n,e,t)=>{let r=n.color;return n.type==="element"&&typeof r=="string"?(0,r1.createElement)("span",{key:t,style:{color:r}},n.children?.map((a,s)=>e(a,s))):e(n,t)};function Zc(n){let e=yt(String(n||"")).toLowerCase().trim();if(!e)return;let t=e;if(t==="dockerfile")return"docker";let r=t.includes(".")?t.split(".").pop():"";if(!r)return;let a={js:"javascript",jsx:"jsx",ts:"typescript",tsx:"tsx",json:"json",jsonl:"json",py:"python",rb:"ruby",php:"php",java:"java",kt:"kotlin",go:"go",rs:"rust",c:"c",h:"c",cpp:"cpp",cc:"cpp",cxx:"cpp",hpp:"cpp",cs:"csharp",swift:"swift",scala:"scala",r:"r",sql:"sql",sh:"bash",bash:"bash",zsh:"bash",fish:"bash",ps1:"powershell",yaml:"yaml",yml:"yaml",toml:"toml",ini:"ini",xml:"xml",html:"html",css:"css",scss:"scss",less:"less",graphql:"graphql",gql:"graphql",lua:"lua",dart:"dart",elm:"elm",tex:"latex",clj:"clojure",ex:"elixir",exs:"elixir",hs:"haskell",nim:"nim",pl:"perl",proto:"protobuf",md:"markdown",mdx:"mdx"};return r==="env"?"bash":a[r]??r}var Qc=W($e(),1);function ed(n,e){let t=e?.wideThresholdPx??900,r=e?.hysteresisPx??60,[a,s]=(0,Qc.useState)(!1);return(0,Qc.useEffect)(()=>{let o=n.current;if(!o){s(!1);return}let i=()=>{let u=o.clientWidth;s(c=>c?u>=t-r:u>=t)};if(i(),typeof ResizeObserver>"u")return;let l=new ResizeObserver(()=>i());return l.observe(o),()=>l.disconnect()},[n,t,r]),a}var td=W(le(),1),HR=[{key:"auto",label:"Auto",Icon:Ps},{key:"unified",label:"Unified",Icon:As},{key:"split",label:"Split",Icon:gs}];function nd({className:n}){let e=B(r=>r.diffViewMode),t=B(r=>r.setDiffViewMode);return(0,td.jsx)("div",{className:q("inline-flex items-center gap-0.5 rounded-md bg-white/5 p-0.5",n),children:HR.map(({key:r,label:a,Icon:s})=>(0,td.jsx)("button",{type:"button",onClick:()=>t(r),className:q("inline-flex items-center justify-center rounded p-1 transition",e===r?"bg-white/12 text-white/90":"text-white/40 hover:text-white/70 hover:bg-white/[0.06]"),title:`Diff layout: ${a}${r==="auto"?" (by width)":""}`,"aria-label":`Diff layout ${a}`,"aria-pressed":e===r,children:(0,td.jsx)(s,{className:"w-3 h-3"})},r))})}var Qe=W(le(),1),UR={"--diff-background-color":"transparent","--diff-text-color":"rgba(255,255,255,0.82)","--diff-font-family":"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace","--diff-selection-background-color":"rgba(139,92,246,0.35)","--diff-gutter-insert-background-color":"rgba(16,185,129,0.16)","--diff-gutter-delete-background-color":"rgba(244,63,94,0.16)","--diff-gutter-selected-background-color":"rgba(139,92,246,0.22)","--diff-code-insert-background-color":"rgba(16,185,129,0.10)","--diff-code-delete-background-color":"rgba(244,63,94,0.10)","--diff-code-insert-edit-background-color":"rgba(16,185,129,0.30)","--diff-code-delete-edit-background-color":"rgba(244,63,94,0.32)","--diff-code-selected-background-color":"rgba(139,92,246,0.16)","--diff-omit-gutter-line-color":"transparent"};function sp(n,e,t,r){let a=r.kind==="working"?{kind:r.kind,staged:r.staged}:r.kind==="commit"?{kind:r.kind,sha:r.sha}:{kind:r.kind,base:r.base,head:r.head};return`diff\0${n}\0${e}\0${t}\0${JSON.stringify(a)}`}function bo({source:n,repo:e="",path:t,mode:r,agentId:a,projectId:s,variant:o="tab",revision:i=0,canWrite:l=!1,runContent:u,peekContent:c}){let[d]=(0,gt.useState)(()=>c?.(`${sp(n,e,t,r)}\0${i}`,sp(n,e,t,r))),[f,h]=(0,gt.useState)(()=>d===void 0?null:d&&d.ok!==!1?d.diff:""),[p,m]=(0,gt.useState)(!1),[g,x]=(0,gt.useState)(null),[w,y]=(0,gt.useState)(()=>d!==void 0&&d.ok!==!1&&d.truncated===!0),[C,k]=(0,gt.useState)(()=>d!==void 0&&d.ok===!1),[v,b]=(0,gt.useState)(0),[P,N]=(0,gt.useState)(null),[M,U]=(0,gt.useState)(null),[I,A]=(0,gt.useState)([]),[G,V]=(0,gt.useState)(null),[K,L]=(0,gt.useState)(!1),R=(0,gt.useRef)(new Map),z=(0,gt.useRef)(0),J=B(te=>te.loadGitStatus),Q=r.kind,re=r.kind==="working"?r.staged:!1,pe=r.kind==="commit"?r.sha:null,ee=r.kind==="range"?r.base:null,ce=r.kind==="range"?r.head:null,ue=(0,gt.useMemo)(()=>Q==="working"?{kind:Q,staged:re}:Q==="commit"?{kind:Q,sha:pe??""}:{kind:Q,base:ee??"",head:ce??""},[Q,re,pe,ee,ce]),He=(0,gt.useMemo)(()=>Xv(ue),[ue]),De=B(te=>te.diffViewMode),je=(0,gt.useRef)(null),et=ed(je),Dt=De==="auto"?et?"split":"unified":De,at=(0,gt.useMemo)(()=>Zc(t),[t]),[vt,Pt]=(0,gt.useState)(!1);(0,gt.useEffect)(()=>{let te=vi(at);if(!te){Pt(!1);return}if(Yc(te)){Pt(!0);return}let Ce=!1;return Pt(!1),eu().then(()=>Jc(te)).then(Ge=>{Ce||Pt(Ge)}),()=>{Ce=!0}},[at]),(0,gt.useEffect)(()=>{if(R.current.clear(),A([]),V(null),L(!1),!a||!n||!t){y(!1),k(!1),h(null),x(null),m(!1);return}let te=++z.current;return m(!0),x(null),(async()=>{try{let Ce=()=>ec({agentId:a,...s?{projectId:s}:{},source:n,...e?{repo:e}:{},path:t,...Kv(ue)}),Ge=sp(n,e,t,ue),Ke={key:`${Ge}\0${i}`,family:Ge,bytes:he=>he&&he.ok!==!1?he.diff.length*2:64,fresh:v>0},Ae=u?await u(Ce,()=>te===z.current,Ke):await Ce();if(!Ae||te!==z.current)return;Ae&&Ae.ok===!1?(h(""),k(!0),y(!1)):(h(typeof Ae?.diff=="string"?Ae.diff:""),k(!1),y(Ae?.truncated===!0)),m(!1)}catch(Ce){if(te!==z.current)return;x(Ce instanceof Error?Ce.message:"Diff failed"),h(null),k(!1),y(!1),m(!1)}})(),()=>{z.current++}},[a,s,n,e,t,ue,v,i,u]);let{files:Ye,truncated:Ne,hunkPatches:tt}=(0,gt.useMemo)(()=>Wv(f,w),[f,w]),Je=Ye.some(te=>te.hunks.length>0),Ft=yt(t)||t,Mt=Qv(g),Te=Ye.length===1?Ye[0]:null,oe=l&&Q==="working"&&!!a&&!!Te&&Te.type==="modify"&&!Ne&&!!tt&&tt.hunks.length===Te.hunks.length,jt=!!a&&!!Te&&!Ne&&Te.hunks.length>0,Kt=(0,gt.useCallback)(async()=>{if(!a)return null;let te=z.current,Ce=He.type==="worktree"?"wt":He.rev,Ge=`${n}\0${e}\0${t}\0${Ce}`,Ke=R.current.get(Ge),Ae=he=>(R.current.set(Ge,he),te===z.current&&(he.ok?V(he.content):L(!0)),he.ok?he.content:null);if(Ke)return Ae(Ke);try{if(He.type==="show"){let xn=()=>U0({agentId:a,...s?{projectId:s}:{},source:n,...e?{repo:e}:{},path:t,rev:He.rev}),yn=u?await u(xn,()=>te===z.current):await xn();return!yn||te!==z.current?null:Ae(yn.ok?{ok:!0,content:yn.content}:{ok:!1})}let he=()=>Ko({agentId:a,...s?{projectId:s}:{},files:[`${n}://${e?`${e}/`:""}${t}`]}),ut=u?await u(he,()=>te===z.current):await he();if(!ut||te!==z.current)return null;let Qt=Yo(ut)[0];return!Qt||typeof Qt.error=="string"?Ae({ok:!1}):Ae({ok:!0,content:Jo(Qt)})}catch{return Ae({ok:!1})}},[a,s,n,e,t,He,u]),de=(0,gt.useMemo)(()=>Te&&G!==null?$c(Te.hunks,G):null,[Te,G]),fe=(0,gt.useMemo)(()=>Ye.map(te=>te!==Te||!de||I.length===0?te.hunks:qv(te.hunks,de,I)),[Ye,Te,de,I]),qe=de?de.length:null,Re=(0,gt.useMemo)(()=>vt?Ye.map((te,Ce)=>a1(fe[Ce]??te.hunks,at)):Ye.map(()=>{}),[Ye,fe,at,vt]),Fe=(0,gt.useCallback)(async te=>{if(!jt)return;let Ce=z.current,Ge=G??await Kt();if(Ge===null||Ce!==z.current||!Te)return;let Ke;if(te.lines===null){let Ae=Ql(Te.hunks[Te.hunks.length-1]??null,$c(Te.hunks,Ge).length);if(!Ae||Ae.lines===null)return;Ke={start:Ae.start,end:Ae.end}}else Ke={start:te.start,end:te.end};A(Ae=>[...Ae,Ke])},[jt,G,Kt,Te]),Lt=(0,gt.useCallback)(async()=>{if(!jt||!Te)return;let te=z.current,Ce=G??await Kt();if(Ce===null||te!==z.current)return;let Ge=jv(Te.hunks,$c(Te.hunks,Ce).length);Ge.length>0&&A(Ke=>[...Ke,...Ge])},[jt,Te,G,Kt]),st=(0,gt.useMemo)(()=>{if(!jt||!Te)return!1;let te=Ye.indexOf(Te),Ce=fe[te]??Te.hunks;for(let Ge=0;Ge<Ce.length;Ge++)if(Vc(Ge===0?null:Ce[Ge-1],Ce[Ge]))return!0;return Ql(Ce[Ce.length-1]??null,qe)!==null},[jt,Te,Ye,fe,qe]),Le=(0,gt.useCallback)(async te=>{if(p||!oe||!tt||!a)return;let Ce=zv(tt.header,tt.hunks[te]);if(!Ce){U("Could not build a hunk patch for this change.");return}N(te),U(null);try{re?await j0({agentId:a,...s?{projectId:s}:{},source:n,...e?{repo:e}:{},hunk:Ce}):await W0({agentId:a,...s?{projectId:s}:{},source:n,...e?{repo:e}:{},hunk:Ce}),R.current.clear(),J({agentId:a,projectId:s}),b(Ge=>Ge+1)}catch(Ge){U(Ge instanceof Error?Ge.message:"Hunk apply failed")}finally{N(null)}},[p,oe,tt,a,s,n,e,re,J]),Ee=te=>{let Ce=te.lines===null?"Expand to end of file":`${te.lines} hidden ${te.lines===1?"line":"lines"}`;return K?te.lines===null?null:(0,Qe.jsx)(qc,{children:(0,Qe.jsxs)("div",{className:"px-3 py-0.5 font-mono text-[10px] text-white/30",children:["\u22EF ",Ce]})},`gap-${te.start}`):(0,Qe.jsx)(qc,{children:(0,Qe.jsxs)("button",{type:"button",onClick:()=>{Fe(te)},className:"block w-full px-3 py-0.5 text-left font-mono text-[10px] text-violet-300/70 transition-colors hover:bg-violet-500/10 hover:text-violet-200/90",title:"Expand this hidden region",children:["\u22EF ",Ce]})},`gap-${te.start}`)},Et=(te,Ce)=>Ce.length===0?null:(0,Qe.jsx)(qc,{children:(0,Qe.jsx)("div",{className:"flex items-center justify-end gap-2 px-2 py-1",children:Ce.map(Ge=>(0,Qe.jsxs)("button",{type:"button",onClick:()=>{Le(Ge)},disabled:P!==null||p,className:q("inline-flex items-center gap-1 rounded-md border px-2 py-0.5 text-[10px] transition-colors disabled:opacity-40",re?"border-white/12 bg-white/[0.04] text-white/70 hover:bg-white/[0.09]":"border-emerald-500/25 bg-emerald-500/12 text-emerald-100/90 hover:bg-emerald-500/18"),title:re?"Unstage this hunk":"Stage this hunk",children:[P===Ge?(0,Qe.jsx)(op.LiveSpinner,{className:"h-3 w-3"}):re?(0,Qe.jsx)(ro,{className:"h-3 w-3"}):(0,Qe.jsx)(Fn,{className:"h-3 w-3"}),re?"Unstage hunk":"Stage hunk",Ce.length>1?(0,Qe.jsxs)("span",{className:"font-mono text-white/45",children:["@",Te?.hunks[Ge]?.oldStart]}):null]},Ge))})},`stage-${te.oldStart}`),qt=(0,Qe.jsxs)("button",{type:"button",onClick:()=>{Lt()},className:"inline-flex shrink-0 items-center gap-1 rounded-md border border-white/10 px-1.5 py-0.5 text-[10px] text-white/55 transition-colors hover:bg-white/[0.06] hover:text-white/80",title:"Expand all hidden regions",children:[(0,Qe.jsx)(Hl,{className:"h-3 w-3"}),"Expand all"]}),Tn=g?Mt?(0,Qe.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-[11px] text-white/40",children:[(0,Qe.jsx)(no,{className:"h-3.5 w-3.5 shrink-0 text-white/35"}),(0,Qe.jsx)("span",{children:"You don't have permission to view this file's changes."})]}):(0,Qe.jsx)("div",{className:"px-3 py-4 text-[11px] text-rose-300/70",children:g}):p&&!f?(0,Qe.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-[11px] text-white/40",children:[(0,Qe.jsx)(op.LiveSpinner,{className:"h-3.5 w-3.5"}),"Loading diff\u2026"]}):C?(0,Qe.jsxs)("div",{className:"flex items-center justify-center gap-1.5 px-3 py-6 text-center text-[11px] text-amber-200/70",children:[(0,Qe.jsx)(dt,{className:"h-3.5 w-3.5 shrink-0"}),(0,Qe.jsx)("span",{children:"Diff too large to display \u2014 the change exceeds the server output bound."})]}):Je?(0,Qe.jsx)("div",{style:UR,className:q("nrs-git-diff px-1 py-1 text-[12px] leading-[18px]"),children:Ye.map((te,Ce)=>{let Ge=te===Te&&jt;return(0,Qe.jsx)(Ev,{viewType:Dt,diffType:te.type,hunks:fe[Ce]??te.hunks,tokens:Re[Ce],renderToken:s1,children:Ke=>{let Ae=[],he=ut=>{ut&&Ae.push(ut)};if(Ke.forEach((ut,Qt)=>{if(Ge){let xn=Vc(Qt===0?null:Ke[Qt-1],ut);xn&&he(Ee(xn))}oe&&te===Te&&he(Et(ut,Vv(ut,te.hunks))),Ae.push((0,Qe.jsx)(np,{hunk:ut},`h-${ut.oldStart}-${ut.oldLines}`))}),Ge){let ut=Ql(Ke[Ke.length-1]??null,qe);ut&&he(Ee(ut))}return Ae}},`${te.oldRevision??""}-${te.newRevision??""}-${Ce}`)})}):(0,Qe.jsx)("div",{className:"px-3 py-6 text-center text-[11px] text-white/35",children:Jv(ue)});return(0,Qe.jsxs)("div",{ref:je,className:q("flex w-full flex-col",o==="tab"&&"h-full min-h-0"),children:[o==="tab"?(0,Qe.jsxs)("div",{className:"flex shrink-0 items-center gap-2 px-3 py-1.5 text-[11px]",style:{borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[(0,Qe.jsx)(ar,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/80"}),(0,Qe.jsx)("span",{className:"shrink-0 font-medium text-white/85",children:Ft}),(0,Qe.jsx)("span",{className:"truncate font-mono text-white/40",children:t}),(0,Qe.jsx)("span",{className:"ml-auto shrink-0 rounded-full border border-white/10 px-2 py-0.5 text-[9px] uppercase tracking-wider text-white/45",children:Yv(ue)}),(0,Qe.jsx)(nd,{}),st&&!K?qt:null]}):st&&!K?(0,Qe.jsx)("div",{className:"flex shrink-0 items-center justify-end px-2 pt-1",children:qt}):null,Ne?(0,Qe.jsxs)("div",{className:"flex shrink-0 items-center gap-1.5 px-3 py-1 text-[10px] text-amber-200/70",children:[(0,Qe.jsx)(dt,{className:"h-3 w-3 shrink-0"}),(0,Qe.jsx)("span",{children:"Diff truncated by the server (2 MB cap) \u2014 showing the leading hunks; hunk staging is disabled."})]}):null,M?(0,Qe.jsxs)("div",{className:"flex shrink-0 items-center gap-1.5 px-3 py-1 text-[10px] text-rose-300/75",children:[(0,Qe.jsx)(dt,{className:"h-3 w-3 shrink-0"}),(0,Qe.jsx)("span",{className:"truncate",children:M})]}):null,o==="tab"?(0,Qe.jsx)("div",{className:"min-h-0 flex-1 overflow-auto",children:Tn}):Tn]})}var nt=W(le(),1),ip={M:"text-amber-400",A:"text-emerald-400",D:"text-rose-400",R:"text-sky-400",C:"text-sky-400",T:"text-white/60"},rd={M:"Modified",A:"Added",D:"Deleted",R:"Renamed",C:"Copied",T:"Type changed"};function GR(n){let e=new Date(n);return Number.isNaN(e.getTime())?n:e.toLocaleString()}var zR=(0,es.memo)(function({file:e,mode:t,source:r,repo:a,agentId:s,projectId:o,defaultExpanded:i,queue:l}){let[u,c]=(0,es.useState)(i),d=(e.status[0]??"M").toUpperCase(),f=e.path.includes("/")?e.path.slice(0,e.path.lastIndexOf("/")):"",h=e.path.includes("/")?e.path.slice(e.path.lastIndexOf("/")+1):e.path;return(0,nt.jsxs)("div",{ref:p=>l.register(e.path,p),className:"overflow-hidden rounded-lg border border-white/8 bg-black/20",children:[(0,nt.jsxs)("button",{type:"button",onClick:()=>c(p=>!p),className:"flex w-full items-center gap-2 px-2.5 py-1.5 text-left transition-colors hover:bg-white/[0.03]",title:e.path,"aria-expanded":u,children:[u?(0,nt.jsx)(Tt,{className:"h-3.5 w-3.5 shrink-0 text-white/40"}):(0,nt.jsx)(un,{className:"h-3.5 w-3.5 shrink-0 text-white/40"}),(0,nt.jsx)("span",{className:q("shrink-0 text-[10px] font-bold leading-none tabular-nums",ip[d]??"text-white/60"),title:rd[d]??"Changed","aria-label":`Status: ${rd[d]??"Changed"}`,children:d}),(0,nt.jsxs)("span",{className:"min-w-0 flex-1 truncate text-xs text-white/85",children:[h,f?(0,nt.jsxs)("span",{className:"ml-1.5 font-mono text-[10px] text-white/30",children:[f,"/"]}):null]}),e.renamedFrom?(0,nt.jsxs)("span",{className:"shrink-0 truncate font-mono text-[10px] text-white/35",title:`Renamed from ${e.renamedFrom}`,children:["\u2190 ",e.renamedFrom]}):null,(0,nt.jsx)(La,{added:e.added,removed:e.removed,binary:e.binary,className:"shrink-0"})]}),u&&l.visible.has(e.path)?(0,nt.jsx)("div",{className:"border-t border-white/5",children:(0,nt.jsx)("div",{className:"max-h-96 overflow-auto",style:{scrollbarGutter:"auto"},children:(0,nt.jsx)(bo,{variant:"card",canWrite:!1,runContent:l.run,source:r,repo:a,path:e.path,mode:t,agentId:s,projectId:o})})}):null]})});function lp({target:n,agentId:e,projectId:t}){let[r,a]=(0,es.useState)(null),s=Sc(r),[o,i]=(0,es.useState)({phase:"loading"}),[l,u]=(0,es.useState)(null),{source:c}=n,d=n.repo??"",f=n.kind==="commit"?`c:${d}:${n.sha}`:`o:${d}:${n.base}..${n.head}`;(0,es.useEffect)(()=>{if(i({phase:"loading"}),u(null),!e||!c)return;let g=!1;return(async()=>{try{if(n.kind==="commit"){let x=await nc({agentId:e,...t?{projectId:t}:{},source:c,...d?{repo:d}:{},sha:n.sha});if(g)return;x.ok===!1?i({phase:"unavailable"}):i({phase:"ready",files:x.files,range:null});try{let w=await tc({agentId:e,...t?{projectId:t}:{},source:c,...d?{repo:d}:{},maxCount:1,ref:n.sha}),y=Array.isArray(w?.commits)?w.commits[0]:void 0;!g&&y&&u({author:y.author,date:y.date})}catch{}}else{let x=await ol({agentId:e,...t?{projectId:t}:{},source:c,...d?{repo:d}:{}});if(g)return;!x.ok||!x.baseSha||!x.headSha?i({phase:"no-upstream"}):i({phase:"ready",files:Array.isArray(x.files)?x.files:[],range:{base:x.baseSha,head:x.headSha}})}}catch(x){if(g)return;i({phase:"error",message:x instanceof Error?x.message:"Change-set failed"})}})(),()=>{g=!0}},[e,t,c,f]);let h=n.kind==="commit"?n:null,p=h!==null,m=o.phase==="ready"&&o.range?`${tn(o.range.base)}..${tn(o.range.head)}`:n.kind==="outgoing"?`${tn(n.base)}..${tn(n.head)}`:"";return(0,nt.jsxs)("div",{className:"flex h-full w-full min-h-0 flex-col",children:[(0,nt.jsx)("div",{className:"flex shrink-0 items-center gap-2 px-3 py-1.5 text-[11px]",style:{borderBottom:"1px solid rgba(255,255,255,0.05)"},children:h?(0,nt.jsxs)(nt.Fragment,{children:[(0,nt.jsx)(Or,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/80"}),(0,nt.jsx)("span",{className:"shrink-0 rounded bg-white/[0.06] px-1.5 py-0.5 font-mono text-[10px] text-violet-200/90",children:tn(h.sha)}),(0,nt.jsx)("span",{className:"min-w-0 truncate font-medium text-white/85",children:h.subject}),l?(0,nt.jsxs)("span",{className:"ml-auto shrink-0 text-[10px] text-white/40",children:[l.author," \xB7 ",GR(l.date)]}):null]}):(0,nt.jsxs)(nt.Fragment,{children:[(0,nt.jsx)(Er,{className:"h-3.5 w-3.5 shrink-0 text-blue-300/80"}),(0,nt.jsx)("span",{className:"shrink-0 font-medium text-white/85",children:"Outgoing changes"}),(0,nt.jsx)("span",{className:"truncate font-mono text-[10px] text-white/40",children:m}),(0,nt.jsx)("span",{className:"ml-auto shrink-0 text-[10px] text-white/35",title:"Computed from local refs (last fetch) \u2014 fetching/pulling remotes lands in a later increment.",children:"Local refs only \u2014 fetch lands later"})]})}),(0,nt.jsx)("div",{ref:a,className:"min-h-0 flex-1 overflow-auto px-2 py-2",children:o.phase==="loading"?(0,nt.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-[11px] text-white/40",children:[(0,nt.jsx)(ze,{className:"h-3.5 w-3.5 animate-spin"}),"Loading changes\u2026"]}):o.phase==="error"?(0,nt.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-4 text-[11px] text-rose-300/70",children:[(0,nt.jsx)(dt,{className:"h-3.5 w-3.5 shrink-0"}),(0,nt.jsx)("span",{className:"truncate",children:o.message})]}):o.phase==="unavailable"?(0,nt.jsx)("div",{className:"px-3 py-6 text-center text-[11px] text-white/35",children:"Commit details unavailable \u2014 the commit may no longer exist in this repository."}):o.phase==="no-upstream"?(0,nt.jsx)("div",{className:"px-3 py-6 text-center text-[11px] text-white/35",children:"No upstream to compare against \u2014 everything here is local."}):o.files.length===0?(0,nt.jsx)("div",{className:"px-3 py-6 text-center text-[11px] text-white/35",children:p?"This commit changed no files.":"Nothing outgoing \u2014 the upstream is up to date."}):(0,nt.jsx)("div",{className:"flex flex-col gap-1.5",children:o.files.map(g=>(0,nt.jsx)(zR,{file:g,mode:h?{kind:"commit",sha:h.sha}:{kind:"range",base:o.range?.base??"",head:o.range?.head??""},source:c,repo:d,agentId:e,projectId:t,defaultExpanded:!0,queue:s},g.path))})})]})}var ae=W(le(),1),Hr=30,d1=16,fp=14,o1=4.5,ad=["#cba6f7","#a6e3a1","#f9e2af","#f38ba8","#94e2d5","#fab387","#b4befe","#89b4fa"];function cp(n){return ad[(n%ad.length+ad.length)%ad.length]}var dp=n=>fp+n*d1;function WR(){let n=null,e=new Set;return{get:()=>n,set:t=>{let r=typeof t=="function"?t(n):t;if(r!==n){n=r;for(let a of e)a()}},subscribe:t=>(e.add(t),()=>{e.delete(t)})}}var jR=null,qR=()=>jR;function VR({store:n,commits:e,expandedShas:t}){let r=it.default.useSyncExternalStore(n.subscribe,n.get,qR);if(!r||t.has(r.sha))return null;let a=e.find(s=>s.sha===r.sha);return a?(0,ae.jsxs)("div",{className:"pointer-events-none absolute z-30 overflow-hidden rounded-md border border-white/10 bg-[#1b1b26] px-2.5 py-2 shadow-lg shadow-black/50",style:{left:fp,right:8,maxHeight:"55%",...r.flip?{bottom:r.above}:{top:r.below}},children:[(0,ae.jsx)("div",{className:"whitespace-pre-wrap break-words text-[11px] font-medium leading-snug text-white/90",children:a.subject||"(no message)"}),a.body?(0,ae.jsx)("div",{className:"mt-1 whitespace-pre-wrap break-words text-[10px] leading-snug text-white/55",children:a.body}):null,(0,ae.jsxs)("div",{className:"mt-1.5 flex items-center gap-2 text-[10px] text-white/40",children:[(0,ae.jsx)("span",{className:"font-mono",children:tn(a.sha)}),(0,ae.jsx)("span",{className:"min-w-0 truncate",children:a.author}),(0,ae.jsx)("span",{children:Rh(a.date)})]})]}):null}function i1(n){let e=dp(n.fromLane),t=dp(n.toLane),r=n.fromY==="edge"?0:Hr/2,a=n.toY==="edge"?Hr:Hr/2;if(e===t)return`M${e} ${r} L${t} ${a}`;if(n.toY==="edge"){let o=2*t-e;return`M${e} ${r} C ${e} ${(r+a)/2} ${(3*e+o)/4} ${(r+3*a)/4} ${t} ${a}`}let s=2*e-t;return`M${e} ${r} C ${(s+3*t)/4} ${(3*r+a)/4} ${t} ${(r+a)/2} ${t} ${a}`}function $R(n){return(n.split("->").pop()??n).replace(/^tag:\s*/,"").trim()}function l1(n,e){(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),e())}function KR({file:n,onClick:e,showCounts:t}){let r=n.path.lastIndexOf("/"),a=r<0?n.path:n.path.slice(r+1),s=r<0?"":n.path.slice(0,r),o=(n.status[0]??"M").toUpperCase(),i=ci(n.path);return(0,ae.jsxs)("button",{type:"button",onClick:()=>e(n),className:"flex w-full min-w-0 items-center gap-1.5 overflow-hidden rounded-md py-1 pl-2 pr-1.5 text-left transition-colors hover:bg-white/[0.05]",title:n.renamedFrom?`${n.renamedFrom} \u2192 ${n.path}`:n.path,children:[(0,ae.jsx)(i,{className:"h-4 w-4 shrink-0 text-white/55"}),(0,ae.jsx)("span",{className:"shrink-0 truncate text-xs text-white/85",children:a}),s?(0,ae.jsx)("span",{className:"min-w-0 flex-1 truncate text-[10px] text-white/35",children:s}):(0,ae.jsx)("span",{className:"flex-1"}),t?(0,ae.jsx)(La,{added:n.added,removed:n.removed,binary:n.binary,className:"mr-1"}):null,(0,ae.jsx)("span",{className:q("shrink-0 text-[10px] font-bold leading-none tabular-nums",ip[o]??"text-white/60"),"aria-label":`Status: ${rd[o]??"Changed"}`,children:o})]})}function u1({entry:n,emptyText:e,unavailableText:t,onFileClick:r,showCounts:a}){return n.status==="loading"?(0,ae.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 text-[10px] text-white/40",children:[(0,ae.jsx)(c1.LiveSpinner,{className:"h-3 w-3"}),"Loading files\u2026"]}):n.status==="error"?(0,ae.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 text-[10px] text-rose-300/70",children:[(0,ae.jsx)(dt,{className:"h-3 w-3 shrink-0"}),(0,ae.jsx)("span",{className:"truncate",children:n.message})]}):n.status==="unavailable"?(0,ae.jsx)("div",{className:"px-2 py-1 text-[10px] text-white/35",children:t}):n.files.length===0?(0,ae.jsx)("div",{className:"px-2 py-1 text-[10px] text-white/35",children:e}):(0,ae.jsx)("div",{className:"space-y-px",children:n.files.map(s=>(0,ae.jsx)(KR,{file:s,onClick:r,showCounts:a},s.path))})}function f1({source:n,repo:e="",agentId:t,projectId:r,repoName:a,showCounts:s=!0,onOutgoingStat:o}){let[i,l]=(0,it.useState)(Ph),[u,c]=(0,it.useState)(!1),[d,f]=(0,it.useState)(null),h=(0,it.useRef)(0),p=(0,it.useRef)(!1),m=(0,it.useRef)(!1),g=(0,it.useRef)(i);g.current=i;let[x,w]=(0,it.useState)(()=>new Set),[y,C]=(0,it.useState)(!1),[k,v]=(0,it.useState)(()=>new Map),[b,P]=(0,it.useState)({status:"idle"}),N=(0,it.useRef)(null),M=(0,it.useRef)(null);M.current===null&&(M.current=WR());let U=M.current,I=(0,it.useRef)(0),A=(0,it.useRef)(0),G=B(de=>de.gitLogNonce),V=B(de=>de.setGitDiffTarget),K=B(de=>de.setGitCommitTarget),L=B(de=>de.setActiveWorkspaceTab),[R,z]=(0,it.useState)(null),[J,Q]=(0,it.useState)(null),[re,pe]=(0,it.useState)({}),ee=(0,it.useRef)(s);ee.current=s;let ce=(0,it.useRef)(o);ce.current=o;let ue=(0,it.useCallback)(async(de,fe,qe)=>{if(!t||!n)return;let Re=++h.current;p.current=!0,c(!0),f(null);try{let Fe=await tc({agentId:t,...r?{projectId:r}:{},source:n,...e?{repo:e}:{},maxCount:fe,skip:de});if(Re!==h.current)return;let Lt={commits:Array.isArray(Fe?.commits)?Fe.commits:[],hasMore:Fe?.hasMore===!0,outgoing:Array.isArray(Fe?.outgoing)?Fe.outgoing:void 0};l(st=>qe==="append"?yw(st,Lt):bw(Lt)),ee.current&&H0({agentId:t,...r?{projectId:r}:{},source:n,...e?{repo:e}:{},maxCount:fe,skip:de}).then(st=>{Re===h.current&&(pe(Le=>qe==="append"?{...Le,...st.stats}:{...st.stats}),qe==="replace"&&ce.current?.(st.outgoingStat??null))}).catch(()=>{}),qe==="replace"&&(A.current++,P(st=>st.status==="idle"?st:{status:"idle"})),c(!1)}catch(Fe){if(Re!==h.current)return;f(Fe instanceof Error?Fe.message:"Git log failed"),c(!1)}finally{Re===h.current&&(p.current=!1)}},[t,r,n,e]);(0,it.useEffect)(()=>{if(h.current++,p.current=!1,I.current++,A.current++,l(Ph),f(null),w(new Set),C(!1),v(new Map),P({status:"idle"}),!t||!n){c(!1);return}ue(0,200,"replace")},[t,r,n,ue]);let He=(0,it.useRef)(G);(0,it.useEffect)(()=>{G!==He.current&&(He.current=G,!(!t||!n)&&ue(0,Nh(g.current.commits.length),"replace"))},[G,t,n,ue]),(0,it.useEffect)(()=>{if(!R||!J||(m.current=!1,typeof IntersectionObserver>"u"))return;let de=new IntersectionObserver(fe=>{for(let Re of fe)m.current=Re.isIntersecting;if(!m.current)return;let qe=g.current;!qe.hasMore||p.current||ue(qe.nextSkip,200,"append")},{root:R,rootMargin:"120px"});return de.observe(J),()=>de.disconnect()},[R,J,ue]),(0,it.useEffect)(()=>{u||d!==null||!m.current||p.current||i.hasMore&&ue(i.nextSkip,200,"append")},[i,u,d,ue]);let De=(0,it.useCallback)(async de=>{if(!t||!n)return;let fe=I.current;v(qe=>new Map(qe).set(de,{status:"loading"}));try{let qe=await nc({agentId:t,...r?{projectId:r}:{},source:n,...e?{repo:e}:{},sha:de});if(fe!==I.current)return;v(Re=>new Map(Re).set(de,qe.ok===!1?{status:"unavailable"}:{status:"ready",files:Array.isArray(qe.files)?qe.files:[]}))}catch(qe){if(fe!==I.current)return;v(Re=>new Map(Re).set(de,{status:"error",message:qe instanceof Error?qe.message:"Commit files failed"}))}},[t,r,n,e]),je=i.commits,et=Ts(n,a),Dt=(0,it.useMemo)(()=>mw(je),[je]),at=Math.max(40,fp+Dt.laneCount*d1+8),vt=(0,it.useMemo)(()=>ww(je,i.outgoing),[je,i.outgoing]),Pt=(0,it.useMemo)(()=>new Set(i.outgoing??[]),[i.outgoing]),Ye=(0,it.useMemo)(()=>vt.some(de=>de.kind==="outgoing-divider"),[vt]);(0,it.useEffect)(()=>{if(!y||b.status!=="idle"||!Ye||!t||!n)return;let de=++A.current;P({status:"loading"}),(async()=>{try{let fe=await ol({agentId:t,...r?{projectId:r}:{},source:n,...e?{repo:e}:{}});if(de!==A.current)return;!fe.ok||!fe.baseSha||!fe.headSha?P({status:"no-upstream"}):P({status:"ready",base:fe.baseSha,head:fe.headSha,files:Array.isArray(fe.files)?fe.files:[]})}catch(fe){if(de!==A.current)return;P({status:"error",message:fe instanceof Error?fe.message:"Outgoing changes failed"})}})()},[y,b.status,Ye,t,r,n,e]);let Ne=ii({count:vt.length,getScrollElement:()=>R,estimateSize:()=>Hr,overscan:12,getItemKey:de=>vw(vt[de],je)}),tt=()=>{!t||!n||ue(0,Nh(g.current.commits.length),"replace")},Je=(de,fe)=>{if(x.has(de)){Ne.resizeItem(fe,Hr),w(Re=>{let Fe=new Set(Re);return Fe.delete(de),Fe});return}w(Re=>new Set(Re).add(de));let qe=k.get(de);(!qe||qe.status==="error")&&De(de)},Ft=de=>{let fe=!y;fe||Ne.resizeItem(de,Hr),fe&&b.status==="error"&&P({status:"idle"}),C(fe)},Mt=e?{repo:e}:{},Te=(de,fe)=>{n&&(V({source:n,...Mt,path:fe.path,commit:de}),L("git-diff"))},oe=de=>{n&&(K({source:n,...Mt,kind:"commit",sha:de.sha,subject:de.subject}),L("git-commit"))},jt=de=>{!n||b.status!=="ready"||(V({source:n,...Mt,path:de.path,base:b.base,head:b.head}),L("git-diff"))},Kt=()=>{if(!n||!t)return;if(b.status==="ready"){K({source:n,...Mt,kind:"outgoing",base:b.base,head:b.head}),L("git-commit");return}let de=++A.current;P({status:"loading"}),(async()=>{try{let fe=await ol({agentId:t,...r?{projectId:r}:{},source:n,...e?{repo:e}:{}});if(de!==A.current)return;if(!fe.ok||!fe.baseSha||!fe.headSha){P({status:"no-upstream"});return}P({status:"ready",base:fe.baseSha,head:fe.headSha,files:Array.isArray(fe.files)?fe.files:[]}),K({source:n,...Mt,kind:"outgoing",base:fe.baseSha,head:fe.headSha}),L("git-commit")}catch(fe){if(de!==A.current)return;P({status:"error",message:fe instanceof Error?fe.message:"Outgoing changes failed"})}})()};return(0,ae.jsxs)("div",{ref:N,className:"relative flex h-full w-full min-h-0 flex-col",children:[(0,ae.jsxs)("div",{className:"flex shrink-0 items-center gap-2 px-3 py-1.5 text-[11px]",style:{borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[(0,ae.jsx)(Or,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/80"}),(0,ae.jsx)("span",{className:"shrink-0 font-medium text-white/85",children:"Commit graph"}),et.prefix?(0,ae.jsxs)(ae.Fragment,{children:[(0,ae.jsx)("span",{className:"shrink-0 font-mono text-white/40",children:et.prefix}),(0,ae.jsx)("span",{className:"truncate font-medium text-white/85",children:et.name})]}):(0,ae.jsx)("span",{className:"truncate font-mono text-white/40",children:et.name}),(0,ae.jsxs)("span",{className:"ml-auto shrink-0 tabular-nums text-white/40",children:[je.length,i.hasMore?"+":""," commit",je.length===1?"":"s"]}),(0,ae.jsx)("button",{type:"button",onClick:tt,className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded text-white/40 transition-colors hover:bg-white/[0.06] hover:text-white/70",title:"Refresh commit graph","aria-label":"Refresh commit graph",children:(0,ae.jsx)(Ht,{className:q("h-3 w-3",u&&"animate-spin")})})]}),d&&je.length>0?(0,ae.jsxs)("div",{className:"flex shrink-0 items-center gap-1.5 border-b border-white/[0.05] px-3 py-1 text-[10px] text-rose-300/70",children:[(0,ae.jsx)(dt,{className:"h-3 w-3 shrink-0"}),(0,ae.jsx)("span",{className:"truncate",children:d})]}):null,(0,ae.jsx)("div",{ref:z,className:"min-h-0 flex-1 overflow-auto",children:d&&je.length===0?(0,ae.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-4 text-[11px] text-rose-300/70",children:[(0,ae.jsx)(dt,{className:"h-3 w-3 shrink-0"}),d]}):u&&je.length===0?(0,ae.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-[11px] text-white/40",children:[(0,ae.jsx)(ze,{className:"h-3.5 w-3.5 animate-spin"}),"Loading commit graph\u2026"]}):je.length===0?(0,ae.jsx)("div",{className:"px-3 py-6 text-center text-[11px] text-white/35",children:"No commits yet."}):(0,ae.jsxs)(ae.Fragment,{children:[(0,ae.jsx)("div",{style:{height:Ne.getTotalSize(),width:"100%",position:"relative"},children:Ne.getVirtualItems().map(de=>{let fe=vt[de.index];if(!fe)return null;if(fe.kind==="outgoing-divider"){let te=b.status==="ready"?{status:"ready",files:b.files}:b.status==="error"?b:{status:"loading"},Ce=vt[de.index+1],Ge=gw(Dt.rowSegments,Ce?.kind==="commit"?Ce.row:-1);return(0,ae.jsxs)("div",{"data-index":de.index,ref:y?Ne.measureElement:void 0,className:"absolute left-0 top-0 w-full",style:{transform:`translateY(${de.start}px)`},children:[(0,ae.jsxs)("div",{role:"button",tabIndex:0,onClick:()=>Ft(de.index),onKeyDown:Ke=>l1(Ke,()=>Ft(de.index)),className:q("group flex w-full min-w-0 cursor-pointer items-center gap-1.5 text-[11px] transition-colors hover:bg-white/[0.04]",Ge.length>0?"pr-2":"px-2"),style:{height:Hr},title:"The blue hollow dots mark commits not yet pushed to origin (local refs only, from the last known upstream). On a diverged/interleaved history this divider is an approximate boundary \u2014 the dots are the source of truth.",children:[Ge.length>0?(0,ae.jsx)("svg",{"data-divider-lanes":!0,width:at,height:Hr,className:"shrink-0",style:{display:"block"},"aria-hidden":!0,children:Ge.map((Ke,Ae)=>(0,ae.jsx)("path",{d:i1(Ke),fill:"none",stroke:cp(Ke.colorLane),strokeWidth:1.5,strokeOpacity:.55,strokeLinecap:"round"},Ae))}):null,y?(0,ae.jsx)(Tt,{className:"h-3 w-3 shrink-0 text-white/40"}):(0,ae.jsx)(un,{className:"h-3 w-3 shrink-0 text-white/40"}),(0,ae.jsx)(Er,{className:"h-3 w-3 shrink-0 text-blue-300/80"}),(0,ae.jsx)("span",{className:"shrink-0 text-[9px] font-bold uppercase tracking-wider text-blue-200/85",children:"Outgoing changes"}),(0,ae.jsx)("span",{className:"shrink-0 rounded bg-blue-400/15 px-1 py-0.5 text-[9px] leading-none tabular-nums text-blue-100/80",children:i.outgoing?.length??0}),(0,ae.jsx)("span",{className:"h-px min-w-0 flex-1 bg-blue-400/20","aria-hidden":!0}),(0,ae.jsx)("button",{type:"button",onClick:Ke=>{Ke.stopPropagation(),Kt()},className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded text-white/40 opacity-0 transition group-hover:opacity-100 focus-visible:opacity-100 hover:bg-white/10 hover:text-white/75",title:"Open Changes (all outgoing files)","aria-label":"Open outgoing changes",children:(0,ae.jsx)(ni,{className:"h-3 w-3"})})]}),y?(0,ae.jsx)("div",{className:"border-t border-white/[0.05] pb-1.5 pl-1 pr-2 pt-1",children:b.status==="no-upstream"?(0,ae.jsx)("div",{className:"px-2 py-1 text-[10px] text-white/35",children:"No upstream to compare against."}):(0,ae.jsx)(u1,{entry:te,emptyText:"Nothing outgoing \u2014 the upstream is up to date.",unavailableText:"Outgoing changes unavailable.",onFileClick:jt,showCounts:s})}):null]},de.key)}let qe=Dt.nodes[fe.row];if(!qe)return null;let Re=qe.commit,Fe=Dt.rowSegments[fe.row]??[],Lt=dp(qe.lane),st=cp(qe.lane),Le=Re.refs??[],Ee=x.has(Re.sha),Et=Sw(qe.isMerge,Pt.has(Re.sha)),qt=Cw(Et,st),Tn=k.get(Re.sha);return(0,ae.jsxs)("div",{"data-index":de.index,ref:Ee?Ne.measureElement:void 0,className:"absolute left-0 top-0 w-full",style:{transform:`translateY(${de.start}px)`},children:[(0,ae.jsxs)("div",{role:"button",tabIndex:0,"data-sha":Re.sha,onClick:()=>Je(Re.sha,de.index),onKeyDown:te=>l1(te,()=>Je(Re.sha,de.index)),onMouseEnter:te=>{if(Ee)return;let Ce=N.current;if(!Ce)return;let Ge=Ce.getBoundingClientRect(),Ke=te.currentTarget.getBoundingClientRect(),Ae=Ke.bottom-Ge.top,he=Ge.bottom-Ke.top;U.set({sha:Re.sha,below:Ae,above:he,flip:Ae>Ge.height*.55})},onMouseLeave:()=>U.set(te=>te&&te.sha===Re.sha?null:te),className:"group/commit relative flex min-w-0 cursor-pointer items-center text-[11px] transition-colors hover:bg-white/[0.04]",style:{height:Hr},children:[(0,ae.jsxs)("svg",{width:at,height:Hr,className:"shrink-0",style:{display:"block"},"aria-hidden":!0,children:[Fe.map((te,Ce)=>(0,ae.jsx)("path",{d:i1(te),fill:"none",stroke:cp(te.colorLane),strokeWidth:1.5,strokeOpacity:te.kind==="stub"?.3:.55,strokeDasharray:te.kind==="stub"?"2 3":void 0,strokeLinecap:"round"},Ce)),qe.isHead?(0,ae.jsx)("circle",{cx:Lt,cy:Hr/2,r:o1+2.5,fill:"none",stroke:qt,strokeWidth:1.5,strokeOpacity:.7}):null,(0,ae.jsx)("circle",{cx:Lt,cy:Hr/2,r:o1,fill:Et==="outgoing"?"transparent":Et==="merge"?"rgba(0,0,0,0.35)":st,stroke:qt,strokeWidth:Et==="filled"?1:1.5,fillOpacity:Et==="filled"?.9:1})]}),(0,ae.jsxs)("div",{className:"flex min-w-0 flex-1 items-center gap-2 pr-1",children:[Ee?(0,ae.jsx)(Tt,{className:"h-3 w-3 shrink-0 text-white/35"}):(0,ae.jsx)(un,{className:"h-3 w-3 shrink-0 text-white/25"}),Le.length?(0,ae.jsx)("span",{className:"flex shrink-0 items-center gap-1",children:Le.slice(0,3).map(te=>{let Ce=kw(te);return(0,ae.jsxs)("span",{className:q("flex max-w-[120px] items-center gap-0.5 rounded px-1 py-0.5 text-[9px] font-medium leading-none",Ce==="tag"?"bg-amber-400/15 text-amber-100/80":Ce==="remote"?"border border-white/20 bg-transparent text-white/55":"bg-violet-400/20 text-violet-100/90"),children:[Ce==="remote"?(0,ae.jsx)(yl,{className:"h-2 w-2 shrink-0","aria-hidden":!0}):null,(0,ae.jsx)("span",{className:"truncate",children:$R(te)})]},te)})}):null,(0,ae.jsx)("span",{className:"min-w-0 flex-1 truncate text-white/82",children:Re.subject||"(no message)"}),(0,ae.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/35 transition-opacity group-hover/commit:opacity-0",children:tn(Re.sha)}),(0,ae.jsx)("span",{className:"hidden shrink-0 max-w-[120px] truncate text-[10px] text-white/40 transition-opacity group-hover/commit:opacity-0 sm:inline",children:Re.author}),s&&re[Re.sha]?(0,ae.jsx)(La,{...re[Re.sha],compact:!0,className:"transition-opacity group-hover/commit:opacity-0"}):null,(0,ae.jsx)("button",{type:"button",onClick:te=>{te.stopPropagation(),oe(Re)},className:"absolute right-1 top-1/2 inline-flex h-5 w-5 -translate-y-1/2 items-center justify-center rounded bg-white/10 text-white/50 opacity-0 transition group-hover/commit:opacity-100 focus-visible:opacity-100 hover:bg-white/20 hover:text-white/85",title:"Open Changes (all files in this commit)","aria-label":`Open changes of commit ${tn(Re.sha)}`,children:(0,ae.jsx)(ni,{className:"h-3 w-3"})})]})]}),Ee?(0,ae.jsxs)("div",{className:"pb-1.5 pl-1 pr-2 pt-0.5",children:[(0,ae.jsxs)("div",{className:"flex items-center gap-2 px-2 text-[10px] text-white/40",children:[(0,ae.jsx)("span",{className:"font-mono",children:tn(Re.sha)}),(0,ae.jsx)("span",{className:"min-w-0 truncate",children:Re.author}),(0,ae.jsx)("span",{title:Re.date,children:Rh(Re.date)})]}),(0,ae.jsx)("div",{className:"mt-1 border-t border-white/[0.05] pt-1",children:(0,ae.jsx)(u1,{entry:Tn??{status:"loading"},emptyText:"This commit changed no files.",unavailableText:"Commit details unavailable \u2014 the commit may no longer exist.",onFileClick:te=>Te(Re.sha,te),showCounts:s})})]}):null]},de.key)})}),i.hasMore?(0,ae.jsxs)("div",{ref:Q,className:"flex items-center justify-center gap-1.5 px-3 py-2 text-[11px] text-white/40",children:[(0,ae.jsx)(ze,{className:q("h-3 w-3",u&&"animate-spin")}),"Loading more commits\u2026"]}):null]})}),(0,ae.jsx)(VR,{store:U,commits:je,expandedShas:x})]})}var pn=W($e(),1);function tu(n){return Number.isFinite(n)?Math.min(20,Math.max(.05,n)):1}function h1(n){return n>0&&n<1?1/n:1}function p1(n){if(!n)return{};try{let e=JSON.parse(n);if(!e||typeof e!="object"||Array.isArray(e))return{};let t={};for(let[r,a]of Object.entries(e)){if(!a||typeof a!="object"||Array.isArray(a))continue;let s=a;typeof s.collapsed!="boolean"||typeof s.weight!="number"||(t[r]={collapsed:s.collapsed,weight:tu(s.weight)})}return t}catch{return{}}}function m1(n){return JSON.stringify(n)}function nu(n,e,t,r=1){return n[e]??{collapsed:t,weight:tu(r)}}function g1(n,e,t,r,a=1){let s=nu(n,e,r,a),o=!t&&s.weight<.15?tu(a):s.weight;return{...n,[e]:{collapsed:t,weight:o}}}function x1(n){let e=n.minBodyPx??72,t=n.heightAbove+n.heightBelow,r=n.weightAbove+n.weightBelow;if(!(t>0)||!(r>0)||t<e*2)return{above:n.weightAbove,below:n.weightBelow};let a=Math.min(t-e,Math.max(e,n.heightAbove+n.deltaY)),s=tu(r*(a/t)),o=tu(r-s);return{above:s,below:o}}var Ur=W(le(),1),XR=4;function YR(n){if(typeof window>"u")return{};try{return p1(window.localStorage.getItem(n))}catch{return{}}}function y1({sections:n,storageKey:e}){let[t,r]=(0,pn.useState)(()=>YR(e)),[a,s]=(0,pn.useState)(!1),o=(0,pn.useRef)(t);o.current=t;let i=(0,pn.useRef)(new Map),l=(0,pn.useRef)(null),u=(0,pn.useRef)(!1),c=(0,pn.useCallback)(b=>{if(typeof window<"u")try{window.localStorage.setItem(e,m1(b))}catch{}},[e]),d=(0,pn.useCallback)((b,P,N)=>{r(M=>{let U=nu(M,b,P,N),I=g1(M,b,!U.collapsed,P,N);return c(I),I})},[c]),f=(0,pn.useCallback)((b,P,N,M,U,I,A)=>{let G=i.current.get(P),V=i.current.get(N);I&&b.preventDefault(),l.current={aboveId:P,belowId:N,startY:b.clientY,weightAbove:M,weightBelow:U,heightAbove:G?.getBoundingClientRect().height??0,heightBelow:V?.getBoundingClientRect().height??0,engaged:I,belowCollapsed:A,expanded:!1,rebaselined:!1},u.current=!1,s(I),b.currentTarget.setPointerCapture(b.pointerId)},[]),h=(0,pn.useCallback)((b,P,N,M,U,I)=>{f(b,P,N,M,U,!0,I)},[f]),p=(0,pn.useCallback)((b,P,N,M,U,I)=>{b.button===0&&f(b,P,N,M,U,!1,I)},[f]),m=(0,pn.useCallback)(()=>{l.current&&(l.current=null,s(!1),c(o.current))},[c]);(0,pn.useEffect)(()=>{if(a)return window.addEventListener("pointerup",m),window.addEventListener("pointercancel",m),()=>{window.removeEventListener("pointerup",m),window.removeEventListener("pointercancel",m)}},[a,m]);let g=(0,pn.useCallback)(b=>{let P=l.current;if(!P)return;if((b.buttons&1)===0){m();return}let N=b.clientY-P.startY;if(!P.engaged){if(Math.abs(N)<XR)return;P.engaged=!0,u.current=!0,s(!0)}if(P.belowCollapsed&&!P.expanded){P.expanded=!0,r(I=>({...I,[P.belowId]:{collapsed:!1,weight:P.weightBelow}}));return}if(P.belowCollapsed&&!P.rebaselined){let I=i.current.get(P.belowId);if(!I)return;let A=i.current.get(P.aboveId);P.heightAbove=A?.getBoundingClientRect().height??P.heightAbove,P.heightBelow=I.getBoundingClientRect().height,P.startY=b.clientY,P.weightAbove=o.current[P.aboveId]?.weight??P.weightAbove,P.weightBelow=o.current[P.belowId]?.weight??P.weightBelow,P.rebaselined=!0;return}let{above:M,below:U}=x1({weightAbove:P.weightAbove,weightBelow:P.weightBelow,heightAbove:P.heightAbove,heightBelow:P.heightBelow,deltaY:N});r(I=>({...I,[P.aboveId]:{...I[P.aboveId]??{collapsed:!1,weight:1},weight:M},[P.belowId]:{...I[P.belowId]??{collapsed:!1,weight:1},weight:U}}))},[m]),x=(0,pn.useCallback)(b=>{b.currentTarget.hasPointerCapture(b.pointerId)&&b.currentTarget.releasePointerCapture(b.pointerId),m()},[m]),w=(0,pn.useCallback)((b,P,N,M)=>{let U=l.current?.engaged??!1,I=l.current!=null;b.currentTarget.hasPointerCapture(b.pointerId)&&b.currentTarget.releasePointerCapture(b.pointerId),m(),I&&!U&&d(P,N,M)},[m,d]),y=n.reduce((b,P)=>{let N=nu(t,P.id,P.defaultCollapsed??!1,P.defaultWeight??1);return N.collapsed?b:b+N.weight},0),C=h1(y),k=[],v=null;for(let b of n){let P=b.defaultCollapsed??!1,N=b.defaultWeight??1,M=nu(t,b.id,P,N),U=v&&!v.collapsed?v:null,I=M.collapsed?N:M.weight;U&&k.push((0,Ur.jsx)("div",{role:"separator","aria-orientation":"horizontal",onPointerDown:A=>h(A,U.id,b.id,U.weight,I,M.collapsed),onPointerMove:g,onPointerUp:x,onPointerCancel:m,onLostPointerCapture:m,className:"relative h-1.5 shrink-0 cursor-row-resize touch-none bg-white/0 transition hover:bg-white/[0.06]",children:(0,Ur.jsx)("div",{className:"absolute inset-x-6 top-1/2 h-[2px] -translate-y-1/2 rounded-full bg-white/[0.07]"})},`h:${U.id}:${b.id}`)),k.push((0,Ur.jsxs)("div",{onPointerDown:U?A=>{A.target.closest("[data-section-actions]")||p(A,U.id,b.id,U.weight,I,M.collapsed)}:void 0,onPointerMove:U?g:void 0,onPointerUp:U?A=>w(A,b.id,P,N):void 0,onPointerCancel:U?m:void 0,onLostPointerCapture:U?m:void 0,className:q("group/section flex h-7 shrink-0 items-center gap-1.5 border-t border-white/[0.04] px-1 first:border-t-0",U&&"touch-none"),children:[(0,Ur.jsxs)("button",{type:"button",onClick:A=>{U&&A.detail!==0||d(b.id,P,N)},"aria-expanded":!M.collapsed,className:"flex h-full min-w-0 flex-1 items-center gap-1 rounded px-1 text-left transition-colors hover:bg-white/[0.04]",children:[(0,Ur.jsx)(un,{className:q("h-3 w-3 shrink-0 text-white/40 transition-transform",!M.collapsed&&"rotate-90")}),(0,Ur.jsx)("span",{className:"truncate text-[10px] font-bold uppercase tracking-wider text-white/40",children:b.title}),typeof b.count=="number"?(0,Ur.jsx)("span",{className:"text-[9px] tabular-nums text-white/30",children:b.count}):null,b.badge]}),b.actions?(0,Ur.jsx)("div",{"data-section-actions":!0,className:"ml-auto flex shrink-0 items-center gap-1 opacity-0 transition-opacity focus-within:opacity-100 group-hover/section:opacity-100",children:b.actions}):null]},`s:${b.id}`)),M.collapsed||k.push((0,Ur.jsx)("div",{ref:A=>{A?i.current.set(b.id,A):i.current.delete(b.id)},className:"min-h-0 overflow-auto",style:{flexGrow:M.weight*C,flexBasis:0},children:b.content},`b:${b.id}`)),v={id:b.id,collapsed:M.collapsed,weight:M.weight}}return(0,Ur.jsx)("div",{className:q("flex min-h-0 flex-1 flex-col overflow-hidden",a&&"cursor-row-resize select-none"),children:k})}var _=W(le(),1);function hp(n,e,t){(0,ye.useEffect)(()=>{if(!n)return;let r=a=>{let s=a.target;s instanceof Node&&e.current?.contains(s)||t()};return document.addEventListener("mousedown",r,!0),()=>document.removeEventListener("mousedown",r,!0)},[n,e,t])}var JR="neuralis.filesystem.gitPanel.sections",b1="neuralis.filesystem.gitPanel.commitOpen",w1="neuralis.filesystem.gitPanel.diffCounts";function ZR(n){return typeof n!="string"||!n?"":n.includes("://")?Ve(n):n}function QR(n){let e=n.lastIndexOf("/");return e<0?{name:n,dir:""}:{name:n.slice(e+1),dir:n.slice(0,e)}}function eM(n){let e={name:"",path:"",children:new Map};for(let t of n){let r=t.path.split("/").filter(Boolean),a=e,s="";for(let o=0;o<r.length;o++){let i=r[o];s=s?`${s}/${i}`:i;let l=a.children.get(i);l||(l={name:i,path:s,children:new Map},a.children.set(i,l)),a=l,o===r.length-1&&(a.change=t)}}return e}function I1(n,e){let t=[],r=[...n.children.values()].sort((a,s)=>{let o=a.children.size>0,i=s.children.size>0;return o!==i?o?-1:1:a.name.localeCompare(s.name)});for(let a of r)t.push({node:a,depth:e}),a.children.size>0&&t.push(...I1(a,e+1));return t}var v1=Object.freeze({}),k1=ye.default.memo(function({change:e,onClick:t,actions:r,busy:a,showCounts:s}){let{name:o,dir:i}=QR(e.path),l=ci(e.path),u=d=>d.stopPropagation(),c=!!(r.onDiscard||r.onUnstage||r.onStage);return(0,_.jsxs)("div",{className:"group/row relative flex w-full items-center rounded-md pr-1.5 transition-colors hover:bg-white/[0.05]",children:[(0,_.jsxs)("button",{type:"button",onClick:()=>t(e),title:e.origPath?`${e.origPath} \u2192 ${e.path}`:e.path,className:"flex min-w-0 flex-1 items-center gap-1.5 overflow-hidden py-1 pl-2 pr-1 text-left",children:[(0,_.jsx)(l,{className:"h-4 w-4 shrink-0 text-white/55"}),(0,_.jsx)("span",{className:"shrink-0 truncate text-xs text-white/85",children:o}),i?(0,_.jsx)("span",{className:"min-w-0 flex-1 truncate text-[10px] text-white/35",children:i}):(0,_.jsx)("span",{className:"flex-1"})]}),s?(0,_.jsx)(La,{added:e.added,removed:e.removed,binary:e.binary,className:"mr-1 transition-opacity group-hover/row:opacity-0"}):null,(0,_.jsx)("span",{className:"flex w-3.5 shrink-0 items-center justify-center",children:(0,_.jsx)(vc,{code:e.code})}),c?(0,_.jsxs)("div",{className:"absolute right-6 top-1/2 flex -translate-y-1/2 items-center gap-0.5 rounded bg-gradient-to-r from-transparent via-black/30 to-black/45 pl-4 opacity-0 transition-opacity group-hover/row:opacity-100 focus-within:opacity-100",children:[r.onDiscard?(0,_.jsx)("button",{type:"button",onClick:d=>{u(d),r.onDiscard(e)},disabled:a,className:"inline-flex h-5 w-5 items-center justify-center rounded text-rose-300/70 transition-colors hover:bg-rose-500/15 hover:text-rose-200 disabled:opacity-40",title:"Discard changes (destructive)","aria-label":`Discard changes to ${o}`,children:(0,_.jsx)(It,{className:"h-3 w-3"})}):null,r.onUnstage?(0,_.jsx)("button",{type:"button",onClick:d=>{u(d),r.onUnstage(e)},disabled:a,className:"inline-flex h-5 w-5 items-center justify-center rounded text-white/50 transition-colors hover:bg-white/10 hover:text-white/80 disabled:opacity-40",title:"Unstage","aria-label":`Unstage ${o}`,children:(0,_.jsx)(ro,{className:"h-3 w-3"})}):null,r.onStage?(0,_.jsx)("button",{type:"button",onClick:d=>{u(d),r.onStage(e)},disabled:a,className:"inline-flex h-5 w-5 items-center justify-center rounded text-emerald-300/80 transition-colors hover:bg-emerald-500/15 hover:text-emerald-200 disabled:opacity-40",title:"Stage","aria-label":`Stage ${o}`,children:(0,_.jsx)(Fn,{className:"h-3 w-3"})}):null]}):null]})});function S1({changes:n,viewMode:e,staged:t,onRowClick:r,actionsFor:a,busy:s,showCounts:o}){let i=(0,ye.useMemo)(()=>e==="tree"?I1(eM(n),0):[],[n,e]),l=(0,ye.useCallback)(u=>r(u,t),[r,t]);return(0,_.jsx)("div",{className:"px-1 py-0.5",children:e==="list"?(0,_.jsx)("div",{className:"space-y-px",children:n.map(u=>(0,_.jsx)(k1,{change:u,onClick:l,actions:a(u),busy:s,showCounts:o},`${u.code}:${u.path}`))}):(0,_.jsx)("div",{className:"space-y-px",children:i.map(({node:u,depth:c})=>u.change?(0,_.jsx)("div",{style:{paddingLeft:`${c*12}px`},children:(0,_.jsx)(k1,{change:u.change,onClick:l,actions:a(u.change),busy:s,showCounts:o})},`f:${u.path}`):(0,_.jsxs)("div",{style:{paddingLeft:`${c*12}px`},className:"flex items-center gap-1.5 px-2 py-1 text-[11px] text-white/45",children:[(0,_.jsx)(Br,{className:"h-3.5 w-3.5 shrink-0 text-white/35"}),(0,_.jsx)("span",{className:"truncate",children:u.name})]},`d:${u.path}`))})})}function pp({tone:n,onClick:e,disabled:t,title:r,children:a}){return(0,_.jsx)("button",{type:"button",onClick:e,disabled:t,className:q("rounded px-1 py-0.5 text-[9px] transition-colors disabled:opacity-40",n==="discard"?"text-rose-300/70 hover:bg-rose-500/15 hover:text-rose-200":n==="unstage"?"text-white/55 hover:bg-white/10 hover:text-white/85":"text-emerald-300/80 hover:bg-emerald-500/15 hover:text-emerald-200"),title:r,children:a})}function A1({agentId:n}){let e=B(D=>D.sources),t=B(D=>D.activeProjectId),r=B(D=>D.activeSource),a=B(D=>D.activeRepoRel),s=B(D=>D.setActiveSource),o=B(D=>D.gitStatus),i=B(D=>D.gitTotals),l=B(D=>D.gitOutgoingStat),u=B(D=>D.setGitOutgoingStat),c=B(D=>D.gitLoading),d=B(D=>D.gitError),f=B(D=>D.gitViewMode),h=B(D=>D.setGitViewMode),p=B(D=>D.gitBranches),m=B(D=>D.loadGitStatus),g=B(D=>D.loadGitBranches),x=B(D=>D.setGitDiffTarget),w=B(D=>D.setActiveWorkspaceTab),y=B(D=>D.gitLogNonce),[C,k]=(0,ye.useState)(!1),[v,b]=(0,ye.useState)(!1),P=(0,ye.useRef)(null),N=(0,ye.useRef)(null),[M,U]=(0,ye.useState)(!1),[I,A]=(0,ye.useState)(!1),[G,V]=(0,ye.useState)(null),[K,L]=(0,ye.useState)(""),[R,z]=(0,ye.useState)(!1),[J,Q]=(0,ye.useState)(()=>Mh(b1,!1)),[re,pe]=(0,ye.useState)(()=>Mh(w1,!0)),ee=(0,ye.useCallback)(()=>{pe(D=>{let me=!D;return Th(w1,me),me})},[]),[ce,ue]=(0,ye.useState)(null),[He,De]=(0,ye.useState)(null),[je,et]=(0,ye.useState)(!1),Dt=(0,ye.useCallback)(()=>k(!1),[]),at=(0,ye.useCallback)(()=>{b(!1),et(!1)},[]),vt=(0,ye.useCallback)(()=>U(!1),[]);hp(C,P,Dt),hp(v,N,at),hp(M,N,vt);let[Pt,Ye]=(0,ye.useState)(""),[Ne,tt]=(0,ye.useState)(""),Je=(0,ye.useMemo)(()=>e.filter(D=>D.git?.isRepo||D.git?.containsRepos),[e]),Ft=(0,ye.useMemo)(()=>Je.map(D=>D.uri_root).join("|"),[Je]),Mt=(0,ye.useMemo)(()=>ZR(r),[r]),Te=(0,ye.useMemo)(()=>Je.find(D=>Ve(D.uri_root)===Mt)??Je[0]??null,[Je,Mt]),oe=Te?Ve(Te.uri_root):"",jt=Je.length>1||Je.some(D=>!D.git?.isRepo&&D.git?.containsRepos),Kt=(0,ye.useRef)(new Map),[de,fe]=(0,ye.useState)(()=>new Map),qe=(0,ye.useCallback)(async(D,me)=>{if(!n||!D)return[];let Yt=Kt.current.get(D);if(Yt&&(Yt instanceof Promise||!me?.force))return Yt;let Ot=(async()=>{try{let Cn=await Xo({agentId:n,...t?{projectId:t}:{},source:D}),Tr=Array.isArray(Cn?.repos)?Cn.repos:[];return Kt.current.set(D,Tr),fe(Gf=>new Map(Gf).set(D,Tr)),Tr}catch{return Kt.current.delete(D),fe(Cn=>Cn.has(D)?Cn:new Map(Cn).set(D,[])),[]}})();return Kt.current.set(D,Ot),Ot},[n,t]),Re=(0,ye.useMemo)(()=>a?de.get(oe)?.find(D=>D.rel===a)??null:null,[a,de,oe]),Fe=a?Re?.canWrite===!0:Te?.git?.canWrite===!0,Lt=a?Re?.canExec===!0:Te?.git?.canExec===!0,st=o?.staged.length??0,Le=Ts(oe,a?Re?.name??a:Te?.git?.repoName),Ee=(0,ye.useMemo)(()=>Lw(o),[o]);(0,ye.useEffect)(()=>{oe&&oe!==Mt&&s(oe)},[n,t,oe,Ft]),(0,ye.useEffect)(()=>{let D=Te?.git;if(!oe||!D||D.isRepo||!D.containsRepos)return;let me=!1;return qe(oe).then(Yt=>{me||a||Yt.length===0||s(oe,Yt[0].rel)}),()=>{me=!0}},[oe,Te,a,qe,s]);let Et=(0,ye.useRef)(y);(0,ye.useEffect)(()=>{if(y===Et.current)return;Et.current=y;let D=Te?.git;!oe||!D||D.isRepo||!D.containsRepos||qe(oe,{force:!0})},[y,oe,Te,qe]),(0,ye.useEffect)(()=>{oe&&m({agentId:n,projectId:t??null,source:oe,repo:a})},[n,t,oe,a,Ft]),(0,ye.useEffect)(()=>{if(!He)return;let D=setTimeout(()=>De(null),9e3);return()=>clearTimeout(D)},[He]);let qt=(0,ye.useCallback)((D,me)=>{k(!1),s(D,me)},[s]),Tn=(0,ye.useCallback)(()=>{b(!1),et(!1),U(!1),k(D=>{let me=!D;if(me)for(let Yt of Je){let Ot=Yt.git;Ot&&!Ot.isRepo&&Ot.containsRepos&&qe(Ve(Yt.uri_root),{force:!0})}return me})},[Je,qe]),te=(0,ye.useCallback)(()=>{Q(D=>{let me=!D;return Th(b1,me),me})},[]),Ge=(0,ye.useCallback)(()=>{oe&&m({agentId:n,projectId:t??null,source:oe,repo:a})},[n,t,oe,a,m]),Ke=(0,ye.useCallback)((D,me)=>{oe&&(x({source:oe,...a?{repo:a}:{},path:D.path,staged:me}),w("git-diff"))},[oe,a,x,w]),Ae=(0,ye.useCallback)(async D=>{if(oe){A(!0),V(null);try{let me=await D();return m({agentId:n,projectId:t??null,source:oe,repo:a}),me}catch(me){V(me instanceof Error?me.message:"Git operation failed");return}finally{A(!1)}}},[oe,a,n,t,m]),he=(0,ye.useMemo)(()=>({...t?{projectId:t}:{},...a?{repo:a}:{}}),[t,a]),ut=(0,ye.useCallback)(D=>{D.length!==0&&Ae(()=>G0({agentId:n,...he,source:oe,paths:D}))},[Ae,n,he,oe]),Qt=(0,ye.useCallback)(D=>{D.length!==0&&Ae(()=>z0({agentId:n,...he,source:oe,paths:D}))},[Ae,n,he,oe]),xn=(0,ye.useCallback)(D=>{(async()=>{let me=await Ae(()=>q0({agentId:n,...he,source:oe,paths:D}));me&&me.rescue&&De({message:`Discarded ${D.length} file${D.length===1?"":"s"} \u2014 recoverable`,rescue:me.rescue})})()},[Ae,n,he,oe]),yn=(0,ye.useCallback)(D=>{D.length!==0&&ue({title:"Discard changes",message:`Overwrite the working-tree version of ${D.length} file${D.length===1?"":"s"} with the last committed/indexed content? A rescue snapshot is saved server-side so it can be recovered.`,confirmLabel:"Discard",onConfirm:()=>{ue(null),xn(D)}})},[xn]),Nr=(0,ye.useCallback)(D=>ut([D.path]),[ut]),Kn=(0,ye.useCallback)(D=>Qt([D.path]),[Qt]),Xn=(0,ye.useCallback)(D=>yn([D.path]),[yn]),Rr=(0,ye.useMemo)(()=>({onStage:Nr}),[Nr]),Yn=(0,ye.useMemo)(()=>({onStage:Nr,onDiscard:Xn}),[Nr,Xn]),Mr=(0,ye.useMemo)(()=>({onUnstage:Kn}),[Kn]),j=(0,ye.useCallback)(D=>Fe?D.code==="??"?Rr:Yn:v1,[Fe,Rr,Yn]),ie=(0,ye.useCallback)(()=>Fe?Mr:v1,[Fe,Mr]),Ue=(0,ye.useCallback)(()=>{let D=K.trim();D&&(async()=>{let me=await Ae(()=>V0({agentId:n,...he,source:oe,message:D,amend:R}));me&&me.ok&&(L(""),z(!1))})()},[K,R,Ae,n,he,oe]),Bt=(0,ye.useCallback)(()=>{k(!1),U(!1),b(D=>{let me=!D;return me&&oe&&g({agentId:n,projectId:t??null,source:oe,repo:a}),me}),et(!1)},[oe,a,n,t,g]),Xt=(0,ye.useCallback)(D=>{b(!1),(async()=>await Ae(()=>Jf({agentId:n,...he,source:oe,ref:D}))&&g({agentId:n,projectId:t??null,source:oe,repo:a}))()},[Ae,n,he,oe,a,g,t]),dn=(0,ye.useCallback)(()=>{let D=Pt.trim();if(!D)return;let me=Ne.trim();b(!1),et(!1),Ye(""),tt(""),(async()=>await Ae(()=>$0({agentId:n,...he,source:oe,name:D,...me?{startPoint:me}:{}}))&&(await Ae(()=>Jf({agentId:n,...he,source:oe,ref:D})),g({agentId:n,projectId:t??null,source:oe,repo:a})))()},[Pt,Ne,Ae,n,he,oe,a,g,t]),Sn=(0,ye.useCallback)(D=>{(async()=>{let me=await Ae(()=>K0({agentId:n,...he,source:oe,name:D}));me&&me.rescue&&De({message:`Deleted branch "${D}" \u2014 recoverable`,rescue:me.rescue}),g({agentId:n,projectId:t??null,source:oe,repo:a})})()},[Ae,n,he,oe,a,g,t]),hr=(0,ye.useCallback)(D=>{b(!1),ue({title:"Delete branch",message:`Delete the local branch "${D.name}"? A rescue ref is saved so it can be recreated (git will refuse if it has unmerged commits).`,confirmLabel:"Delete branch",onConfirm:()=>{ue(null),Sn(D.name)}})},[Sn]),Ua=(0,ye.useCallback)(()=>{if(!He)return;let D=He.rescue;De(null),Ae(()=>X0({agentId:n,...he,source:oe,rescue:D}))},[He,Ae,n,he,oe]),Jr=(0,ye.useCallback)(()=>{U(!1),Ae(()=>Y0({agentId:n,...he,source:oe}))},[Ae,n,he,oe]),Ys=(0,ye.useCallback)(()=>{U(!1),Ae(()=>J0({agentId:n,...he,source:oe}))},[Ae,n,he,oe]),Hn=(0,ye.useCallback)(()=>{U(!1),Ae(()=>Z0({agentId:n,...he,source:oe}))},[Ae,n,he,oe]),rn=o?.unstaged??[],Jn=o?.staged??[],pr=o?.untracked??[],E=(0,ye.useMemo)(()=>[...rn,...pr].sort((D,me)=>D.path.localeCompare(me.path)),[rn,pr]);if(Je.length===0)return(0,_.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 px-4 py-10 text-center",children:[(0,_.jsx)(Ln,{className:"h-5 w-5 text-white/25"}),(0,_.jsx)("div",{className:"text-xs text-white/40",children:"No git repositories"}),(0,_.jsx)("div",{className:"max-w-[200px] text-[10px] text-white/30",children:"Sources whose root is \u2014 or whose folders contain \u2014 a git checkout appear here."})]});let ne=Fe&&K.trim().length>0&&(st>0||R)&&!I,O=d?(0,_.jsx)("div",{className:"px-2 py-3 text-[11px] text-rose-300/70",children:d}):c&&!o?(0,_.jsx)("div",{className:"px-2 py-3 text-[11px] text-white/35",children:"Loading git status\u2026"}):E.length===0?(0,_.jsx)("div",{className:"px-2 py-4 text-center text-[11px] text-white/35",children:"No changes"}):(0,_.jsx)(S1,{changes:E,viewMode:f,staged:!1,showCounts:re,onRowClick:Ke,actionsFor:j,busy:I}),Pe=[{id:"changes",title:"Changes",count:E.length,badge:i?(0,_.jsx)(La,{...i.changes,compact:!0,className:"ml-auto pr-1"}):void 0,actions:Fe&&E.length>0?(0,_.jsxs)(_.Fragment,{children:[rn.length>0?(0,_.jsx)(pp,{tone:"discard",onClick:()=>yn(rn.map(D=>D.path)),disabled:I,title:"Discard all tracked changes in this group (destructive)",children:"Discard all"}):null,(0,_.jsx)(pp,{tone:"stage",onClick:()=>ut(E.map(D=>D.path)),disabled:I,title:"Stage all",children:"Stage all"})]}):void 0,content:O},...Jn.length>0?[{id:"staged",title:"Staged Changes",count:Jn.length,badge:i?(0,_.jsx)(La,{...i.staged,compact:!0,className:"ml-auto pr-1"}):void 0,actions:Fe?(0,_.jsx)(pp,{tone:"unstage",onClick:()=>Qt(Jn.map(D=>D.path)),disabled:I,title:"Unstage all",children:"Unstage all"}):void 0,content:(0,_.jsx)(S1,{changes:Jn,viewMode:f,staged:!0,showCounts:re,onRowClick:Ke,actionsFor:ie,busy:I})}]:[],{id:"graph",title:"Graph",badge:l?(0,_.jsx)(La,{added:l.added,removed:l.removed,unknown:l.commits-l.covered,compact:!0,className:"ml-auto pr-1"}):void 0,defaultCollapsed:!0,defaultWeight:2,content:(0,_.jsx)(f1,{showCounts:re,onOutgoingStat:u,source:oe,repo:a,agentId:n,projectId:t??null,repoName:a?Re?.name??a:Te?.git?.repoName},`${oe}\0${a}`)}];return(0,_.jsxs)("div",{className:"flex h-full min-h-0 flex-col",children:[(0,_.jsxs)("div",{ref:P,className:"relative px-2 pt-1 pb-1.5",children:[(0,_.jsxs)("div",{className:"flex items-center gap-1",children:[(0,_.jsxs)("button",{type:"button",onClick:Tn,disabled:!jt,className:q("flex min-w-0 flex-1 items-center gap-1.5 rounded-md px-2 py-1 text-left transition-colors","bg-white/[0.03] hover:bg-white/[0.06] disabled:hover:bg-white/[0.03]"),title:oe?Le.title:"Select a repository",children:[(0,_.jsx)(Ln,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/80"}),Le.prefix?(0,_.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/40",children:Le.prefix}):null,(0,_.jsx)("span",{className:"min-w-0 flex-1 truncate text-xs font-medium text-white/85",children:Le.name||"Select repository"}),jt?(0,_.jsx)(Tt,{className:"h-3 w-3 shrink-0 text-white/40"}):null]}),(0,_.jsx)("button",{type:"button",onClick:Ge,className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-white/40 transition-colors hover:bg-white/[0.06] hover:text-white/70",title:"Refresh git status","aria-label":"Refresh git status",children:(0,_.jsx)(Ht,{className:q("h-3.5 w-3.5",c&&"animate-spin")})}),(0,_.jsx)(L1.SkillLauncher,{variant:"icon",size:"sm",skill:"git",packageId:"@neuralis/brain-core",scripts:["scripts/git.sh"],label:"Status, diff, commit, branch, fetch or push with the agent",icon:"GitBranch"})]}),C&&jt?(0,_.jsx)(_.Fragment,{children:(0,_.jsx)("div",{className:"absolute left-2 right-2 z-50 mt-1 max-h-56 overflow-auto rounded-md border border-white/10 bg-[rgba(var(--w-bg-rgb),0.96)] py-1 shadow-lg",children:Je.map(D=>{let me=Ve(D.uri_root);if(D.git?.isRepo){let Ot=me===oe&&!a,Cn=Ts(me,D.git?.repoName);return(0,_.jsxs)("button",{type:"button",onClick:()=>qt(me,""),className:q("flex w-full items-center gap-1.5 px-2 py-1.5 text-left text-xs transition-colors hover:bg-white/[0.06]",Ot?"text-white/90":"text-white/65"),children:[(0,_.jsx)(Ln,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/70"}),Cn.prefix?(0,_.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/40",children:Cn.prefix}):null,(0,_.jsx)("span",{className:"min-w-0 flex-1 truncate",children:Cn.name}),D.git?.branch?(0,_.jsx)("span",{className:"shrink-0 truncate text-[10px] text-white/35",children:D.git.branch}):null,Ot?(0,_.jsx)(Dn,{className:"h-3 w-3 shrink-0 text-violet-300/80"}):null]},D.uri_root)}let Yt=de.get(me);return Yt?Yt.length===0?(0,_.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1.5 text-[11px] text-white/35",children:[(0,_.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/40",children:`${me}://`}),(0,_.jsx)("span",{className:"truncate",children:"No repositories found."})]},D.uri_root):Yt.map(Ot=>{let Cn=me===oe&&a===Ot.rel,Tr=Ts(me,Ot.name||Ot.rel);return(0,_.jsxs)("button",{type:"button",onClick:()=>qt(me,Ot.rel),className:q("flex w-full items-center gap-1.5 px-2 py-1.5 text-left text-xs transition-colors hover:bg-white/[0.06]",Cn?"text-white/90":"text-white/65"),children:[(0,_.jsx)(Ln,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/70"}),Tr.prefix?(0,_.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/40",children:Tr.prefix}):null,(0,_.jsx)("span",{className:"min-w-0 flex-1 truncate",children:Tr.name}),Ot.branch?(0,_.jsx)("span",{className:"shrink-0 truncate text-[10px] text-white/35",children:Ot.branch}):null,Cn?(0,_.jsx)(Dn,{className:"h-3 w-3 shrink-0 text-violet-300/80"}):null]},`${D.uri_root}\0${Ot.rel}`)}):(0,_.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1.5 text-[11px] text-white/35",children:[(0,_.jsx)(ze,{className:"h-3 w-3 shrink-0 animate-spin"}),(0,_.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/40",children:`${me}://`}),(0,_.jsx)("span",{className:"truncate",children:"Scanning repositories\u2026"})]},D.uri_root)})})}):null]}),(0,_.jsxs)("div",{ref:N,className:"relative flex items-center justify-between gap-2 px-2 pb-1.5",children:[(0,_.jsxs)("div",{className:"flex min-w-0 items-center gap-1",children:[(0,_.jsxs)("button",{type:"button",onClick:Bt,className:"flex min-w-0 items-center gap-1.5 rounded-md px-1.5 py-0.5 text-[11px] text-white/55 transition-colors hover:bg-white/[0.05] hover:text-white/80",title:"Switch or create branch","aria-haspopup":"menu","aria-expanded":v,children:[(0,_.jsx)(Ln,{className:"h-3 w-3 shrink-0 text-white/40"}),(0,_.jsx)("span",{className:"truncate",children:o?.branch??"\u2014"}),(0,_.jsx)(Tt,{className:"h-3 w-3 shrink-0 text-white/30"})]}),Fe?(0,_.jsx)("button",{type:"button",onClick:()=>{k(!1),b(!1),et(!1),U(D=>!D)},className:"flex shrink-0 items-center gap-1.5 rounded bg-white/[0.05] px-1.5 py-0.5 text-[10px] leading-none tabular-nums text-white/60 transition-colors hover:bg-white/[0.08] hover:text-white/85",title:"Fetch / pull / push","aria-haspopup":"menu","aria-expanded":M,children:Ee?(0,_.jsxs)(_.Fragment,{children:[(0,_.jsxs)("span",{className:"flex items-center gap-0.5","aria-label":`${Ee.ahead} commits ahead of ${Ee.upstream}`,children:[(0,_.jsx)("span",{className:"text-blue-300/60",children:"\u2191"}),(0,_.jsx)("span",{className:"text-blue-200/90",children:Ee.ahead})]}),(0,_.jsxs)("span",{className:"flex items-center gap-0.5","aria-label":`${Ee.behind} commits behind ${Ee.upstream}`,children:[(0,_.jsx)("span",{className:"text-white/40",children:"\u2193"}),(0,_.jsx)("span",{className:"text-white/70",children:Ee.behind})]})]}):(0,_.jsx)(hl,{className:"h-3 w-3 text-white/40"})}):Ee?(0,_.jsxs)("span",{className:"flex shrink-0 cursor-default items-center gap-1.5 rounded bg-white/[0.05] px-1 py-0.5 text-[10px] leading-none tabular-nums",title:`${Ee.upstream}: ahead/behind vs the tracked upstream (local refs)`,children:[(0,_.jsxs)("span",{className:"flex items-center gap-0.5","aria-label":`${Ee.ahead} commits ahead of ${Ee.upstream}`,children:[(0,_.jsx)("span",{className:"text-blue-300/60",children:"\u2191"}),(0,_.jsx)("span",{className:"text-blue-200/90",children:Ee.ahead})]}),(0,_.jsxs)("span",{className:"flex items-center gap-0.5","aria-label":`${Ee.behind} commits behind ${Ee.upstream}`,children:[(0,_.jsx)("span",{className:"text-white/40",children:"\u2193"}),(0,_.jsx)("span",{className:"text-white/70",children:Ee.behind})]})]}):null,Fe?(0,_.jsxs)("button",{type:"button",onClick:te,className:"flex shrink-0 items-center gap-1 rounded-md px-1.5 py-0.5 text-[11px] text-white/55 transition-colors hover:bg-white/[0.05] hover:text-white/80",title:J?"Hide the commit box":"Show the commit box","aria-expanded":J,children:[(0,_.jsx)("span",{children:"Commit"}),st>0?(0,_.jsx)("span",{className:"rounded bg-white/[0.08] px-1 py-0.5 text-[9px] leading-none tabular-nums text-white/70",children:st}):null,J?(0,_.jsx)(ja,{className:"h-3 w-3 shrink-0 text-white/30"}):(0,_.jsx)(Tt,{className:"h-3 w-3 shrink-0 text-white/30"})]}):null]}),(0,_.jsxs)("div",{className:"flex shrink-0 items-center gap-0.5 rounded-md bg-white/[0.03] p-0.5",children:[(0,_.jsx)("button",{type:"button",onClick:()=>h("list"),className:q("inline-flex h-5 w-5 items-center justify-center rounded transition-colors",f==="list"?"bg-white/10 text-white/85":"text-white/40 hover:text-white/70"),title:"Flat list","aria-label":"Flat list view","aria-pressed":f==="list",children:(0,_.jsx)(to,{className:"h-3 w-3"})}),(0,_.jsx)("button",{type:"button",onClick:()=>h("tree"),className:q("inline-flex h-5 w-5 items-center justify-center rounded transition-colors",f==="tree"?"bg-white/10 text-white/85":"text-white/40 hover:text-white/70"),title:"Folder tree","aria-label":"Folder tree view","aria-pressed":f==="tree",children:(0,_.jsx)(Cl,{className:"h-3 w-3"})})]}),(0,_.jsx)("button",{type:"button",onClick:ee,className:q("inline-flex h-5 w-5 shrink-0 items-center justify-center rounded transition-colors",re?"text-white/85":"text-white/35 hover:text-white/60"),title:re?"Hide per-row diff counts":"Show per-row diff counts","aria-label":"Toggle per-row diff counts","aria-pressed":re,children:(0,_.jsx)(Bl,{className:"h-3 w-3"})}),v?(0,_.jsx)(_.Fragment,{children:(0,_.jsxs)("div",{className:"absolute left-2 right-2 top-full z-50 mt-1 max-h-72 overflow-auto rounded-md border border-white/10 bg-[rgba(var(--w-bg-rgb),0.97)] py-1 shadow-lg",children:[(0,_.jsx)("div",{className:"px-2 py-1 text-[9px] font-bold uppercase tracking-wider text-white/35",children:"Branches"}),p.length===0?(0,_.jsx)("div",{className:"px-2 py-1.5 text-[11px] text-white/35",children:"No branches loaded."}):p.map(D=>(0,_.jsxs)("div",{className:"group flex items-center gap-1.5 pr-1",children:[(0,_.jsxs)("button",{type:"button",onClick:()=>!D.current&&Xt(D.name),disabled:D.current||I,className:q("flex min-w-0 flex-1 items-center gap-1.5 px-2 py-1.5 text-left text-xs transition-colors",D.current?"text-violet-200/90":"text-white/70 hover:bg-white/[0.06]"),title:D.current?`${D.name} (current)`:`Switch to ${D.name}`,children:[(0,_.jsx)(Ln,{className:"h-3.5 w-3.5 shrink-0 text-white/40"}),(0,_.jsx)("span",{className:"min-w-0 flex-1 truncate",children:D.name}),D.current?(0,_.jsx)(Dn,{className:"h-3 w-3 shrink-0 text-violet-300/80"}):null]}),Fe&&!D.current?(0,_.jsx)("button",{type:"button",onClick:()=>hr(D),disabled:I,className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded text-rose-300/60 opacity-0 transition group-hover:opacity-100 hover:bg-rose-500/15 hover:text-rose-200 disabled:opacity-40",title:`Delete branch ${D.name}`,"aria-label":`Delete branch ${D.name}`,children:(0,_.jsx)(It,{className:"h-3 w-3"})}):null]},D.name)),Fe?(0,_.jsx)("div",{className:"mt-1 border-t border-white/[0.06] pt-1",children:je?(0,_.jsxs)("div",{className:"px-2 py-1.5",children:[(0,_.jsx)("input",{value:Pt,onChange:D=>Ye(D.target.value),onKeyDown:D=>{D.key==="Enter"&&dn()},placeholder:"new-branch-name",autoFocus:!0,className:"mb-1 h-6 w-full rounded border border-white/[0.12] bg-white/[0.04] px-1.5 text-[11px] text-white/85 outline-none placeholder:text-white/25 focus:border-white/25"}),(0,_.jsx)("input",{value:Ne,onChange:D=>tt(D.target.value),onKeyDown:D=>{D.key==="Enter"&&dn()},placeholder:"from (optional ref \u2014 default HEAD)",className:"mb-1.5 h-6 w-full rounded border border-white/[0.12] bg-white/[0.04] px-1.5 text-[11px] text-white/85 outline-none placeholder:text-white/25 focus:border-white/25"}),(0,_.jsxs)("div",{className:"flex items-center gap-1",children:[(0,_.jsxs)("button",{type:"button",onClick:dn,disabled:I||Pt.trim().length===0,className:"inline-flex items-center gap-1 rounded bg-violet-500/20 px-2 py-1 text-[10px] text-violet-100/90 transition-colors hover:bg-violet-500/30 disabled:opacity-40",children:[(0,_.jsx)(Fn,{className:"h-3 w-3"})," Create & switch"]}),(0,_.jsx)("button",{type:"button",onClick:()=>{et(!1),Ye(""),tt("")},className:"rounded px-2 py-1 text-[10px] text-white/50 transition-colors hover:bg-white/[0.06] hover:text-white/80",children:"Cancel"})]})]}):(0,_.jsxs)("button",{type:"button",onClick:()=>et(!0),className:"flex w-full items-center gap-1.5 px-2 py-1.5 text-left text-xs text-white/70 transition-colors hover:bg-white/[0.06]",children:[(0,_.jsx)(Fn,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/70"}),(0,_.jsx)("span",{children:"Create new branch\u2026"})]})}):null]})}):null,M?(0,_.jsx)(_.Fragment,{children:(0,_.jsxs)("div",{className:"absolute right-2 top-full z-50 mt-1 w-52 max-w-[calc(100%-1rem)] overflow-auto rounded-md border border-white/10 bg-[rgba(var(--w-bg-rgb),0.97)] py-1 shadow-lg",children:[(0,_.jsx)("div",{className:"px-2 py-1 text-[9px] font-bold uppercase tracking-wider text-white/35",children:"Remote"}),Lt?(0,_.jsxs)(_.Fragment,{children:[(0,_.jsxs)("button",{type:"button",onClick:Ys,disabled:I,className:"flex w-full items-center gap-2 px-2 py-1.5 text-left text-xs text-white/75 transition-colors hover:bg-white/[0.06] disabled:opacity-40",title:"Fetch + fast-forward merge (git pull, ff-only)",children:[(0,_.jsx)(fl,{className:"h-3.5 w-3.5 shrink-0 text-white/45"}),(0,_.jsx)("span",{className:"min-w-0 flex-1",children:"Pull"}),Ee&&Ee.behind>0?(0,_.jsxs)("span",{className:"shrink-0 tabular-nums text-[10px] text-white/50",children:["\u2193",Ee.behind]}):null]}),(0,_.jsxs)("button",{type:"button",onClick:Hn,disabled:I,className:"flex w-full items-center gap-2 px-2 py-1.5 text-left text-xs text-white/75 transition-colors hover:bg-white/[0.06] disabled:opacity-40",title:"Push the current branch (git push origin HEAD)",children:[(0,_.jsx)(pl,{className:"h-3.5 w-3.5 shrink-0 text-blue-300/60"}),(0,_.jsx)("span",{className:"min-w-0 flex-1",children:"Push"}),Ee&&Ee.ahead>0?(0,_.jsxs)("span",{className:"shrink-0 tabular-nums text-[10px] text-blue-200/80",children:["\u2191",Ee.ahead]}):null]}),(0,_.jsxs)("button",{type:"button",onClick:Jr,disabled:I,className:"flex w-full items-center gap-2 px-2 py-1.5 text-left text-xs text-white/75 transition-colors hover:bg-white/[0.06] disabled:opacity-40",title:"Fetch remote refs (git fetch origin)",children:[(0,_.jsx)(Ht,{className:"h-3.5 w-3.5 shrink-0 text-white/45"}),(0,_.jsx)("span",{className:"min-w-0 flex-1",children:"Fetch"})]})]}):(0,_.jsxs)("div",{className:"flex items-start gap-1.5 px-2 py-2",children:[(0,_.jsx)(no,{className:"mt-0.5 h-3 w-3 shrink-0 text-amber-300/70"}),(0,_.jsxs)("div",{className:"min-w-0 text-[11px] leading-snug text-white/55",children:["Remote git operations need ",(0,_.jsx)("span",{className:"font-medium text-white/75",children:"exec"})," permission on this source. Ask an owner to grant it."]})]})]})}):null]}),He?(0,_.jsxs)("div",{className:"mx-2 mb-1 flex items-start gap-1.5 rounded-md border border-amber-500/20 bg-amber-500/[0.07] px-2 py-1.5",children:[(0,_.jsx)(dt,{className:"mt-0.5 h-3 w-3 shrink-0 text-amber-300/80"}),(0,_.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,_.jsx)("div",{className:"text-[11px] text-amber-100/85",children:He.message}),(0,_.jsxs)("div",{className:"truncate font-mono text-[9px] text-amber-100/45",title:He.rescue.ref,children:["rescue: ",He.rescue.ref]})]}),(0,_.jsx)("button",{type:"button",onClick:Ua,disabled:I,className:"shrink-0 rounded px-1.5 py-0.5 text-[10px] font-semibold text-amber-100 transition-colors hover:bg-amber-500/20 disabled:opacity-40",children:"Undo"}),(0,_.jsx)("button",{type:"button",onClick:()=>De(null),className:"shrink-0 rounded p-0.5 text-amber-200/60 transition-colors hover:bg-amber-500/15 hover:text-amber-100","aria-label":"Dismiss recovery notice",children:(0,_.jsx)(Ut,{className:"h-3 w-3"})})]}):null,G?(0,_.jsxs)("div",{className:"mx-2 mb-1 flex items-start gap-1.5 rounded-md border border-rose-500/20 bg-rose-500/[0.06] px-2 py-1.5",children:[(0,_.jsx)(dt,{className:"mt-0.5 h-3 w-3 shrink-0 text-rose-300/80"}),(0,_.jsx)("div",{className:"min-w-0 flex-1 text-[11px] text-rose-200/85",children:G}),(0,_.jsx)("button",{type:"button",onClick:()=>V(null),className:"shrink-0 rounded p-0.5 text-rose-200/60 transition-colors hover:bg-rose-500/15 hover:text-rose-100","aria-label":"Dismiss error",children:(0,_.jsx)(Ut,{className:"h-3 w-3"})})]}):null,Fe&&J?(0,_.jsxs)("div",{className:"mx-2 mb-1.5 rounded-md border border-white/[0.07] bg-white/[0.02] p-1",children:[(0,_.jsx)("textarea",{value:K,onChange:D=>L(D.target.value),onKeyDown:D=>{D.key==="Enter"&&(D.metaKey||D.ctrlKey)&&!D.nativeEvent.isComposing&&ne&&(D.preventDefault(),Ue())},placeholder:st>0?`Commit message (${st} staged)`:"Commit message",rows:2,className:"w-full resize-none rounded bg-transparent px-1 text-[11px] text-white/85 outline-none placeholder:text-white/30"}),(0,_.jsxs)("div",{className:"mt-0.5 flex items-center justify-end gap-2",children:[(0,_.jsxs)("label",{className:"flex cursor-pointer select-none items-center gap-1 text-[10px] text-white/50",children:[(0,_.jsx)("input",{type:"checkbox",checked:R,onChange:D=>z(D.target.checked),className:"h-3 w-3 accent-violet-400"}),"Amend"]}),(0,_.jsxs)("button",{type:"button",onClick:Ue,disabled:!ne,className:"inline-flex items-center gap-1 rounded-md bg-violet-500/20 px-2.5 py-1 text-[11px] font-medium text-violet-100/90 transition-colors hover:bg-violet-500/30 disabled:opacity-40",title:R?"Amend the last commit":"Commit the staged changes",children:[I?(0,_.jsx)(ze,{className:"h-3 w-3 animate-spin"}):(0,_.jsx)(Dn,{className:"h-3 w-3"}),R?"Amend":"Commit"]})]})]}):null,(0,_.jsx)(y1,{storageKey:JR,sections:Pe}),ce&&typeof document<"u"?(0,C1.createPortal)((0,_.jsxs)("div",{className:"fixed inset-0 z-[100000] flex items-center justify-center p-4",children:[(0,_.jsx)("button",{type:"button","aria-hidden":!0,tabIndex:-1,onClick:()=>ue(null),className:"absolute inset-0 cursor-default bg-black/50"}),(0,_.jsxs)("div",{className:"relative z-10 w-full max-w-xs rounded-lg border border-white/10 bg-[rgba(var(--w-bg-rgb),0.98)] p-4 shadow-xl",children:[(0,_.jsxs)("div",{className:"mb-1 flex items-center gap-2",children:[(0,_.jsx)(dt,{className:"h-4 w-4 shrink-0 text-rose-300/80"}),(0,_.jsx)("span",{className:"text-sm font-semibold text-white/90",children:ce.title})]}),(0,_.jsx)("p",{className:"mb-3 text-[11px] leading-relaxed text-white/55",children:ce.message}),(0,_.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,_.jsx)("button",{type:"button",onClick:()=>ue(null),className:"rounded-md px-3 py-1.5 text-[11px] text-white/60 transition-colors hover:bg-white/[0.06] hover:text-white/85",children:"Cancel"}),(0,_.jsxs)("button",{type:"button",onClick:ce.onConfirm,className:"inline-flex items-center gap-1 rounded-md border border-rose-500/30 bg-rose-500/15 px-3 py-1.5 text-[11px] font-semibold text-rose-100 transition-colors hover:bg-rose-500/25",children:[(0,_.jsx)(It,{className:"h-3 w-3"}),ce.confirmLabel]})]})]})]}),document.body):null]})}var St=W(le(),1),P1={},N1="brain://",tM=32,nM=28,rM=114;function aM(n){return n==="header"?tM:n==="empty"?rM:nM}function sM(n){return n!=="node"}function R1(n,e){return n.type===e.type?n.name.localeCompare(e.name):n.type==="folder"?-1:1}function oM(n){let e=new Map,t=new Set;for(let a of n)t.add(a.uri);for(let a of n){let s=a.parentUri??ot(a.uri);if(!s||a.uri===s)continue;let o=e.get(s);o?o.push(a):e.set(s,[a])}for(let a of e.values())a.sort(R1);let r=new Map;for(let a of n){let s=rr(a.uri);if(!s||a.uri===s)continue;let o=a.parentUri??ot(a.uri);if(!(!o||o===s||!t.has(o)))continue;let l=r.get(s);l?l.push(a):r.set(s,[a])}for(let a of r.values())a.sort(R1);return{childrenByParent:e,rootsBySource:r}}function iM(n,e,t){let r=[],a=(o,i)=>{r.push({node:o,depth:i});let l=o.storeKey||Wa(o);if(o.type==="folder"&&t.has(l)){let u=n.childrenByParent.get(o.uri);if(u)for(let c=0;c<u.length;c++)a(u[c],i+1)}},s=n.rootsBySource.get(e);if(s)for(let o=0;o<s.length;o++)a(s[o],0);return r}function mp(n){let{agentId:e,sidebarView:t="tree"}=n,r=hn(),a=B(E=>E.files),s=B(E=>E.folderBadges),o=B(E=>E.expandedFolders),i=B(E=>E.activeFile),l=B(E=>E.toggleFolder),u=B(E=>E.openFile),c=B(E=>E.activeProjectId),d=B(E=>E.setActiveFolderPath),f=B(E=>E.activeFolderPath),h=B(E=>E.uploadMany),p=B(E=>E.moveFileToFolder),m=B(E=>E.uploading),g=B(E=>E.sources),x=B(E=>E.sourcesLoading),w=B(E=>E.hydrationState),y=B(E=>E.dirtySources),C=B(E=>E.organizeError),k=B(E=>E.clearOrganizeError),v=B(E=>E.snapshotError),b=B(E=>E.clearSnapshotError),P=B(E=>E.loadList),N=B(E=>E.pendingReviewPaths),M=B(E=>E.renameNode),U=B(E=>E.deleteNodes),I=B(E=>E.createNode),A=B(E=>E.pasteNodes),[G,V]=(0,_e.useState)(null),[K,L]=(0,_e.useState)({}),[R,z]=(0,_e.useState)(()=>new Set),[J,Q]=(0,_e.useState)(null),[re,pe]=(0,_e.useState)(null),[ee,ce]=(0,_e.useState)(null),[ue,He]=(0,_e.useState)(null),[De,je]=(0,_e.useState)(null),[et,Dt]=(0,_e.useState)(null),[at,vt]=(0,_e.useState)(!1),[Pt,Ye]=(0,_e.useState)(!1),Ne=B(E=>E.setPendingSourceSuggestion),tt=B(E=>E.setWorkspacePanelOpen);(0,_e.useEffect)(()=>{if(!i)return;let E=`${Ve(i)}://`;L(ne=>ne[E]?ne:{...ne,[E]:!0})},[i]);let Je=r.useFileMarks(e),Ft=r.useAgents(),Mt=r.usePackageIconBySlug?.()??P1,Te=(0,_e.useMemo)(()=>Je||P1,[Je]),oe=(0,_e.useMemo)(()=>Ns(Ft),[Ft]),jt=(0,_e.useMemo)(()=>oe.byId.get(e)??null,[oe,e]),Kt=(0,_e.useMemo)(()=>{let E={};for(let ne of N){let O=ga(ne);for(let Pe of O)E[Pe]=(E[Pe]||0)+1}return E},[N]),de=g.length>0,fe=(0,_e.useMemo)(()=>Object.values(a),[a]),qe=(0,_e.useMemo)(()=>oM(fe),[fe]),Re=(0,_e.useMemo)(()=>{let E={uri_root:N1,source_kind:"brain",writable:!0};return de?g.length>0?g:[E]:[E]},[de,g]),Fe=t==="search",Lt=(0,_e.useMemo)(()=>{let E=f?rr(f):null;return E&&Re.some(O=>O.uri_root===E)?E:Re.find(O=>O.source_kind!=="brain")?.uri_root??Re[0]?.uri_root??N1},[f,Re]),st=(0,_e.useMemo)(()=>{if(Fe)return[];let E=[];for(let ne of Re){let O=K[ne.uri_root]??!1;if(E.push({kind:"header",key:`h:${ne.uri_root}`,info:ne,expanded:O}),!O)continue;let Pe=iM(qe,ne.uri_root,o);if(Pe.length===0)E.push({kind:"empty",key:`e:${ne.uri_root}`,sourceRoot:ne.uri_root});else for(let D of Pe)E.push({kind:"node",key:`n:${D.node.uri}`,node:D.node,depth:D.depth})}if(ee){let ne=ee.parentUri,O=-1,Pe=0;if(ne.endsWith("://"))O=E.findIndex(D=>D.kind==="header"&&D.info.uri_root===ne),Pe=0;else{let D=E.findIndex(me=>me.kind==="node"&&me.node.uri===ne);D>=0&&(O=D,Pe=E[D].depth+1)}O>=0&&E.splice(O+1,0,{kind:"creating",key:"creating-row",parentUri:ne,createKind:ee.kind,depth:Pe})}return E},[qe,o,Re,K,Fe,ee]),Le=(0,_e.useMemo)(()=>st.filter(E=>E.kind==="node").map(E=>E.node.uri),[st]),Ee=(0,_e.useCallback)(({node:E,additive:ne,range:O})=>{z(Pe=>{if(O&&J){let D=Le.indexOf(J),me=Le.indexOf(E.uri);if(D>=0&&me>=0){let[Yt,Ot]=D<=me?[D,me]:[me,D];return new Set(Le.slice(Yt,Ot+1))}}if(ne){let D=new Set(Pe);return D.has(E.uri)?D.delete(E.uri):D.add(E.uri),D}return new Set([E.uri])}),O||Q(E.uri)},[Le,J]),Et=(0,_e.useCallback)(({node:E,x:ne,y:O})=>{z(Pe=>Pe.has(E.uri)&&Pe.size>1?Pe:new Set([E.uri])),Q(E.uri),je({kind:"node",node:E,x:ne,y:O})},[]),qt=(0,_e.useCallback)((E,ne)=>{ne.preventDefault(),ne.stopPropagation(),L(O=>O[E]?O:{...O,[E]:!0}),je({kind:"source",sourceRoot:E,x:ne.clientX,y:ne.clientY})},[]),Tn=(0,_e.useCallback)(E=>{E.target.closest('button, input, textarea, [role="menu"]')||qt(Lt,E)},[Lt,qt]),te=(0,_e.useMemo)(()=>De?.kind!=="node"?[]:(R.has(De.node.uri)&&R.size>0?[...R]:[De.node.uri]).map(ne=>a[ne]).filter(Boolean),[De,R,a]),Ce=(0,_e.useMemo)(()=>oi({grantedFeatures:[...r.grantedFeatures??[]]},{features:["drive.sync"]}),[r.grantedFeatures]),[Ge,Ke]=(0,_e.useState)(null),Ae=(0,_e.useMemo)(()=>{if(De?.kind==="source")return{"new-file":!0,"new-folder":Ve(De.sourceRoot)!=="brain"};let E=te.length===1?te[0]:null,ne=E??te[0],O=ne?ne.type==="folder"?ne.uri:ot(ne.uri):null;return{"copy-path":!!E,"copy-relative-path":!!E,reembed:!!E&&Ce&&Ve(E.uri)!=="brain",rename:!!E,delete:te.length>0,"new-file":!!E,"new-folder":!!E&&Ve(E.uri)!=="brain",cut:te.length>0,copy:te.length>0,paste:!!ue&&ue.uris.length>0&&!!O}},[De,te,ue,Ce]),he=(0,_e.useCallback)(E=>{if(De?.kind==="source"){(E==="new-file"||E==="new-folder")&&ce({parentUri:De.sourceRoot,kind:E==="new-file"?"file":"folder"});return}let ne=te,O=ne.length===1?ne[0]:null;if(E==="copy-path"&&O)navigator.clipboard?.writeText(O.uri);else if(E==="copy-relative-path"&&O)navigator.clipboard?.writeText(O.uri.replace(/^[a-z0-9_-]+:\/\//i,""));else if(E==="reembed"&&O){let Pe=Ve(O.uri);Pe&&Ke({source:Pe,...O.type==="folder"?{folder:O.uri}:{uri:O.uri},label:O.type==="folder"?`${O.name}/`:O.name})}else if(E==="rename"&&O)pe(O.uri);else if(E==="delete")ne.length&&Dt({targets:ne.map(Pe=>({uri:Pe.uri,id:Pe.id,name:Pe.name}))});else if(E==="cut"||E==="copy")ne.length&&He({op:E,uris:ne.map(Pe=>Pe.uri)});else if(E==="paste"){let Pe=O??ne[0];if(Pe&&ue){let D=Pe.type==="folder"?Pe.uri:ot(Pe.uri);D&&(A({agentId:e,projectId:c??null,targetFolderUri:D,op:ue.op,uris:ue.uris}),ue.op==="cut"&&He(null))}}else if(E==="new-file"||E==="new-folder"){let Pe=E==="new-file"?"file":"folder",D=O??ne[0];if(!D)return;let me=D.type==="folder"?D.uri:ot(D.uri);if(!me)return;!me.endsWith("://")&&!o.has(me)&&(l(me),B.getState().ensureFolderLoaded({agentId:e,projectId:c,uri:me})),ce({parentUri:me,kind:Pe})}},[De,te,o,l,e,c,ue,A]),ut=(0,_e.useCallback)(async E=>{let ne=ee;if(ce(null),!ne)return;let O=(E??"").trim();O&&await I({agentId:e,projectId:c??null,parentUri:ne.parentUri,name:O,kind:ne.kind})},[ee,I,e,c]),Qt=(0,_e.useCallback)(()=>ce(null),[]),xn=(0,_e.useCallback)(async({node:E,newName:ne})=>{pe(null);let O=(ne??"").trim();!O||O===E.name||await M({agentId:e,projectId:c??null,uri:E.uri,id:E.id,newName:O})},[M,e,c]),yn=(0,_e.useCallback)(()=>pe(null),[]),Nr=(0,_e.useCallback)(async()=>{if(et){vt(!0);try{await U({agentId:e,projectId:c??null,targets:et.targets.map(E=>({uri:E.uri,id:E.id}))}),z(new Set)}finally{vt(!1),Dt(null)}}},[et,U,e,c]),Kn=(0,_e.useCallback)(E=>{if(!re)if(E.key==="F2"){let ne=R.size===1?[...R][0]:null;ne&&a[ne]&&(E.preventDefault(),pe(ne))}else if(E.key==="Delete"||E.key==="Backspace"){let ne=[...R].map(O=>a[O]).filter(O=>!!O);ne.length&&(E.preventDefault(),Dt({targets:ne.map(O=>({uri:O.uri,id:O.id,name:O.name}))}))}else E.key==="Escape"&&z(new Set)},[re,R,a]),Xn=(0,_e.useCallback)(async E=>{let ne=o.has(E.key);d(E.key),l(E.key),!ne&&await B.getState().ensureFolderLoaded({agentId:e,projectId:c,uri:E.key})},[e,o,c,d,l]),Rr=(0,_e.useCallback)(E=>{E.uri&&d(ot(E.uri)),u(E)},[d,u]),Yn=(0,_e.useCallback)(E=>{r.clearFileMark(E)},[r]),Mr=(0,_e.useCallback)(E=>{L(ne=>({...ne,[E]:!ne[E]}))},[]),j=(0,_e.useCallback)(async E=>{if(!e)return;let ne=B.getState();if(L(O=>O[E]?O:{...O,[E]:!0}),ne.loadedFolders?.[E]){let O=Ve(E);O&&await ne.reconcileSourceFolders({agentId:e,projectId:c,source:O});return}await ne.ensureFolderLoaded({agentId:e,projectId:c,uri:E,force:!0})},[e,c]);(0,_e.useEffect)(()=>{if(!e)return;let E=B.getState(),ne=[];for(let O of Re)K[O.uri_root]&&ne.push(O.uri_root);for(let O of o)ne.push(O);for(let O of ne){if(E.loadedFolders?.[O])continue;let Pe=E.hydrationState?.[O];Pe&&Pe!=="idle"||E.ensureFolderLoaded({agentId:e,projectId:c,uri:O})}},[e,c,Re,K,o]);let ie=(0,_e.useCallback)(async({fromUri:E,id:ne,toFolderUri:O})=>{await p({agentId:e,projectId:c??null,fromUri:E,toFolderUri:O,id:ne})},[e,c,p]),Ue=(0,_e.useMemo)(()=>Re.every(E=>!K[E.uri_root]),[Re,K]),Bt=(0,_e.useMemo)(()=>oi({grantedFeatures:[...r.grantedFeatures??[]]},{features:["drive.mount"]}),[r.grantedFeatures]),Xt=jb({agentId:e,projectId:c??void 0,enabled:Bt&&Ue}),dn=Ue&&Bt&&Xt.length>0,Sn=(0,_e.useCallback)(E=>{Ne(E),tt("sources",!0)},[Ne,tt]),hr=(0,_e.useCallback)(()=>Ye(E=>!E),[]),Ua=(0,_e.useRef)(null),Jr=(0,_e.useRef)(st);Jr.current=st;let Ys=(0,_e.useCallback)(E=>aM(Jr.current[E]?.kind??"node"),[]),Hn=(0,_e.useCallback)(E=>Jr.current[E]?.key??E,[]),rn=ii({count:st.length,getScrollElement:()=>Ua.current,estimateSize:Ys,overscan:8,getItemKey:Hn});if(t==="git")return(0,St.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:(0,St.jsx)(A1,{agentId:e})});if(x&&!de&&!Fe)return(0,St.jsx)("div",{className:"p-4 text-center text-xs text-white/40 animate-pulse",children:"Loading sources"});let Jn=v&&!Fe?(0,St.jsxs)("div",{role:"status",className:"mx-2 mb-1 mt-1 flex items-start gap-2 rounded-md border border-rose-400/30 bg-rose-500/10 px-2 py-1.5 text-[11px] text-rose-100/90",children:[(0,St.jsx)("span",{className:"min-w-0 flex-1 break-words",children:v}),(0,St.jsx)("button",{type:"button",onClick:()=>{e&&P({agentId:e,projectId:c??null})},className:"shrink-0 rounded px-1 font-medium text-rose-200/80 transition-colors hover:text-rose-100",children:"Retry"}),(0,St.jsx)("button",{type:"button",onClick:b,"aria-label":"Dismiss",className:"shrink-0 rounded px-1 text-rose-200/70 transition-colors hover:text-rose-100",children:"\xD7"})]}):null;if(!fe.length&&!Fe&&!de)return Jn??(0,St.jsx)("div",{className:"p-4 text-center text-xs text-white/30",children:"Empty Drive"});let pr=(E,ne)=>{let O=E.type==="folder",Pe=E.storeKey||Wa(E);return(0,St.jsx)(aw,{node:E,depth:ne,agentId:e,projectId:c,isActive:!O&&i===Pe,isExpanded:O&&o.has(Pe),badgeCount:O?s[Pe]:void 0,isDrop:G===Pe,isSelectedFolder:O&&f===Pe,mark:Te[E.uri],agentIndex:oe,fallbackAgent:jt,uploading:m,packageIconBySlug:Mt,onToggleFolder:Xn,onOpenFile:Rr,onClearFileMark:Yn,onSetDropTarget:V,onUploadMany:h,onMoveFileToFolder:ie,pendingReviewCount:O?Kt[Pe]:void 0,isSelected:R.has(E.uri),isCut:ue?.op==="cut"&&ue.uris.includes(E.uri),renaming:re===E.uri,onNodeClick:Ee,onNodeContextMenu:Et,onRenameCommit:xn,onRenameCancel:yn})};return(0,St.jsxs)("div",{className:"relative flex min-h-0 flex-1 flex-col",children:[(0,St.jsxs)("div",{ref:Ua,tabIndex:0,onKeyDown:Kn,onContextMenu:Tn,className:"min-h-0 flex-1 overflow-auto pt-0 pb-2 outline-none",children:[Jn,C&&!Fe?(0,St.jsxs)("div",{role:"status",className:"mx-2 mb-1 mt-1 flex items-start gap-2 rounded-md border border-amber-400/30 bg-amber-500/10 px-2 py-1.5 text-[11px] text-amber-100/90",children:[(0,St.jsx)("span",{className:"min-w-0 flex-1 break-words",children:C}),(0,St.jsx)("button",{type:"button",onClick:k,"aria-label":"Dismiss",className:"shrink-0 rounded px-1 text-amber-200/70 transition-colors hover:text-amber-100",children:"\xD7"})]}):null,Fe?(0,St.jsx)(pw,{agentId:e}):null,Fe?null:(0,St.jsx)("div",{style:{height:rn.getTotalSize(),width:"100%",position:"relative"},children:rn.getVirtualItems().map(E=>{let ne=st[E.index];if(!ne)return null;let O=sM(ne.kind);return(0,St.jsx)("div",{"data-index":E.index,ref:O?rn.measureElement:void 0,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${E.start}px)`},children:ne.kind==="header"?(0,St.jsx)(hw,{info:ne.info,expanded:ne.expanded,onToggle:Mr,onContextMenu:qt,onRefresh:j,hydration:w[ne.info.uri_root]??"idle",dirty:!!y[Ve(ne.info.uri_root)],hideChevron:!0,compact:!0}):ne.kind==="empty"?(0,St.jsxs)("div",{className:"flex flex-col items-start gap-1.5 px-4 py-2",onContextMenu:Pe=>qt(ne.sourceRoot,Pe),children:[(0,St.jsxs)("span",{className:"text-xs text-white/35",children:["No files for ",Ve(ne.sourceRoot)]}),(0,St.jsx)(M1.SkillLauncher,{variant:"label",skill:"manage-files",packageId:"@neuralis/brain-core",scripts:["scripts/upload.sh","scripts/modify.sh"],label:"Populate this source with the agent"})]}):ne.kind==="creating"?(0,St.jsx)(lM,{kind:ne.createKind,depth:ne.depth,onCommit:ut,onCancel:Qt}):pr(ne.node,ne.depth)},E.key)})}),De?(0,St.jsx)(ow,{x:De.x,y:De.y,variant:De.kind==="source"?"source":"node",enabled:Ae,onAction:he,onClose:()=>je(null)}):null,Ge?(0,St.jsx)(kc,{agentId:e,...c?{projectId:c}:{},target:Ge,onClose:()=>Ke(null)}):null,et?(0,St.jsx)(uw,{names:et.targets.map(E=>E.name),busy:at,onCancel:()=>{at||Dt(null)},onConfirm:Nr}):null]}),dn&&!Fe?(0,St.jsx)(Yb,{suggestions:Xt,expanded:Pt,onToggleExpanded:hr,onPick:Sn,overlay:Pt}):null]})}function lM({kind:n,depth:e,onCommit:t,onCancel:r}){let a=(0,_e.useRef)(!1),s=n==="folder"?wr:ks;return(0,St.jsxs)("div",{className:"flex h-7 items-center gap-1.5 px-2",style:{paddingLeft:`${e*12+8}px`},children:[(0,St.jsx)("span",{className:"w-3.5 h-3.5 inline-block shrink-0"}),(0,St.jsx)(s,{className:"w-4 h-4 shrink-0 text-sky-300/80"}),(0,St.jsx)("input",{autoFocus:!0,spellCheck:!1,placeholder:n==="folder"?"Folder name":"File name",onClick:o=>o.stopPropagation(),onMouseDown:o=>o.stopPropagation(),onKeyDown:o=>{o.stopPropagation(),o.key==="Enter"?a.current||(a.current=!0,t(o.currentTarget.value)):o.key==="Escape"&&(a.current||(a.current=!0,r()))},onBlur:o=>{if(a.current)return;a.current=!0;let i=o.currentTarget.value.trim();i?t(i):r()},className:"min-w-0 flex-1 rounded border border-sky-400/60 bg-black/50 px-1 py-0 text-xs text-white outline-none placeholder:text-white/30"})]})}var bt=W($e(),1);function T1(n){if(!n)return{lines:new Map,deletedBefore:new Set};let e=new Map,t=new Set,r=0,a=!1,s=0,o=0,i=()=>{s>0&&o===0&&t.add(r),s=0,o=0};for(let l of n.split(`
32
- `)){if(l.startsWith("@@")){i();let u=/^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(l);r=u?parseInt(u[1],10):0,a=r>0;continue}a&&(l.startsWith("+")&&!l.startsWith("+++")?(e.set(r,s>0?"modified":"added"),o++,r++):l.startsWith("-")&&!l.startsWith("---")?s++:(i(),l.startsWith(" ")&&r++))}return i(),{lines:e,deletedBefore:t}}function sd(n){return n.lines.size===0&&n.deletedBefore.size===0}var zn=W($e(),1),F1=W(Ya(),1);var ru=W(le(),1);function gp({sourceType:n,className:e}){return n==="blob"?(0,ru.jsx)("span",{title:"Blob + Vector",children:(0,ru.jsx)(Gn,{className:q("w-3 h-3",e)})}):(0,ru.jsx)("span",{title:"Vector only",children:(0,ru.jsx)(br,{className:q("w-3 h-3",e)})})}var Gr=W(le(),1);function xp({node:n,active:e,mark:t,isDirty:r,hasPendingReview:a,preview:s,pinned:o,onTogglePin:i}){let l=B(h=>h.setActiveFile),u=B(h=>h.closeFile),c=B(h=>h.activeAgentId),d=hn(),f=n.status==="deleted";return(0,Gr.jsxs)("div",{className:q("group flex items-center gap-1.5 px-3 py-2 text-xs cursor-pointer min-w-[120px] max-w-[240px] rounded-lg",e?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>{l(n.storeKey||n.path),c&&t&&d.clearFileMark({agentId:c,path:n.path})},onDoubleClick:()=>i?.(),title:n.path,children:[(0,Gr.jsx)(gp,{sourceType:n.sourceType,className:q("shrink-0",n.sourceType==="blob"?"text-sky-400/60":"text-violet-400/60")}),(0,Gr.jsxs)("span",{className:q("truncate flex-1",s&&"italic",f&&"line-through text-white/45"),children:[n.name,r?(0,Gr.jsx)("span",{className:"ml-1",style:{color:"var(--warning)"},children:"*"}):null]}),a?(0,Gr.jsx)("span",{className:"inline-flex items-center rounded-full px-1.5 py-0.5 text-[9px] font-semibold bg-amber-500/15 text-amber-200",children:"REVIEW"}):t?(0,Gr.jsx)("span",{className:q("inline-flex items-center rounded-full px-1.5 py-0.5 text-[9px] font-semibold",t==="new"?"bg-emerald-500/15 text-emerald-200":"bg-blue-500/15 text-blue-200"),children:t==="new"?"NEW":"MOD"}):null,o?(0,Gr.jsx)("button",{onClick:h=>{h.stopPropagation(),i?.()},className:"p-0.5 rounded text-amber-300/80 hover:bg-white/10",title:"Unpin tab",children:(0,Gr.jsx)(so,{className:"w-3 h-3 fill-current"})}):(0,Gr.jsx)("button",{onClick:h=>{h.stopPropagation(),u(n.storeKey||n.path)},className:q("opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-white/10"),title:"Close (double-click tab to pin)",children:(0,Gr.jsx)(Ut,{className:"w-3 h-3"})})]})}var An=W(le(),1),od="data-tab-scroller",D1="data-tab-active";function uM(n,e){return e.left<n.left?e.left-n.left:e.right>n.right?Math.min(e.right-n.right,e.left-n.left):0}function cM(n,e){return e.scrollWidth<=e.clientWidth||Math.abs(n.deltaX)>=Math.abs(n.deltaY)?0:n.deltaY}function E1(){let n=B(y=>y.openFiles),e=B(y=>y.activeFile),t=B(y=>y.files),r=B(y=>y.tabMeta),a=B(y=>y.fileContentByPath),s=B(y=>y.fileBaseContentByPath),o=B(y=>y.filePrevByPath),i=B(y=>y.activeAgentId),l=B(y=>y.reorderOpenFiles),u=B(y=>y.toggleTabPin),d=hn().useFileMarks(i??void 0)||{},[f,h]=(0,zn.useState)(null),[p,m]=(0,zn.useState)(null),g=(0,zn.useRef)(null),x=n.length>0,w=(0,zn.useCallback)(()=>{let y=g.current,C=y?.closest(`[${od}]`),k=y?.querySelector(`[${D1}="true"]`);if(!C||!k)return;let v=uM(C.getBoundingClientRect(),k.getBoundingClientRect());v!==0&&(C.scrollLeft+=v)},[]);return(0,zn.useLayoutEffect)(()=>{w()},[e,n,w]),(0,zn.useEffect)(()=>{let y=g.current?.closest(`[${od}]`);if(!y)return;let C=v=>{let b=cM(v,y);b!==0&&(v.preventDefault(),y.scrollLeft+=b)};y.addEventListener("wheel",C,{passive:!1});let k=typeof ResizeObserver<"u"?new ResizeObserver(()=>{y.clientWidth>0&&w()}):null;return k?.observe(y),()=>{y.removeEventListener("wheel",C),k?.disconnect()}},[x,w]),n.length===0?null:(0,An.jsx)("div",{ref:g,className:"flex items-center",children:n.map(y=>{let C=t[y],k=r[y],v=C?.uri??y,b=C?.name??k?.name??yt(y),P=C?.status??k?.status,N=a[y]??"",M=s[y],U=typeof M=="string"&&M!==N,A=!!o[y]&&P==="pending_review";return(0,An.jsx)("div",{draggable:!0,[D1]:e===y?"true":void 0,onDragStart:G=>{h(y),G.dataTransfer.effectAllowed="move";try{G.dataTransfer.setData("text/plain",y)}catch{}},onDragOver:G=>{G.preventDefault(),G.dataTransfer.dropEffect="move",p!==y&&m(y)},onDrop:G=>{G.preventDefault(),f&&f!==y&&l(f,y),h(null),m(null)},onDragEnd:()=>{h(null),m(null)},className:q("shrink-0 rounded-lg",p===y&&f&&f!==y?"ring-1 ring-violet-400/50":"",f===y?"opacity-50":""),children:(0,An.jsx)(xp,{node:{storeKey:C?.storeKey??y,path:v,name:b,status:P,sourceAgentId:C?.sourceAgentId??k?.sourceAgentId,sourceType:C?.sourceType},active:e===y,mark:d[v]?.kind,isDirty:U,hasPendingReview:A,preview:!!k?.preview,pinned:!!k?.pinned,onTogglePin:()=>u(y)})},y)})})}function B1(){let n=B(p=>p.openFiles),e=B(p=>p.activeFile),t=B(p=>p.closeAllFiles),r=B(p=>p.closeSavedFiles),a=B(p=>p.closeOtherFiles),s=B(p=>p.previewEditorsEnabled),o=B(p=>p.setPreviewEditorsEnabled),[i,l]=(0,zn.useState)(!1),[u,c]=(0,zn.useState)(null),d=(0,zn.useRef)(null),f=(0,zn.useRef)(null);return(0,zn.useEffect)(()=>{if(!i)return;let p=x=>{let w=x.target;d.current?.contains(w)||f.current?.contains(w)||l(!1)},m=x=>{x.key==="Escape"&&l(!1)},g=()=>l(!1);return document.addEventListener("mousedown",p),document.addEventListener("keydown",m),window.addEventListener("resize",g),window.addEventListener("scroll",g,!0),()=>{document.removeEventListener("mousedown",p),document.removeEventListener("keydown",m),window.removeEventListener("resize",g),window.removeEventListener("scroll",g,!0)}},[i]),n.length===0?null:(0,An.jsxs)("div",{className:"flex shrink-0 items-center border-l border-white/[0.05]",children:[(0,An.jsx)("button",{ref:d,type:"button",onClick:()=>{if(i){l(!1);return}let p=d.current?.getBoundingClientRect();p&&c({top:p.bottom+4,right:Math.max(4,window.innerWidth-p.right)}),l(!0)},className:q("flex items-center justify-center w-6 h-6 mx-1 rounded-md transition",i?"bg-white/10 text-white/80":"text-white/40 hover:bg-white/5 hover:text-white/70"),title:"Editor actions","aria-haspopup":"menu","aria-expanded":i,children:(0,An.jsx)(xs,{className:"w-4 h-4"})}),i&&u?(0,F1.createPortal)((0,An.jsxs)("div",{ref:f,role:"menu",style:{position:"fixed",top:u.top,right:u.right},className:"z-[1000] min-w-[190px] rounded-lg border border-white/10 bg-[#14141b] py-1 text-[11px] text-white/80 shadow-[0_18px_46px_-20px_rgba(0,0,0,0.8)]",children:[(0,An.jsx)(yp,{label:"Close All",onClick:()=>{t(),l(!1)}}),(0,An.jsx)(yp,{label:"Close Saved",onClick:()=>{r(),l(!1)}}),(0,An.jsx)(yp,{label:"Close Others",disabled:!e,onClick:()=>{e&&a(e),l(!1)}}),(0,An.jsx)("div",{className:"my-1 h-px bg-white/[0.06]"}),(0,An.jsxs)("button",{type:"button",role:"menuitemcheckbox","aria-checked":s,onClick:()=>o(!s),className:"flex w-full items-center gap-2 px-3 py-1.5 text-left hover:bg-white/[0.06]",children:[(0,An.jsx)("span",{className:"w-3.5 shrink-0 text-emerald-300",children:s?(0,An.jsx)(Dn,{className:"w-3.5 h-3.5"}):null}),(0,An.jsx)("span",{children:"Enable Preview Editors"})]})]}),document.body):null]})}function yp({label:n,onClick:e,disabled:t}){return(0,An.jsx)("button",{type:"button",role:"menuitem",disabled:t,onClick:e,className:"flex w-full items-center px-3 py-1.5 text-left hover:bg-white/[0.06] disabled:opacity-40 disabled:cursor-not-allowed",children:n})}var wo=W($e(),1);var pt=W(le(),1);function dM(n){return n<1024?`${n} B`:n<1024*1024?`${(n/1024).toFixed(1)} KB`:`${(n/(1024*1024)).toFixed(1)} MB`}function bp(n){if(!n)return null;try{return new Date(n).toLocaleString(void 0,{dateStyle:"medium",timeStyle:"short"})}catch{return n}}function wp({node:n,className:e,hideVersionDiff:t=!1}){let{tags:r,category:a,createdAt:s,updatedAt:o,metadata:i,sourceAgentId:l,version:u,readSource:c}=n,d=n.uri?Ve(n.uri):void 0,h=hn().useAgents(),p=(0,wo.useMemo)(()=>Ns(h),[h]),m=(0,wo.useMemo)(()=>l?p.byId.get(l)??null:null,[p,l]),g=m?.name||m?.slug,x=ui(m?.id,p);if(!vp(n))return null;let y=i&&typeof i.mimeType=="string"?i.mimeType:void 0,C=i&&typeof i.size=="number"?i.size:void 0,k=jl(n),v=u?.sync,b=fo(u?.changedAt),P=Ch(u?.changedAt),N=Ch(v?.syncedAt);return(0,pt.jsxs)("div",{className:q("flex flex-wrap items-center gap-1.5 px-2 py-2 text-[10px]",e),style:{background:"linear-gradient(180deg, rgba(255,255,255,0.03) 0%, rgba(255,255,255,0.01) 100%)",borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[(0,pt.jsxs)("span",{className:q("inline-flex items-center gap-1 rounded-full border px-2 py-1",k.highlightTone,"border-white/[0.07]",k.tone),children:[(0,pt.jsx)(k.icon,{className:q("w-3 h-3",k.iconTone)}),k.label]}),d?(0,pt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.03] px-2 py-1 text-white/60",children:[(0,pt.jsx)($a,{className:"w-3 h-3 text-white/35"}),(0,pt.jsx)("span",{className:"uppercase font-semibold tracking-wide",children:d})]}):null,n.os_uri?(0,pt.jsx)(fM,{value:n.os_uri}):null,g?(0,pt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.03] px-2 py-1 text-white/55",title:`Created by ${g}`,children:[(0,pt.jsx)(ml,{className:"w-3 h-3 text-white/35"}),(0,pt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wide",style:{color:x||"var(--icon-muted)",backgroundColor:x?`${x}20`:"rgba(255,255,255,0.04)"},children:[(0,pt.jsx)("span",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:x||"var(--icon-muted)"}}),g]})]}):null,a?(0,pt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.03] px-2 py-1 text-white/55",children:[(0,pt.jsx)(Br,{className:"w-3 h-3 text-white/35"}),a]}):null,r&&r.length>0?(0,pt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.03] px-2 py-1 text-white/55",children:[(0,pt.jsx)(_l,{className:"w-3 h-3 text-white/35"}),r.map(M=>(0,pt.jsx)("span",{className:"inline-flex rounded-full px-1.5 py-0.5 text-[9px] font-medium bg-white/[0.06] text-white/70",children:M},M))]}):null,y?(0,pt.jsx)("span",{className:"rounded-full border border-white/[0.06] bg-white/[0.02] px-2 py-1 text-white/40",children:y}):null,C?(0,pt.jsx)("span",{className:"rounded-full border border-white/[0.06] bg-white/[0.02] px-2 py-1 text-white/40",children:dM(C)}):null,s?(0,pt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.02] px-2 py-1 text-white/38",children:[(0,pt.jsx)(ya,{className:"w-3 h-3"}),bp(s)]}):null,o&&o!==s?(0,pt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.02] px-2 py-1 text-white/40",children:[(0,pt.jsx)(Ht,{className:"w-2.5 h-2.5"}),bp(o)]}):null,u?.changedAt?(0,pt.jsxs)("span",{className:q("inline-flex items-center gap-1 rounded-full border px-2 py-1",b.pillClassName),children:[(0,pt.jsx)(ya,{className:q("w-3 h-3",b.iconClassName)}),"changed ",P?`${P} ago`:bp(u.changedAt)]}):null,!t&&u?.diff?(0,pt.jsxs)("span",{className:q("inline-flex items-center gap-1 rounded-full border px-2 py-1",b.pillClassName),children:[(0,pt.jsx)(ar,{className:q("w-3 h-3",b.iconClassName)}),(0,pt.jsxs)("span",{className:"text-emerald-200/95",children:["+",u.diff.added]}),(0,pt.jsx)("span",{className:"text-white/25",children:"/"}),(0,pt.jsxs)("span",{className:"text-rose-200/95",children:["-",u.diff.removed]})]}):null,N?(0,pt.jsxs)("span",{className:"rounded-full border border-white/[0.06] bg-white/[0.02] px-2 py-1 text-white/38",children:["synced ",N," ago"]}):null]})}function fM({value:n}){let[e,t]=(0,wo.useState)(!1),r=(0,wo.useCallback)(()=>{navigator.clipboard.writeText(n).then(()=>{t(!0),setTimeout(()=>t(!1),1500)}).catch(()=>{})},[n]),a=n.length>60?"..."+n.slice(-57):n;return(0,pt.jsxs)("button",{type:"button",onClick:r,title:n,className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.03] px-2 py-1 text-white/45 hover:text-white/70 hover:bg-white/[0.06] transition-colors cursor-pointer",children:[e?(0,pt.jsx)(ra,{className:"w-3 h-3 text-emerald-300/80"}):(0,pt.jsx)(Gn,{className:"w-3 h-3 text-white/35"}),(0,pt.jsx)("span",{className:"font-mono truncate max-w-[280px]",children:a})]})}function vp(n){let{tags:e,category:t,createdAt:r,updatedAt:a,metadata:s,sourceAgentId:o,version:i}=n,l=n.uri?Ve(n.uri):void 0;return!!o||!!e?.length||!!t||!!l||!!n.os_uri||!!r||!!a||!!i||!!(s&&Object.keys(s).length>0)}var pf=W($e(),1);var Sp=[],U1=[];(()=>{let n="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,1n,9,16,o,,x,1i,3,,i,,7,a,2,t,3,1k,,,7,2,2,2,3,9,,a,2,q,,2,3,1k,,,5,4,2,2,3,3,,u,2,3,,b,3,1k,,,8,,3,,3,k,2,m,6,,3,1k,,,7,2,2,2,3,7,3,a,2,u,,1n,5,3,3,,4,9,,14,5,1j,,,7,,3,,4,7,2,b,2,t,3,1k,,,7,,3,,4,7,2,b,2,f,,c,4,1j,2,,7,,3,,4,9,,a,2,t,3,1y,,4,6,,,,8,i,2,1p,,,8,c,8,2q,,,a,b,7,21,2,r,,,,,,4,2,1d,k,,2,5,b,,10,9,,2u,b,,6,n,4,4,3,g,4,d,,,3,6,,f,,jj,3,qa,4,s,3,t,2,u,2,1s,w,9,,19,3,,,39,2,y,,3a,c,4,c,63,5,1l,a,,,,,2,o,2,,1c,1a,2,c,k,5,1b,h,12,9,c,3,u,d,1k,e,1c,k,48,3,,l,4,,6,,2,3,5i,1s,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,n,5,4,,2b,2,1e,i,q,i,d,,12,8,p,d,18,4,1b,e,10,,1v,e,c,,8,2,1a,,1f,,,3,2,2,5,2,,,15,5,5,2,6k,8,,2,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,1t,5,8t,2,25,6,1y,b,1d,4,3e,3,1h,f,15,,2,2,a,4,19,b,7,,1p,3,10,e,g,2,18,,c,3,1c,e,8,4,,2,2k,c,6,,2,,4d,c,l,4,1j,2,,7,2,2,2,3,9,,a,2,2,7,3,5,1v,9,,,2,,,4,,5,,,e,2,2a,i,n,,29,k,6j,7,2,9,r,2,2a,h,2y,d,2t,3,2,a,74,f,6t,6,,2,2,4,,,,2,3x,7,2,7,3,,s,a,14,7,,4,8,,9,b,1a,g,5i,8,5j,8,,8,2a,m,,e,3e,6,3,,,2,,7,,,1u,5,,2,,5,9n,4,9,2,,,1c,7,3,5,n,,44l,,6,f,8ug,i,1xc,5,1n,7,t4,,,1j,7,4,29,,b,2,f57,2,3mp,1a,2,n,f2,5,3,6,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,2s,,4g,7,af,,1p,4,e4,4,72,2,6r,,2,,7,2,5,,d6,7,31,7,240,5".split(",").map(e=>e?parseInt(e,36):1);for(let e=0,t=0;e<n.length;e++)(e%2?U1:Sp).push(t=t+n[e])})();function hM(n){if(n<768)return!1;for(let e=0,t=Sp.length;;){let r=e+t>>1;if(n<Sp[r])t=r;else if(n>=U1[r])e=r+1;else return!0;if(e==t)return!1}}function O1(n){return n>=127462&&n<=127487}var _1=8205;function G1(n,e,t=!0,r=!0){return(t?z1:pM)(n,e,r)}function z1(n,e,t){if(e==n.length)return e;e&&W1(n.charCodeAt(e))&&j1(n.charCodeAt(e-1))&&e--;let r=kp(n,e);for(e+=H1(r);e<n.length;){let a=kp(n,e);if(r==_1||a==_1||t&&hM(a))e+=H1(a),r=a;else if(O1(a)){let s=0,o=e-2;for(;o>=0&&O1(kp(n,o));)s++,o-=2;if(s%2==0)break;e+=2}else break}return e}function pM(n,e,t){for(;e>1;){let r=z1(n,e-2,t);if(r<e)return r;e--}return 0}function kp(n,e){let t=n.charCodeAt(e);if(!j1(t)||e+1==n.length)return t;let r=n.charCodeAt(e+1);return W1(r)?(t-55296<<10)+(r-56320)+65536:t}function W1(n){return n>=56320&&n<57344}function j1(n){return n>=55296&&n<56320}function H1(n){return n<65536?1:2}var ct=class n{lineAt(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,r){[e,t]=Ii(this,e,t);let a=[];return this.decompose(0,e,a,2),r.length&&r.decompose(0,r.length,a,3),this.decompose(t,this.length,a,1),Si.from(a,this.length-(t-e)+r.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=Ii(this,e,t);let r=[];return this.decompose(e,t,r,0),Si.from(r,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),r=this.length-this.scanIdentical(e,-1),a=new Co(this),s=new Co(e);for(let o=t,i=t;;){if(a.next(o),s.next(o),o=0,a.lineBreak!=s.lineBreak||a.done!=s.done||a.value!=s.value)return!1;if(i+=a.value.length,a.done||i>=r)return!0}}iter(e=1){return new Co(this,e)}iterRange(e,t=this.length){return new dd(this,e,t)}iterLines(e,t){let r;if(e==null)r=this.iter();else{t==null&&(t=this.lines+1);let a=this.line(e).from;r=this.iterRange(a,Math.max(a,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new fd(r)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?n.empty:e.length<=32?new Cr(e):Si.from(Cr.split(e,[]))}},Cr=class n extends ct{constructor(e,t=mM(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,r,a){for(let s=0;;s++){let o=this.text[s],i=a+o.length;if((t?r:i)>=e)return new Lp(a,i,r,o);a=i+1,r++}}decompose(e,t,r,a){let s=e<=0&&t>=this.length?this:new n(q1(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(a&1){let o=r.pop(),i=cd(s.text,o.text.slice(),0,s.length);if(i.length<=32)r.push(new n(i,o.length+s.length));else{let l=i.length>>1;r.push(new n(i.slice(0,l)),new n(i.slice(l)))}}else r.push(s)}replace(e,t,r){if(!(r instanceof n))return super.replace(e,t,r);[e,t]=Ii(this,e,t);let a=cd(this.text,cd(r.text,q1(this.text,0,e)),t),s=this.length+r.length-(t-e);return a.length<=32?new n(a,s):Si.from(n.split(a,[]),s)}sliceString(e,t=this.length,r=`
33
- `){[e,t]=Ii(this,e,t);let a="";for(let s=0,o=0;s<=t&&o<this.text.length;o++){let i=this.text[o],l=s+i.length;s>e&&o&&(a+=r),e<l&&t>s&&(a+=i.slice(Math.max(0,e-s),t-s)),s=l+1}return a}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(e,t){let r=[],a=-1;for(let s of e)r.push(s),a+=s.length+1,r.length==32&&(t.push(new n(r,a)),r=[],a=-1);return a>-1&&t.push(new n(r,a)),t}},Si=class n extends ct{constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let r of e)this.lines+=r.lines}lineInner(e,t,r,a){for(let s=0;;s++){let o=this.children[s],i=a+o.length,l=r+o.lines-1;if((t?l:i)>=e)return o.lineInner(e,t,r,a);a=i+1,r=l+1}}decompose(e,t,r,a){for(let s=0,o=0;o<=t&&s<this.children.length;s++){let i=this.children[s],l=o+i.length;if(e<=l&&t>=o){let u=a&((o<=e?1:0)|(l>=t?2:0));o>=e&&l<=t&&!u?r.push(i):i.decompose(e-o,t-o,r,u)}o=l+1}}replace(e,t,r){if([e,t]=Ii(this,e,t),r.lines<this.lines)for(let a=0,s=0;a<this.children.length;a++){let o=this.children[a],i=s+o.length;if(e>=s&&t<=i){let l=o.replace(e-s,t-s,r),u=this.lines-o.lines+l.lines;if(l.lines<u>>4&&l.lines>u>>6){let c=this.children.slice();return c[a]=l,new n(c,this.length-(t-e)+r.length)}return super.replace(s,i,l)}s=i+1}return super.replace(e,t,r)}sliceString(e,t=this.length,r=`
34
- `){[e,t]=Ii(this,e,t);let a="";for(let s=0,o=0;s<this.children.length&&o<=t;s++){let i=this.children[s],l=o+i.length;o>e&&s&&(a+=r),e<l&&t>o&&(a+=i.sliceString(e-o,t-o,r)),o=l+1}return a}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof n))return 0;let r=0,[a,s,o,i]=t>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;a+=t,s+=t){if(a==o||s==i)return r;let l=this.children[a],u=e.children[s];if(l!=u)return r+l.scanIdentical(u,t);r+=l.length+1}}static from(e,t=e.reduce((r,a)=>r+a.length+1,-1)){let r=0;for(let h of e)r+=h.lines;if(r<32){let h=[];for(let p of e)p.flatten(h);return new Cr(h,t)}let a=Math.max(32,r>>5),s=a<<1,o=a>>1,i=[],l=0,u=-1,c=[];function d(h){let p;if(h.lines>s&&h instanceof n)for(let m of h.children)d(m);else h.lines>o&&(l>o||!l)?(f(),i.push(h)):h instanceof Cr&&l&&(p=c[c.length-1])instanceof Cr&&h.lines+p.lines<=32?(l+=h.lines,u+=h.length+1,c[c.length-1]=new Cr(p.text.concat(h.text),p.length+1+h.length)):(l+h.lines>a&&f(),l+=h.lines,u+=h.length+1,c.push(h))}function f(){l!=0&&(i.push(c.length==1?c[0]:n.from(c,u)),u=-1,l=c.length=0)}for(let h of e)d(h);return f(),i.length==1?i[0]:new n(i,t)}};ct.empty=new Cr([""],0);function mM(n){let e=-1;for(let t of n)e+=t.length+1;return e}function cd(n,e,t=0,r=1e9){for(let a=0,s=0,o=!0;s<n.length&&a<=r;s++){let i=n[s],l=a+i.length;l>=t&&(l>r&&(i=i.slice(0,r-a)),a<t&&(i=i.slice(t-a)),o?(e[e.length-1]+=i,o=!1):e.push(i)),a=l+1}return e}function q1(n,e,t){return cd(n,[""],e,t)}var Co=class{constructor(e,t=1){this.dir=t,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[e],this.offsets=[t>0?1:(e instanceof Cr?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let r=this.nodes.length-1,a=this.nodes[r],s=this.offsets[r],o=s>>1,i=a instanceof Cr?a.text.length:a.children.length;if(o==(t>0?i:0)){if(r==0)return this.done=!0,this.value="",this;t>0&&this.offsets[r-1]++,this.nodes.pop(),this.offsets.pop()}else if((s&1)==(t>0?0:1)){if(this.offsets[r]+=t,e==0)return this.lineBreak=!0,this.value=`
35
- `,this;e--}else if(a instanceof Cr){let l=a.text[o+(t<0?-1:0)];if(this.offsets[r]+=t,l.length>Math.max(0,e))return this.value=e==0?l:t>0?l.slice(e):l.slice(0,l.length-e),this;e-=l.length}else{let l=a.children[o+(t<0?-1:0)];e>l.length?(e-=l.length,this.offsets[r]+=t):(t<0&&this.offsets[r]--,this.nodes.push(l),this.offsets.push(t>0?1:(l instanceof Cr?l.text.length:l.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}},dd=class{constructor(e,t,r){this.value="",this.done=!1,this.cursor=new Co(e,t>r?-1:1),this.pos=t>r?e.length:0,this.from=Math.min(t,r),this.to=Math.max(t,r)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let r=t<0?this.pos-this.from:this.to-this.pos;e>r&&(e=r),r-=e;let{value:a}=this.cursor.next(e);return this.pos+=(a.length+e)*t,this.value=a.length<=r?a:t<0?a.slice(a.length-r):a.slice(0,r),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}},fd=class{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:t,lineBreak:r,value:a}=this.inner.next(e);return t&&this.afterBreak?(this.value="",this.afterBreak=!1):t?(this.done=!0,this.value=""):r?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=a,this.afterBreak=!1),this}get lineBreak(){return!1}};typeof Symbol<"u"&&(ct.prototype[Symbol.iterator]=function(){return this.iter()},Co.prototype[Symbol.iterator]=dd.prototype[Symbol.iterator]=fd.prototype[Symbol.iterator]=function(){return this});var Lp=class{constructor(e,t,r,a){this.from=e,this.to=t,this.number=r,this.text=a}get length(){return this.to-this.from}};function Ii(n,e,t){return e=Math.max(0,Math.min(n.length,e)),[e,Math.max(e,Math.min(n.length,t))]}function Nn(n,e,t=!0,r=!0){return G1(n,e,t,r)}function gM(n){return n>=56320&&n<57344}function xM(n){return n>=55296&&n<56320}function Y1(n,e){let t=n.charCodeAt(e);if(!xM(t)||e+1==n.length)return t;let r=n.charCodeAt(e+1);return gM(r)?(t-55296<<10)+(r-56320)+65536:t}function J1(n){return n<65536?1:2}var Ip=/\r\n?|\n/,ir=(function(n){return n[n.Simple=0]="Simple",n[n.TrackDel=1]="TrackDel",n[n.TrackBefore=2]="TrackBefore",n[n.TrackAfter=3]="TrackAfter",n})(ir||(ir={})),ts=class n{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let r=this.sections[t+1];e+=r<0?this.sections[t]:r}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,r=0,a=0;t<this.sections.length;){let s=this.sections[t++],o=this.sections[t++];o<0?(e(r,a,s),a+=s):a+=o,r+=s}}iterChangedRanges(e,t=!1){Ap(this,e,t)}get invertedDesc(){let e=[];for(let t=0;t<this.sections.length;){let r=this.sections[t++],a=this.sections[t++];a<0?e.push(r,a):e.push(a,r)}return new n(e)}composeDesc(e){return this.empty?e:e.empty?this:Z1(this,e)}mapDesc(e,t=!1){return e.empty?this:Pp(this,e,t)}mapPos(e,t=-1,r=ir.Simple){let a=0,s=0;for(let o=0;o<this.sections.length;){let i=this.sections[o++],l=this.sections[o++],u=a+i;if(l<0){if(u>e)return s+(e-a);s+=i}else{if(r!=ir.Simple&&u>=e&&(r==ir.TrackDel&&a<e&&u>e||r==ir.TrackBefore&&a<e||r==ir.TrackAfter&&u>e))return null;if(u>e||u==e&&t<0&&!i)return e==a||t<0?s:s+l;s+=l}a=u}if(e>a)throw new RangeError(`Position ${e} is out of range for changeset of length ${a}`);return s}touchesRange(e,t=e){for(let r=0,a=0;r<this.sections.length&&a<=t;){let s=this.sections[r++],o=this.sections[r++],i=a+s;if(o>=0&&a<=t&&i>=e)return a<e&&i>t?"cover":!0;a=i}return!1}toString(){let e="";for(let t=0;t<this.sections.length;){let r=this.sections[t++],a=this.sections[t++];e+=(e?" ":"")+r+(a>=0?":"+a:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(t=>typeof t!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new n(e)}static create(e){return new n(e)}},Rn=class n extends ts{constructor(e,t){super(e),this.inserted=t}apply(e){if(this.length!=e.length)throw new RangeError("Applying change set to a document with the wrong length");return Ap(this,(t,r,a,s,o)=>e=e.replace(a,a+(r-t),o),!1),e}mapDesc(e,t=!1){return Pp(this,e,t,!0)}invert(e){let t=this.sections.slice(),r=[];for(let a=0,s=0;a<t.length;a+=2){let o=t[a],i=t[a+1];if(i>=0){t[a]=i,t[a+1]=o;let l=a>>1;for(;r.length<l;)r.push(ct.empty);r.push(o?e.slice(s,s+o):ct.empty)}s+=o}return new n(t,r)}compose(e){return this.empty?e:e.empty?this:Z1(this,e,!0)}map(e,t=!1){return e.empty?this:Pp(this,e,t,!0)}iterChanges(e,t=!1){Ap(this,e,t)}get desc(){return ts.create(this.sections)}filter(e){let t=[],r=[],a=[],s=new Lo(this);e:for(let o=0,i=0;;){let l=o==e.length?1e9:e[o++];for(;i<l||i==l&&s.len==0;){if(s.done)break e;let c=Math.min(s.len,l-i);Wn(a,c,-1);let d=s.ins==-1?-1:s.off==0?s.ins:0;Wn(t,c,d),d>0&&Os(r,t,s.text),s.forward(c),i+=c}let u=e[o++];for(;i<u;){if(s.done)break e;let c=Math.min(s.len,u-i);Wn(t,c,-1),Wn(a,c,s.ins==-1?-1:s.off==0?s.ins:0),s.forward(c),i+=c}}return{changes:new n(t,r),filtered:ts.create(a)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let r=this.sections[t],a=this.sections[t+1];a<0?e.push(r):a==0?e.push([r]):e.push([r].concat(this.inserted[t>>1].toJSON()))}return e}static of(e,t,r){let a=[],s=[],o=0,i=null;function l(c=!1){if(!c&&!a.length)return;o<t&&Wn(a,t-o,-1);let d=new n(a,s);i=i?i.compose(d.map(i)):d,a=[],s=[],o=0}function u(c){if(Array.isArray(c))for(let d of c)u(d);else if(c instanceof n){if(c.length!=t)throw new RangeError(`Mismatched change set length (got ${c.length}, expected ${t})`);l(),i=i?i.compose(c.map(i)):c}else{let{from:d,to:f=d,insert:h}=c;if(d>f||d<0||f>t)throw new RangeError(`Invalid change range ${d} to ${f} (in doc of length ${t})`);let p=h?typeof h=="string"?ct.of(h.split(r||Ip)):h:ct.empty,m=p.length;if(d==f&&m==0)return;d<o&&l(),d>o&&Wn(a,d-o,-1),Wn(a,f-d,m),Os(s,a,p),o=f}}return u(e),l(!i),i}static empty(e){return new n(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],r=[];for(let a=0;a<e.length;a++){let s=e[a];if(typeof s=="number")t.push(s,-1);else{if(!Array.isArray(s)||typeof s[0]!="number"||s.some((o,i)=>i&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(s.length==1)t.push(s[0],0);else{for(;r.length<a;)r.push(ct.empty);r[a]=ct.of(s.slice(1)),t.push(s[0],r[a].length)}}}return new n(t,r)}static createSet(e,t){return new n(e,t)}};function Wn(n,e,t,r=!1){if(e==0&&t<=0)return;let a=n.length-2;a>=0&&t<=0&&t==n[a+1]?n[a]+=e:a>=0&&e==0&&n[a]==0?n[a+1]+=t:r?(n[a]+=e,n[a+1]+=t):n.push(e,t)}function Os(n,e,t){if(t.length==0)return;let r=e.length-2>>1;if(r<n.length)n[n.length-1]=n[n.length-1].append(t);else{for(;n.length<r;)n.push(ct.empty);n.push(t)}}function Ap(n,e,t){let r=n.inserted;for(let a=0,s=0,o=0;o<n.sections.length;){let i=n.sections[o++],l=n.sections[o++];if(l<0)a+=i,s+=i;else{let u=a,c=s,d=ct.empty;for(;u+=i,c+=l,l&&r&&(d=d.append(r[o-2>>1])),!(t||o==n.sections.length||n.sections[o+1]<0);)i=n.sections[o++],l=n.sections[o++];e(a,u,s,c,d),a=u,s=c}}}function Pp(n,e,t,r=!1){let a=[],s=r?[]:null,o=new Lo(n),i=new Lo(e);for(let l=-1;;){if(o.done&&i.len||i.done&&o.len)throw new Error("Mismatched change set lengths");if(o.ins==-1&&i.ins==-1){let u=Math.min(o.len,i.len);Wn(a,u,-1),o.forward(u),i.forward(u)}else if(i.ins>=0&&(o.ins<0||l==o.i||o.off==0&&(i.len<o.len||i.len==o.len&&!t))){let u=i.len;for(Wn(a,i.ins,-1);u;){let c=Math.min(o.len,u);o.ins>=0&&l<o.i&&o.len<=c&&(Wn(a,0,o.ins),s&&Os(s,a,o.text),l=o.i),o.forward(c),u-=c}i.next()}else if(o.ins>=0){let u=0,c=o.len;for(;c;)if(i.ins==-1){let d=Math.min(c,i.len);u+=d,c-=d,i.forward(d)}else if(i.ins==0&&i.len<c)c-=i.len,i.next();else break;Wn(a,u,l<o.i?o.ins:0),s&&l<o.i&&Os(s,a,o.text),l=o.i,o.forward(o.len-c)}else{if(o.done&&i.done)return s?Rn.createSet(a,s):ts.create(a);throw new Error("Mismatched change set lengths")}}}function Z1(n,e,t=!1){let r=[],a=t?[]:null,s=new Lo(n),o=new Lo(e);for(let i=!1;;){if(s.done&&o.done)return a?Rn.createSet(r,a):ts.create(r);if(s.ins==0)Wn(r,s.len,0,i),s.next();else if(o.len==0&&!o.done)Wn(r,0,o.ins,i),a&&Os(a,r,o.text),o.next();else{if(s.done||o.done)throw new Error("Mismatched change set lengths");{let l=Math.min(s.len2,o.len),u=r.length;if(s.ins==-1){let c=o.ins==-1?-1:o.off?0:o.ins;Wn(r,l,c,i),a&&c&&Os(a,r,o.text)}else o.ins==-1?(Wn(r,s.off?0:s.len,l,i),a&&Os(a,r,s.textBit(l))):(Wn(r,s.off?0:s.len,o.off?0:o.ins,i),a&&!o.off&&Os(a,r,o.text));i=(s.ins>l||o.ins>=0&&o.len>l)&&(i||r.length>u),s.forward2(l),o.forward(l)}}}}var Lo=class{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,t=this.i-2>>1;return t>=e.length?ct.empty:e[t]}textBit(e){let{inserted:t}=this.set,r=this.i-2>>1;return r>=t.length&&!e?ct.empty:t[r].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}},vo=class n{constructor(e,t,r,a){this.from=e,this.to=t,this.flags=r,this.goalColumn=a}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get undirectional(){return(this.flags&64)>0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}map(e,t=-1){let r,a;return this.empty?r=a=e.mapPos(this.from,t):(r=e.mapPos(this.from,1),a=e.mapPos(this.to,-1)),r==this.from&&a==this.to?this:new n(r,a,this.flags,this.goalColumn)}extend(e,t=e,r=0){if(e<=this.anchor&&t>=this.anchor)return se.range(e,t,void 0,void 0,r);let a=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return se.range(this.anchor,a,void 0,void 0,r)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&this.goalColumn==e.goalColumn&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return se.range(e.anchor,e.head)}static create(e,t,r,a){return new n(e,t,r,a)}},se=class n{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:n.create(this.ranges.map(r=>r.map(e,t)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let r=0;r<this.ranges.length;r++)if(!this.ranges[r].eq(e.ranges[r],t))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new n([this.main],0)}addRange(e,t=!0){return n.create([e].concat(this.ranges),t?0:this.mainIndex+1)}replaceRange(e,t=this.mainIndex){let r=this.ranges.slice();return r[t]=e,n.create(r,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new n(e.ranges.map(t=>vo.fromJSON(t)),e.main)}static single(e,t=e){return new n([n.range(e,t)],0)}static create(e,t=0){if(e.length==0)throw new RangeError("A selection needs at least one range");for(let r=0,a=0;a<e.length;a++){let s=e[a];if(s.empty?s.from<=r:s.from<r)return n.normalized(e.slice(),t);r=s.to}return new n(e,t)}static cursor(e,t=0,r,a){return vo.create(e,e,(t==0?0:t<0?8:16)|(r==null?7:Math.min(6,r)),a)}static range(e,t,r,a,s){let o=a==null?7:Math.min(6,a);return!s&&e!=t&&(s=t<e?1:-1),s&&(o|=s<0?8:16),t<e?vo.create(t,e,o|32,r):vo.create(e,t,o,r)}static undirectionalRange(e,t){return vo.create(e,t,64,void 0)}static normalized(e,t=0){let r=e[t];e.sort((a,s)=>a.from-s.from),t=e.indexOf(r);for(let a=1;a<e.length;a++){let s=e[a],o=e[a-1];if(s.empty?s.from<=o.to:s.from<o.to){let i=o.from,l=Math.max(s.to,o.to);a<=t&&t--,e.splice(--a,2,s.anchor>s.head?n.range(l,i):n.range(i,l))}}return new n(e,t)}};function Q1(n,e){for(let t of n.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}var _p=0,Me=class n{constructor(e,t,r,a,s){this.combine=e,this.compareInput=t,this.compare=r,this.isStatic=a,this.id=_p++,this.default=e([]),this.extensions=typeof s=="function"?s(this):s}get reader(){return this}static define(e={}){return new n(e.combine||(t=>t),e.compareInput||((t,r)=>t===r),e.compare||(e.combine?(t,r)=>t===r:Hp),!!e.static,e.enables)}of(e){return new Ci([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Ci(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Ci(e,this,2,t)}from(e,t){return t||(t=r=>r),this.compute([e],r=>t(r.field(e)))}};function Hp(n,e){return n==e||n.length==e.length&&n.every((t,r)=>t===e[r])}var Ci=class{constructor(e,t,r,a){this.dependencies=e,this.facet=t,this.type=r,this.value=a,this.id=_p++}dynamicSlot(e){var t;let r=this.value,a=this.facet.compareInput,s=this.id,o=e[s]>>1,i=this.type==2,l=!1,u=!1,c=[];for(let d of this.dependencies)d=="doc"?l=!0:d=="selection"?u=!0:(((t=e[d.id])!==null&&t!==void 0?t:1)&1)==0&&c.push(e[d.id]);return{create(d){return d.values[o]=r(d),1},update(d,f){if(l&&f.docChanged||u&&(f.docChanged||f.selection)||Np(d,c)){let h=r(d);if(i?!V1(h,d.values[o],a):!a(h,d.values[o]))return d.values[o]=h,1}return 0},reconfigure:(d,f)=>{let h,p=f.config.address[s];if(p!=null){let m=md(f,p);if(this.dependencies.every(g=>g instanceof Me?f.facet(g)===d.facet(g):g instanceof vn?f.field(g,!1)==d.field(g,!1):!0)||(i?V1(h=r(d),m,a):a(h=r(d),m)))return d.values[o]=m,0}else h=r(d);return d.values[o]=h,1}}}get extension(){return this}};function V1(n,e,t){if(n.length!=e.length)return!1;for(let r=0;r<n.length;r++)if(!t(n[r],e[r]))return!1;return!0}function Np(n,e){let t=!1;for(let r of e)su(n,r)&1&&(t=!0);return t}function yM(n,e,t){let r=t.map(l=>n[l.id]),a=t.map(l=>l.type),s=r.filter(l=>!(l&1)),o=n[e.id]>>1;function i(l){let u=[];for(let c=0;c<r.length;c++){let d=md(l,r[c]);if(a[c]==2)for(let f of d)u.push(f);else u.push(d)}return e.combine(u)}return{create(l){for(let u of r)su(l,u);return l.values[o]=i(l),1},update(l,u){if(!Np(l,s))return 0;let c=i(l);return e.compare(c,l.values[o])?0:(l.values[o]=c,1)},reconfigure(l,u){let c=Np(l,r),d=u.config.facets[e.id],f=u.facet(e);if(d&&!c&&Hp(t,d))return l.values[o]=f,0;let h=i(l);return e.compare(h,f)?(l.values[o]=f,0):(l.values[o]=h,1)}}}var id=Me.define({static:!0}),vn=class n{constructor(e,t,r,a,s){this.id=e,this.createF=t,this.updateF=r,this.compareF=a,this.spec=s,this.provides=void 0}static define(e){let t=new n(_p++,e.create,e.update,e.compare||((r,a)=>r===a),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(id).find(r=>r.field==this);return(t?.create||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:r=>(r.values[t]=this.create(r),1),update:(r,a)=>{let s=r.values[t],o=this.updateF(s,a);return this.compareF(s,o)?0:(r.values[t]=o,1)},reconfigure:(r,a)=>{let s=r.facet(id),o=a.facet(id),i;return(i=s.find(l=>l.field==this))&&i!=o.find(l=>l.field==this)?(r.values[t]=i.create(r),1):a.config.address[this.id]!=null?(r.values[t]=a.field(this),0):(r.values[t]=this.create(r),1)}}}init(e){return[this,id.of({field:this,create:e})]}get extension(){return this}},ko={lowest:4,low:3,default:2,high:1,highest:0};function au(n){return e=>new hd(e,n)}var Na={highest:au(ko.highest),high:au(ko.high),default:au(ko.default),low:au(ko.low),lowest:au(ko.lowest)},hd=class{constructor(e,t){this.inner=e,this.prec=t}get extension(){return this}},zr=class n{of(e){return new ou(this,e)}reconfigure(e){return n.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}},ou=class{constructor(e,t){this.compartment=e,this.inner=t}get extension(){return this}},pd=class n{constructor(e,t,r,a,s,o){for(this.base=e,this.compartments=t,this.dynamicSlots=r,this.address=a,this.staticValues=s,this.facets=o,this.statusTemplate=[];this.statusTemplate.length<r.length;)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return t==null?e.default:this.staticValues[t>>1]}static resolve(e,t,r){let a=[],s=Object.create(null),o=new Map;for(let f of bM(e,t,o))f instanceof vn?a.push(f):(s[f.facet.id]||(s[f.facet.id]=[])).push(f);let i=Object.create(null),l=[],u=[];for(let f of a)i[f.id]=u.length<<1,u.push(h=>f.slot(h));let c=r?.config.facets;for(let f in s){let h=s[f],p=h[0].facet,m=c&&c[f]||[];if(h.every(g=>g.type==0))if(i[p.id]=l.length<<1|1,Hp(m,h))l.push(r.facet(p));else{let g=p.combine(h.map(x=>x.value));l.push(r&&p.compare(g,r.facet(p))?r.facet(p):g)}else{for(let g of h)g.type==0?(i[g.id]=l.length<<1|1,l.push(g.value)):(i[g.id]=u.length<<1,u.push(x=>g.dynamicSlot(x)));i[p.id]=u.length<<1,u.push(g=>yM(g,p,h))}}let d=u.map(f=>f(i));return new n(e,o,d,i,l,s)}};function bM(n,e,t){let r=[[],[],[],[],[]],a=new Map;function s(o,i){let l=a.get(o);if(l!=null){if(l<=i)return;let u=r[l].indexOf(o);u>-1&&r[l].splice(u,1),o instanceof ou&&t.delete(o.compartment)}if(a.set(o,i),Array.isArray(o))for(let u of o)s(u,i);else if(o instanceof ou){if(t.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let u=e.get(o.compartment)||o.inner;t.set(o.compartment,u),s(u,i)}else if(o instanceof hd)s(o.inner,o.prec);else if(o instanceof vn)r[i].push(o),o.provides&&s(o.provides,i);else if(o instanceof Ci)r[i].push(o),o.facet.extensions&&s(o.facet.extensions,ko.default);else{let u=o.extension;if(!u)throw new Error(`Unrecognized extension value in extension set (${o}).`);if(u==o)throw new Error(`Unrecognized extension value in extension set (${o}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);s(u,i)}}return s(n,ko.default),r.reduce((o,i)=>o.concat(i))}function su(n,e){if(e&1)return 2;let t=e>>1,r=n.status[t];if(r==4)throw new Error("Cyclic dependency between fields and/or facets");if(r&2)return r;n.status[t]=4;let a=n.computeSlot(n,n.config.dynamicSlots[t]);return n.status[t]=2|a}function md(n,e){return e&1?n.config.staticValues[e>>1]:n.values[e>>1]}var ek=Me.define(),Rp=Me.define({combine:n=>n.some(e=>e),static:!0}),tk=Me.define({combine:n=>n.length?n[0]:void 0,static:!0}),nk=Me.define(),rk=Me.define(),ak=Me.define(),sk=Me.define({combine:n=>n.length?n[0]:!1}),Wr=class{constructor(e,t){this.type=e,this.value=t}static define(){return new Mp}},Mp=class{of(e){return new Wr(this,e)}},Tp=class{constructor(e){this.map=e}of(e){return new xt(this,e)}},xt=class n{constructor(e,t){this.type=e,this.value=t}map(e){let t=this.type.map(this.value,e);return t===void 0?void 0:t==this.value?this:new n(this.type,t)}is(e){return this.type==e}static define(e={}){return new Tp(e.map||(t=>t))}static mapEffects(e,t){if(!e.length)return e;let r=[];for(let a of e){let s=a.map(t);s&&r.push(s)}return r}};xt.reconfigure=xt.define();xt.appendConfig=xt.define();var Pn=class n{constructor(e,t,r,a,s,o){this.startState=e,this.changes=t,this.selection=r,this.effects=a,this.annotations=s,this.scrollIntoView=o,this._doc=null,this._state=null,r&&Q1(r,t.newLength),s.some(i=>i.type==n.time)||(this.annotations=s.concat(n.time.of(Date.now())))}static create(e,t,r,a,s,o){return new n(e,t,r,a,s,o)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(e){let t=this.annotation(n.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}};Pn.time=Wr.define();Pn.userEvent=Wr.define();Pn.addToHistory=Wr.define();Pn.remote=Wr.define();function wM(n,e){let t=[];for(let r=0,a=0;;){let s,o;if(r<n.length&&(a==e.length||e[a]>=n[r]))s=n[r++],o=n[r++];else if(a<e.length)s=e[a++],o=e[a++];else return t;!t.length||t[t.length-1]<s?t.push(s,o):t[t.length-1]<o&&(t[t.length-1]=o)}}function ok(n,e,t){var r;let a,s,o;return t?(a=e.changes,s=Rn.empty(e.changes.length),o=n.changes.compose(e.changes)):(a=e.changes.map(n.changes),s=n.changes.mapDesc(e.changes,!0),o=n.changes.compose(a)),{changes:o,selection:e.selection?e.selection.map(s):(r=n.selection)===null||r===void 0?void 0:r.map(a),effects:xt.mapEffects(n.effects,a).concat(xt.mapEffects(e.effects,s)),annotations:n.annotations.length?n.annotations.concat(e.annotations):e.annotations,scrollIntoView:n.scrollIntoView||e.scrollIntoView}}function Dp(n,e,t){let r=e.selection,a=Li(e.annotations);return e.userEvent&&(a=a.concat(Pn.userEvent.of(e.userEvent))),{changes:e.changes instanceof Rn?e.changes:Rn.of(e.changes||[],t,n.facet(tk)),selection:r&&(r instanceof se?r:se.single(r.anchor,r.head)),effects:Li(e.effects),annotations:a,scrollIntoView:!!e.scrollIntoView}}function ik(n,e,t){let r=Dp(n,e.length?e[0]:{},n.doc.length);e.length&&e[0].filter===!1&&(t=!1);for(let s=1;s<e.length;s++){e[s].filter===!1&&(t=!1);let o=!!e[s].sequential;r=ok(r,Dp(n,e[s],o?r.changes.newLength:n.doc.length),o)}let a=Pn.create(n,r.changes,r.selection,r.effects,r.annotations,r.scrollIntoView);return kM(t?vM(a):a)}function vM(n){let e=n.startState,t=!0;for(let a of e.facet(nk)){let s=a(n);if(s===!1){t=!1;break}Array.isArray(s)&&(t=t===!0?s:wM(t,s))}if(t!==!0){let a,s;if(t===!1)s=n.changes.invertedDesc,a=Rn.empty(e.doc.length);else{let o=n.changes.filter(t);a=o.changes,s=o.filtered.mapDesc(o.changes).invertedDesc}n=Pn.create(e,a,n.selection&&n.selection.map(s),xt.mapEffects(n.effects,s),n.annotations,n.scrollIntoView)}let r=e.facet(rk);for(let a=r.length-1;a>=0;a--){let s=r[a](n);s instanceof Pn?n=s:Array.isArray(s)&&s.length==1&&s[0]instanceof Pn?n=s[0]:n=ik(e,Li(s),!1)}return n}function kM(n){let e=n.startState,t=e.facet(ak),r=n;for(let a=t.length-1;a>=0;a--){let s=t[a](n);s&&Object.keys(s).length&&(r=ok(r,Dp(e,s,n.changes.newLength),!0))}return r==n?n:Pn.create(e,n.changes,n.selection,r.effects,r.annotations,r.scrollIntoView)}var SM=[];function Li(n){return n==null?SM:Array.isArray(n)?n:[n]}var oa=(function(n){return n[n.Word=0]="Word",n[n.Space=1]="Space",n[n.Other=2]="Other",n})(oa||(oa={})),CM=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/,Fp;try{Fp=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function LM(n){if(Fp)return Fp.test(n);for(let e=0;e<n.length;e++){let t=n[e];if(/\w/.test(t)||t>"\x80"&&(t.toUpperCase()!=t.toLowerCase()||CM.test(t)))return!0}return!1}function IM(n){return e=>{if(!/\S/.test(e))return oa.Space;if(LM(e))return oa.Word;for(let t=0;t<n.length;t++)if(e.indexOf(n[t])>-1)return oa.Word;return oa.Other}}var Ct=class n{constructor(e,t,r,a,s,o){this.config=e,this.doc=t,this.selection=r,this.values=a,this.status=e.statusTemplate.slice(),this.computeSlot=s,o&&(o._state=this);for(let i=0;i<this.config.dynamicSlots.length;i++)su(this,i<<1);this.computeSlot=null}field(e,t=!0){let r=this.config.address[e.id];if(r==null){if(t)throw new RangeError("Field is not present in this state");return}return su(this,r),md(this,r)}update(...e){return ik(this,e,!0)}applyTransaction(e){let t=this.config,{base:r,compartments:a}=t;for(let i of e.effects)i.is(zr.reconfigure)?(t&&(a=new Map,t.compartments.forEach((l,u)=>a.set(u,l)),t=null),a.set(i.value.compartment,i.value.extension)):i.is(xt.reconfigure)?(t=null,r=i.value):i.is(xt.appendConfig)&&(t=null,r=Li(r).concat(i.value));let s;t?s=e.startState.values.slice():(t=pd.resolve(r,a,this),s=new n(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(l,u)=>u.reconfigure(l,this),null).values);let o=e.startState.facet(Rp)?e.newSelection:e.newSelection.asSingle();new n(t,e.newDoc,o,s,(i,l)=>l.update(i,e),e)}replaceSelection(e){return typeof e=="string"&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:se.cursor(t.from+e.length,-1)}))}changeByRange(e){let t=this.selection,r=e(t.ranges[0]),a=this.changes(r.changes),s=[r.range],o=Li(r.effects);for(let i=1;i<t.ranges.length;i++){let l=e(t.ranges[i]),u=this.changes(l.changes),c=u.map(a);for(let f=0;f<i;f++)s[f]=s[f].map(c);let d=a.mapDesc(u,!0);s.push(l.range.map(d)),a=a.compose(c),o=xt.mapEffects(o,c).concat(xt.mapEffects(Li(l.effects),d))}return{changes:a,selection:se.create(s,t.mainIndex),effects:o}}changes(e=[]){return e instanceof Rn?e:Rn.of(e,this.doc.length,this.facet(n.lineSeparator))}toText(e){return ct.of(e.split(this.facet(n.lineSeparator)||Ip))}sliceDoc(e=0,t=this.doc.length){return this.doc.sliceString(e,t,this.lineBreak)}facet(e){let t=this.config.address[e.id];return t==null?e.default:(su(this,t),md(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let r in e){let a=e[r];a instanceof vn&&this.config.address[a.id]!=null&&(t[r]=a.spec.toJSON(this.field(e[r]),this))}return t}static fromJSON(e,t={},r){if(!e||typeof e.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let a=[];if(r){for(let s in r)if(Object.prototype.hasOwnProperty.call(e,s)){let o=r[s],i=e[s];a.push(o.init(l=>o.spec.fromJSON(i,l)))}}return n.create({doc:e.doc,selection:se.fromJSON(e.selection),extensions:t.extensions?a.concat([t.extensions]):a})}static create(e={}){let t=pd.resolve(e.extensions||[],new Map),r=e.doc instanceof ct?e.doc:ct.of((e.doc||"").split(t.staticFacet(n.lineSeparator)||Ip)),a=e.selection?e.selection instanceof se?e.selection:se.single(e.selection.anchor,e.selection.head):se.single(0);return Q1(a,r.length),t.staticFacet(Rp)||(a=a.asSingle()),new n(t,r,a,t.dynamicSlots.map(()=>null),(s,o)=>o.create(s),null)}get tabSize(){return this.facet(n.tabSize)}get lineBreak(){return this.facet(n.lineSeparator)||`
36
- `}get readOnly(){return this.facet(sk)}phrase(e,...t){for(let r of this.facet(n.phrases))if(Object.prototype.hasOwnProperty.call(r,e)){e=r[e];break}return t.length&&(e=e.replace(/\$(\$|\d*)/g,(r,a)=>{if(a=="$")return"$";let s=+(a||1);return!s||s>t.length?r:t[s-1]})),e}languageDataAt(e,t,r=-1){let a=[];for(let s of this.facet(ek))for(let o of s(this,t,r))Object.prototype.hasOwnProperty.call(o,e)&&a.push(o[e]);return a}charCategorizer(e){let t=this.languageDataAt("wordChars",e);return IM(t.length?t[0]:"")}wordAt(e){let{text:t,from:r,length:a}=this.doc.lineAt(e),s=this.charCategorizer(e),o=e-r,i=e-r;for(;o>0;){let l=Nn(t,o,!1);if(s(t.slice(l,o))!=oa.Word)break;o=l}for(;i<a;){let l=Nn(t,i);if(s(t.slice(i,l))!=oa.Word)break;i=l}return o==i?null:se.range(o+r,i+r)}};Ct.allowMultipleSelections=Rp;Ct.tabSize=Me.define({combine:n=>n.length?n[0]:4});Ct.lineSeparator=tk;Ct.readOnly=sk;Ct.phrases=Me.define({compare(n,e){let t=Object.keys(n),r=Object.keys(e);return t.length==r.length&&t.every(a=>n[a]==e[a])}});Ct.languageData=ek;Ct.changeFilter=nk;Ct.transactionFilter=rk;Ct.transactionExtender=ak;zr.reconfigure=xt.define();function Ai(n,e,t={}){let r={};for(let a of n)for(let s of Object.keys(a)){let o=a[s],i=r[s];if(i===void 0)r[s]=o;else if(!(i===o||o===void 0))if(Object.hasOwnProperty.call(t,s))r[s]=t[s](i,o);else throw new Error("Config merge conflict for field "+s)}for(let a in e)r[a]===void 0&&(r[a]=e[a]);return r}var Pa=class{eq(e){return this==e}range(e,t=e){return iu.create(e,t,this)}};Pa.prototype.startSide=Pa.prototype.endSide=0;Pa.prototype.point=!1;Pa.prototype.mapMode=ir.TrackDel;function Up(n,e){return n==e||n.constructor==e.constructor&&n.eq(e)}var iu=class n{constructor(e,t,r){this.from=e,this.to=t,this.value=r}static create(e,t,r){return new n(e,t,r)}};function Ep(n,e){return n.from-e.from||n.value.startSide-e.value.startSide}var Bp=class n{constructor(e,t,r,a){this.from=e,this.to=t,this.value=r,this.maxPoint=a}get length(){return ki(this.to)}findIndex(e,t,r,a=0){let s=r?this.to:this.from;for(let o=a,i=s.length;;){if(o==i)return o;let l=o+i>>1,u=s[l]-e||(r?this.value[l].endSide:this.value[l].startSide)-t;if(l==o)return u>=0?o:i;u>=0?i=l:o=l+1}}between(e,t,r,a){for(let s=this.findIndex(t,-1e9,!0),o=this.findIndex(r,1e9,!1,s);s<o;s++)if(a(this.from[s]+e,this.to[s]+e,this.value[s])===!1)return!1}map(e,t,r,a,s){let o=[],i=[],l=[],u=-1,c=-1;e:for(let d=0;d<this.value.length;d++){let f=this.value[d],h=this.from[d]+e,p=this.to[d]+e,m,g;if(h==p){let x=t.mapPos(h,f.startSide,f.mapMode);if(x==null||(m=g=x,f.startSide!=f.endSide&&(g=t.mapPos(h,f.endSide),g<m)))continue}else if(m=t.mapPos(h,f.startSide),g=t.mapPos(p,f.endSide),m>g||m==g&&f.startSide>0&&f.endSide<=0)continue;if(!((g-m||f.endSide-f.startSide)<0))if(u<0&&(u=m),f.point&&(c=Math.max(c,g-m)),(m-r||f.startSide-a)>=0)o.push(f),i.push(m-u),l.push(g-u),r=g,a=f.endSide;else{if(m==g)for(let x=o.length;x>0;x--){if((m-(l[x-1]+u)||f.startSide-o[x-1].endSide)>=0){o.splice(x,0,f),i.splice(x,0,m-u),l.splice(x,0,g-u);continue e}if((m-(i[x-1]+u)||f.endSide-o[x-1].startSide)>0)break}s(m,g,f)}}return{mapped:o.length?new n(i,l,o,c):null,pos:u}}},wt=class n{constructor(e,t,r,a){this.chunkPos=e,this.chunk=t,this.nextLayer=r,this.maxPoint=a}static create(e,t,r,a){return new n(e,t,r,a)}get length(){let e=this.chunk.length-1;return e<0?0:Math.max(this.chunkEnd(e),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let e=this.nextLayer.size;for(let t of this.chunk)e+=t.value.length;return e}chunkEnd(e){return this.chunkPos[e]+this.chunk[e].length}update(e){let{add:t=[],sort:r=!1,filterFrom:a=0,filterTo:s=this.length}=e,o=e.filter;if(t.length==0&&!o)return this;if(r&&(t=t.slice().sort(Ep)),this.isEmpty)return t.length?n.of(t):this;let i=new gd(this,null,-1).goto(0),l=0,u=[],c=new jn;for(;i.value||l<t.length;)if(l<t.length&&(i.from-t[l].from||i.startSide-t[l].value.startSide)>=0){let d=t[l++];c.addInner(d.from,d.to,d.value,!1)||u.push(d)}else i.rangeIndex==1&&i.chunkIndex<this.chunk.length&&(l==t.length||this.chunkEnd(i.chunkIndex)<t[l].from)&&(!o||a>this.chunkEnd(i.chunkIndex)||s<this.chunkPos[i.chunkIndex])&&c.addChunk(this.chunkPos[i.chunkIndex],this.chunk[i.chunkIndex])?i.nextChunk():((!o||a>i.to||s<i.from||o(i.from,i.to,i.value))&&(c.addInner(i.from,i.to,i.value,!1)||u.push(iu.create(i.from,i.to,i.value))),i.next());return c.finishInner(this.nextLayer.isEmpty&&!u.length?n.empty:this.nextLayer.update({add:u,filter:o,filterFrom:a,filterTo:s}))}map(e){if(e.empty||this.isEmpty)return this;let t=[],r=[],a=-1,s,o=(l,u,c)=>{s||(s=new jn),s.addRange(l,u,c,!1)};for(let l=0;l<this.chunk.length;l++){let u=this.chunkPos[l],c=this.chunk[l],d=e.touchesRange(u,u+c.length);if(d===!1)a=Math.max(a,c.maxPoint),t.push(c),r.push(e.mapPos(u));else if(d===!0){let[f,h]=t.length?[ki(r)+ki(t).length,ki(ki(t).value).endSide]:[-1,-1],{mapped:p,pos:m}=c.map(u,e,f,h,o);p&&(a=Math.max(a,p.maxPoint),t.push(p),r.push(m))}}let i=this.nextLayer.map(e);return s&&(i=s.finishInner(i)),t.length==0?i:new n(r,t,i||n.empty,a)}between(e,t,r){if(!this.isEmpty){for(let a=0;a<this.chunk.length;a++){let s=this.chunkPos[a],o=this.chunk[a];if(t>=s&&e<=s+o.length&&o.between(s,e-s,t-s,r)===!1)return}this.nextLayer.between(e,t,r)}}iter(e=0){return lu.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return lu.from(e).goto(t)}static compare(e,t,r,a,s=-1){let o=e.filter(d=>d.maxPoint>0||!d.isEmpty&&d.maxPoint>=s),i=t.filter(d=>d.maxPoint>0||!d.isEmpty&&d.maxPoint>=s),l=$1(o,i,r),u=new So(o,l,s),c=new So(i,l,s);r.iterGaps((d,f,h)=>K1(u,d,c,f,h,a)),r.empty&&r.length==0&&K1(u,0,c,0,0,a)}static eq(e,t,r=0,a){a==null&&(a=999999999);let s=e.filter(c=>!c.isEmpty&&t.indexOf(c)<0),o=t.filter(c=>!c.isEmpty&&e.indexOf(c)<0);if(s.length!=o.length)return!1;if(!s.length)return!0;let i=$1(s,o),l=new So(s,i,0).goto(r),u=new So(o,i,0).goto(r);for(;;){if(l.to!=u.to||!Op(l.active,u.active)||l.point&&(!u.point||!Up(l.point,u.point)))return!1;if(l.to>a)return!0;l.next(),u.next()}}static spans(e,t,r,a,s=-1){let o=new So(e,null,s).goto(t),i=t,l=o.openStart;for(;;){let u=Math.min(o.to,r);if(o.point){let c=o.activeForPoint(o.to),d=o.pointFrom<t?c.length+1:o.point.startSide<0?c.length:Math.min(c.length,l);a.point(i,u,o.point,c,d,o.pointRank),l=Math.min(o.openEnd(u),c.length)}else u>i&&(a.span(i,u,o.active,l),l=o.openEnd(u));if(o.to>r)return l+(o.point&&o.to>r?1:0);i=o.to,o.next()}}static of(e,t=!1){let r=new jn;for(let a of e instanceof iu?[e]:t?AM(e):e)r.add(a.from,a.to,a.value);return r.finish()}static join(e){if(!e.length)return n.empty;let t=ki(e);for(let r=e.length-2;r>=0;r--)for(let a=e[r];a!=n.empty;a=a.nextLayer)t=new n(a.chunkPos,a.chunk,t,Math.max(a.maxPoint,t.maxPoint));return t}};wt.empty=new wt([],[],null,-1);function ki(n){return n[n.length-1]}function AM(n){if(n.length>1)for(let e=n[0],t=1;t<n.length;t++){let r=n[t];if(Ep(e,r)>0)return n.slice().sort(Ep);e=r}return n}wt.empty.nextLayer=wt.empty;var jn=class n{finishChunk(e){this.chunks.push(new Bp(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,e&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(e,t,r){this.addRange(e,t,r,!0)}addRange(e,t,r,a){this.addInner(e,t,r,a)||(this.nextLayer||(this.nextLayer=new n)).addRange(e,t,r,a)}addInner(e,t,r,a){let s=e-this.lastTo||r.startSide-this.last.endSide;if(a&&s<=0&&(e-this.lastFrom||r.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return s<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=e),this.from.push(e-this.chunkStart),this.to.push(t-this.chunkStart),this.last=r,this.lastFrom=e,this.lastTo=t,this.value.push(r),r.point&&(this.maxPoint=Math.max(this.maxPoint,t-e)),!0)}addChunk(e,t){if((e-this.lastTo||t.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,t.maxPoint),this.chunks.push(t),this.chunkPos.push(e);let r=t.value.length-1;return this.last=t.value[r],this.lastFrom=t.from[r]+e,this.lastTo=t.to[r]+e,!0}finish(){return this.finishInner(wt.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=wt.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}};function $1(n,e,t){let r=new Map;for(let s of n)for(let o=0;o<s.chunk.length;o++)s.chunk[o].maxPoint<=0&&r.set(s.chunk[o],s.chunkPos[o]);let a=new Set;for(let s of e)for(let o=0;o<s.chunk.length;o++){let i=r.get(s.chunk[o]);i!=null&&(t?t.mapPos(i):i)==s.chunkPos[o]&&!t?.touchesRange(i,i+s.chunk[o].length)&&a.add(s.chunk[o])}return a}var gd=class{constructor(e,t,r,a=0){this.layer=e,this.skip=t,this.minPoint=r,this.rank=a}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(e,t=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(e,t,!1),this}gotoInner(e,t,r){for(;this.chunkIndex<this.layer.chunk.length;){let a=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(a)||this.layer.chunkEnd(this.chunkIndex)<e||a.maxPoint<this.minPoint))break;this.chunkIndex++,r=!1}if(this.chunkIndex<this.layer.chunk.length){let a=this.layer.chunk[this.chunkIndex].findIndex(e-this.layer.chunkPos[this.chunkIndex],t,!0);(!r||this.rangeIndex<a)&&this.setRangeIndex(a)}this.next()}forward(e,t){(this.to-e||this.endSide-t)<0&&this.gotoInner(e,t,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let e=this.layer.chunkPos[this.chunkIndex],t=this.layer.chunk[this.chunkIndex],r=e+t.from[this.rangeIndex];if(this.from=r,this.to=e+t.to[this.rangeIndex],this.value=t.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=e}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(e){return this.from-e.from||this.startSide-e.startSide||this.rank-e.rank||this.to-e.to||this.endSide-e.endSide}},lu=class n{constructor(e){this.heap=e}static from(e,t=null,r=-1){let a=[];for(let s=0;s<e.length;s++)for(let o=e[s];!o.isEmpty;o=o.nextLayer)o.maxPoint>=r&&a.push(new gd(o,t,r,s));return a.length==1?a[0]:new n(a)}get startSide(){return this.value?this.value.startSide:0}goto(e,t=-1e9){for(let r of this.heap)r.goto(e,t);for(let r=this.heap.length>>1;r>=0;r--)Cp(this.heap,r);return this.next(),this}forward(e,t){for(let r of this.heap)r.forward(e,t);for(let r=this.heap.length>>1;r>=0;r--)Cp(this.heap,r);(this.to-e||this.value.endSide-t)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let e=this.heap[0];this.from=e.from,this.to=e.to,this.value=e.value,this.rank=e.rank,e.value&&e.next(),Cp(this.heap,0)}}};function Cp(n,e){for(let t=n[e];;){let r=(e<<1)+1;if(r>=n.length)break;let a=n[r];if(r+1<n.length&&a.compare(n[r+1])>=0&&(a=n[r+1],r++),t.compare(a)<0)break;n[r]=t,n[e]=a,e=r}}var So=class{constructor(e,t,r){this.minPoint=r,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=lu.from(e,t,r)}goto(e,t=-1e9){return this.cursor.goto(e,t),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=e,this.endSide=t,this.openStart=-1,this.next(),this}forward(e,t){for(;this.minActive>-1&&(this.activeTo[this.minActive]-e||this.active[this.minActive].endSide-t)<0;)this.removeActive(this.minActive);this.cursor.forward(e,t)}removeActive(e){ld(this.active,e),ld(this.activeTo,e),ld(this.activeRank,e),this.minActive=X1(this.active,this.activeTo)}addActive(e){let t=0,{value:r,to:a,rank:s}=this.cursor;for(;t<this.activeRank.length&&(s-this.activeRank[t]||a-this.activeTo[t])>0;)t++;ud(this.active,t,r),ud(this.activeTo,t,a),ud(this.activeRank,t,s),e&&ud(e,t,this.cursor.from),this.minActive=X1(this.active,this.activeTo)}next(){let e=this.to,t=this.point;this.point=null;let r=this.openStart<0?[]:null;for(;;){let a=this.minActive;if(a>-1&&(this.activeTo[a]-this.cursor.from||this.active[a].endSide-this.cursor.startSide)<0){if(this.activeTo[a]>e){this.to=this.activeTo[a],this.endSide=this.active[a].endSide;break}this.removeActive(a),r&&ld(r,a)}else if(this.cursor.value)if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let s=this.cursor.value;if(!s.point)this.addActive(r),this.cursor.next();else if(t&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=s,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=s.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(r){this.openStart=0;for(let a=r.length-1;a>=0&&r[a]<e;a--)this.openStart++}}activeForPoint(e){if(!this.active.length)return this.active;let t=[];for(let r=this.active.length-1;r>=0&&!(this.activeRank[r]<this.pointRank);r--)(this.activeTo[r]>e||this.activeTo[r]==e&&this.active[r].endSide>=this.point.endSide)&&t.push(this.active[r]);return t.reverse()}openEnd(e){let t=0;for(let r=this.activeTo.length-1;r>=0&&this.activeTo[r]>e;r--)t++;return t}};function K1(n,e,t,r,a,s){n.goto(e),t.goto(r);let o=r+a,i=r,l=r-e,u=!!s.boundChange;for(let c=!1;;){let d=n.to+l-t.to,f=d||n.endSide-t.endSide,h=f<0?n.to+l:t.to,p=Math.min(h,o);if(n.point||t.point?(n.point&&t.point&&Up(n.point,t.point)&&Op(n.activeForPoint(n.to),t.activeForPoint(t.to))||s.comparePoint(i,p,n.point,t.point),c=!1):(c&&(s.boundChange(i),c=!1),p>i&&!Op(n.active,t.active)&&s.compareRange(i,p,n.active,t.active),u&&p<o&&(d||n.openEnd(h)!=t.openEnd(h))&&(c=!0)),h>o)break;i=h,f<=0&&n.next(),f>=0&&t.next()}}function Op(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(n[t]!=e[t]&&!Up(n[t],e[t]))return!1;return!0}function ld(n,e){for(let t=e,r=n.length-1;t<r;t++)n[t]=n[t+1];n.pop()}function ud(n,e,t){for(let r=n.length-1;r>=e;r--)n[r+1]=n[r];n[e]=t}function X1(n,e){let t=-1,r=1e9;for(let a=0;a<e.length;a++)(e[a]-r||n[a].endSide-n[t].endSide)<0&&(t=a,r=e[a]);return t}function Io(n,e,t=n.length){let r=0;for(let a=0;a<t&&a<n.length;)n.charCodeAt(a)==9?(r+=e-r%e,a++):(r++,a=Nn(n,a));return r}function lk(n,e,t,r){for(let a=0,s=0;;){if(s>=e)return a;if(a==n.length)break;s+=n.charCodeAt(a)==9?t-s%t:1,a=Nn(n,a)}return r===!0?-1:n.length}var uk=typeof Symbol>"u"?"__\u037C":Symbol.for("\u037C"),Gp=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),ck=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{},lr=class{constructor(e,t){this.rules=[];let{finish:r}=t||{};function a(o){return/^@/.test(o)?[o]:o.split(/,\s*/)}function s(o,i,l,u){let c=[],d=/^@(\w+)\b/.exec(o[0]),f=d&&d[1]=="keyframes";if(d&&i==null)return l.push(o[0]+";");for(let h in i){let p=i[h];if(/&/.test(h))s(h.split(/,\s*/).map(m=>o.map(g=>m.replace(/&/,g))).reduce((m,g)=>m.concat(g)),p,l);else if(p&&typeof p=="object"){if(!d)throw new RangeError("The value of a property ("+h+") should be a primitive value.");s(a(h),p,c,f)}else p!=null&&c.push(h.replace(/_.*/,"").replace(/[A-Z]/g,m=>"-"+m.toLowerCase())+": "+p+";")}(c.length||f)&&l.push((r&&!d&&!u?o.map(r):o).join(", ")+" {"+c.join(" ")+"}")}for(let o in e)s(a(o),e[o],this.rules)}getRules(){return this.rules.join(`
37
- `)}static newName(){let e=ck[uk]||1;return ck[uk]=e+1,"\u037C"+e.toString(36)}static mount(e,t,r){let a=e[Gp],s=r&&r.nonce;a?s&&a.setNonce(s):a=new zp(e,s),a.mount(Array.isArray(t)?t:[t],e)}},dk=new Map,zp=class{constructor(e,t){let r=e.ownerDocument||e,a=r.defaultView;if(!e.head&&e.adoptedStyleSheets&&a.CSSStyleSheet){let s=dk.get(r);if(s)return e[Gp]=s;this.sheet=new a.CSSStyleSheet,dk.set(r,this)}else this.styleTag=r.createElement("style"),t&&this.styleTag.setAttribute("nonce",t);this.modules=[],e[Gp]=this}mount(e,t){let r=this.sheet,a=0,s=0,o=!1;for(let i=0;i<e.length;i++){let l=e[i],u=this.modules.indexOf(l);if(u<s&&u>-1&&(this.modules.splice(u,1),o=!0,s--,u=-1),u==-1){if(this.modules.splice(s++,0,l),o=!0,r)for(let c=0;c<l.rules.length;c++)r.insertRule(l.rules[c],a++)}else{for(;s<u;)a+=this.modules[s++].rules.length;a+=l.rules.length,s++}}if(r)t.adoptedStyleSheets.indexOf(this.sheet)<0&&(t.adoptedStyleSheets=[this.sheet,...t.adoptedStyleSheets]);else{if(o){let l="";for(let u=0;u<this.modules.length;u++)l+=this.modules[u].getRules()+`
38
- `;this.styleTag.textContent=l}let i=t.head||t;this.styleTag.parentNode!=i&&i.insertBefore(this.styleTag,i.firstChild)}}setNonce(e){this.styleTag&&this.styleTag.getAttribute("nonce")!=e&&this.styleTag.setAttribute("nonce",e)}};var ns={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},Pi={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},PM=typeof navigator<"u"&&/Mac/.test(navigator.platform),NM=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(mn=0;mn<10;mn++)ns[48+mn]=ns[96+mn]=String(mn);var mn;for(mn=1;mn<=24;mn++)ns[mn+111]="F"+mn;var mn;for(mn=65;mn<=90;mn++)ns[mn]=String.fromCharCode(mn+32),Pi[mn]=String.fromCharCode(mn);var mn;for(xd in ns)Pi.hasOwnProperty(xd)||(Pi[xd]=ns[xd]);var xd;function fk(n){var e=PM&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||NM&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?Pi:ns)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}var er=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},Xp=typeof document<"u"?document:{documentElement:{style:{}}},Yp=/Edge\/(\d+)/.exec(er.userAgent),jk=/MSIE \d/.test(er.userAgent),Jp=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(er.userAgent),zd=!!(jk||Jp||Yp),hk=!zd&&/gecko\/(\d+)/i.test(er.userAgent),Wp=!zd&&/Chrome\/(\d+)/.exec(er.userAgent),pk="webkitFontSmoothing"in Xp.documentElement.style,Zp=!zd&&/Apple Computer/.test(er.vendor),mk=Zp&&(/Mobile\/\w+/.test(er.userAgent)||er.maxTouchPoints>2),we={mac:mk||/Mac/.test(er.platform),windows:/Win/.test(er.platform),linux:/Linux|X11/.test(er.platform),ie:zd,ie_version:jk?Xp.documentMode||6:Jp?+Jp[1]:Yp?+Yp[1]:0,gecko:hk,gecko_version:hk?+(/Firefox\/(\d+)/.exec(er.userAgent)||[0,0])[1]:0,chrome:!!Wp,chrome_version:Wp?+Wp[1]:0,ios:mk,android:/Android\b/.test(er.userAgent),webkit:pk,webkit_version:pk?+(/\bAppleWebKit\/(\d+)/.exec(er.userAgent)||[0,0])[1]:0,safari:Zp,safari_version:Zp?+(/\bVersion\/(\d+(\.\d+)?)/.exec(er.userAgent)||[0,0])[1]:0,tabSize:Xp.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};function Hm(n,e){for(let t in n)t=="class"&&e.class?e.class+=" "+n.class:t=="style"&&e.style?e.style+=";"+n.style:e[t]=n[t];return e}var Pd=Object.create(null);function Um(n,e,t){if(n==e)return!0;n||(n=Pd),e||(e=Pd);let r=Object.keys(n),a=Object.keys(e);if(r.length-(t&&r.indexOf(t)>-1?1:0)!=a.length-(t&&a.indexOf(t)>-1?1:0))return!1;for(let s of r)if(s!=t&&(a.indexOf(s)==-1||n[s]!==e[s]))return!1;return!0}function RM(n,e){for(let t=n.attributes.length-1;t>=0;t--){let r=n.attributes[t].name;e[r]==null&&n.removeAttribute(r)}for(let t in e){let r=e[t];t=="style"?n.style.cssText=r:n.getAttribute(t)!=r&&n.setAttribute(t,r)}}function gk(n,e,t){let r=!1;if(e)for(let a in e)t&&a in t||(r=!0,a=="style"?n.style.cssText="":n.removeAttribute(a));if(t)for(let a in t)e&&e[a]==t[a]||(r=!0,a=="style"?n.style.cssText=t[a]:n.setAttribute(a,t[a]));return r}function MM(n){let e=Object.create(null);for(let t=0;t<n.attributes.length;t++){let r=n.attributes[t];e[r.name]=r.value}return e}var Ir=class{eq(e){return!1}updateDOM(e,t,r){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(e){return!0}coordsAt(e,t,r){return null}get isHidden(){return!1}get editable(){return!1}destroy(e){}},Bn=(function(n){return n[n.Text=0]="Text",n[n.WidgetBefore=1]="WidgetBefore",n[n.WidgetAfter=2]="WidgetAfter",n[n.WidgetRange=3]="WidgetRange",n})(Bn||(Bn={})),Xe=class extends Pa{constructor(e,t,r,a){super(),this.startSide=e,this.endSide=t,this.widget=r,this.spec=a}get heightRelevant(){return!1}static mark(e){return new vu(e)}static widget(e){let t=Math.max(-1e4,Math.min(1e4,e.side||0)),r=!!e.block;return t+=r&&!e.inlineOrder?t>0?3e8:-4e8:t>0?1e8:-1e8,new Ro(e,t,t,r,e.widget||null,!1)}static replace(e){let t=!!e.block,r,a;if(e.isBlockGap)r=-5e8,a=4e8;else{let{start:s,end:o}=qk(e,t);r=(s?t?-3e8:-1:5e8)-1,a=(o?t?2e8:1:-6e8)+1}return new Ro(e,r,a,t,e.widget||null,!0)}static line(e){return new ku(e)}static set(e,t=!1){return wt.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}};Xe.none=wt.empty;var vu=class n extends Xe{constructor(e){let{start:t,end:r}=qk(e);super(t?-1:5e8,r?1:-6e8,null,e),this.tagName=e.tagName||"span",this.attrs=e.class&&e.attributes?Hm(e.attributes,{class:e.class}):e.class?{class:e.class}:e.attributes||Pd}eq(e){return this==e||e instanceof n&&this.tagName==e.tagName&&Um(this.attrs,e.attrs)}range(e,t=e){if(e>=t)throw new RangeError("Mark decorations may not be empty");return super.range(e,t)}};vu.prototype.point=!1;var ku=class n extends Xe{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof n&&this.spec.class==e.spec.class&&Um(this.spec.attributes,e.spec.attributes)}range(e,t=e){if(t!=e)throw new RangeError("Line decoration ranges must be zero-length");return super.range(e,t)}};ku.prototype.mapMode=ir.TrackBefore;ku.prototype.point=!0;var Ro=class n extends Xe{constructor(e,t,r,a,s,o){super(t,r,s,e),this.block=a,this.isReplace=o,this.mapMode=a?t<=0?ir.TrackBefore:ir.TrackAfter:ir.TrackDel}get type(){return this.startSide!=this.endSide?Bn.WidgetRange:this.startSide<=0?Bn.WidgetBefore:Bn.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(e){return e instanceof n&&TM(this.widget,e.widget)&&this.block==e.block&&this.startSide==e.startSide&&this.endSide==e.endSide}range(e,t=e){if(this.isReplace&&(e>t||e==t&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&t!=e)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(e,t)}};Ro.prototype.point=!0;function qk(n,e=!1){let{inclusiveStart:t,inclusiveEnd:r}=n;return t==null&&(t=n.inclusive),r==null&&(r=n.inclusive),{start:t??e,end:r??e}}function TM(n,e){return n==e||!!(n&&e&&n.compare(e))}function Di(n,e,t,r=0){let a=t.length-1;a>=0&&t[a]+r>=n?t[a]=Math.max(t[a],e):t.push(n,e)}var Nd=class n extends Pa{constructor(e,t,r){super(),this.tagName=e,this.attributes=t,this.rank=r}eq(e){return e==this||e instanceof n&&this.tagName==e.tagName&&Um(this.attributes,e.attributes)}static create(e){return new n(e.tagName,e.attributes||Pd,e.rank==null?50:Math.max(0,Math.min(e.rank,100)))}static set(e,t=!1){return wt.of(e,t)}};Nd.prototype.startSide=Nd.prototype.endSide=-1;function Su(n){let e;return n.nodeType==11?e=n.getSelection?n:n.ownerDocument:e=n,e.getSelection()}function Qp(n,e){return e?n==e||n.contains(e.nodeType!=1?e.parentNode:e):!1}function du(n,e){if(!e.anchorNode)return!1;try{return Qp(n,e.anchorNode)}catch{return!1}}function fu(n){return n.nodeType==3?Lu(n,0,n.nodeValue.length).getClientRects():n.nodeType==1?n.getClientRects():[]}function hu(n,e,t,r){return t?xk(n,e,t,r,-1)||xk(n,e,t,r,1):!1}function Us(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e}function Rd(n){return n.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(n.nodeName)}function xk(n,e,t,r,a){for(;;){if(n==t&&e==r)return!0;if(e==(a<0?0:ss(n))){if(n.nodeName=="DIV")return!1;let s=n.parentNode;if(!s||s.nodeType!=1)return!1;e=Us(n)+(a<0?0:1),n=s}else if(n.nodeType==1){if(n=n.childNodes[e+(a<0?-1:0)],n.nodeType==1&&n.contentEditable=="false")return!1;e=a<0?ss(n):0}else return!1}}function ss(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Cu(n,e){let{left:t,right:r}=n;if(t==r)return n;let a=e?t:r;return{left:a,right:a,top:n.top,bottom:n.bottom}}function DM(n){let e=n.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.innerWidth,top:0,bottom:n.innerHeight}}function Vk(n,e){let t=e.width/n.offsetWidth,r=e.height/n.offsetHeight;return(t>.995&&t<1.005||!isFinite(t)||Math.abs(e.width-n.offsetWidth)<1)&&(t=1),(r>.995&&r<1.005||!isFinite(r)||Math.abs(e.height-n.offsetHeight)<1)&&(r=1),{scaleX:t,scaleY:r}}function FM(n,e,t,r,a,s,o,i){let l=n.ownerDocument,u=l.defaultView||window;for(let c=n,d=!1;c&&!d;)if(c.nodeType==1){let f,h=c==l.body,p=1,m=1;if(h)f=DM(u);else{if(/^(fixed|sticky)$/.test(getComputedStyle(c).position)&&(d=!0),c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.assignedSlot||c.parentNode;continue}let w=c.getBoundingClientRect();({scaleX:p,scaleY:m}=Vk(c,w)),f={left:w.left,right:w.left+c.clientWidth*p,top:w.top,bottom:w.top+c.clientHeight*m}}let g=0,x=0;if(a=="nearest")e.top<f.top+o?(x=e.top-(f.top+o),t>0&&e.bottom>f.bottom+x&&(x=e.bottom-f.bottom+o)):e.bottom>f.bottom-o&&(x=e.bottom-f.bottom+o,t<0&&e.top-x<f.top&&(x=e.top-(f.top+o)));else{let w=e.bottom-e.top,y=f.bottom-f.top;x=(a=="center"&&w<=y?e.top+w/2-y/2:a=="start"||a=="center"&&t<0?e.top-o:e.bottom-y+o)-f.top}if(r=="nearest"?e.left<f.left+s?(g=e.left-(f.left+s),t>0&&e.right>f.right+g&&(g=e.right-f.right+s)):e.right>f.right-s&&(g=e.right-f.right+s,t<0&&e.left<f.left+g&&(g=e.left-(f.left+s))):g=(r=="center"?e.left+(e.right-e.left)/2-(f.right-f.left)/2:r=="start"==i?e.left-s:e.right-(f.right-f.left)+s)-f.left,g||x)if(h)u.scrollBy(g,x);else{let w=0,y=0;if(x){let C=c.scrollTop;c.scrollTop+=x/m,y=(c.scrollTop-C)*m}if(g){let C=c.scrollLeft;c.scrollLeft+=g/p,w=(c.scrollLeft-C)*p}e={left:e.left-w,top:e.top-y,right:e.right-w,bottom:e.bottom-y},w&&Math.abs(w-g)<1&&(r="nearest"),y&&Math.abs(y-x)<1&&(a="nearest")}if(h)break;(e.top<f.top||e.bottom>f.bottom||e.left<f.left||e.right>f.right)&&(e={left:Math.max(e.left,f.left),right:Math.min(e.right,f.right),top:Math.max(e.top,f.top),bottom:Math.min(e.bottom,f.bottom)}),c=c.assignedSlot||c.parentNode}else if(c.nodeType==11)c=c.host;else break}function $k(n,e=!0){let t=n.ownerDocument,r=null,a=null;for(let s=n.parentNode;s&&!(s==t.body||(!e||r)&&a);)if(s.nodeType==1)!a&&s.scrollHeight>s.clientHeight&&(a=s),e&&!r&&s.scrollWidth>s.clientWidth&&(r=s),s=s.assignedSlot||s.parentNode;else if(s.nodeType==11)s=s.host;else break;return{x:r,y:a}}var em=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(e){return this.anchorNode==e.anchorNode&&this.anchorOffset==e.anchorOffset&&this.focusNode==e.focusNode&&this.focusOffset==e.focusOffset}setRange(e){let{anchorNode:t,focusNode:r}=e;this.set(t,Math.min(e.anchorOffset,t?ss(t):0),r,Math.min(e.focusOffset,r?ss(r):0))}set(e,t,r,a){this.anchorNode=e,this.anchorOffset=t,this.focusNode=r,this.focusOffset=a}};function Kk(n){let e=[];for(let t=n;t;t=t.nodeType==11?t.host:t.parentNode)t.nodeType==1&&e.push({node:t,left:t.scrollLeft,top:t.scrollTop});return e}function Xk(n,e=!0){for(let{node:t,left:r,top:a}of n)e&&t.scrollTop!=a&&(t.scrollTop=a),t.scrollLeft!=r&&(t.scrollLeft=r)}var Ao=null;we.safari&&we.safari_version>=26&&(Ao=!1);function Yk(n){if(n.setActive)return n.setActive();if(Ao)return n.focus(Ao);let e=Kk(n);n.focus(Ao==null?{get preventScroll(){return Ao={preventScroll:!0},!0}}:void 0),Ao||(Ao=!1,Xk(e))}var yk;function Lu(n,e,t=e){let r=yk||(yk=document.createRange());return r.setEnd(n,t),r.setStart(n,e),r}function Fi(n,e,t,r){let a={key:e,code:e,keyCode:t,which:t,cancelable:!0};r&&({altKey:a.altKey,ctrlKey:a.ctrlKey,shiftKey:a.shiftKey,metaKey:a.metaKey}=r);let s=new KeyboardEvent("keydown",a);s.synthetic=!0,n.dispatchEvent(s);let o=new KeyboardEvent("keyup",a);return o.synthetic=!0,n.dispatchEvent(o),s.defaultPrevented||o.defaultPrevented}function EM(n){for(;n;){if(n&&(n.nodeType==9||n.nodeType==11&&n.host))return n;n=n.assignedSlot||n.parentNode}return null}function BM(n,e){let t=e.focusNode,r=e.focusOffset;if(!t||e.anchorNode!=t||e.anchorOffset!=r)return!1;for(r=Math.min(r,ss(t));;)if(r){if(t.nodeType!=1)return!1;let a=t.childNodes[r-1];a.contentEditable=="false"?r--:(t=a,r=ss(t))}else{if(t==n)return!0;r=Us(t),t=t.parentNode}}function Jk(n){return n instanceof Window?n.pageYOffset>Math.max(0,n.document.documentElement.scrollHeight-n.innerHeight-4):n.scrollTop>Math.max(1,n.scrollHeight-n.clientHeight-4)}function Zk(n,e){for(let t=n,r=e;;){if(t.nodeType==3&&r>0)return{node:t,offset:r};if(t.nodeType==1&&r>0){if(t.contentEditable=="false")return null;t=t.childNodes[r-1],r=ss(t)}else if(t.parentNode&&!Rd(t))r=Us(t),t=t.parentNode;else return null}}function Qk(n,e){for(let t=n,r=e;;){if(t.nodeType==3&&r<t.nodeValue.length)return{node:t,offset:r};if(t.nodeType==1&&r<t.childNodes.length){if(t.contentEditable=="false")return null;t=t.childNodes[r],r=0}else if(t.parentNode&&!Rd(t))r=Us(t)+1,t=t.parentNode;else return null}}var Ma=class n{constructor(e,t,r=!0){this.node=e,this.offset=t,this.precise=r}static before(e,t){return new n(e.parentNode,Us(e),t)}static after(e,t){return new n(e.parentNode,Us(e)+1,t)}},Wt=(function(n){return n[n.LTR=0]="LTR",n[n.RTL=1]="RTL",n})(Wt||(Wt={})),Mo=Wt.LTR,Gm=Wt.RTL;function eS(n){let e=[];for(let t=0;t<n.length;t++)e.push(1<<+n[t]);return e}var OM=eS("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),_M=eS("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),tm=Object.create(null),Ra=[];for(let n of["()","[]","{}"]){let e=n.charCodeAt(0),t=n.charCodeAt(1);tm[e]=t,tm[t]=-e}function tS(n){return n<=247?OM[n]:1424<=n&&n<=1524?2:1536<=n&&n<=1785?_M[n-1536]:1774<=n&&n<=2220?4:8192<=n&&n<=8204?256:64336<=n&&n<=65023?4:1}var HM=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/,Vr=class{get dir(){return this.level%2?Gm:Mo}constructor(e,t,r){this.from=e,this.to=t,this.level=r}side(e,t){return this.dir==t==e?this.to:this.from}forward(e,t){return e==(this.dir==t)}static find(e,t,r,a){let s=-1;for(let o=0;o<e.length;o++){let i=e[o];if(i.from<=t&&i.to>=t){if(i.level==r)return o;(s<0||(a!=0?a<0?i.from<t:i.to>t:e[s].level>i.level))&&(s=o)}}if(s<0)throw new RangeError("Index out of range");return s}};function nS(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++){let r=n[t],a=e[t];if(r.from!=a.from||r.to!=a.to||r.direction!=a.direction||!nS(r.inner,a.inner))return!1}return!0}var Gt=[];function UM(n,e,t,r,a){for(let s=0;s<=r.length;s++){let o=s?r[s-1].to:e,i=s<r.length?r[s].from:t,l=s?256:a;for(let u=o,c=l,d=l;u<i;u++){let f=tS(n.charCodeAt(u));f==512?f=c:f==8&&d==4&&(f=16),Gt[u]=f==4?2:f,f&7&&(d=f),c=f}for(let u=o,c=l,d=l;u<i;u++){let f=Gt[u];if(f==128)u<i-1&&c==Gt[u+1]&&c&24?f=Gt[u]=c:Gt[u]=256;else if(f==64){let h=u+1;for(;h<i&&Gt[h]==64;)h++;let p=u&&c==8||h<t&&Gt[h]==8?d==1?1:8:256;for(let m=u;m<h;m++)Gt[m]=p;u=h-1}else f==8&&d==1&&(Gt[u]=1);c=f,f&7&&(d=f)}}}function GM(n,e,t,r,a){let s=a==1?2:1;for(let o=0,i=0,l=0;o<=r.length;o++){let u=o?r[o-1].to:e,c=o<r.length?r[o].from:t;for(let d=u,f,h,p;d<c;d++)if(h=tm[f=n.charCodeAt(d)])if(h<0){for(let m=i-3;m>=0;m-=3)if(Ra[m+1]==-h){let g=Ra[m+2],x=g&2?a:g&4?g&1?s:a:0;x&&(Gt[d]=Gt[Ra[m]]=x),i=m;break}}else{if(Ra.length==189)break;Ra[i++]=d,Ra[i++]=f,Ra[i++]=l}else if((p=Gt[d])==2||p==1){let m=p==a;l=m?0:1;for(let g=i-3;g>=0;g-=3){let x=Ra[g+2];if(x&2)break;if(m)Ra[g+2]|=2;else{if(x&4)break;Ra[g+2]|=4}}}}}function zM(n,e,t,r){for(let a=0,s=r;a<=t.length;a++){let o=a?t[a-1].to:n,i=a<t.length?t[a].from:e;for(let l=o;l<i;){let u=Gt[l];if(u==256){let c=l+1;for(;;)if(c==i){if(a==t.length)break;c=t[a++].to,i=a<t.length?t[a].from:e}else if(Gt[c]==256)c++;else break;let d=s==1,f=(c<e?Gt[c]:r)==1,h=d==f?d?1:2:r;for(let p=c,m=a,g=m?t[m-1].to:n;p>l;)p==g&&(p=t[--m].from,g=m?t[m-1].to:n),Gt[--p]=h;l=c}else s=u,l++}}}function nm(n,e,t,r,a,s,o){let i=r%2?2:1;if(r%2==a%2)for(let l=e,u=0;l<t;){let c=!0,d=!1;if(u==s.length||l<s[u].from){let m=Gt[l];m!=i&&(c=!1,d=m==16)}let f=!c&&i==1?[]:null,h=c?r:r+1,p=l;e:for(;;)if(u<s.length&&p==s[u].from){if(d)break e;let m=s[u];if(!c)for(let g=m.to,x=u+1;;){if(g==t)break e;if(x<s.length&&s[x].from==g)g=s[x++].to;else{if(Gt[g]==i)break e;break}}if(u++,f)f.push(m);else{m.from>l&&o.push(new Vr(l,m.from,h));let g=m.direction==Mo!=!(h%2);rm(n,g?r+1:r,a,m.inner,m.from,m.to,o),l=m.to}p=m.to}else{if(p==t||(c?Gt[p]!=i:Gt[p]==i))break;p++}f?nm(n,l,p,r+1,a,f,o):l<p&&o.push(new Vr(l,p,h)),l=p}else for(let l=t,u=s.length;l>e;){let c=!0,d=!1;if(!u||l>s[u-1].to){let m=Gt[l-1];m!=i&&(c=!1,d=m==16)}let f=!c&&i==1?[]:null,h=c?r:r+1,p=l;e:for(;;)if(u&&p==s[u-1].to){if(d)break e;let m=s[--u];if(!c)for(let g=m.from,x=u;;){if(g==e)break e;if(x&&s[x-1].to==g)g=s[--x].from;else{if(Gt[g-1]==i)break e;break}}if(f)f.push(m);else{m.to<l&&o.push(new Vr(m.to,l,h));let g=m.direction==Mo!=!(h%2);rm(n,g?r+1:r,a,m.inner,m.from,m.to,o),l=m.from}p=m.from}else{if(p==e||(c?Gt[p-1]!=i:Gt[p-1]==i))break;p--}f?nm(n,p,l,r+1,a,f,o):p<l&&o.push(new Vr(p,l,h)),l=p}}function rm(n,e,t,r,a,s,o){let i=e%2?2:1;UM(n,a,s,r,i),GM(n,a,s,r,i),zM(a,s,r,i),nm(n,a,s,e,t,r,o)}function WM(n,e,t){if(!n)return[new Vr(0,0,e==Gm?1:0)];if(e==Mo&&!t.length&&!HM.test(n))return rS(n.length);if(t.length)for(;n.length>Gt.length;)Gt[Gt.length]=256;let r=[],a=e==Mo?0:1;return rm(n,a,a,t,0,n.length,r),r}function rS(n){return[new Vr(0,n,0)]}var aS="";function jM(n,e,t,r,a){var s;if(!n.length)return null;let o=r.head-n.from,i;if(r.head==n.from&&r.assoc<0){if(!a)return null;o=e[i=0].side(!1,t)}else if(r.head==n.to&&r.assoc>0){if(a)return null;o=e[i=e.length-1].side(!0,t)}else i=Vr.find(e,o,(s=r.bidiLevel)!==null&&s!==void 0?s:-1,r.assoc);let l=e[i],u=l.side(a,t);if(o==u){let f=i+=a?1:-1;if(f<0||f>=e.length)return null;l=e[i=f],o=l.side(!a,t),u=l.side(a,t)}let c=Nn(n.text,o,l.forward(a,t));(c<l.from||c>l.to)&&(c=u),aS=n.text.slice(Math.min(o,c),Math.max(o,c));let d=i==(a?e.length-1:0)?null:e[i+(a?1:-1)];if(c==u){if(!d)return a?se.cursor(n.to,1):se.cursor(n.from,-1);if(d.level+(a?0:1)<l.level)return se.cursor(d.side(!a,t)+n.from,d.forward(a,t)?1:-1,d.level)}return se.cursor(c+n.from,l.forward(a,t)?-1:1,l.level)}function qM(n,e,t){for(let r=e;r<t;r++){let a=tS(n.charCodeAt(r));if(a==1)return Mo;if(a==2||a==4)return Gm}return Mo}var sS=Me.define(),oS=Me.define(),iS=Me.define(),lS=Me.define(),am=Me.define(),uS=Me.define(),cS=Me.define(),zm=Me.define(),Wm=Me.define(),dS=Me.define({combine:n=>n.some(e=>e)}),fS=Me.define({combine:n=>n.some(e=>e)}),hS=Me.define(),pu=class n{constructor(e,t,r,a,s,o=!1){this.range=e,this.y=t,this.x=r,this.yMargin=a,this.xMargin=s,this.isSnapshot=o}map(e){return e.empty?this:new n(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(e){return this.range.to<=e.doc.length?this:new n(se.cursor(e.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}},yd=xt.define({map:(n,e)=>n.map(e)}),pS=xt.define();function la(n,e,t){let r=n.facet(lS);r.length?r[0](e):window.onerror&&window.onerror(String(e),t,void 0,void 0,e)||(t?console.error(t+":",e):console.error(e))}var rs=Me.define({combine:n=>n.length?n[0]:!0}),VM=0,Ri=Me.define({combine(n){return n.filter((e,t)=>{for(let r=0;r<t;r++)if(n[r].plugin==e.plugin)return!1;return!0})}}),cr=class n{constructor(e,t,r,a,s){this.id=e,this.create=t,this.domEventHandlers=r,this.domEventObservers=a,this.baseExtensions=s(this),this.extension=this.baseExtensions.concat(Ri.of({plugin:this,arg:void 0}))}of(e){return this.baseExtensions.concat(Ri.of({plugin:this,arg:e}))}static define(e,t){let{eventHandlers:r,eventObservers:a,provide:s,decorations:o}=t||{};return new n(VM++,e,r,a,i=>{let l=[];return o&&l.push(Wd.of(u=>{let c=u.plugin(i);return c?o(c):Xe.none})),s&&l.push(s(i)),l})}static fromClass(e,t){return n.define((r,a)=>new e(r,a),t)}},mu=class{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(e){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(r){if(la(t.state,r,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(e,this.spec.arg)}catch(t){la(e.state,t,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(e){var t;if(!((t=this.value)===null||t===void 0)&&t.destroy)try{this.value.destroy()}catch(r){la(e.state,r,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}},mS=Me.define(),jm=Me.define(),Wd=Me.define(),gS=Me.define(),qm=Me.define(),Iu=Me.define(),xS=Me.define();function bk(n,e){let t=n.state.facet(xS);if(!t.length)return t;let r=t.map(s=>s instanceof Function?s(n):s),a=[];return wt.spans(r,e.from,e.to,{point(){},span(s,o,i,l){let u=s-e.from,c=o-e.from,d=a;for(let f=i.length-1;f>=0;f--,l--){let h=i[f].spec.bidiIsolate,p;if(h==null&&(h=qM(e.text,u,c)),l>0&&d.length&&(p=d[d.length-1]).to==u&&p.direction==h)p.to=c,d=p.inner;else{let m={from:u,to:c,direction:h,inner:[]};d.push(m),d=m.inner}}}}),a}var yS=Me.define();function bS(n){let e=0,t=0,r=0,a=0;for(let s of n.state.facet(yS)){let o=s(n);o&&(o.left!=null&&(e=Math.max(e,o.left)),o.right!=null&&(t=Math.max(t,o.right)),o.top!=null&&(r=Math.max(r,o.top)),o.bottom!=null&&(a=Math.max(a,o.bottom)))}return{left:e,right:t,top:r,bottom:a}}var uu=Me.define(),ua=class n{constructor(e,t,r,a){this.fromA=e,this.toA=t,this.fromB=r,this.toB=a}join(e){return new n(Math.min(this.fromA,e.fromA),Math.max(this.toA,e.toA),Math.min(this.fromB,e.fromB),Math.max(this.toB,e.toB))}addToSet(e){let t=e.length,r=this;for(;t>0;t--){let a=e[t-1];if(!(a.fromA>r.toA)){if(a.toA<r.fromA)break;r=r.join(a),e.splice(t-1,1)}}return e.splice(t,0,r),e}static extendWithRanges(e,t){if(t.length==0)return e;let r=[];for(let a=0,s=0,o=0;;){let i=a<e.length?e[a].fromB:1e9,l=s<t.length?t[s]:1e9,u=Math.min(i,l);if(u==1e9)break;let c=u+o,d=u,f=c;for(;;)if(s<t.length&&t[s]<=d){let h=t[s+1];s+=2,d=Math.max(d,h);for(let p=a;p<e.length&&e[p].fromB<=d;p++)o=e[p].toA-e[p].toB;f=Math.max(f,h+o)}else if(a<e.length&&e[a].fromB<=d){let h=e[a++];d=Math.max(d,h.toB),f=Math.max(f,h.toA),o=h.toA-h.toB}else break;r.push(new n(c,f,u,d))}return r}},Md=class n{constructor(e,t,r){this.view=e,this.state=t,this.transactions=r,this.flags=0,this.startState=e.state,this.changes=Rn.empty(this.startState.doc.length);for(let s of r)this.changes=this.changes.compose(s.changes);let a=[];this.changes.iterChangedRanges((s,o,i,l)=>a.push(new ua(s,o,i,l))),this.changedRanges=a}static create(e,t,r){return new n(e,t,r)}get viewportChanged(){return(this.flags&4)>0}get viewportMoved(){return(this.flags&8)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&18)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(e=>e.selection)}get empty(){return this.flags==0&&this.transactions.length==0}},$M=[],Zt=class{constructor(e,t,r=0){this.dom=e,this.length=t,this.flags=r,this.parent=null,e.cmTile=this}get breakAfter(){return this.flags&1}get children(){return $M}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(e){if(this.flags|=2,this.flags&4){this.flags&=-5;let t=this.domAttrs;t&&RM(this.dom,t)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:"")+(this.breakAfter?"#":"")}destroy(){this.parent=null}setDOM(e){this.dom=e,e.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e,t=this.posAtStart){let r=t;for(let a of this.children){if(a==e)return r;r+=a.length+a.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(e){return this.posBefore(e)+e.length}covers(e){return!0}coordsIn(e,t,r){return null}domPosFor(e,t){let r=Us(this.dom),a=this.length?e>0:t>0;return new Ma(this.parent.dom,r+(a?1:0),e==0||e==this.length)}markDirty(e){this.flags&=-3,e&&(this.flags|=4),this.parent&&this.parent.flags&2&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let e=this;e;e=e.parent)if(e instanceof Bi)return e;return null}static get(e){return e.cmTile}},Ei=class extends Zt{constructor(e){super(e,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(e){this.children.push(e),e.parent=this}sync(e){if(this.flags&2)return;super.sync(e);let t=this.dom,r=null,a,s=e?.node==t?e:null,o=0;for(let i of this.children){if(i.sync(e),o+=i.length+i.breakAfter,a=r?r.nextSibling:t.firstChild,s&&a!=i.dom&&(s.written=!0),i.dom.parentNode==t)for(;a&&a!=i.dom;)a=wk(a);else t.insertBefore(i.dom,a);r=i.dom}for(a=r?r.nextSibling:t.firstChild,s&&a&&(s.written=!0);a;)a=wk(a);this.length=o}};function wk(n){let e=n.nextSibling;return n.parentNode.removeChild(n),e}var Bi=class extends Ei{constructor(e,t){super(t),this.view=e}owns(e){for(;e;e=e.parent)if(e==this)return!0;return!1}isBlock(){return!0}nearest(e){for(;;){if(!e)return null;let t=Zt.get(e);if(t&&this.owns(t))return t;e=e.parentNode}}blockTiles(e){for(let t=[],r=this,a=0,s=0;;)if(a==r.children.length){if(!t.length)return;r=r.parent,r.breakAfter&&s++,a=t.pop()}else{let o=r.children[a++];if(o instanceof as)t.push(a),r=o,a=0;else{let i=s+o.length,l=e(o,s);if(l!==void 0)return l;s=i+o.breakAfter}}}resolveBlock(e,t){let r,a=-1,s,o=-1;if(this.blockTiles((i,l)=>{let u=l+i.length;if(e>=l&&e<=u){if(i.isWidget()&&t>=-1&&t<=1){if(i.flags&32)return!0;i.flags&16&&(r=void 0)}(l<e||e==u&&(t<-1?i.length:i.covers(1)))&&(!r||!i.isWidget()&&r.isWidget())&&(r=i,a=e-l),(u>e||e==l&&(t>1?i.length:i.covers(-1)))&&(!s||!i.isWidget()&&s.isWidget())&&(s=i,o=e-l)}}),!r&&!s)throw new Error("No tile at position "+e);return r&&t<0||!s?{tile:r,offset:a}:{tile:s,offset:o}}},as=class n extends Ei{constructor(e,t){super(e),this.wrapper=t}isBlock(){return!0}covers(e){return this.children.length?e<0?this.children[0].covers(-1):this.lastChild.covers(1):!1}get domAttrs(){return this.wrapper.attributes}static of(e,t){let r=new n(t||document.createElement(e.tagName),e);return t||(r.flags|=4),r}},Oi=class n extends Ei{constructor(e,t){super(e),this.attrs=t}isLine(){return!0}static start(e,t,r){let a=new n(t||document.createElement("div"),e);return(!t||!r)&&(a.flags|=4),a}get domAttrs(){return this.attrs}resolveInline(e,t,r){let a=null,s=-1,o=null,i=-1;function l(c,d){for(let f=0,h=0;f<c.children.length&&h<=d;f++){let p=c.children[f],m=h+p.length;m>=d&&(p.isComposite()?l(p,d-h):(!o||o.isHidden&&(t>0&&!(o.flags&32)||r&&XM(o,p)))&&(m>d||p.flags&32&&t<=1)?(o=p,i=d-h):(h<d||p.flags&16&&!p.isHidden&&t>=-1)&&(a=p,s=d-h)),h=m}}l(this,e);let u=(t<0?a:o)||a||o;return u?{tile:u,offset:u==a?s:i}:null}coordsIn(e,t,r){let a=this.resolveInline(e,t,!0);return a?a.tile.coordsIn(Math.max(0,a.offset),t,r):KM(this)}domIn(e,t){let r=this.resolveInline(e,t);if(r){let{tile:a,offset:s}=r;if(this.dom.contains(a.dom))return a.isText()?new Ma(a.dom,Math.min(a.dom.nodeValue.length,s)):a.domPosFor(s,a.flags&16?1:a.flags&32?-1:t);let o=r.tile.parent,i=!1;for(let l of o.children){if(i)return new Ma(l.dom,0);l==r.tile&&(i=!0)}}return new Ma(this.dom,0)}};function KM(n){let e=n.dom.lastChild;if(!e)return n.dom.getBoundingClientRect();let t=fu(e);return t[t.length-1]||null}function XM(n,e){let t=n.coordsIn(0,1),r=e.coordsIn(0,1);return t&&r&&r.top<t.bottom}var ur=class n extends Ei{constructor(e,t){super(e),this.mark=t}get domAttrs(){return this.mark.attrs}static of(e,t){let r=new n(t||document.createElement(e.tagName),e);return t||(r.flags|=4),r}},Po=class n extends Zt{constructor(e,t){super(e,t.length),this.text=t}sync(e){this.flags&2||(super.sync(e),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text))}isText(){return!0}toString(){return JSON.stringify(this.text)}coordsIn(e,t,r){let a=this.dom.nodeValue.length;e>a&&(e=a);let s=e,o=e,i=0;e==0&&t<0||e==a&&t>=0?we.chrome||we.gecko||(e?(s--,i=1):o<a&&(o++,i=-1)):t<0?s--:o<a&&o++;let l=Lu(this.dom,s,o).getClientRects();if(!l.length)return null;let u=l[(i?i<0:t>=0)?0:l.length-1];return we.safari&&!i&&u.width==0&&(u=Array.prototype.find.call(l,c=>c.width)||u),r==null?u:Cu(u,(i?i>0:t<0)==r)}static of(e,t){let r=new n(t||document.createTextNode(e),e);return t||(r.flags|=2),r}},To=class n extends Zt{constructor(e,t,r,a){super(e,t,a),this.widget=r}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(e){return this.flags&48?!1:(this.flags&(e<0?64:128))>0}coordsIn(e,t){return this.coordsInWidget(e,t,!1)}coordsInWidget(e,t,r){let a=this.widget.coordsAt(this.dom,e,t);if(a)return a;if(r)return Cu(this.dom.getBoundingClientRect(),this.length?e==0:t<=0);{let s=this.dom.getClientRects(),o=null;if(!s.length)return null;let i=this.flags&16?!0:this.flags&32?!1:e>0;for(let l=i?s.length-1:0;o=s[l],!(e>0?l==0:l==s.length-1||o.top<o.bottom);l+=i?-1:1);return Cu(o,!i)}}get overrideDOMText(){if(!this.length)return ct.empty;let{root:e}=this;if(!e)return ct.empty;let t=this.posAtStart;return e.view.state.doc.slice(t,t+this.length)}destroy(){super.destroy(),this.widget.destroy(this.dom)}static of(e,t,r,a,s){return s||(s=e.toDOM(t),e.editable||(s.contentEditable="false")),new n(s,r,e,a)}},_i=class extends Zt{constructor(e){let t=document.createElement("img");t.className="cm-widgetBuffer",t.setAttribute("aria-hidden","true"),super(t,0,e)}get isHidden(){return!0}get overrideDOMText(){return ct.empty}coordsIn(e,t,r){let a=this.dom.getBoundingClientRect();return r==null?a:Cu(a,t>0==r)}},sm=class{constructor(e){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=e}advance(e,t,r){let{tile:a,index:s,beforeBreak:o,parents:i}=this;for(;e||t>0;)if(a.isComposite())if(o){if(!e)break;r&&r.break(),e--,o=!1}else if(s==a.children.length){if(!e&&!i.length)break;r&&r.leave(a),o=!!a.breakAfter,{tile:a,index:s}=i.pop(),s++}else{let l=a.children[s],u=l.breakAfter;(t>0?l.length<=e:l.length<e)&&(!r||r.skip(l,0,l.length)!==!1||!l.isComposite)?(o=!!u,s++,e-=l.length):(i.push({tile:a,index:s}),a=l,s=0,r&&l.isComposite()&&r.enter(l))}else{let l=a.length;if(s<l&&e){let u=Math.min(e,l-s);r&&r.skip(a,s,s+u),e-=u,s+=u}if(s==l)o=!!a.breakAfter,{tile:a,index:s}=i.pop(),s++;else if(!e)break}return this.tile=a,this.index=s,this.beforeBreak=o,this}get root(){return this.parents.length?this.parents[0].tile:this.tile}},om=class{constructor(e,t,r,a){this.from=e,this.to=t,this.wrapper=r,this.rank=a}},im=class{constructor(e,t,r){this.cache=e,this.root=t,this.blockWrappers=r,this.curLine=null,this.lastBlock=null,this.afterWidget=null,this.pos=0,this.wrappers=[],this.wrapperPos=0}addText(e,t,r,a){var s;this.flushBuffer();let o=this.ensureMarks(t,r),i=o.lastChild;if(i&&i.isText()&&!(i.flags&8)&&i.length+e.length<512){this.cache.reused.set(i,2);let l=o.children[o.children.length-1]=new Po(i.dom,i.text+e);l.parent=o}else o.append(a||Po.of(e,(s=this.cache.find(Po))===null||s===void 0?void 0:s.dom));this.pos+=e.length,this.afterWidget=null}addComposition(e,t){let r=this.curLine;r.dom!=t.line.dom&&(r.setDOM(this.cache.reused.has(t.line)?jp(t.line.dom):t.line.dom),this.cache.reused.set(t.line,2));let a=r;for(let i=t.marks.length-1;i>=0;i--){let l=t.marks[i],u=a.lastChild;if(u instanceof ur&&u.mark.eq(l.mark))u.dom!=l.dom&&u.setDOM(jp(l.dom)),a=u;else{let{dom:c}=l;this.cache.reused.get(l)&&Zt.get(l.dom)&&(c=jp(l.dom));let d=ur.of(l.mark,c);a.append(d),a=d}this.cache.reused.set(l,2)}let s=Zt.get(e.text);s&&this.cache.reused.set(s,2);let o=new Po(e.text,e.text.nodeValue);o.flags|=8,this.pos=e.range.toB,a.append(o)}addInlineWidget(e,t,r){let a=this.afterWidget&&e.flags&48&&(this.afterWidget.flags&48)==(e.flags&48);a||this.flushBuffer();let s=this.ensureMarks(t,r);!a&&!(e.flags&16)&&s.append(this.getBuffer(1)),s.append(e),this.pos+=e.length,this.afterWidget=e}addMark(e,t,r){this.flushBuffer(),this.ensureMarks(t,r).append(e),this.pos+=e.length,this.afterWidget=null}addBlockWidget(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}continueWidget(e){let t=this.afterWidget||this.lastBlock;t.length+=e,this.pos+=e}addLineStart(e,t){var r;e||(e=wS);let a=Oi.start(e,t||((r=this.cache.find(Oi))===null||r===void 0?void 0:r.dom),!!t);this.getBlockPos().append(this.lastBlock=this.curLine=a)}addLine(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(e){this.blockPosCovered()||this.addLineStart(e)}ensureLine(e){this.curLine||this.addLineStart(e)}ensureMarks(e,t){var r;let a=this.curLine;for(let s=e.length-1;s>=0;s--){let o=e[s],i;if(t>0&&(i=a.lastChild)&&i instanceof ur&&i.mark.eq(o))a=i,t--;else{let l=ur.of(o,(r=this.cache.find(ur,u=>u.mark.eq(o)))===null||r===void 0?void 0:r.dom);a.append(l),a=l,t=0}}return a}endLine(){if(this.curLine){this.flushBuffer();let e=this.curLine.lastChild;(!e||!vk(this.curLine,!1)||e.dom.nodeName!="BR"&&e.isWidget()&&!(we.ios&&vk(this.curLine,!0)))&&this.curLine.append(this.cache.findWidget(qp,0,32)||new To(qp.toDOM(),0,qp,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let e=this.wrappers.length-1;e>=0;e--)this.wrappers[e].to<this.pos&&this.wrappers.splice(e,1);for(let e=this.blockWrappers;e.value&&e.from<=this.pos;e.next())if(e.to>=this.pos){let t=e.rank*102+e.value.rank,r=new om(e.from,e.to,e.value,t),a=this.wrappers.length;for(;a>0&&(this.wrappers[a-1].rank-r.rank||this.wrappers[a-1].to-r.to)<0;)a--;this.wrappers.splice(a,0,r)}this.wrapperPos=this.pos}getBlockPos(){var e;this.updateBlockWrappers();let t=this.root;for(let r of this.wrappers){let a=t.lastChild;if(r.from<this.pos&&a instanceof as&&a.wrapper.eq(r.wrapper))t=a;else{let s=as.of(r.wrapper,(e=this.cache.find(as,o=>o.wrapper.eq(r.wrapper)))===null||e===void 0?void 0:e.dom);t.append(s),t=s}}return t}blockPosCovered(){let e=this.lastBlock;return e!=null&&!e.breakAfter&&(!e.isWidget()||(e.flags&160)>0)}getBuffer(e){let t=2|(e<0?16:32),r=this.cache.find(_i,void 0,1);return r&&(r.flags=t),r||new _i(t)}flushBuffer(){this.afterWidget&&!(this.afterWidget.flags&32)&&(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}},lm=class{constructor(e){this.skipCount=0,this.text="",this.textOff=0,this.cursor=e.iter()}skip(e){this.textOff+e<=this.text.length?this.textOff+=e:(this.skipCount+=e-(this.text.length-this.textOff),this.text="",this.textOff=0)}next(e){if(this.textOff==this.text.length){let{value:a,lineBreak:s,done:o}=this.cursor.next(this.skipCount);if(this.skipCount=0,o)throw new Error("Ran out of text content when drawing inline views");this.text=a;let i=this.textOff=Math.min(e,a.length);return s?null:a.slice(0,i)}let t=Math.min(this.text.length,this.textOff+e),r=this.text.slice(this.textOff,t);return this.textOff=t,r}},Td=[To,Oi,Po,ur,_i,as,Bi];for(let n=0;n<Td.length;n++)Td[n].bucket=n;var um=class{constructor(e){this.view=e,this.buckets=Td.map(()=>[]),this.index=Td.map(()=>0),this.reused=new Map}add(e){let t=e.constructor.bucket,r=this.buckets[t];r.length<6?r.push(e):r[this.index[t]=(this.index[t]+1)%6]=e}find(e,t,r=2){let a=e.bucket,s=this.buckets[a],o=this.index[a];for(let i=0;i<s.length;i++){let l=(i+o)%s.length,u=s[l];if((!t||t(u))&&!this.reused.has(u))return s.splice(l,1),l<o&&this.index[a]--,this.reused.set(u,r),u}return null}findWidget(e,t,r){let a=this.buckets[0];if(a.length)for(let s=0,o=0;;s++){if(s==a.length){if(o)return null;o=1,s=0}let i=a[s];if(!this.reused.has(i)&&(o==0?i.widget.compare(e):i.widget.constructor==e.constructor&&e.updateDOM(i.dom,this.view,i.widget)))return a.splice(s,1),s<this.index[0]&&this.index[0]--,i.widget==e&&i.length==t&&(i.flags&497)==r?(this.reused.set(i,1),i):(this.reused.set(i,2),new To(i.dom,t,e,i.flags&-498|r))}}reuse(e){return this.reused.set(e,1),e}maybeReuse(e,t=2){if(!this.reused.has(e))return this.reused.set(e,t),e.dom}clear(){for(let e=0;e<this.buckets.length;e++)this.buckets[e].length=this.index[e]=0}},cm=class{constructor(e,t,r,a,s){this.view=e,this.decorations=a,this.disallowBlockEffectsFor=s,this.openWidget=!1,this.openMarks=0,this.cache=new um(e),this.text=new lm(e.state.doc),this.builder=new im(this.cache,new Bi(e,e.contentDOM),wt.iter(r)),this.cache.reused.set(t,2),this.old=new sm(t),this.reuseWalker={skip:(o,i,l)=>{if(this.cache.add(o),o.isComposite())return!1},enter:o=>this.cache.add(o),leave:()=>{},break:()=>{}}}run(e,t){let r=t&&this.getCompositionContext(t.text);for(let a=0,s=0,o=0;;){let i=o<e.length?e[o++]:null,l=i?i.fromA:this.old.root.length;if(l>a){let u=l-a;this.preserve(u,!o,!i),a=l,s+=u}if(!i)break;t&&i.fromA<=t.range.fromA&&i.toA>=t.range.toA?(this.forward(i.fromA,t.range.fromA,t.range.fromA<t.range.toA?1:-1),this.emit(s,t.range.fromB),this.builder.flushBuffer(),this.cache.clear(),this.builder.addComposition(t,r),this.text.skip(t.range.toB-t.range.fromB),this.forward(t.range.fromA,i.toA),this.emit(t.range.toB,i.toB)):(this.forward(i.fromA,i.toA),this.emit(s,i.toB)),s=i.toB,a=i.toA}return this.builder.curLine&&this.builder.endLine(),this.builder.root}preserve(e,t,r){let a=ZM(this.old),s=this.openMarks;this.old.advance(e,r?1:-1,{skip:(o,i,l)=>{if(o.isWidget())if(this.openWidget)this.builder.continueWidget(l-i);else{let u=l>0||i<o.length?To.of(o.widget,this.view,l-i,o.flags&496,this.cache.maybeReuse(o)):this.cache.reuse(o);u.flags&256?(u.flags&=-2,this.builder.addBlockWidget(u)):(this.builder.ensureLine(null),this.builder.addInlineWidget(u,a,s),s=a.length)}else if(o.isText())this.builder.ensureLine(null),!i&&l==o.length&&!this.cache.reused.has(o)?this.builder.addText(o.text,a,s,this.cache.reuse(o)):(this.cache.add(o),this.builder.addText(o.text.slice(i,l),a,s)),s=a.length;else if(o.isLine())o.flags&=-2,this.cache.reused.set(o,1),this.builder.addLine(o);else if(o instanceof _i)this.cache.add(o);else if(o instanceof ur)this.builder.ensureLine(null),this.builder.addMark(o,a,s),this.cache.reused.set(o,1),s=a.length;else return!1;this.openWidget=!1},enter:o=>{o.isLine()?this.builder.addLineStart(o.attrs,this.cache.maybeReuse(o)):(this.cache.add(o),o instanceof ur&&a.unshift(o.mark)),this.openWidget=!1},leave:o=>{o.isLine()?a.length&&(a.length=s=0):o instanceof ur&&(a.shift(),s=Math.min(s,a.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(e)}emit(e,t){let r=null,a=this.builder,s=-1,o=wt.spans(this.decorations,e,t,{point:(i,l,u,c,d,f)=>{if(u instanceof Ro){if(this.disallowBlockEffectsFor[f]){if(u.block)throw new RangeError("Block decorations may not be specified via plugins");if(l>this.view.state.doc.lineAt(i).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}if(s=c.length,d>c.length)a.continueWidget(l-i);else{let h=u.widget||(u.block?Gs.block:Gs.inline),p=YM(u),m=this.cache.findWidget(h,l-i,p)||To.of(h,this.view,l-i,p);u.block?(u.startSide>0&&a.addLineStartIfNotCovered(r),a.addBlockWidget(m)):(a.ensureLine(r),a.addInlineWidget(m,c,d))}r=null}else r=JM(r,u);l>i&&this.text.skip(l-i)},span:(i,l,u,c)=>{for(let d=i;d<l;){let f=this.text.next(Math.min(512,l-d));f==null?(a.addLineStartIfNotCovered(r),a.addBreak(),d++):(a.ensureLine(r),a.addText(f,u,d==i?c:u.length),d+=f.length),r=null}s=u.length}});s>-1&&(this.openWidget=o>s),this.openWidget||a.addLineStartIfNotCovered(r),this.openMarks=o}forward(e,t,r=1){t-e<=10?this.old.advance(t-e,r,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(t-e-10,-1),this.old.advance(5,r,this.reuseWalker))}getCompositionContext(e){let t=[],r=null;for(let a=e.parentNode;;a=a.parentNode){let s=Zt.get(a);if(a==this.view.contentDOM)break;s instanceof ur?t.push(s):s?.isLine()?r=s:s instanceof as||(a.nodeName=="DIV"&&!r?r=new Oi(a,wS):r||t.push(ur.of(new vu({tagName:a.nodeName.toLowerCase(),attributes:MM(a)}),a)))}return r?{line:r,marks:t}:null}};function vk(n,e){let t=r=>{for(let a of r.children)if((e?a.isText():a.length)||t(a))return!0;return!1};return t(n)}function YM(n){let e=n.isReplace?(n.startSide<0?64:0)|(n.endSide>0?128:0):n.startSide>0?32:16;return n.block&&(e|=256),e}var wS={class:"cm-line"};function JM(n,e){let t=e.spec.attributes,r=e.spec.class;return!t&&!r||(n||(n={class:"cm-line"}),t&&Hm(t,n),r&&(n.class+=" "+r)),n}function ZM(n){let e=[];for(let t=n.parents.length;t>1;t--){let r=t==n.parents.length?n.tile:n.parents[t].tile;r instanceof ur&&e.push(r.mark)}return e}function jp(n){let e=Zt.get(n);return e&&e.setDOM(n.cloneNode()),n}var Gs=class extends Ir{constructor(e){super(),this.tag=e}eq(e){return e.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(e){return e.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}};Gs.inline=new Gs("span");Gs.block=new Gs("div");var qp=new class extends Ir{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}},Dd=class{constructor(e){this.view=e,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=Xe.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new Bi(e,e.contentDOM),this.updateInner([new ua(0,0,0,e.state.doc.length)],null)}update(e){var t;let r=e.changedRanges;this.minWidth>0&&r.length&&(r.every(({fromA:c,toA:d})=>d<this.minWidthFrom||c>this.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(e);let a=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((t=this.domChanged)===null||t===void 0)&&t.newSel?a=this.domChanged.newSel.head:!oT(e.changes,this.hasComposition)&&!e.selectionSet&&(a=e.state.selection.main.head));let s=a>-1?eT(this.view,e.changes,a):null;if(this.domChanged=null,this.hasComposition){let{from:c,to:d}=this.hasComposition;r=new ua(c,d,e.changes.mapPos(c,-1),e.changes.mapPos(d,1)).addToSet(r.slice())}this.hasComposition=s?{from:s.range.fromB,to:s.range.toB}:null,(we.ie||we.chrome)&&!s&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let o=this.decorations,i=this.blockWrappers;this.updateDeco();let l=rT(o,this.decorations,e.changes);l.length&&(r=ua.extendWithRanges(r,l));let u=aT(i,this.blockWrappers,e.changes);return u.length&&(r=ua.extendWithRanges(r,u)),s&&!r.some(c=>c.fromA<=s.range.fromA&&c.toA>=s.range.toA)&&(r=s.range.addToSet(r.slice())),this.tile.flags&2&&r.length==0?!1:(this.updateInner(r,s),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t){this.view.viewState.mustMeasureContent=!0;let{observer:r}=this.view;r.ignore(()=>{if(t||e.length){let o=this.tile,i=new cm(this.view,o,this.blockWrappers,this.decorations,this.dynamicDecorationMap);t&&Zt.get(t.text)&&i.cache.reused.set(Zt.get(t.text),2),this.tile=i.run(e,t),dm(o,i.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let s=we.chrome||we.ios?{node:r.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(s),s&&(s.written||r.selectionRange.focusNode!=s.node||!this.tile.dom.contains(s.node))&&(this.forceSelection=!0),this.tile.dom.style.height=""});let a=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let s of this.tile.children)s.isWidget()&&s.widget instanceof gu&&a.push(s.dom);r.updateGaps(a)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let t of e.transactions)for(let r of t.effects)r.is(pS)&&(this.editContextFormatting=r.value)}updateSelection(e=!1,t=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let{dom:r}=this.tile,a=this.view.root.activeElement,s=a==r,o=!s&&!(this.view.state.facet(rs)||r.tabIndex>-1)&&du(r,this.view.observer.selectionRange)&&!(a&&r.contains(a));if(!(s||t||o))return;let i=this.forceSelection;this.forceSelection=!1;let l=this.view.state.selection.main,u,c;if(l.empty?c=u=this.inlineDOMNearPos(l.anchor,l.assoc||1):(c=this.inlineDOMNearPos(l.head,l.head==l.from?1:-1),u=this.inlineDOMNearPos(l.anchor,l.anchor==l.from?1:-1)),we.gecko&&l.empty&&!this.hasComposition&&QM(u)){let f=document.createTextNode("");this.view.observer.ignore(()=>u.node.insertBefore(f,u.node.childNodes[u.offset]||null)),u=c=new Ma(f,0),i=!0}let d=this.view.observer.selectionRange;(i||!d.focusNode||(!hu(u.node,u.offset,d.anchorNode,d.anchorOffset)||!hu(c.node,c.offset,d.focusNode,d.focusOffset))&&!this.suppressWidgetCursorChange(d,l))&&(this.view.observer.ignore(()=>{we.android&&we.chrome&&r.contains(d.focusNode)&&sT(d.focusNode,r)&&(r.blur(),r.focus({preventScroll:!0}));let f=Su(this.view.root);if(f)if(l.empty){if(we.gecko){let h=tT(u.node,u.offset);if(h&&h!=3){let p=(h==1?Zk:Qk)(u.node,u.offset);p&&(u=new Ma(p.node,p.offset))}}f.collapse(u.node,u.offset),l.bidiLevel!=null&&f.caretBidiLevel!==void 0&&(f.caretBidiLevel=l.bidiLevel)}else if(f.extend){f.collapse(u.node,u.offset);try{f.extend(c.node,c.offset)}catch{}}else{let h=document.createRange();l.anchor>l.head&&([u,c]=[c,u]),h.setEnd(c.node,c.offset),h.setStart(u.node,u.offset),f.removeAllRanges(),f.addRange(h)}o&&this.view.root.activeElement==r&&(r.blur(),a&&a.focus())}),this.view.observer.setSelectionRange(u,c)),this.impreciseAnchor=u.precise?null:new Ma(d.anchorNode,d.anchorOffset),this.impreciseHead=c.precise?null:new Ma(d.focusNode,d.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&hu(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)&&this.posFromDOM(e.focusNode,e.focusOffset)==t.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,t=e.state.selection.main,r=Su(e.root),{anchorNode:a,anchorOffset:s}=e.observer.selectionRange;if(!r||!t.empty||!t.assoc||!r.modify)return;let o=this.lineAt(t.head,t.assoc);if(!o)return;let i=o.posAtStart;if(t.head==i||t.head==i+o.length)return;let l=this.coordsAt(t.head,-1),u=this.coordsAt(t.head,1);if(!l||!u||l.bottom>u.top)return;let c=this.domAtPos(t.head+t.assoc,t.assoc);r.collapse(c.node,c.offset),r.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let d=e.observer.selectionRange;e.docView.posFromDOM(d.anchorNode,d.anchorOffset)!=t.from&&r.collapse(a,s)}posFromDOM(e,t){let r=this.tile.nearest(e);if(!r)return this.tile.dom.compareDocumentPosition(e)&2?0:this.view.state.doc.length;let a=r.posAtStart;if(r.isComposite()){let s;if(e==r.dom)s=r.dom.childNodes[t];else{let o=ss(e)==0?0:t==0?-1:1;for(;;){let i=e.parentNode;if(i==r.dom)break;o==0&&i.firstChild!=i.lastChild&&(e==i.firstChild?o=-1:o=1),e=i}o<0?s=e:s=e.nextSibling}if(s==r.dom.firstChild)return a;for(;s&&!Zt.get(s);)s=s.nextSibling;if(!s)return a+r.length;for(let o=0,i=a;;o++){let l=r.children[o];if(l.dom==s)return i;i+=l.length+l.breakAfter}}else return r.isText()?e==r.dom?a+t:a+(t?r.length:0):a}domAtPos(e,t){let{tile:r,offset:a}=this.tile.resolveBlock(e,t);return r.isWidget()?r.domPosFor(a,t):r.domIn(a,t)}inlineDOMNearPos(e,t){let r,a=-1,s=!1,o,i=-1,l=!1;return this.tile.blockTiles((u,c)=>{if(u.isWidget()){if(u.flags&32&&c>=e)return!0;u.flags&16&&(s=!0)}else{let d=c+u.length;if(c<=e&&(r=u,a=e-c,s=d<e),d>=e&&!o&&(o=u,i=e-c,l=c>e),c>e&&o)return!0}}),!r&&!o?this.domAtPos(e,t):(s&&o?r=null:l&&r&&(o=null),r&&t<0||!o?r.domIn(a,t):o.domIn(i,t))}coordsAt(e,t,r){let{tile:a,offset:s}=this.tile.resolveBlock(e,t);return a.isWidget()?a.widget instanceof gu?null:a.coordsInWidget(s,t,!0):a.coordsIn(s,t,r)}lineAt(e,t){let{tile:r}=this.tile.resolveBlock(e,t);return r.isLine()?r:null}coordsForChar(e){let{tile:t,offset:r}=this.tile.resolveBlock(e,1);if(!t.isLine())return null;function a(s,o){if(s.isComposite())for(let i of s.children){if(i.length>=o){let l=a(i,o);if(l)return l}if(o-=i.length,o<0)break}else if(s.isText()&&o<s.length){let i=Nn(s.text,o);if(i==o)return null;let l=Lu(s.dom,o,i).getClientRects();for(let u=0;u<l.length;u++){let c=l[u];if(u==l.length-1||c.top<c.bottom&&c.left<c.right)return c}}return null}return a(t,r)}measureVisibleLineHeights(e){let t=[],{from:r,to:a}=e,s=this.view.contentDOM.clientWidth,o=s>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,i=-1,l=this.view.textDirection==Wt.LTR,u=0,c=(d,f,h)=>{for(let p=0;p<d.children.length&&!(f>a);p++){let m=d.children[p],g=f+m.length,x=m.dom.getBoundingClientRect(),{height:w}=x;if(h&&!p&&(u+=x.top-h.top),m instanceof as)g>r&&c(m,f,x);else if(f>=r&&(u>0&&t.push(-u),t.push(w+u),u=0,o)){let y=m.dom.lastChild,C=y?fu(y):[];if(C.length){let k=C[C.length-1],v=l?k.right-x.left:x.right-k.left;v>i&&(i=v,this.minWidth=s,this.minWidthFrom=f,this.minWidthTo=g)}}h&&p==d.children.length-1&&(u+=h.bottom-x.bottom),f=g+m.breakAfter}};return c(this.tile,0,null),t}textDirectionAt(e){let{tile:t}=this.tile.resolveBlock(e,1);return getComputedStyle(t.dom).direction=="rtl"?Wt.RTL:Wt.LTR}measureTextSize(){let e=this.tile.blockTiles(o=>{if(o.isLine()&&o.children.length&&o.length<=20){let i=0,l;for(let u of o.children){if(!u.isText()||/[^ -~]/.test(u.text))return;let c=fu(u.dom);if(c.length!=1)return;i+=c[0].width,l=c[0].height}if(i)return{lineHeight:o.dom.getBoundingClientRect().height,charWidth:i/o.length,textHeight:l}}});if(e)return e;let t=document.createElement("div"),r,a,s;return t.className="cm-line",t.style.width="99999px",t.style.position="absolute",t.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.tile.dom.appendChild(t);let o=fu(t.firstChild)[0];r=t.getBoundingClientRect().height,a=o&&o.width?o.width/27:7,s=o&&o.height?o.height:r,t.remove()}),{lineHeight:r,charWidth:a,textHeight:s}}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let r=0,a=0;;a++){let s=a==t.viewports.length?null:t.viewports[a],o=s?s.from-1:this.view.state.doc.length;if(o>r){let i=(t.lineBlockAt(o).bottom-t.lineBlockAt(r).top)/this.view.scaleY;e.push(Xe.replace({widget:new gu(i),block:!0,inclusive:!0,isBlockGap:!0}).range(r,o))}if(!s)break;r=s.to+1}return Xe.set(e)}updateDeco(){let e=1,t=this.view.state.facet(Wd).map(s=>(this.dynamicDecorationMap[e++]=typeof s=="function")?s(this.view):s),r=!1,a=this.view.state.facet(qm).map((s,o)=>{let i=typeof s=="function";return i&&(r=!0),i?s(this.view):s});for(a.length&&(this.dynamicDecorationMap[e++]=r,t.push(wt.join(a))),this.decorations=[this.editContextFormatting,...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];e<this.decorations.length;)this.dynamicDecorationMap[e++]=!1;this.blockWrappers=this.view.state.facet(gS).map(s=>typeof s=="function"?s(this.view):s)}scrollIntoView(e){if(e.isSnapshot){let u=this.view.viewState.lineBlockAt(e.range.head);this.view.scrollDOM.scrollTop=u.top-e.yMargin,this.view.scrollDOM.scrollLeft=e.xMargin;return}for(let u of this.view.state.facet(hS))try{if(u(this.view,e.range,e))return!0}catch(c){la(this.view.state,c,"scroll handler")}let{range:t}=e,r=this.coordsAt(t.head,t.assoc||(t.head>t.anchor?-1:1)),a;if(!r)return;!t.empty&&(a=this.coordsAt(t.anchor,t.anchor>t.head?-1:1))&&(r={left:Math.min(r.left,a.left),top:Math.min(r.top,a.top),right:Math.max(r.right,a.right),bottom:Math.max(r.bottom,a.bottom)});let s=bS(this.view),o={left:r.left-s.left,top:r.top-s.top,right:r.right+s.right,bottom:r.bottom+s.bottom},{offsetWidth:i,offsetHeight:l}=this.view.scrollDOM;if(FM(this.view.scrollDOM,o,t.head<t.anchor?-1:1,e.x,e.y,Math.max(Math.min(e.xMargin,i),-i),Math.max(Math.min(e.yMargin,l),-l),this.view.textDirection==Wt.LTR),window.visualViewport&&window.innerHeight-window.visualViewport.height>1&&(r.top>window.visualViewport.offsetTop+window.visualViewport.height||r.bottom<window.visualViewport.offsetTop)){let u=this.view.docView.lineAt(t.head,1);if(u){let c=Kk(u.dom);u.dom.scrollIntoView({block:"nearest"}),Xk(c,!1)}}}lineHasWidget(e){let t=r=>r.isWidget()||r.children.some(t);return t(this.tile.resolveBlock(e,1).tile)}destroy(){dm(this.tile)}};function dm(n,e){let t=e?.get(n);if(t!=1){t==null&&n.destroy();for(let r of n.children)dm(r,e)}}function QM(n){return n.node.nodeType==1&&n.node.firstChild&&(n.offset==0||n.node.childNodes[n.offset-1].contentEditable=="false")&&(n.offset==n.node.childNodes.length||n.node.childNodes[n.offset].contentEditable=="false")}function vS(n,e){let t=n.observer.selectionRange;if(!t.focusNode)return null;let r=Zk(t.focusNode,t.focusOffset),a=Qk(t.focusNode,t.focusOffset),s=r||a;if(a&&r&&a.node!=r.node){let i=Zt.get(a.node);if(!i||i.isText()&&i.text!=a.node.nodeValue)s=a;else if(n.docView.lastCompositionAfterCursor){let l=Zt.get(r.node);!l||l.isText()&&l.text!=r.node.nodeValue||(s=a)}}if(n.docView.lastCompositionAfterCursor=s!=r,!s)return null;let o=e-s.offset;return{from:o,to:o+s.node.nodeValue.length,node:s.node}}function eT(n,e,t){let r=vS(n,t);if(!r)return null;let{node:a,from:s,to:o}=r,i=a.nodeValue;if(/[\n\r]/.test(i)||n.state.doc.sliceString(r.from,r.to)!=i)return null;let l=e.invertedDesc;return{range:new ua(l.mapPos(s),l.mapPos(o),s,o),text:a}}function tT(n,e){return n.nodeType!=1?0:(e&&n.childNodes[e-1].contentEditable=="false"?1:0)|(e<n.childNodes.length&&n.childNodes[e].contentEditable=="false"?2:0)}var nT=class{constructor(){this.changes=[]}compareRange(e,t){Di(e,t,this.changes)}comparePoint(e,t){Di(e,t,this.changes)}boundChange(e){Di(e,e,this.changes)}};function rT(n,e,t){let r=new nT;return wt.compare(n,e,t,r),r.changes}var fm=class{constructor(){this.changes=[]}compareRange(e,t){Di(e,t,this.changes)}comparePoint(){}boundChange(e){Di(e,e,this.changes)}};function aT(n,e,t){let r=new fm;return wt.compare(n,e,t,r),r.changes}function sT(n,e){for(let t=n;t&&t!=e;t=t.assignedSlot||t.parentNode)if(t.nodeType==1&&t.contentEditable=="false")return!0;return!1}function oT(n,e){let t=!1;return e&&n.iterChangedRanges((r,a)=>{r<e.to&&a>e.from&&(t=!0)}),t}var gu=class extends Ir{constructor(e){super(),this.height=e}toDOM(){let e=document.createElement("div");return e.className="cm-gap",this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}};function iT(n,e,t=1){let r=n.charCategorizer(e),a=n.doc.lineAt(e),s=e-a.from;if(a.length==0)return se.cursor(e);s==0?t=1:s==a.length&&(t=-1);let o=s,i=s;t<0?o=Nn(a.text,s,!1):i=Nn(a.text,s);let l=r(a.text.slice(o,i));for(;o>0;){let u=Nn(a.text,o,!1);if(r(a.text.slice(u,o))!=l)break;o=u}for(;i<a.length;){let u=Nn(a.text,i);if(r(a.text.slice(i,u))!=l)break;i=u}return se.undirectionalRange(o+a.from,i+a.from)}function lT(n,e,t,r,a){let s=Math.round((r-e.left)*n.defaultCharacterWidth);if(n.lineWrapping&&t.height>n.defaultLineHeight*1.5){let i=n.viewState.heightOracle.textHeight,l=Math.floor((a-t.top-(n.defaultLineHeight-i)*.5)/i);s+=l*n.viewState.heightOracle.lineLength}let o=n.state.sliceDoc(t.from,t.to);return t.from+lk(o,s,n.state.tabSize)}function hm(n,e,t){let r=n.lineBlockAt(e);if(Array.isArray(r.type)){let a;for(let s of r.type){if(s.from>e)break;if(!(s.to<e)){if(s.from<e&&s.to>e)return s;(!a||s.type==Bn.Text&&(a.type!=s.type||(t<0?s.from<e:s.to>e)))&&(a=s)}}return a||r}return r}function uT(n,e,t,r){let a=hm(n,e.head,e.assoc||-1),s=!r||a.type!=Bn.Text||!(n.lineWrapping||a.widgetLineBreaks)?null:n.coordsAtPos(e.assoc<0&&e.head>a.from?e.head-1:e.head);if(s){let o=n.dom.getBoundingClientRect(),i=n.textDirectionAt(a.from),l=n.posAtCoords({x:t==(i==Wt.LTR)?o.right-1:o.left+1,y:(s.top+s.bottom)/2});if(l!=null)return se.cursor(l,t?-1:1)}return se.cursor(t?a.to:a.from,t?-1:1)}function kk(n,e,t,r){let a=n.state.doc.lineAt(e.head),s=n.bidiSpans(a),o=n.textDirectionAt(a.from);for(let i=e,l=null;;){let u=jM(a,s,o,i,t),c=aS;if(!u){if(a.number==(t?n.state.doc.lines:1))return i;c=`
39
- `,a=n.state.doc.line(a.number+(t?1:-1)),s=n.bidiSpans(a),u=t?se.cursor(a.from,-1):se.cursor(a.to,1)}if(l){if(!l(c))return i}else{if(!r)return u;l=r(c)}i=u}}function cT(n,e,t){let r=n.state.charCategorizer(e),a=r(t);return s=>{let o=r(s);return a==oa.Space&&(a=o),a==o}}function dT(n,e,t,r){let a=e.head,s=t?1:-1;if(a==(t?n.state.doc.length:0))return se.cursor(a,e.assoc);let o=e.goalColumn,i,l=n.contentDOM.getBoundingClientRect(),u=n.coordsAtPos(a,e.assoc||((e.empty?t:e.head==e.from)?1:-1)),c=n.documentTop;if(u)o==null&&(o=u.left-l.left),i=s<0?u.top:u.bottom;else{let p=n.viewState.lineBlockAt(a);o==null&&(o=Math.min(l.right-l.left,n.defaultCharacterWidth*(a-p.from))),i=(s<0?p.top:p.bottom)+c}let d=l.left+o,f=n.viewState.heightOracle.textHeight>>1,h=r??f;for(let p=0;;p+=f){let m=i+(h+p)*s,g=pm(n,{x:d,y:m},!1,s);if(t?m>l.bottom:m<l.top)return se.cursor(g.pos,g.assoc);let x=n.coordsAtPos(g.pos,g.assoc),w=x?(x.top+x.bottom)/2:0;if(!x||(t?w>i:w<i))return se.cursor(g.pos,g.assoc,void 0,o)}}function xu(n,e,t){for(;;){let r=0;for(let a of n)a.between(e-1,e+1,(s,o,i)=>{if(e>s&&e<o){let l=r||t||(e-s<o-e?-1:1);e=l<0?s:o,r=l}});if(!r)return e}}function kS(n,e){let t=null;for(let r=0;r<e.ranges.length;r++){let a=e.ranges[r],s=null;if(a.empty){let o=xu(n,a.from,0);o!=a.from&&(s=se.cursor(o,-1))}else{let o=xu(n,a.from,-1),i=xu(n,a.to,1);(o!=a.from||i!=a.to)&&(a.undirectional?s=se.undirectionalRange(a.from,a.to):s=se.range(a.from==a.anchor?o:i,a.from==a.head?o:i))}s&&(t||(t=e.ranges.slice()),t[r]=s)}return t?se.create(t,e.mainIndex):e}function Vp(n,e,t){let r=xu(n.state.facet(Iu).map(a=>a(n)),t.from,e.head>t.from?-1:1);return r==t.from?t:se.cursor(r,r<t.from?1:-1)}var qr=class{constructor(e,t){this.pos=e,this.assoc=t}};function pm(n,e,t,r){let a=n.contentDOM.getBoundingClientRect(),s=a.top+n.viewState.paddingTop,{x:o,y:i}=e,l=i-s,u;for(;;){if(l<0)return new qr(0,1);if(l>n.viewState.docHeight)return new qr(n.state.doc.length,-1);if(u=n.elementAtHeight(l),r==null)break;if(u.type==Bn.Text){if(r<0?u.to<n.viewport.from:u.from>n.viewport.to)break;let f=n.docView.coordsAt(r<0?u.from:u.to,r>0?-1:1);if(f&&(r<0?f.top<=l+s:f.bottom>=l+s))break}let d=n.viewState.heightOracle.textHeight/2;l=r>0?u.bottom+d:u.top-d}if(n.viewport.from>=u.to||n.viewport.to<=u.from){if(t)return null;if(u.type==Bn.Text){let d=lT(n,a,u,o,i);return new qr(d,d==u.from?1:-1)}}if(u.type!=Bn.Text)return l<(u.top+u.bottom)/2?new qr(u.from,1):new qr(u.to,-1);let c=n.docView.lineAt(u.from,2);return(!c||c.length!=u.length)&&(c=n.docView.lineAt(u.from,-2)),new mm(n,o,i,n.textDirectionAt(u.from)).scanTile(c,u.from)}var mm=class{constructor(e,t,r,a){this.view=e,this.x=t,this.y=r,this.baseDir=a,this.line=null,this.spans=null}bidiSpansAt(e){return(!this.line||this.line.from>e||this.line.to<e)&&(this.line=this.view.state.doc.lineAt(e),this.spans=this.view.bidiSpans(this.line)),this}baseDirAt(e,t){let{line:r,spans:a}=this.bidiSpansAt(e);return a[Vr.find(a,e-r.from,-1,t)].level==this.baseDir}dirAt(e,t){let{line:r,spans:a}=this.bidiSpansAt(e);return a[Vr.find(a,e-r.from,-1,t)].dir}bidiIn(e,t){let{spans:r,line:a}=this.bidiSpansAt(e);return r.length>1||r.length&&(r[0].level!=this.baseDir||r[0].to+a.from<t)}scan(e,t,r=!1){let a=0,s=e.length-1,o=new Set,i=this.bidiIn(e[0],e[s]),l,u,c=-1,d=1e9,f;e:for(;a<s;){let p=s-a,m=a+s>>1;t:if(o.has(m)){for(let w=1;w<p;w++){let y=m+w;if(y>=s&&(y-=p),!o.has(y)){m=y;break t}}break e}o.add(m);let g=t(m),x=0;if(g)for(let w=0;w<g.length;w++){let y=g[w];if(!(y.width==0&&g.length>1))if(y.bottom<this.y)(!l||l.bottom<y.bottom)&&(l=y),x=1;else if(y.top>this.y)(!u||u.top>y.top)&&(u=y),x=-1;else{let C=y.left>this.x?this.x-y.left:y.right<this.x?this.x-y.right:0,k=Math.abs(C);k<d&&(c=m,d=k,f=y),C&&(x=C<0==(this.baseDir==Wt.LTR)?-1:1)}}x==-1&&(!i||this.baseDirAt(e[m],1))?s=m:x==1&&(!i||this.baseDirAt(e[m+1],-1))&&(a=m+1)}if(!f){if(!u&&!l)return{i:0,after:!1};let p=l&&(!u||this.y-l.bottom<u.top-this.y)?l:u;return this.y=(p.top+p.bottom)/2,this.scan(e,t,!0)}if(d&&!r){let{top:p,bottom:m}=f;if(l&&l.bottom>(p+p+m)/3)return this.y=l.bottom-1,this.scan(e,t,!0);if(u&&u.top<(p+m+m)/3)return this.y=u.top+1,this.scan(e,t,!0)}let h=(i?this.dirAt(e[c],1):this.baseDir)==Wt.LTR;return{i:c,after:this.x>(f.left+f.right)/2==h}}scanText(e,t){let r=[];for(let s=0;s<e.length;s=Nn(e.text,s))r.push(t+s);r.push(t+e.length);let a=this.scan(r,s=>{let o=r[s]-t,i=r[s+1]-t;return Lu(e.dom,o,i).getClientRects()});return a.after?new qr(r[a.i+1],-1):new qr(r[a.i],1)}scanTile(e,t){if(!e.length)return new qr(t,1);if(e.children.length==1){let i=e.children[0];if(i.isText())return this.scanText(i,t);if(i.isComposite())return this.scanTile(i,t)}let r=[t];for(let i=0,l=t;i<e.children.length;i++)r.push(l+=e.children[i].length);let a=this.scan(r,i=>{let l=e.children[i];return l.flags&48?null:(l.dom.nodeType==1?l.dom:Lu(l.dom,0,l.length)).getClientRects()}),s=e.children[a.i],o=r[a.i];return s.isText()?this.scanText(s,o):s.isComposite()?this.scanTile(s,o):a.after?new qr(r[a.i+1],-1):new qr(o,1)}},Ni="\uFFFF",gm=class{constructor(e,t){this.points=e,this.view=t,this.text="",this.lineSeparator=t.state.facet(Ct.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=Ni}readRange(e,t){if(!e)return this;let r=e.parentNode;for(let a=e;;){this.findPointBefore(r,a);let s=this.text.length;this.readNode(a);let o=Zt.get(a),i=a.nextSibling;if(i==t){o?.breakAfter&&!i&&r!=this.view.contentDOM&&this.lineBreak();break}let l=Zt.get(i);(o&&l?o.breakAfter:(o?o.breakAfter:Rd(a))||Rd(i)&&(a.nodeName!="BR"||o?.isWidget())&&this.text.length>s)&&!hT(i,t)&&this.lineBreak(),a=i}return this.findPointBefore(r,t),this}readTextNode(e){let t=e.nodeValue;for(let r of this.points)r.node==e&&(r.pos=this.text.length+Math.min(r.offset,t.length));for(let r=0,a=this.lineSeparator?null:/\r\n?|\n/g;;){let s=-1,o=1,i;if(this.lineSeparator?(s=t.indexOf(this.lineSeparator,r),o=this.lineSeparator.length):(i=a.exec(t))&&(s=i.index,o=i[0].length),this.append(t.slice(r,s<0?t.length:s)),s<0)break;if(this.lineBreak(),o>1)for(let l of this.points)l.node==e&&l.pos>this.text.length&&(l.pos-=o-1);r=s+o}}readNode(e){let t=Zt.get(e),r=t&&t.overrideDOMText;if(r!=null){this.findPointInside(e,r.length);for(let a=r.iter();!a.next().done;)a.lineBreak?this.lineBreak():this.append(a.value)}else e.nodeType==3?this.readTextNode(e):e.nodeName=="BR"?e.nextSibling&&this.lineBreak():e.nodeType==1&&this.readRange(e.firstChild,null)}findPointBefore(e,t){for(let r of this.points)r.node==e&&e.childNodes[r.offset]==t&&(r.pos=this.text.length)}findPointInside(e,t){for(let r of this.points)(e.nodeType==3?r.node==e:e.contains(r.node))&&(r.pos=this.text.length+(fT(e,r.node,r.offset)?t:0))}};function fT(n,e,t){for(;;){if(!e||t<ss(e))return!1;if(e==n)return!0;t=Us(e)+1,e=e.parentNode}}function hT(n,e){let t;for(;!(n==e||!n);n=n.nextSibling){let r=Zt.get(n);if(!r?.isWidget())return!1;r&&(t||(t=[])).push(r)}if(t)for(let r of t){let a=r.overrideDOMText;if(a?.length)return!1}return!0}var Fd=class{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}},xm=class{constructor(e,t,r,a){this.typeOver=a,this.bounds=null,this.text="",this.domChanged=t>-1;let{impreciseHead:s,impreciseAnchor:o}=e.docView,i=e.state.selection;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=SS(e.docView.tile,t,r,0))){let l=s||o?[]:mT(e),u=new gm(l,e);u.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=u.text,this.newSel=gT(l,this.bounds.from)}else{let l=e.observer.selectionRange,u=s&&s.node==l.focusNode&&s.offset==l.focusOffset||!Qp(e.contentDOM,l.focusNode)?i.main.head:e.docView.posFromDOM(l.focusNode,l.focusOffset),c=o&&o.node==l.anchorNode&&o.offset==l.anchorOffset||!Qp(e.contentDOM,l.anchorNode)?i.main.anchor:e.docView.posFromDOM(l.anchorNode,l.anchorOffset),d=e.viewport;if((we.ios||we.chrome)&&u!=c&&Math.min(u,c)<=i.main.from&&Math.max(u,c)>=i.main.to&&(d.from>0||d.to<e.state.doc.length)){let f=Math.min(u,c),h=Math.max(u,c),p=d.from-f,m=d.to-h;(p==0||p==1||f==0)&&(m==0||m==-1||h==e.state.doc.length)&&(u=0,c=e.state.doc.length)}if(e.inputState.composing>-1&&i.ranges.length>1)this.newSel=i.replaceRange(se.range(c,u));else if(e.lineWrapping&&c==u&&!(i.main.empty&&i.main.head==u)&&e.inputState.lastTouchTime>Date.now()-100){let f=e.coordsAtPos(u,-1),h=0;f&&(h=e.inputState.lastTouchY<=f.bottom?-1:1),this.newSel=se.create([se.cursor(u,h)])}else this.newSel=se.single(c,u)}}};function SS(n,e,t,r){if(n.isComposite()){let a=-1,s=-1,o=-1,i=-1;for(let l=0,u=r,c=r;l<n.children.length;l++){let d=n.children[l],f=u+d.length;if(u<e&&f>t)return SS(d,e,t,u);if(f>=e&&a==-1&&(a=l,s=u),u>t&&d.dom.parentNode==n.dom){o=l,i=c;break}c=f,u=f+d.breakAfter}return{from:s,to:i<0?r+n.length:i,startDOM:(a?n.children[a-1].dom.nextSibling:null)||n.dom.firstChild,endDOM:o<n.children.length&&o>=0?n.children[o].dom:null}}else return n.isText()?{from:r,to:r+n.length,startDOM:n.dom,endDOM:n.dom.nextSibling}:null}function CS(n,e){let t,{newSel:r}=e,{state:a}=n,s=a.selection.main,o=n.inputState.lastKeyTime>Date.now()-100?n.inputState.lastKeyCode:-1;if(e.bounds){let{from:i,to:l}=e.bounds,u=s.from,c=null;(o===8||we.android&&e.text.length<l-i)&&(u=s.to,c="end");let d=a.doc.sliceString(i,l,Ni),f,h;!s.empty&&s.from>=i&&s.to<=l&&(e.typeOver||d!=e.text)&&d.slice(0,s.from-i)==e.text.slice(0,s.from-i)&&d.slice(s.to-i)==e.text.slice(f=e.text.length-(d.length-(s.to-i)))?t={from:s.from,to:s.to,insert:ct.of(e.text.slice(s.from-i,f).split(Ni))}:(h=LS(d,e.text,u-i,c))&&(we.chrome&&o==13&&h.toB==h.from+2&&e.text.slice(h.from,h.toB)==Ni+Ni&&h.toB--,t={from:i+h.from,to:i+h.toA,insert:ct.of(e.text.slice(h.from,h.toB).split(Ni))})}else r&&(!n.hasFocus&&a.facet(rs)||Ed(r,s))&&(r=null);if(!t&&!r)return!1;if((we.mac||we.android)&&t&&t.from==t.to&&t.from==s.head-1&&/^\. ?$/.test(t.insert.toString())&&n.contentDOM.getAttribute("autocorrect")=="off"?(r&&t.insert.length==2&&(r=se.single(r.main.anchor-1,r.main.head-1)),t={from:t.from,to:t.to,insert:ct.of([t.insert.toString().replace("."," ")])}):a.doc.lineAt(s.from).to<s.to&&n.docView.lineHasWidget(s.to)&&n.inputState.insertingTextAt>Date.now()-50?t={from:s.from,to:s.to,insert:a.toText(n.inputState.insertingText)}:we.chrome&&t&&t.from==t.to&&t.from==s.head&&t.insert.toString()==`
40
- `&&n.lineWrapping&&(r&&(r=se.single(r.main.anchor-1,r.main.head-1)),t={from:s.from,to:s.to,insert:ct.of([" "])}),t)return Vm(n,t,r,o);if(r&&!Ed(r,s)){let i=!1,l="select";return n.inputState.lastSelectionTime>Date.now()-50&&(n.inputState.lastSelectionOrigin=="select"&&(i=!0),l=n.inputState.lastSelectionOrigin,l=="select.pointer"&&(r=kS(a.facet(Iu).map(u=>u(n)),r))),n.dispatch({selection:r,scrollIntoView:i,userEvent:l}),!0}else return!1}function Vm(n,e,t,r=-1){if(we.ios&&n.inputState.flushIOSKey(e))return!0;let a=n.state.selection.main;if(we.android&&(e.to==a.to&&(e.from==a.from||e.from==a.from-1&&n.state.sliceDoc(e.from,a.from)==" ")&&e.insert.length==1&&e.insert.lines==2&&Fi(n.contentDOM,"Enter",13)||(e.from==a.from-1&&e.to==a.to&&e.insert.length==0||r==8&&e.insert.length<e.to-e.from&&e.to>a.head)&&Fi(n.contentDOM,"Backspace",8)||e.from==a.from&&e.to==a.to+1&&e.insert.length==0&&Fi(n.contentDOM,"Delete",46)))return!0;let s=e.insert.toString();n.inputState.composing>=0&&n.inputState.composing++;let o,i=()=>o||(o=pT(n,e,t));return n.state.facet(uS).some(l=>l(n,e.from,e.to,s,i))||n.dispatch(i()),!0}function pT(n,e,t){let r,a=n.state,s=a.selection.main,o=-1;if(e.from==e.to&&e.from<s.from||e.from>s.to){let l=e.from<s.from?-1:1,u=l<0?s.from:s.to,c=xu(a.facet(Iu).map(d=>d(n)),u,l);e.from==c&&(o=c)}if(o>-1)r={changes:e,selection:se.cursor(e.from+e.insert.length,-1)};else if(e.from>=s.from&&e.to<=s.to&&e.to-e.from>=(s.to-s.from)/3&&(!t||t.main.empty&&t.main.from==e.from+e.insert.length)&&n.inputState.composing<0){let l=s.from<e.from?a.sliceDoc(s.from,e.from):"",u=s.to>e.to?a.sliceDoc(e.to,s.to):"";r=a.replaceSelection(n.state.toText(l+e.insert.sliceString(0,void 0,n.state.lineBreak)+u))}else{let l=a.changes(e),u=t&&t.main.to<=l.newLength?t.main:void 0;if(a.selection.ranges.length>1&&(n.inputState.composing>=0||n.inputState.compositionPendingChange)&&e.to<=s.to+10&&e.to>=s.to-10){let c=n.state.sliceDoc(e.from,e.to),d,f=t&&vS(n,t.main.head);if(f){let p=e.insert.length-(e.to-e.from);d={from:f.from,to:f.to-p}}else d=n.state.doc.lineAt(s.head);let h=s.to-e.to;r=a.changeByRange(p=>{if(p.from==s.from&&p.to==s.to)return{changes:l,range:u||p.map(l)};let m=p.to-h,g=m-c.length;if(n.state.sliceDoc(g,m)!=c||m>=d.from&&g<=d.to)return{range:p};let x=a.changes({from:g,to:m,insert:e.insert}),w=p.to-s.to;return{changes:x,range:u?se.range(Math.max(0,u.anchor+w),Math.max(0,u.head+w)):p.map(x)}})}else r={changes:l,selection:u&&a.selection.replaceRange(u)}}let i="input.type";return(n.composing||n.inputState.compositionPendingChange&&n.inputState.compositionEndedAt>Date.now()-50)&&(n.inputState.compositionPendingChange=!1,i+=".compose",n.inputState.compositionFirstChange&&(i+=".start",n.inputState.compositionFirstChange=!1)),a.update(r,{userEvent:i,scrollIntoView:!0})}function LS(n,e,t,r){let a=Math.min(n.length,e.length),s=0;for(;s<a&&n.charCodeAt(s)==e.charCodeAt(s);)s++;if(s==a&&n.length==e.length)return null;let o=n.length,i=e.length;for(;o>0&&i>0&&n.charCodeAt(o-1)==e.charCodeAt(i-1);)o--,i--;if(r=="end"){let l=Math.max(0,s-Math.min(o,i));t-=o+l-s}if(o<s&&n.length<e.length){let l=t<=s&&t>=o?s-t:0;s-=l,i=s+(i-o),o=s}else if(i<s){let l=t<=s&&t>=i?s-t:0;s-=l,o=s+(o-i),i=s}return{from:s,toA:o,toB:i}}function mT(n){let e=[];if(n.root.activeElement!=n.contentDOM)return e;let{anchorNode:t,anchorOffset:r,focusNode:a,focusOffset:s}=n.observer.selectionRange;return t&&(e.push(new Fd(t,r)),(a!=t||s!=r)&&e.push(new Fd(a,s))),e}function gT(n,e){if(n.length==0)return null;let t=n[0].pos,r=n.length==2?n[1].pos:t;return t<0||r<0?null:t==r?se.create([se.cursor(r+e,-1)]):se.single(t+e,r+e)}function Ed(n,e){return e.head==n.main.head&&e.anchor==n.main.anchor}var ym=class{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.touchActive=!1,this.lastTouchTime=0,this.lastTouchX=0,this.lastTouchY=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.lastWheelEvent=0,this.pendingIOSKey=void 0,this.lastIOSMomentumScroll=0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,we.safari&&e.contentDOM.addEventListener("input",()=>null),we.gecko&&MT(e.contentDOM.ownerDocument)}handleEvent(e){!CT(this.view,e)||this.ignoreDuringComposition(e)||e.type=="keydown"&&this.keydown(e)||(this.view.updateState!=0?Promise.resolve().then(()=>this.runHandlers(e.type,e)):this.runHandlers(e.type,e))}runHandlers(e,t){let r=this.handlers[e];if(r){for(let a of r.observers)a(this.view,t);for(let a of r.handlers){if(t.defaultPrevented)break;if(a(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=yT(e),r=this.handlers,a=this.view.contentDOM;for(let s in t)if(s!="scroll"){let o=!t[s].handlers.length,i=r[s];i&&o!=!i.handlers.length&&(a.removeEventListener(s,this.handleEvent),i=null),i||a.addEventListener(s,this.handleEvent,{passive:o})}for(let s in r)s!="scroll"&&!t[s]&&a.removeEventListener(s,this.handleEvent);this.handlers=t}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),e.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&e.keyCode!=27&&AS.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),we.android&&we.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;if(we.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&(IS.some(t=>t.keyCode==e.keyCode)&&!e.ctrlKey||bT.indexOf(e.key)>-1&&e.ctrlKey)){let t={ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey,shiftKey:e.shiftKey};t.shiftKey&&we.ios&&!/^(off|none)$/.test(this.view.contentDOM.autocapitalize)&&xT(this.view.win)&&(t.shiftKey=!1);let r=this.pendingIOSKey={key:e.key,keyCode:e.keyCode,mods:t};return setTimeout(()=>{this.pendingIOSKey==r&&this.flushIOSKey()},50),!0}return e.keyCode!=229&&this.view.observer.forceFlush(),!1}flushIOSKey(e){let t=this.pendingIOSKey;return!t||this.view.observer.pendingRecords().length||t.key=="Enter"&&e&&e.from<e.to&&/^\S+$/.test(e.insert.toString())?!1:(this.pendingIOSKey=void 0,Fi(this.view.contentDOM,t.key,t.keyCode,t.mods))}ignoreDuringComposition(e){return!/^key/.test(e.type)||e.synthetic?!1:this.composing>0?!0:we.safari&&!we.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.view.observer.update(e),this.mouseSelection&&this.mouseSelection.update(e),this.draggedContent&&e.docChanged&&(this.draggedContent=this.draggedContent.map(e.changes)),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}};function xT(n){return n.visualViewport?n.visualViewport.height*n.visualViewport.scale/n.document.documentElement.clientHeight<.85:!1}function Sk(n,e){return(t,r)=>{try{return e.call(n,r,t)}catch(a){la(t.state,a)}}}function yT(n){let e=Object.create(null);function t(r){return e[r]||(e[r]={observers:[],handlers:[]})}for(let r of n){let a=r.spec,s=a&&a.plugin.domEventHandlers,o=a&&a.plugin.domEventObservers;if(s)for(let i in s){let l=s[i];l&&t(i).handlers.push(Sk(r.value,l))}if(o)for(let i in o){let l=o[i];l&&t(i).observers.push(Sk(r.value,l))}}for(let r in ca)t(r).handlers.push(ca[r]);for(let r in tr)t(r).observers.push(tr[r]);return e}var IS=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],bT="dthko",AS=[16,17,18,20,91,92,224,225],bd=6;function wd(n){return Math.max(0,n)*.7+8}function wT(n,e){return Math.max(Math.abs(n.clientX-e.clientX),Math.abs(n.clientY-e.clientY))}var bm=class{constructor(e,t,r,a){this.view=e,this.startEvent=t,this.style=r,this.mustSelect=a,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParents=$k(e.contentDOM),this.atoms=e.state.facet(Iu).map(o=>o(e));let s=e.contentDOM.ownerDocument;s.addEventListener("mousemove",this.move=this.move.bind(this)),s.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(Ct.allowMultipleSelections)&&vT(e,t),this.dragging=ST(e,t)&&RS(t)==1?null:!1}start(e){this.dragging===!1&&this.select(e)}move(e){if(e.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&wT(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let t=0,r=0,a=0,s=0,o=this.view.win.innerWidth,i=this.view.win.innerHeight;this.scrollParents.x&&({left:a,right:o}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:s,bottom:i}=this.scrollParents.y.getBoundingClientRect());let l=bS(this.view);e.clientX-l.left<=a+bd?t=-wd(a-e.clientX):e.clientX+l.right>=o-bd&&(t=wd(e.clientX-o)),e.clientY-l.top<=s+bd?r=-wd(s-e.clientY):e.clientY+l.bottom>=i-bd&&(r=wd(e.clientY-i)),this.setScrollSpeed(t,r)}up(e){this.dragging==null&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(e,t){this.scrollSpeed={x:e,y:t},e||t?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:e,y:t}=this.scrollSpeed;e&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=e,e=0),t&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=t,t=0),(e||t)&&this.view.win.scrollBy(e,t),this.dragging===!1&&this.select(this.lastEvent)}select(e){let{view:t}=this,r=kS(this.atoms,this.style.get(e,this.extend,this.multiple));(this.mustSelect||!r.eq(t.state.selection,this.dragging===!1))&&this.view.dispatch({selection:r,userEvent:"select.pointer"}),this.mustSelect=!1}update(e){e.transactions.some(t=>t.isUserEvent("input.type"))?this.destroy():this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}};function vT(n,e){let t=n.state.facet(sS);return t.length?t[0](e):we.mac?e.metaKey:e.ctrlKey}function kT(n,e){let t=n.state.facet(oS);return t.length?t[0](e):we.mac?!e.altKey:!e.ctrlKey}function ST(n,e){let{main:t}=n.state.selection;if(t.empty)return!1;let r=Su(n.root);if(!r||r.rangeCount==0)return!0;let a=r.getRangeAt(0).getClientRects();for(let s=0;s<a.length;s++){let o=a[s];if(o.left<=e.clientX&&o.right>=e.clientX&&o.top<=e.clientY&&o.bottom>=e.clientY)return!0}return!1}function CT(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target,r;t!=n.contentDOM;t=t.parentNode)if(!t||t.nodeType==11||(r=Zt.get(t))&&r.isWidget()&&!r.isHidden&&r.widget.ignoreEvent(e))return!1;return!0}var ca=Object.create(null),tr=Object.create(null),PS=we.ie&&we.ie_version<15||we.ios&&we.webkit_version<604;function LT(n){let e=n.dom.parentNode;if(!e)return;let t=e.appendChild(document.createElement("textarea"));t.style.cssText="position: fixed; left: -10000px; top: 10px",t.focus(),setTimeout(()=>{n.focus(),t.remove(),NS(n,t.value)},50)}function jd(n,e,t){for(let r of n.facet(e))t=r(t,n);return t}function NS(n,e){e=jd(n.state,zm,e);let{state:t}=n,r,a=1,s=t.toText(e),o=s.lines==t.selection.ranges.length;if(wm!=null&&t.selection.ranges.every(l=>l.empty)&&wm==s.toString()){let l=-1;r=t.changeByRange(u=>{let c=t.doc.lineAt(u.from);if(c.from==l)return{range:u};l=c.from;let d=t.toText((o?s.line(a++).text:e)+t.lineBreak);return{changes:{from:c.from,insert:d},range:se.cursor(u.from+d.length,-1)}})}else o?r=t.changeByRange(l=>{let u=s.line(a++);return{changes:{from:l.from,to:l.to,insert:u.text},range:se.cursor(l.from+u.length,-1)}}):r=t.replaceSelection(s);n.dispatch(r,{userEvent:"input.paste",scrollIntoView:!0})}tr.scroll=n=>{let e=n.inputState;e.lastScrollTop=n.scrollDOM.scrollTop,e.lastScrollLeft=n.scrollDOM.scrollLeft,we.ios&&!e.touchActive&&(e.lastIOSMomentumScroll=Date.now())};tr.wheel=tr.mousewheel=n=>{n.inputState.lastWheelEvent=Date.now()};ca.keydown=(n,e)=>(n.inputState.setSelectionOrigin("select"),e.keyCode==27&&n.inputState.tabFocusMode!=0&&(n.inputState.tabFocusMode=Date.now()+2e3),!1);tr.touchstart=(n,e)=>{let t=n.inputState,r=e.targetTouches[0];t.touchActive=!0,t.lastTouchTime=Date.now(),r&&(t.lastTouchX=r.clientX,t.lastTouchY=r.clientY),t.setSelectionOrigin("select.pointer")};tr.touchmove=n=>{n.inputState.setSelectionOrigin("select.pointer")};tr.touchend=(n,e)=>{n.inputState.touchActive=!1};ca.mousedown=(n,e)=>{if(n.observer.flush(),n.inputState.lastTouchTime>Date.now()-2e3)return!1;let t=null;for(let r of n.state.facet(iS))if(t=r(n,e),t)break;if(!t&&e.button==0&&(t=AT(n,e)),t){let r=!n.hasFocus;n.inputState.startMouseSelection(new bm(n,e,t,r)),r&&n.observer.ignore(()=>{Yk(n.contentDOM);let s=n.root.activeElement;s&&!s.contains(n.contentDOM)&&s.blur()});let a=n.inputState.mouseSelection;if(a)return a.start(e),a.dragging===!1}else n.inputState.setSelectionOrigin("select.pointer");return!1};function Ck(n,e,t,r){if(r==1)return se.cursor(e,t);if(r==2)return iT(n.state,e,t);{let a=n.docView.lineAt(e,t),s=n.state.doc.lineAt(a?a.posAtEnd:e),o=a?a.posAtStart:s.from,i=a?a.posAtEnd:s.to;return i<n.state.doc.length&&i==s.to&&i++,se.undirectionalRange(o,i)}}var IT=we.ie&&we.ie_version<=11,Lk=null,Ik=0,Ak=0;function RS(n){if(!IT)return n.detail;let e=Lk,t=Ak;return Lk=n,Ak=Date.now(),Ik=!e||t>Date.now()-400&&Math.abs(e.clientX-n.clientX)<2&&Math.abs(e.clientY-n.clientY)<2?(Ik+1)%3:1}function AT(n,e){let t=n.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),r=RS(e),a=n.state.selection;return{update(s){s.docChanged&&(t.pos=s.changes.mapPos(t.pos),a=a.map(s.changes))},get(s,o,i){let l=n.posAndSideAtCoords({x:s.clientX,y:s.clientY},!1),u,c=Ck(n,l.pos,l.assoc,r);if(t.pos!=l.pos&&!o){let d=Ck(n,t.pos,t.assoc,r),f=Math.min(d.from,c.from),h=Math.max(d.to,c.to);c=f<c.from?se.range(f,h,c.assoc):se.range(h,f,c.assoc)}return o?a.replaceRange(a.main.extend(c.from,c.to,c.assoc)):i&&r==1&&a.ranges.length>1&&(u=PT(a,l.pos))?u:i?a.addRange(c):se.create([c])}}}function PT(n,e){for(let t=0;t<n.ranges.length;t++){let{from:r,to:a}=n.ranges[t];if(r<=e&&a>=e)return se.create(n.ranges.slice(0,t).concat(n.ranges.slice(t+1)),n.mainIndex==t?0:n.mainIndex-(n.mainIndex>t?1:0))}return null}ca.dragstart=(n,e)=>{let{selection:{main:t}}=n.state;if(e.target.draggable){let a=n.docView.tile.nearest(e.target);if(a&&a.isWidget()){let s=a.posAtStart,o=s+a.length;(s>=t.to||o<=t.from)&&(t=se.undirectionalRange(s,o))}}let{inputState:r}=n;return r.mouseSelection&&(r.mouseSelection.dragging=!0),r.draggedContent=t,e.dataTransfer&&(e.dataTransfer.setData("Text",jd(n.state,Wm,n.state.sliceDoc(t.from,t.to))),e.dataTransfer.effectAllowed="copyMove"),!1};ca.dragend=n=>(n.inputState.draggedContent=null,!1);function Pk(n,e,t,r){if(t=jd(n.state,zm,t),!t)return;let a=n.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:s}=n.inputState,o=r&&s&&kT(n,e)?{from:s.from,to:s.to}:null,i={from:a,insert:t},l=n.state.changes(o?[o,i]:i);n.focus(),n.dispatch({changes:l,selection:{anchor:l.mapPos(a,-1),head:l.mapPos(a,1)},userEvent:o?"move.drop":"input.drop"}),n.inputState.draggedContent=null}ca.drop=(n,e)=>{if(!e.dataTransfer)return!1;if(n.state.readOnly)return!0;let t=e.dataTransfer.files;if(t&&t.length){let r=Array(t.length),a=0,s=()=>{++a==t.length&&Pk(n,e,r.filter(o=>o!=null).join(n.state.lineBreak),!1)};for(let o=0;o<t.length;o++){let i=new FileReader;i.onerror=s,i.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(i.result)||(r[o]=i.result),s()},i.readAsText(t[o])}return!0}else{let r=e.dataTransfer.getData("Text");if(r)return Pk(n,e,r,!0),!0}return!1};ca.paste=(n,e)=>{if(n.state.readOnly)return!0;n.observer.flush();let t=PS?null:e.clipboardData;return t?(NS(n,t.getData("text/plain")||t.getData("text/uri-list")),!0):(LT(n),!1)};function NT(n,e){let t=n.dom.parentNode;if(!t)return;let r=t.appendChild(document.createElement("textarea"));r.style.cssText="position: fixed; left: -10000px; top: 10px",r.value=e,r.focus(),r.selectionEnd=e.length,r.selectionStart=0,setTimeout(()=>{r.remove(),n.focus()},50)}function RT(n){let e=[],t=[],r=!1;for(let a of n.selection.ranges)a.empty||(e.push(n.sliceDoc(a.from,a.to)),t.push(a));if(!e.length){let a=-1;for(let{from:s}of n.selection.ranges){let o=n.doc.lineAt(s);o.number>a&&(e.push(o.text),t.push({from:o.from,to:Math.min(n.doc.length,o.to+1)})),a=o.number}r=!0}return{text:jd(n,Wm,e.join(n.lineBreak)),ranges:t,linewise:r}}var wm=null;ca.copy=ca.cut=(n,e)=>{if(!du(n.contentDOM,n.observer.selectionRange))return!1;let{text:t,ranges:r,linewise:a}=RT(n.state);if(!t&&!a)return!1;wm=a?t:null,e.type=="cut"&&!n.state.readOnly&&n.dispatch({changes:r,scrollIntoView:!0,userEvent:"delete.cut"});let s=PS?null:e.clipboardData;return s?(s.clearData(),s.setData("text/plain",t),!0):(NT(n,t),!1)};var MS=Wr.define();function TS(n,e){let t=[];for(let r of n.facet(cS)){let a=r(n,e);a&&t.push(a)}return t.length?n.update({effects:t,annotations:MS.of(!0)}):null}function DS(n){setTimeout(()=>{let e=n.hasFocus;if(e!=n.inputState.notifiedFocused){let t=TS(n.state,e);t?n.dispatch(t):n.update([])}},10)}tr.focus=n=>{n.inputState.lastFocusTime=Date.now(),!n.scrollDOM.scrollTop&&(n.inputState.lastScrollTop||n.inputState.lastScrollLeft)&&(n.scrollDOM.scrollTop=n.inputState.lastScrollTop,n.scrollDOM.scrollLeft=n.inputState.lastScrollLeft),DS(n)};tr.blur=n=>{n.observer.clearSelectionRange(),DS(n)};tr.compositionstart=tr.compositionupdate=n=>{if(!n.observer.editContext&&(n.inputState.compositionFirstChange==null&&(n.inputState.compositionFirstChange=!0),n.inputState.composing<0)){let{main:e}=n.state.selection;!e.empty&&n.lineBlockAt(e.from).from!=n.lineBlockAt(e.to).from&&n.dispatch({changes:n.state.selection.ranges.filter(t=>!t.empty).map(t=>({from:t.from,to:t.to})),userEvent:"input"}),n.inputState.composing=0}};tr.compositionend=n=>{n.observer.editContext||(n.inputState.composing=-1,n.inputState.compositionEndedAt=Date.now(),n.inputState.compositionPendingKey=!0,n.inputState.compositionPendingChange=n.observer.pendingRecords().length>0,n.inputState.compositionFirstChange=null,we.chrome&&we.android?n.observer.flushSoon():n.inputState.compositionPendingChange?Promise.resolve().then(()=>n.observer.flush()):setTimeout(()=>{n.inputState.composing<0&&n.docView.hasComposition&&n.update([])},50))};tr.contextmenu=n=>{n.inputState.lastContextMenu=Date.now()};ca.beforeinput=(n,e)=>{var t,r;if((e.inputType=="insertText"||e.inputType=="insertCompositionText")&&(n.inputState.insertingText=e.data,n.inputState.insertingTextAt=Date.now()),e.inputType=="insertReplacementText"&&n.observer.editContext){let s=(t=e.dataTransfer)===null||t===void 0?void 0:t.getData("text/plain"),o=e.getTargetRanges();if(s&&o.length){let i=o[0],l=n.posAtDOM(i.startContainer,i.startOffset),u=n.posAtDOM(i.endContainer,i.endOffset);return Vm(n,{from:l,to:u,insert:n.state.toText(s)},null),!0}}let a;if(we.chrome&&we.android&&(a=IS.find(s=>s.inputType==e.inputType))&&(n.observer.delayAndroidKey(a.key,a.keyCode),a.key=="Backspace"||a.key=="Delete")){let s=((r=window.visualViewport)===null||r===void 0?void 0:r.height)||0;setTimeout(()=>{var o;(((o=window.visualViewport)===null||o===void 0?void 0:o.height)||0)>s+10&&n.hasFocus&&(n.contentDOM.blur(),n.focus())},100)}return we.ios&&e.inputType=="deleteContentForward"&&n.observer.flushSoon(),we.safari&&e.inputType=="insertText"&&n.inputState.composing>=0&&setTimeout(()=>tr.compositionend(n,e),20),!1};var Nk=new Set;function MT(n){Nk.has(n)||(Nk.add(n),n.addEventListener("copy",()=>{}),n.addEventListener("cut",()=>{}))}var Rk=["pre-wrap","normal","pre-line","break-spaces"],Hi=!1;function Mk(){Hi=!1}var vm=class{constructor(e){this.lineWrapping=e,this.doc=ct.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(e,t){let r=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(r+=Math.max(0,Math.ceil((t-e-r*this.lineLength*.5)/this.lineLength))),this.lineHeight*r}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return Rk.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let r=0;r<e.length;r++){let a=e[r];a<0?r++:this.heightSamples[Math.floor(a*10)]||(t=!0,this.heightSamples[Math.floor(a*10)]=!0)}return t}refresh(e,t,r,a,s,o){let i=Rk.indexOf(e)>-1,l=Math.abs(t-this.lineHeight)>.3||this.lineWrapping!=i;if(this.lineWrapping=i,this.lineHeight=t,this.charWidth=r,this.textHeight=a,this.lineLength=s,l){this.heightSamples={};for(let u=0;u<o.length;u++){let c=o[u];c<0?u++:this.heightSamples[Math.floor(c*10)]=!0}}return l}},km=class{constructor(e,t){this.from=e,this.heights=t,this.index=0}get more(){return this.index<this.heights.length}},ia=class n{constructor(e,t,r,a,s){this.from=e,this.length=t,this.top=r,this.height=a,this._content=s}get type(){return typeof this._content=="number"?Bn.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof Ro?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(e){let t=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(e._content)?e._content:[e]);return new n(this.from,this.length+e.length,this.top,this.height+e.height,t)}},zt=(function(n){return n[n.ByPos=0]="ByPos",n[n.ByHeight=1]="ByHeight",n[n.ByPosNoHeight=2]="ByPosNoHeight",n})(zt||(zt={})),Ld=.001,Lr=class n{constructor(e,t,r=2){this.length=e,this.height=t,this.flags=r}get outdated(){return(this.flags&2)>0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>Ld&&(Hi=!0),this.height=e)}replace(e,t,r){return n.of(r)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,r,a){let s=this,o=r.doc;for(let i=a.length-1;i>=0;i--){let{fromA:l,toA:u,fromB:c,toB:d}=a[i],f=s.lineAt(l,zt.ByPosNoHeight,r.setDoc(t),0,0),h=f.to>=u?f:s.lineAt(u,zt.ByPosNoHeight,r,0,0);for(d+=h.to-u,u=h.to;i>0&&f.from<=a[i-1].toA;)l=a[i-1].fromA,c=a[i-1].fromB,i--,l<f.from&&(f=s.lineAt(l,zt.ByPosNoHeight,r,0,0));c+=f.from-l,l=f.from;let p=Cm.build(r.setDoc(o),e,c,d);s=Bd(s,s.replace(l,u,p))}return s.updateHeight(r,0)}static empty(){return new jr(0,0,0)}static of(e){if(e.length==1)return e[0];let t=0,r=e.length,a=0,s=0;for(;;)if(t==r)if(a>s*2){let i=e[t-1];i.break?e.splice(--t,1,i.left,null,i.right):e.splice(--t,1,i.left,i.right),r+=1+i.break,a-=i.size}else if(s>a*2){let i=e[r];i.break?e.splice(r,1,i.left,null,i.right):e.splice(r,1,i.left,i.right),r+=2+i.break,s-=i.size}else break;else if(a<s){let i=e[t++];i&&(a+=i.size)}else{let i=e[--r];i&&(s+=i.size)}let o=!1;return e[t-1]==null?(o=!0,t--):e[t]==null&&(o=!0,r++),new Sm(n.of(e.slice(0,t)),o,n.of(e.slice(r)))}};function Bd(n,e){return n==e?n:(n.constructor!=e.constructor&&(Hi=!0),e)}Lr.prototype.size=1;var TT=Xe.replace({}),Od=class extends Lr{constructor(e,t,r){super(e,t),this.deco=r,this.spaceAbove=0}mainBlock(e,t){return new ia(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(e,t,r,a){return this.spaceAbove&&e<r+this.spaceAbove?new ia(a,0,r,this.spaceAbove,TT):this.mainBlock(r,a)}lineAt(e,t,r,a,s){let o=this.mainBlock(a,s);return this.spaceAbove?this.blockAt(0,r,a,s).join(o):o}forEachLine(e,t,r,a,s,o){e<=s+this.length&&t>=s&&o(this.lineAt(0,zt.ByPos,r,a,s))}setMeasuredHeight(e){let t=e.heights[e.index++];t<0?(this.spaceAbove=-t,t=e.heights[e.index++]):this.spaceAbove=0,this.setHeight(t)}updateHeight(e,t=0,r=!1,a){return a&&a.from<=t&&a.more&&this.setMeasuredHeight(a),this.outdated=!1,this}toString(){return`block(${this.length})`}},jr=class n extends Od{constructor(e,t,r){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=r}mainBlock(e,t){return new ia(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(e,t,r){let a=r[0];return r.length==1&&(a instanceof n||a instanceof Hs&&a.flags&4)&&Math.abs(this.length-a.length)<10?(a instanceof Hs?a=new n(a.length,this.height,this.spaceAbove):a.height=this.height,this.outdated||(a.outdated=!1),a):Lr.of(r)}updateHeight(e,t=0,r=!1,a){return a&&a.from<=t&&a.more?this.setMeasuredHeight(a):(r||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}},Hs=class n extends Lr{constructor(e){super(e,0)}heightMetrics(e,t){let r=e.doc.lineAt(t).number,a=e.doc.lineAt(t+this.length).number,s=a-r+1,o,i=0;if(e.lineWrapping){let l=Math.min(this.height,e.lineHeight*s);o=l/s,this.length>s+1&&(i=(this.height-l)/(this.length-s-1))}else o=this.height/s;return{firstLine:r,lastLine:a,perLine:o,perChar:i}}blockAt(e,t,r,a){let{firstLine:s,lastLine:o,perLine:i,perChar:l}=this.heightMetrics(t,a);if(t.lineWrapping){let u=a+(e<t.lineHeight?0:Math.round(Math.max(0,Math.min(1,(e-r)/this.height))*this.length)),c=t.doc.lineAt(u),d=i+c.length*l,f=Math.max(r,e-d/2);return new ia(c.from,c.length,f,d,0)}else{let u=Math.max(0,Math.min(o-s,Math.floor((e-r)/i))),{from:c,length:d}=t.doc.line(s+u);return new ia(c,d,r+i*u,i,0)}}lineAt(e,t,r,a,s){if(t==zt.ByHeight)return this.blockAt(e,r,a,s);if(t==zt.ByPosNoHeight){let{from:h,to:p}=r.doc.lineAt(e);return new ia(h,p-h,0,0,0)}let{firstLine:o,perLine:i,perChar:l}=this.heightMetrics(r,s),u=r.doc.lineAt(e),c=i+u.length*l,d=u.number-o,f=a+i*d+l*(u.from-s-d);return new ia(u.from,u.length,Math.max(a,Math.min(f,a+this.height-c)),c,0)}forEachLine(e,t,r,a,s,o){e=Math.max(e,s),t=Math.min(t,s+this.length);let{firstLine:i,perLine:l,perChar:u}=this.heightMetrics(r,s);for(let c=e,d=a;c<=t;){let f=r.doc.lineAt(c);if(c==e){let p=f.number-i;d+=l*p+u*(e-s-p)}let h=l+u*f.length;o(new ia(f.from,f.length,d,h,0)),d+=h,c=f.to+1}}replace(e,t,r){let a=this.length-t;if(a>0){let s=r[r.length-1];s instanceof n?r[r.length-1]=new n(s.length+a):r.push(null,new n(a-1))}if(e>0){let s=r[0];s instanceof n?r[0]=new n(e+s.length):r.unshift(new n(e-1),null)}return Lr.of(r)}decomposeLeft(e,t){t.push(new n(e-1),null)}decomposeRight(e,t){t.push(null,new n(this.length-e-1))}updateHeight(e,t=0,r=!1,a){let s=t+this.length;if(a&&a.from<=t+this.length&&a.more){let o=[],i=Math.max(t,a.from),l=-1;for(a.from>t&&o.push(new n(a.from-t-1).updateHeight(e,t));i<=s&&a.more;){let c=e.doc.lineAt(i).length;o.length&&o.push(null);let d=a.heights[a.index++],f=0;d<0&&(f=-d,d=a.heights[a.index++]),l==-1?l=d:Math.abs(d-l)>=Ld&&(l=-2);let h=new jr(c,d,f);h.outdated=!1,o.push(h),i+=c+1}i<=s&&o.push(null,new n(s-i).updateHeight(e,i));let u=Lr.of(o);return(l<0||Math.abs(u.height-this.height)>=Ld||Math.abs(l-this.heightMetrics(e,t).perLine)>=Ld)&&(Hi=!0),Bd(this,u)}else(r||this.outdated)&&(this.setHeight(e.heightForGap(t,t+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}},Sm=class extends Lr{constructor(e,t,r){super(e.length+(t?1:0)+r.length,e.height+r.height,(t?1:0)|(e.outdated||r.outdated?2:0)),this.left=e,this.right=r,this.size=e.size+r.size}get break(){return this.flags&1}blockAt(e,t,r,a){let s=r+this.left.height;return e<s?this.left.blockAt(e,t,r,a):this.right.blockAt(e,t,s,a+this.left.length+this.break)}lineAt(e,t,r,a,s){let o=a+this.left.height,i=s+this.left.length+this.break,l=t==zt.ByHeight?e<o:e<i,u=l?this.left.lineAt(e,t,r,a,s):this.right.lineAt(e,t,r,o,i);if(this.break||(l?u.to<i:u.from>i))return u;let c=t==zt.ByPosNoHeight?zt.ByPosNoHeight:zt.ByPos;return l?u.join(this.right.lineAt(i,c,r,o,i)):this.left.lineAt(i,c,r,a,s).join(u)}forEachLine(e,t,r,a,s,o){let i=a+this.left.height,l=s+this.left.length+this.break;if(this.break)e<l&&this.left.forEachLine(e,t,r,a,s,o),t>=l&&this.right.forEachLine(e,t,r,i,l,o);else{let u=this.lineAt(l,zt.ByPos,r,a,s);e<u.from&&this.left.forEachLine(e,Math.min(t,u.from-1),r,a,s,o),u.to>=e&&u.from<=t&&o(u),t>u.to&&this.right.forEachLine(Math.max(e,u.to+1),t,r,i,l,o)}}replace(e,t,r){let a=this.left.length+this.break;if(t<a)return this.balanced(this.left.replace(e,t,r),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-a,t-a,r));let s=[];e>0&&this.decomposeLeft(e,s);let o=s.length;for(let i of r)s.push(i);if(e>0&&Tk(s,o-1),t<this.length){let i=s.length;this.decomposeRight(t,s),Tk(s,i)}return Lr.of(s)}decomposeLeft(e,t){let r=this.left.length;if(e<=r)return this.left.decomposeLeft(e,t);t.push(this.left),this.break&&(r++,e>=r&&t.push(null)),e>r&&this.right.decomposeLeft(e-r,t)}decomposeRight(e,t){let r=this.left.length,a=r+this.break;if(e>=a)return this.right.decomposeRight(e-a,t);e<r&&this.left.decomposeRight(e,t),this.break&&e<a&&t.push(null),t.push(this.right)}balanced(e,t){return e.size>2*t.size||t.size>2*e.size?Lr.of(this.break?[e,null,t]:[e,t]):(this.left=Bd(this.left,e),this.right=Bd(this.right,t),this.setHeight(e.height+t.height),this.outdated=e.outdated||t.outdated,this.size=e.size+t.size,this.length=e.length+this.break+t.length,this)}updateHeight(e,t=0,r=!1,a){let{left:s,right:o}=this,i=t+s.length+this.break,l=null;return a&&a.from<=t+s.length&&a.more?l=s=s.updateHeight(e,t,r,a):s.updateHeight(e,t,r),a&&a.from<=i+o.length&&a.more?l=o=o.updateHeight(e,i,r,a):o.updateHeight(e,i,r),l?this.balanced(s,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}};function Tk(n,e){let t,r;n[e]==null&&(t=n[e-1])instanceof Hs&&(r=n[e+1])instanceof Hs&&n.splice(e-1,3,new Hs(t.length+1+r.length))}var DT=5,Cm=class n{constructor(e,t){this.pos=e,this.oracle=t,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=e}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(e,t){if(this.lineStart>-1){let r=Math.min(t,this.lineEnd),a=this.nodes[this.nodes.length-1];a instanceof jr?a.length+=r-this.pos:(r>this.pos||!this.isCovered)&&this.nodes.push(new jr(r-this.pos,-1,0)),this.writtenTo=r,t>r&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,r){if(e<t||r.heightRelevant){let a=r.widget?r.widget.estimatedHeight:0,s=r.widget?r.widget.lineBreaks:0;a<0&&(a=this.oracle.lineHeight);let o=t-e;r.block?this.addBlock(new Od(o,a,r)):(o||s||a>=DT)&&this.addLineDeco(a,s,o)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenTo<e&&((this.writtenTo<e-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,e-1)),this.nodes.push(null)),this.pos>e&&this.nodes.push(new jr(this.pos-e,-1,0)),this.writtenTo=this.pos}blankContent(e,t){let r=new Hs(t-e);return this.oracle.doc.lineAt(e).to==t&&(r.flags|=4),r}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof jr)return e;let t=new jr(0,-1,0);return this.nodes.push(t),t}addBlock(e){this.enterLine();let t=e.deco;t&&t.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,t&&t.endSide>0&&(this.covering=e)}addLineDeco(e,t,r){let a=this.ensureLine();a.length+=r,a.collapsed+=r,a.widgetHeight=Math.max(a.widgetHeight,e),a.breaks+=t,this.writtenTo=this.pos=this.pos+r}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof jr)&&!this.isCovered?this.nodes.push(new jr(0,-1,0)):(this.writtenTo<this.pos||t==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let r=e;for(let a of this.nodes)a instanceof jr&&a.updateHeight(this.oracle,r),r+=a?a.length:1;return this.nodes}static build(e,t,r,a){let s=new n(r,e);return wt.spans(t,r,a,s,0),s.finish(r)}};function FT(n,e,t){let r=new Lm;return wt.compare(n,e,t,r,0),r.changes}var Lm=class{constructor(){this.changes=[]}compareRange(){}comparePoint(e,t,r,a){(e<t||r&&r.heightRelevant||a&&a.heightRelevant)&&Di(e,t,this.changes,5)}};function ET(n,e){let t=n.getBoundingClientRect(),r=n.ownerDocument,a=r.defaultView||window,s=Math.max(0,t.left),o=Math.min(a.innerWidth,t.right),i=Math.max(0,t.top),l=Math.min(a.innerHeight,t.bottom);for(let u=n.parentNode;u&&u!=r.body;)if(u.nodeType==1){let c=u,d=window.getComputedStyle(c);if((c.scrollHeight>c.clientHeight||c.scrollWidth>c.clientWidth)&&d.overflow!="visible"){let f=c.getBoundingClientRect();s=Math.max(s,f.left),o=Math.min(o,f.right),i=Math.max(i,f.top),l=Math.min(u==n.parentNode?a.innerHeight:l,f.bottom)}u=d.position=="absolute"||d.position=="fixed"?c.offsetParent:c.parentNode}else if(u.nodeType==11)u=u.host;else break;return{left:s-t.left,right:Math.max(s,o)-t.left,top:i-(t.top+e),bottom:Math.max(i,l)-(t.top+e)}}function BT(n){let e=n.getBoundingClientRect(),t=n.ownerDocument.defaultView||window;return e.left<t.innerWidth&&e.right>0&&e.top<t.innerHeight&&e.bottom>0}function OT(n,e){let t=n.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}var yu=class{constructor(e,t,r,a){this.from=e,this.to=t,this.size=r,this.displaySize=a}static same(e,t){if(e.length!=t.length)return!1;for(let r=0;r<e.length;r++){let a=e[r],s=t[r];if(a.from!=s.from||a.to!=s.to||a.size!=s.size)return!1}return!0}draw(e,t){return Xe.replace({widget:new Im(this.displaySize*(t?e.scaleY:e.scaleX),t)}).range(this.from,this.to)}},Im=class extends Ir{constructor(e,t){super(),this.size=e,this.vertical=t}eq(e){return e.size==this.size&&e.vertical==this.vertical}toDOM(){let e=document.createElement("div");return this.vertical?e.style.height=this.size+"px":(e.style.width=this.size+"px",e.style.height="2px",e.style.display="inline-block"),e}get estimatedHeight(){return this.vertical?this.size:-1}},_d=class{constructor(e,t){this.view=e,this.state=t,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scaleX=1,this.scaleY=1,this.scrollOffset=0,this.scrolledToBottom=!1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=Dk,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=Wt.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let r=t.facet(jm).some(a=>typeof a!="function"&&a.class=="cm-lineWrapping");this.heightOracle=new vm(r),this.stateDeco=Fk(t),this.heightMap=Lr.empty().applyChanges(this.stateDeco,ct.empty,this.heightOracle.setDoc(t.doc),[new ua(0,0,0,t.doc.length)]);for(let a=0;a<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());a++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=Xe.set(this.lineGaps.map(a=>a.draw(this,!1))),this.scrollParent=e.scrollDOM,this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let r=0;r<=1;r++){let a=r?t.head:t.anchor;if(!e.some(({from:s,to:o})=>a>=s&&a<=o)){let{from:s,to:o}=this.lineBlockAt(a);e.push(new Mi(s,o))}}return this.viewports=e.sort((r,a)=>r.from-a.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?Dk:new Am(this.heightOracle,this.heightMap,this.viewports),e.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,e=>{this.viewportLines.push(cu(e,this.scaler))})}update(e,t=null){this.state=e.state;let r=this.stateDeco;this.stateDeco=Fk(this.state);let a=e.changedRanges,s=ua.extendWithRanges(a,FT(r,this.stateDeco,e?e.changes:Rn.empty(this.state.doc.length))),o=this.heightMap.height,i=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollOffset);Mk(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),s),(this.heightMap.height!=o||Hi)&&(e.flags|=2),i?(this.scrollAnchorPos=e.changes.mapPos(i.from,-1),this.scrollAnchorHeight=i.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=o);let l=s.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.head<l.from||t.range.head>l.to)||!this.viewportIsAppropriate(l))&&(l=this.getViewport(0,t));let u=l.from!=this.viewport.from||l.to!=this.viewport.to;this.viewport=l,e.flags|=this.updateForViewport(),(u||!e.changes.empty||e.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(e.changes),t&&(this.scrollTarget=t),!this.mustEnforceCursorAssoc&&(e.selectionSet||e.focusChanged)&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(fS)&&(this.mustEnforceCursorAssoc=!0)}measure(){let{view:e}=this,t=e.contentDOM,r=window.getComputedStyle(t),a=this.heightOracle,s=r.whiteSpace;this.defaultTextDirection=r.direction=="rtl"?Wt.RTL:Wt.LTR;let o=this.heightOracle.mustRefreshForWrapping(s)||this.mustMeasureContent==="refresh",i=t.getBoundingClientRect(),l=o||this.mustMeasureContent||this.contentDOMHeight!=i.height;this.contentDOMHeight=i.height,this.mustMeasureContent=!1;let u=0,c=0;if(i.width&&i.height){let{scaleX:k,scaleY:v}=Vk(t,i);(k>.005&&Math.abs(this.scaleX-k)>.005||v>.005&&Math.abs(this.scaleY-v)>.005)&&(this.scaleX=k,this.scaleY=v,u|=16,o=l=!0)}let d=(parseInt(r.paddingTop)||0)*this.scaleY,f=(parseInt(r.paddingBottom)||0)*this.scaleY;(this.paddingTop!=d||this.paddingBottom!=f)&&(this.paddingTop=d,this.paddingBottom=f,u|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(a.lineWrapping&&(l=!0),this.editorWidth=e.scrollDOM.clientWidth,u|=16);let h=$k(this.view.contentDOM,!1).y;h!=this.scrollParent&&(this.scrollParent=h,this.scrollAnchorHeight=-1,this.scrollOffset=0);let p=this.getScrollOffset();this.scrollOffset!=p&&(this.scrollAnchorHeight=-1,this.scrollOffset=p),this.scrolledToBottom=Jk(this.scrollParent||e.win);let m=(this.printing?OT:ET)(t,this.paddingTop),g=m.top-this.pixelViewport.top,x=m.bottom-this.pixelViewport.bottom;this.pixelViewport=m;let w=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(w!=this.inView&&(this.inView=w,w&&(l=!0)),!this.inView&&!this.scrollTarget&&!BT(e.dom))return 0;let y=i.width;if((this.contentDOMWidth!=y||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=i.width,this.editorHeight=e.scrollDOM.clientHeight,u|=16),l){let k=e.docView.measureVisibleLineHeights(this.viewport);if(a.mustRefreshForHeights(k)&&(o=!0),o||a.lineWrapping&&Math.abs(y-this.contentDOMWidth)>a.charWidth){let{lineHeight:v,charWidth:b,textHeight:P}=e.docView.measureTextSize();o=v>0&&a.refresh(s,v,b,P,Math.max(5,y/b),k),o&&(e.docView.minWidth=0,u|=16)}g>0&&x>0?c=Math.max(g,x):g<0&&x<0&&(c=Math.min(g,x)),Mk();for(let v of this.viewports){let b=v.from==this.viewport.from?k:e.docView.measureVisibleLineHeights(v);this.heightMap=(o?Lr.empty().applyChanges(this.stateDeco,ct.empty,this.heightOracle,[new ua(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(a,0,o,new km(v.from,b))}Hi&&(u|=2)}let C=!this.viewportIsAppropriate(this.viewport,c)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return C&&(u&2&&(u|=this.updateScaler()),this.viewport=this.getViewport(c,this.scrollTarget),u|=this.updateForViewport()),(u&2||C)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,e)),u|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),u}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,t){let r=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),a=this.heightMap,s=this.heightOracle,{visibleTop:o,visibleBottom:i}=this,l=new Mi(a.lineAt(o-r*1e3,zt.ByHeight,s,0,0).from,a.lineAt(i+(1-r)*1e3,zt.ByHeight,s,0,0).to);if(t){let{head:u}=t.range;if(u<l.from||u>l.to){let c=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),d=a.lineAt(u,zt.ByPos,s,0,0),f;t.y=="center"?f=(d.top+d.bottom)/2-c/2:t.y=="start"||t.y=="nearest"&&u<l.from?f=d.top:f=d.bottom-c,l=new Mi(a.lineAt(f-1e3/2,zt.ByHeight,s,0,0).from,a.lineAt(f+c+1e3/2,zt.ByHeight,s,0,0).to)}}return l}mapViewport(e,t){let r=t.mapPos(e.from,-1),a=t.mapPos(e.to,1);return new Mi(this.heightMap.lineAt(r,zt.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(a,zt.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:t},r=0){if(!this.inView)return!0;let{top:a}=this.heightMap.lineAt(e,zt.ByPos,this.heightOracle,0,0),{bottom:s}=this.heightMap.lineAt(t,zt.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:i}=this;return(e==0||a<=o-Math.max(10,Math.min(-r,250)))&&(t==this.state.doc.length||s>=i+Math.max(10,Math.min(r,250)))&&a>o-2*1e3&&s<i+2*1e3}mapLineGaps(e,t){if(!e.length||t.empty)return e;let r=[];for(let a of e)t.touchesRange(a.from,a.to)||r.push(new yu(t.mapPos(a.from),t.mapPos(a.to),a.size,a.displaySize));return r}ensureLineGaps(e,t){let r=this.heightOracle.lineWrapping,a=r?1e4:2e3,s=a>>1,o=a<<1;if(this.defaultTextDirection!=Wt.LTR&&!r)return[];let i=[],l=(c,d,f,h)=>{if(d-c<s)return;let p=this.state.selection.main,m=[p.from];p.empty||m.push(p.to);for(let x of m)if(x>c&&x<d){l(c,x-10,f,h),l(x+10,d,f,h);return}let g=HT(e,x=>x.from>=f.from&&x.to<=f.to&&Math.abs(x.from-c)<s&&Math.abs(x.to-d)<s&&!m.some(w=>x.from<w&&x.to>w));if(!g){if(d<f.to&&t&&r&&t.visibleRanges.some(y=>y.from<=d&&y.to>=d)){let y=t.moveToLineBoundary(se.cursor(d),!1,!0).head;y>c&&(d=y)}let x=this.gapSize(f,c,d,h),w=r||x<2e6?x:2e6;g=new yu(c,d,x,w)}i.push(g)},u=c=>{if(c.length<o||c.type!=Bn.Text)return;let d=_T(c.from,c.to,this.stateDeco);if(d.total<o)return;let f=this.scrollTarget?this.scrollTarget.range.head:null,h,p;if(r){let m=a/this.heightOracle.lineLength*this.heightOracle.lineHeight,g,x;if(f!=null){let w=kd(d,f),y=((this.visibleBottom-this.visibleTop)/2+m)/c.height;g=w-y,x=w+y}else g=(this.visibleTop-c.top-m)/c.height,x=(this.visibleBottom-c.top+m)/c.height;h=vd(d,g),p=vd(d,x)}else{let m=d.total*this.heightOracle.charWidth,g=a*this.heightOracle.charWidth,x=0;if(m>2e6)for(let v of e)v.from>=c.from&&v.from<c.to&&v.size!=v.displaySize&&v.from*this.heightOracle.charWidth+x<this.pixelViewport.left&&(x=v.size-v.displaySize);let w=this.pixelViewport.left+x,y=this.pixelViewport.right+x,C,k;if(f!=null){let v=kd(d,f),b=((y-w)/2+g)/m;C=v-b,k=v+b}else C=(w-g)/m,k=(y+g)/m;h=vd(d,C),p=vd(d,k)}h>c.from&&l(c.from,h,c,d),p<c.to&&l(p,c.to,c,d)};for(let c of this.viewportLines)Array.isArray(c.type)?c.type.forEach(u):u(c);return i}gapSize(e,t,r,a){let s=kd(a,r)-kd(a,t);return this.heightOracle.lineWrapping?e.height*s:a.total*this.heightOracle.charWidth*s}updateLineGaps(e){yu.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=Xe.set(e.map(t=>t.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(e){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let r=[];wt.spans(t,this.viewport.from,this.viewport.to,{span(s,o){r.push({from:s,to:o})},point(){}},20);let a=0;if(r.length!=this.visibleRanges.length)a=12;else for(let s=0;s<r.length&&!(a&8);s++){let o=this.visibleRanges[s],i=r[s];(o.from!=i.from||o.to!=i.to)&&(a|=4,e&&e.mapPos(o.from,-1)==i.from&&e.mapPos(o.to,1)==i.to||(a|=8))}return this.visibleRanges=r,a}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||cu(this.heightMap.lineAt(e,zt.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return e>=this.viewportLines[0].top&&e<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(t=>t.top<=e&&t.bottom>=e)||cu(this.heightMap.lineAt(this.scaler.fromDOM(e),zt.ByHeight,this.heightOracle,0,0),this.scaler)}getScrollOffset(){return this.scrollParent==this.view.scrollDOM?this.scrollParent.scrollTop*this.scaleY:(this.scrollParent?this.scrollParent.getBoundingClientRect().top:0)-this.view.contentDOM.getBoundingClientRect().top}scrollAnchorAt(e){let t=this.lineBlockAtHeight(e+8);return t.from>=this.viewport.from||this.viewportLines[0].top-e>200?t:this.viewportLines[0]}elementAtHeight(e){return cu(this.heightMap.blockAt(this.scaler.fromDOM(e),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}},Mi=class{constructor(e,t){this.from=e,this.to=t}};function _T(n,e,t){let r=[],a=n,s=0;return wt.spans(t,n,e,{span(){},point(o,i){o>a&&(r.push({from:a,to:o}),s+=o-a),a=i}},20),a<e&&(r.push({from:a,to:e}),s+=e-a),{total:s,ranges:r}}function vd({total:n,ranges:e},t){if(t<=0)return e[0].from;if(t>=1)return e[e.length-1].to;let r=Math.floor(n*t);for(let a=0;;a++){let{from:s,to:o}=e[a],i=o-s;if(r<=i)return s+r;r-=i}}function kd(n,e){let t=0;for(let{from:r,to:a}of n.ranges){if(e<=a){t+=e-r;break}t+=a-r}return t/n.total}function HT(n,e){for(let t of n)if(e(t))return t}var Dk={toDOM(n){return n},fromDOM(n){return n},scale:1,eq(n){return n==this}};function Fk(n){let e=n.facet(Wd).filter(r=>typeof r!="function"),t=n.facet(qm).filter(r=>typeof r!="function");return t.length&&e.push(wt.join(t)),e}var Am=class n{constructor(e,t,r){let a=0,s=0,o=0;this.viewports=r.map(({from:i,to:l})=>{let u=t.lineAt(i,zt.ByPos,e,0,0).top,c=t.lineAt(l,zt.ByPos,e,0,0).bottom;return a+=c-u,{from:i,to:l,top:u,bottom:c,domTop:0,domBottom:0}}),this.scale=(7e6-a)/(t.height-a);for(let i of this.viewports)i.domTop=o+(i.top-s)*this.scale,o=i.domBottom=i.domTop+(i.bottom-i.top),s=i.bottom}toDOM(e){for(let t=0,r=0,a=0;;t++){let s=t<this.viewports.length?this.viewports[t]:null;if(!s||e<s.top)return a+(e-r)*this.scale;if(e<=s.bottom)return s.domTop+(e-s.top);r=s.bottom,a=s.domBottom}}fromDOM(e){for(let t=0,r=0,a=0;;t++){let s=t<this.viewports.length?this.viewports[t]:null;if(!s||e<s.domTop)return r+(e-a)/this.scale;if(e<=s.domBottom)return s.top+(e-s.domTop);r=s.bottom,a=s.domBottom}}eq(e){return e instanceof n?this.scale==e.scale&&this.viewports.length==e.viewports.length&&this.viewports.every((t,r)=>t.from==e.viewports[r].from&&t.to==e.viewports[r].to):!1}};function cu(n,e){if(e.scale==1)return n;let t=e.toDOM(n.top),r=e.toDOM(n.bottom);return new ia(n.from,n.length,t,r-t,Array.isArray(n._content)?n._content.map(a=>cu(a,e)):n._content)}var Sd=Me.define({combine:n=>n.join(" ")}),Pm=Me.define({combine:n=>n.indexOf(!0)>-1}),Nm=lr.newName(),FS=lr.newName(),ES=lr.newName(),BS={"&light":"."+FS,"&dark":"."+ES};function Rm(n,e,t){return new lr(e,{finish(r){return/&/.test(r)?r.replace(/&\w*/,a=>{if(a=="&")return n;if(!t||!t[a])throw new RangeError(`Unsupported selector: ${a}`);return t[a]}):n+" "+r}})}var UT=Rm("."+Nm,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{userSelect:"none",position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-selectionHandle":{backgroundColor:"currentColor",width:"1.5px"},".cm-selectionHandle-start::before, .cm-selectionHandle-end::before":{content:'""',backgroundColor:"inherit",borderRadius:"50%",width:"8px",height:"8px",position:"absolute",left:"-3.25px"},".cm-selectionHandle-start::before":{top:"-8px"},".cm-selectionHandle-end::before":{bottom:"-8px"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},".cm-panels-top":{top:"0"},".cm-panels-bottom":{bottom:"0"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{background:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 0) no-repeat",backgroundSize:".4em",backgroundPosition:"calc(min(50%, 0px)) center"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},BS),GT={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},$p=we.ie&&we.ie_version<=11,Mm=class{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new em,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(t=>{for(let r of t)this.queue.push(r);(we.ie&&we.ie_version<=11||we.ios&&e.composing)&&t.some(r=>r.type=="childList"&&r.removedNodes.length||r.type=="characterData"&&r.oldValue.length>r.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&we.android&&e.constructor.EDIT_CONTEXT!==!1&&!(we.chrome&&we.chrome_version<126)&&(this.editContext=new Tm(e),e.state.facet(rs)&&(e.contentDOM.editContext=this.editContext.editContext)),$p&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var t;((t=this.view.docView)===null||t===void 0?void 0:t.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(e.scrollDOM)),this.addWindowListeners(this.win=e.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(t=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(e){this.view.inputState.runHandlers("scroll",e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(e){(e.type=="change"||!e.type)&&!e.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((t,r)=>t!=e[r]))){this.gapIntersection.disconnect();for(let t of e)this.gapIntersection.observe(t);this.gaps=e}}onSelectionChange(e){let t=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:r}=this,a=this.selectionRange;if(r.state.facet(rs)?r.root.activeElement!=this.dom:!du(this.dom,a))return;let s=a.anchorNode&&r.docView.tile.nearest(a.anchorNode);if(s&&s.isWidget()&&s.widget.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(we.ie&&we.ie_version<=11||we.android&&we.chrome)&&!r.state.selection.main.empty&&a.focusNode&&hu(a.focusNode,a.focusOffset,a.anchorNode,a.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=Su(e.root);if(!t)return!1;let r=we.safari&&e.root.nodeType==11&&e.root.activeElement==this.dom&&zT(this.view,t)||t;if(!r||this.selectionRange.eq(r))return!1;let a=du(this.dom,r);return a&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&BM(this.dom,r)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(r),a&&(this.selectionChanged=!0),!0)}setSelectionRange(e,t){this.selectionRange.set(e.node,e.offset,t.node,t.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let e=0,t=null;for(let r=this.dom;r;)if(r.nodeType==1)!t&&e<this.scrollTargets.length&&this.scrollTargets[e]==r?e++:t||(t=this.scrollTargets.slice(0,e)),t&&t.push(r),r=r.assignedSlot||r.parentNode;else if(r.nodeType==11)r=r.host;else break;if(e<this.scrollTargets.length&&!t&&(t=this.scrollTargets.slice(0,e)),t){for(let r of this.scrollTargets)r.removeEventListener("scroll",this.onScroll);for(let r of this.scrollTargets=t)r.addEventListener("scroll",this.onScroll)}}ignore(e){if(!this.active)return e();try{return this.stop(),e()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,GT),$p&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),$p&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,t){var r;if(!this.delayedAndroidKey){let a=()=>{let s=this.delayedAndroidKey;s&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=s.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&s.force&&Fi(this.dom,s.key,s.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(a)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange<Date.now()-50||!!(!((r=this.delayedAndroidKey)===null||r===void 0)&&r.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let t=-1,r=-1,a=!1;for(let s of e){let o=this.readMutation(s);o&&(o.typeOver&&(a=!0),t==-1?{from:t,to:r}=o:(t=Math.min(o.from,t),r=Math.max(o.to,r)))}return{from:t,to:r,typeOver:a}}readChange(){let{from:e,to:t,typeOver:r}=this.processRecords(),a=this.selectionChanged&&du(this.dom,this.selectionRange);if(e<0&&!a)return null;e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let s=new xm(this.view,e,t,r);return this.view.docView.domChanged={newSel:s.newSel?s.newSel.main:null},s}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let t=this.readChange();if(!t)return this.view.requestMeasure(),!1;let r=this.view.state,a=CS(this.view,t);return this.view.state==r&&(t.domChanged||t.newSel&&!Ed(this.view.state.selection,t.newSel.main))&&this.view.update([]),a}readMutation(e){let t=this.view.docView.tile.nearest(e.target);if(!t||t.isWidget())return null;if(t.markDirty(e.type=="attributes"),e.type=="childList"){let r=Ek(t,e.previousSibling||e.target.previousSibling,-1),a=Ek(t,e.nextSibling||e.target.nextSibling,1);return{from:r?t.posAfter(r):t.posAtStart,to:a?t.posBefore(a):t.posAtEnd,typeOver:!1}}else return e.type=="characterData"?{from:t.posAtStart,to:t.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}:null}setWindow(e){e!=this.win&&(this.removeWindowListeners(this.win),this.win=e,this.addWindowListeners(this.win))}addWindowListeners(e){e.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):e.addEventListener("beforeprint",this.onPrint),e.addEventListener("scroll",this.onScroll),e.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(e){e.removeEventListener("scroll",this.onScroll),e.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}update(e){this.editContext&&(this.editContext.update(e),e.startState.facet(rs)!=e.state.facet(rs)&&(e.view.contentDOM.editContext=e.state.facet(rs)?this.editContext.editContext:null))}destroy(){var e,t,r;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(t=this.gapIntersection)===null||t===void 0||t.disconnect(),(r=this.resizeScroll)===null||r===void 0||r.disconnect();for(let a of this.scrollTargets)a.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}};function Ek(n,e,t){for(;e;){let r=Zt.get(e);if(r&&r.parent==n)return r;let a=e.parentNode;e=a!=n.dom?a:t>0?e.nextSibling:e.previousSibling}return null}function Bk(n,e){let t=e.startContainer,r=e.startOffset,a=e.endContainer,s=e.endOffset,o=n.docView.domAtPos(n.state.selection.main.anchor,1);return hu(o.node,o.offset,a,s)&&([t,r,a,s]=[a,s,t,r]),{anchorNode:t,anchorOffset:r,focusNode:a,focusOffset:s}}function zT(n,e){if(e.getComposedRanges){let a=e.getComposedRanges(n.root)[0];if(a)return Bk(n,a)}let t=null;function r(a){a.preventDefault(),a.stopImmediatePropagation(),t=a.getTargetRanges()[0]}return n.contentDOM.addEventListener("beforeinput",r,!0),n.dom.ownerDocument.execCommand("indent"),n.contentDOM.removeEventListener("beforeinput",r,!0),t?Bk(n,t):null}var Tm=class{constructor(e){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(e.state);let t=this.editContext=new window.EditContext({text:e.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,e.state.selection.main.anchor))),selectionEnd:this.toContextPos(e.state.selection.main.head)});this.handlers.textupdate=r=>{let a=e.state.selection.main,{anchor:s,head:o}=a,i=this.toEditorPos(r.updateRangeStart),l=this.toEditorPos(r.updateRangeEnd);e.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:r.updateRangeStart,editorBase:i,drifted:!1});let u=l-i>r.text.length;i==this.from&&s<this.from?i=s:l==this.to&&s>this.to&&(l=s);let c=LS(e.state.sliceDoc(i,l),r.text,(u?a.from:a.to)-i,u?"end":null);if(!c){let f=se.single(this.toEditorPos(r.selectionStart),this.toEditorPos(r.selectionEnd));Ed(f,a)||e.dispatch({selection:f,userEvent:"select"});return}let d={from:c.from+i,to:c.toA+i,insert:ct.of(r.text.slice(c.from,c.toB).split(`
41
- `))};if((we.mac||we.android)&&d.from==o-1&&/^\. ?$/.test(r.text)&&e.contentDOM.getAttribute("autocorrect")=="off"&&(d={from:i,to:l,insert:ct.of([r.text.replace("."," ")])}),this.pendingContextChange=d,!e.state.readOnly){let f=this.to-this.from+(d.to-d.from+d.insert.length);Vm(e,d,se.single(this.toEditorPos(r.selectionStart,f),this.toEditorPos(r.selectionEnd,f)))}this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state)),d.from<d.to&&!d.insert.length&&e.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(t.text.slice(Math.max(0,r.updateRangeStart-1),Math.min(t.text.length,r.updateRangeStart+1)))&&this.handlers.compositionend(r)},this.handlers.characterboundsupdate=r=>{let a=[],s=null;for(let o=this.toEditorPos(r.rangeStart),i=this.toEditorPos(r.rangeEnd);o<i;o++){let l=e.coordsForChar(o);s=l&&new DOMRect(l.left,l.top,l.right-l.left,l.bottom-l.top)||s||new DOMRect,a.push(s)}t.updateCharacterBounds(r.rangeStart,a)},this.handlers.textformatupdate=r=>{let a=[];for(let s of r.getTextFormats()){let o=s.underlineStyle,i=s.underlineThickness;if(!/none/i.test(o)&&!/none/i.test(i)){let l=this.toEditorPos(s.rangeStart),u=this.toEditorPos(s.rangeEnd);if(l<u){let c=`text-decoration: underline ${/^[a-z]/.test(o)?o+" ":o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${/thin/i.test(i)?1:2}px`;a.push(Xe.mark({attributes:{style:c}}).range(l,u))}}}e.dispatch({effects:pS.of(Xe.set(a))})},this.handlers.compositionstart=()=>{e.inputState.composing<0&&(e.inputState.composing=0,e.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(e.inputState.composing=-1,e.inputState.compositionFirstChange=null,this.composing){let{drifted:r}=this.composing;this.composing=null,r&&this.reset(e.state)}};for(let r in this.handlers)t.addEventListener(r,this.handlers[r]);this.measureReq={read:r=>{let a=Su(r.root);a&&a.rangeCount&&this.editContext.updateSelectionBounds(a.getRangeAt(0).getBoundingClientRect())}}}applyEdits(e){let t=0,r=!1,a=this.pendingContextChange;return e.changes.iterChanges((s,o,i,l,u)=>{if(r)return;let c=u.length-(o-s);if(a&&o>=a.to)if(a.from==s&&a.to==o&&a.insert.eq(u)){a=this.pendingContextChange=null,t+=c,this.to+=c;return}else a=null,this.revertPending(e.state);if(s+=t,o+=t,o<=this.from)this.from+=c,this.to+=c;else if(s<this.to){if(s<this.from||o>this.to||this.to-this.from+u.length>3e4){r=!0;return}this.editContext.updateText(this.toContextPos(s),this.toContextPos(o),u.toString()),this.to+=c}t+=c}),a&&!r&&this.revertPending(e.state),!r}update(e){let t=this.pendingContextChange,r=e.startState.selection.main;this.composing&&(this.composing.drifted||!e.changes.touchesRange(r.from,r.to)&&e.transactions.some(a=>!a.isUserEvent("input.type")&&a.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=e.changes.mapPos(this.composing.editorBase)):!this.applyEdits(e)||!this.rangeIsValid(e.state)?(this.pendingContextChange=null,this.reset(e.state)):(e.docChanged||e.selectionSet||t)&&this.setSelection(e.state),(e.geometryChanged||e.docChanged||e.selectionSet)&&e.view.requestMeasure(this.measureReq)}resetRange(e){let{head:t}=e.selection.main;this.from=Math.max(0,t-1e4),this.to=Math.min(e.doc.length,t+1e4)}reset(e){this.resetRange(e),this.editContext.updateText(0,this.editContext.text.length,e.doc.sliceString(this.from,this.to)),this.setSelection(e)}revertPending(e){let t=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(t.from),this.toContextPos(t.from+t.insert.length),e.doc.sliceString(t.from,t.to))}setSelection(e){let{main:t}=e.selection,r=this.toContextPos(Math.max(this.from,Math.min(this.to,t.anchor))),a=this.toContextPos(t.head);(this.editContext.selectionStart!=r||this.editContext.selectionEnd!=a)&&this.editContext.updateSelection(r,a)}rangeIsValid(e){let{head:t}=e.selection.main;return!(this.from>0&&t-this.from<500||this.to<e.doc.length&&this.to-t<500||this.to-this.from>1e4*3)}toEditorPos(e,t=this.to-this.from){e=Math.min(e,t);let r=this.composing;return r&&r.drifted?r.editorBase+(e-r.contextBase):e+this.from}toContextPos(e){let t=this.composing;return t&&t.drifted?t.contextBase+(e-t.editorBase):e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}},Ie=class n{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(e={}){var t;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.clearAnnouncement=-1,this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),e.parent&&e.parent.appendChild(this.dom);let{dispatch:r}=e;this.dispatchTransactions=e.dispatchTransactions||r&&(a=>a.forEach(s=>r(s,this)))||(a=>this.update(a)),this.dispatch=this.dispatch.bind(this),this._root=e.root||EM(e.parent)||document,this.viewState=new _d(this,e.state||Ct.create(e)),e.scrollTo&&e.scrollTo.is(yd)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Ri).map(a=>new mu(a));for(let a of this.plugins)a.update(this);this.observer=new Mm(this),this.inputState=new ym(this),this.inputState.ensureHandlers(this.plugins),this.docView=new Dd(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((t=document.fonts)===null||t===void 0)&&t.ready&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent="refresh",this.requestMeasure()})}dispatch(...e){let t=e.length==1&&e[0]instanceof Pn?e:e.length==1&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(t,this)}update(e){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let t=!1,r=!1,a,s=this.state;for(let f of e){if(f.startState!=s)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");s=f.state}if(this.destroyed){this.viewState.state=s;return}let o=this.hasFocus,i=0,l=null;e.some(f=>f.annotation(MS))?(this.inputState.notifiedFocused=o,i=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,l=TS(s,o),l||(i=1));let u=this.observer.delayedAndroidKey,c=null;if(u?(this.observer.clearDelayedAndroidKey(),c=this.observer.readChange(),(c&&!this.state.doc.eq(s.doc)||!this.state.selection.eq(s.selection))&&(c=null)):this.observer.clear(),s.facet(Ct.phrases)!=this.state.facet(Ct.phrases))return this.setState(s);a=Md.create(this,s,e),a.flags|=i;let d=this.viewState.scrollTarget;try{this.updateState=2;for(let f of e){if(d&&(d=d.map(f.changes)),f.scrollIntoView){let{main:h}=f.state.selection,{x:p,y:m}=this.state.facet(n.cursorScrollMargin);d=new pu(h.empty?h:se.cursor(h.head,h.head>h.anchor?-1:1),"nearest","nearest",m,p)}for(let h of f.effects)h.is(yd)&&(d=h.value.clip(this.state))}this.viewState.update(a,d),this.bidiCache=Hd.update(this.bidiCache,a.changes),a.empty||(this.updatePlugins(a),this.inputState.update(a)),t=this.docView.update(a),this.state.facet(uu)!=this.styleModules&&this.mountStyles(),r=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(t,e.some(f=>f.isUserEvent("select.pointer")))}finally{this.updateState=0}if(a.startState.facet(Sd)!=a.state.facet(Sd)&&(this.viewState.mustMeasureContent=!0),(t||r||d||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),t&&this.docViewUpdate(),!a.empty)for(let f of this.state.facet(am))try{f(a)}catch(h){la(this.state,h,"update listener")}(l||c)&&Promise.resolve().then(()=>{l&&this.state==l.startState&&this.dispatch(l),c&&!CS(this,c)&&u.force&&Fi(this.contentDOM,u.key,u.keyCode)})}setState(e){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=e;return}this.updateState=2;let t=this.hasFocus;try{for(let r of this.plugins)r.destroy(this);this.viewState=new _d(this,e),this.plugins=e.facet(Ri).map(r=>new mu(r)),this.pluginMap.clear();for(let r of this.plugins)r.update(this);this.docView.destroy(),this.docView=new Dd(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}t&&this.focus(),this.requestMeasure()}updatePlugins(e){let t=e.startState.facet(Ri),r=e.state.facet(Ri);if(t!=r){let a=[];for(let s of r){let o=t.indexOf(s);if(o<0)a.push(new mu(s));else{let i=this.plugins[o];i.mustUpdate=e,a.push(i)}}for(let s of this.plugins)s.mustUpdate!=e&&s.destroy(this);this.plugins=a,this.pluginMap.clear()}else for(let a of this.plugins)a.mustUpdate=e;for(let a=0;a<this.plugins.length;a++)this.plugins[a].update(this);t!=r&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let e of this.plugins){let t=e.value;if(t&&t.docViewUpdate)try{t.docViewUpdate(this)}catch(r){la(this.state,r,"doc view update listener")}}}measure(e=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,r=this.viewState.scrollParent,a=this.viewState.getScrollOffset(),{scrollAnchorPos:s,scrollAnchorHeight:o,scaleY:i}=this.viewState;Math.abs(a-this.viewState.scrollOffset)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0){if(Jk(r||this.win))s=-1,o=this.viewState.heightMap.height/this.viewState.scaleY;else{let p=this.viewState.scrollAnchorAt(a);s=p.from,o=p.top}i=this.viewState.scaleY}this.updateState=1;let u=this.viewState.measure();if(!u&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(l>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let c=[];u&4||([this.measureRequests,c]=[c,this.measureRequests]);let d=c.map(p=>{try{return p.read(this)}catch(m){return la(this.state,m),Ok}}),f=Md.create(this,this.state,[]),h=!1;f.flags|=u,t?t.flags|=u:t=f,this.updateState=2,f.empty||(this.updatePlugins(f),this.inputState.update(f),this.updateAttrs(),h=this.docView.update(f),h&&this.docViewUpdate());for(let p=0;p<c.length;p++)if(d[p]!=Ok)try{let m=c[p];m.write&&m.write(d[p],this)}catch(m){la(this.state,m)}if(h&&this.docView.updateSelection(!0),!f.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,o=-1;continue}else{let m=(s<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(s).top)/this.viewState.scaleY-o/i;if((m>1||m<-1)&&!(we.ios&&this.inputState.lastIOSMomentumScroll>Date.now()-100)&&(r==this.scrollDOM||this.hasFocus||Math.max(this.inputState.lastWheelEvent,this.inputState.lastTouchTime)>Date.now()-100)){a=a+m,r?s<0?r.scrollTop=r.scrollHeight:r.scrollTop+=m:this.win.scrollBy(0,m),o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let l of this.state.facet(am))l(t)}get themeClasses(){return Nm+" "+(this.state.facet(Pm)?ES:FS)+" "+this.state.facet(Sd)}updateAttrs(){let e=_k(this,mS,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(rs)?"true":"false",class:"cm-content",style:`${we.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),_k(this,jm,t);let r=this.observer.ignore(()=>{let a=gk(this.contentDOM,this.contentAttrs,t),s=gk(this.dom,this.editorAttrs,e);return a||s});return this.editorAttrs=e,this.contentAttrs=t,r}showAnnouncements(e){let t=!0;for(let r of e)for(let a of r.effects)if(a.is(n.announce)){t&&(this.announceDOM.textContent="",this.win.clearTimeout(this.clearAnnouncement),this.clearAnnouncement=this.win.setTimeout(()=>{this.announceDOM.textContent="\xA0"},200),t=!1);let s=this.announceDOM.appendChild(document.createElement("div"));s.textContent=a.value}}mountStyles(){this.styleModules=this.state.facet(uu);let e=this.state.facet(n.cspNonce);lr.mount(this.root,this.styleModules.concat(UT).reverse(),e?{nonce:e}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),e){if(this.measureRequests.indexOf(e)>-1)return;if(e.key!=null){for(let t=0;t<this.measureRequests.length;t++)if(this.measureRequests[t].key===e.key){this.measureRequests[t]=e;return}}this.measureRequests.push(e)}}plugin(e){let t=this.pluginMap.get(e);return(t===void 0||t&&t.plugin!=e)&&this.pluginMap.set(e,t=this.plugins.find(r=>r.plugin==e)||null),t&&t.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,t,r){return Vp(this,e,kk(this,e,t,r))}moveByGroup(e,t){return Vp(this,e,kk(this,e,t,r=>cT(this,e.head,r)))}visualLineSide(e,t){return t?se.cursor(e.to,1):se.cursor(e.from,-1)}moveToLineBoundary(e,t,r=!0){return uT(this,e,t,r)}moveVertically(e,t,r){return Vp(this,e,dT(this,e,t,r))}domAtPos(e,t=1){return this.docView.domAtPos(e,t)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){this.readMeasured();let r=pm(this,e,t);return r&&r.pos}posAndSideAtCoords(e,t=!0){return this.readMeasured(),pm(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let r=this.state.doc.lineAt(e),a=this.bidiSpans(r),s=a[Vr.find(a,e-r.from,-1,t)];return r.length&&(e==r.from&&t<0||e==r.to&&t>0)&&s.dir!=this.textDirectionAt(r.from)&&(e==r.to?(e=r.from+s.from,t=1):(e=r.from+s.to,t=-1)),this.docView.coordsAt(e,t,s.dir==Wt.RTL)}coordsForChar(e){return this.readMeasured(),this.docView.coordsForChar(e)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet(dS)||e<this.viewport.from||e>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>WT)return rS(e.length);let t=this.textDirectionAt(e.from),r;for(let s of this.bidiCache)if(s.from==e.from&&s.dir==t&&(s.fresh||nS(s.isolates,r=bk(this,e))))return s.order;r||(r=bk(this,e));let a=WM(e.text,t,r);return this.bidiCache.push(new Hd(e.from,e.to,t,r,!0,a)),a}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||we.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Yk(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((e.nodeType==9?e:e.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.win.clearTimeout(this.clearAnnouncement),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){var r,a,s,o;return yd.of(new pu(typeof e=="number"?se.cursor(e):e,(r=t.y)!==null&&r!==void 0?r:"nearest",(a=t.x)!==null&&a!==void 0?a:"nearest",(s=t.yMargin)!==null&&s!==void 0?s:5,(o=t.xMargin)!==null&&o!==void 0?o:5))}scrollSnapshot(){let{scrollTop:e,scrollLeft:t}=this.scrollDOM,r=this.viewState.scrollAnchorAt(e);return yd.of(new pu(se.cursor(r.from),"start","start",r.top-e,t,!0))}setTabFocusMode(e){e==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof e=="boolean"?this.inputState.tabFocusMode=e?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+e)}static domEventHandlers(e){return cr.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return cr.define(()=>({}),{eventObservers:e})}static theme(e,t){let r=lr.newName(),a=[Sd.of(r),uu.of(Rm(`.${r}`,e))];return t&&t.dark&&a.push(Pm.of(!0)),a}static baseTheme(e){return Na.lowest(uu.of(Rm("."+Nm,e,BS)))}static findFromDOM(e){var t;let r=e.querySelector(".cm-content"),a=r&&Zt.get(r)||Zt.get(e);return((t=a?.root)===null||t===void 0?void 0:t.view)||null}};Ie.styleModule=uu;Ie.inputHandler=uS;Ie.clipboardInputFilter=zm;Ie.clipboardOutputFilter=Wm;Ie.scrollHandler=hS;Ie.focusChangeEffect=cS;Ie.perLineTextDirection=dS;Ie.exceptionSink=lS;Ie.updateListener=am;Ie.editable=rs;Ie.mouseSelectionStyle=iS;Ie.dragMovesSelection=oS;Ie.clickAddsSelectionRange=sS;Ie.decorations=Wd;Ie.blockWrappers=gS;Ie.outerDecorations=qm;Ie.atomicRanges=Iu;Ie.bidiIsolatedRanges=xS;Ie.cursorScrollMargin=Me.define({combine:n=>{let e=5,t=5;for(let r of n)typeof r=="number"?e=t=r:{x:e,y:t}=r;return{x:e,y:t}}});Ie.scrollMargins=yS;Ie.darkTheme=Pm;Ie.cspNonce=Me.define({combine:n=>n.length?n[0]:""});Ie.contentAttributes=jm;Ie.editorAttributes=mS;Ie.lineWrapping=Ie.contentAttributes.of({class:"cm-lineWrapping"});Ie.announce=xt.define();var WT=4096,Ok={},Hd=class n{constructor(e,t,r,a,s,o){this.from=e,this.to=t,this.dir=r,this.isolates=a,this.fresh=s,this.order=o}static update(e,t){if(t.empty&&!e.some(s=>s.fresh))return e;let r=[],a=e.length?e[e.length-1].dir:Wt.LTR;for(let s=Math.max(0,e.length-10);s<e.length;s++){let o=e[s];o.dir==a&&!t.touchesRange(o.from,o.to)&&r.push(new n(t.mapPos(o.from,1),t.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return r}};function _k(n,e,t){for(let r=n.state.facet(e),a=r.length-1;a>=0;a--){let s=r[a],o=typeof s=="function"?s(n):s;o&&Hm(o,t)}return t}var jT=we.mac?"mac":we.windows?"win":we.linux?"linux":"key";function qT(n,e){let t=n.split(/-(?!$)/),r=t[t.length-1];r=="Space"&&(r=" ");let a,s,o,i;for(let l=0;l<t.length-1;++l){let u=t[l];if(/^(cmd|meta|m)$/i.test(u))i=!0;else if(/^a(lt)?$/i.test(u))a=!0;else if(/^(c|ctrl|control)$/i.test(u))s=!0;else if(/^s(hift)?$/i.test(u))o=!0;else if(/^mod$/i.test(u))e=="mac"?i=!0:s=!0;else throw new Error("Unrecognized modifier name: "+u)}return a&&(r="Alt-"+r),s&&(r="Ctrl-"+r),i&&(r="Meta-"+r),o&&(r="Shift-"+r),r}function Cd(n,e,t){return e.altKey&&(n="Alt-"+n),e.ctrlKey&&(n="Ctrl-"+n),e.metaKey&&(n="Meta-"+n),t!==!1&&e.shiftKey&&(n="Shift-"+n),n}var VT=Na.default(Ie.domEventHandlers({keydown(n,e){return YT($T(e.state),n,e,"editor")}})),$m=Me.define({enables:VT}),Hk=new WeakMap;function $T(n){let e=n.facet($m),t=Hk.get(e);return t||Hk.set(e,t=XT(e.reduce((r,a)=>r.concat(a),[]))),t}var _s=null,KT=4e3;function XT(n,e=jT){let t=Object.create(null),r=Object.create(null),a=(o,i)=>{let l=r[o];if(l==null)r[o]=i;else if(l!=i)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},s=(o,i,l,u,c)=>{var d,f;let h=t[o]||(t[o]=Object.create(null)),p=i.split(/ (?!$)/).map(x=>qT(x,e));for(let x=1;x<p.length;x++){let w=p.slice(0,x).join(" ");a(w,!0),h[w]||(h[w]={preventDefault:!0,stopPropagation:!1,run:[y=>{let C=_s={view:y,prefix:w,scope:o};return setTimeout(()=>{_s==C&&(_s=null)},KT),!0}]})}let m=p.join(" ");a(m,!1);let g=h[m]||(h[m]={preventDefault:!1,stopPropagation:!1,run:((f=(d=h._any)===null||d===void 0?void 0:d.run)===null||f===void 0?void 0:f.slice())||[]});l&&g.run.push(l),u&&(g.preventDefault=!0),c&&(g.stopPropagation=!0)};for(let o of n){let i=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let u of i){let c=t[u]||(t[u]=Object.create(null));c._any||(c._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:d}=o;for(let f in c)c[f].run.push(h=>d(h,Dm))}let l=o[e]||o.key;if(l)for(let u of i)s(u,l,o.run,o.preventDefault,o.stopPropagation),o.shift&&s(u,"Shift-"+l,o.shift,o.preventDefault,o.stopPropagation)}return t}var Dm=null;function YT(n,e,t,r){Dm=e;let a=fk(e),s=Y1(a,0),o=J1(s)==a.length&&a!=" ",i="",l=!1,u=!1,c=!1;_s&&_s.view==t&&_s.scope==r&&(i=_s.prefix+" ",AS.indexOf(e.keyCode)<0&&(u=!0,_s=null));let d=new Set,f=g=>{if(g){for(let x of g.run)if(!d.has(x)&&(d.add(x),x(t)))return g.stopPropagation&&(c=!0),!0;g.preventDefault&&(g.stopPropagation&&(c=!0),u=!0)}return!1},h=n[r],p,m;return h&&(f(h[i+Cd(a,e,!o)])?l=!0:o&&(e.altKey||e.metaKey||e.ctrlKey)&&!(we.windows&&e.ctrlKey&&e.altKey)&&!(we.mac&&e.altKey&&!(e.ctrlKey||e.metaKey))&&(p=ns[e.keyCode])&&p!=a?(f(h[i+Cd(p,e,!0)])||e.shiftKey&&(m=Pi[e.keyCode])!=a&&m!=p&&f(h[i+Cd(m,e,!1)]))&&(l=!0):o&&e.shiftKey&&f(h[i+Cd(a,e,!0)])&&(l=!0),!l&&f(h._any)&&(l=!0)),u&&(l=!0),l&&c&&e.stopPropagation(),Dm=null,l}var No=class n{constructor(e,t,r,a,s){this.className=e,this.left=t,this.top=r,this.width=a,this.height=s}draw(){let e=document.createElement("div");return e.className=this.className,this.adjust(e),e}update(e,t){return t.className!=this.className?!1:(this.adjust(e),!0)}adjust(e){e.style.left=this.left+"px",e.style.top=this.top+"px",this.width!=null&&(e.style.width=this.width+"px"),e.style.height=this.height+"px"}eq(e){return this.left==e.left&&this.top==e.top&&this.width==e.width&&this.height==e.height&&this.className==e.className}static forRange(e,t,r){if(r.empty){let a=e.coordsAtPos(r.head,r.assoc||1);if(!a)return[];let s=OS(e);return[new n(t,a.left-s.left,a.top-s.top,null,a.bottom-a.top)]}else return JT(e,t,r)}};function OS(n){let e=n.scrollDOM.getBoundingClientRect();return{left:(n.textDirection==Wt.LTR?e.left:e.right-n.scrollDOM.clientWidth*n.scaleX)-n.scrollDOM.scrollLeft*n.scaleX,top:e.top-n.scrollDOM.scrollTop*n.scaleY}}function Uk(n,e,t,r){let a=n.coordsAtPos(e,t*2);if(!a)return r;let s=n.dom.getBoundingClientRect(),o=(a.top+a.bottom)/2,i=n.posAtCoords({x:s.left+1,y:o}),l=n.posAtCoords({x:s.right-1,y:o});return i==null||l==null?r:{from:Math.max(r.from,Math.min(i,l)),to:Math.min(r.to,Math.max(i,l))}}function JT(n,e,t){if(t.to<=n.viewport.from||t.from>=n.viewport.to)return[];let r=Math.max(t.from,n.viewport.from),a=Math.min(t.to,n.viewport.to),s=n.textDirection==Wt.LTR,o=n.contentDOM,i=o.getBoundingClientRect(),l=OS(n),u=o.querySelector(".cm-line"),c=u&&window.getComputedStyle(u),d=i.left+(c?parseInt(c.paddingLeft)+Math.min(0,parseInt(c.textIndent)):0),f=i.right-(c?parseInt(c.paddingRight):0),h=hm(n,r,1),p=hm(n,a,-1),m=h.type==Bn.Text?h:null,g=p.type==Bn.Text?p:null;if(m&&(n.lineWrapping||h.widgetLineBreaks)&&(m=Uk(n,r,1,m)),g&&(n.lineWrapping||p.widgetLineBreaks)&&(g=Uk(n,a,-1,g)),m&&g&&m.from==g.from&&m.to==g.to)return w(y(t.from,t.to,m));{let k=m?y(t.from,null,m):C(h,!1),v=g?y(null,t.to,g):C(p,!0),b=[];return(m||h).to<(g||p).from-(m&&g?1:0)||h.widgetLineBreaks>1&&k.bottom+n.defaultLineHeight/2<v.top?b.push(x(d,k.bottom,f,v.top)):k.bottom<v.top&&n.elementAtHeight((k.bottom+v.top)/2).type==Bn.Text&&(k.bottom=v.top=(k.bottom+v.top)/2),w(k).concat(b).concat(w(v))}function x(k,v,b,P){return new No(e,k-l.left,v-l.top,Math.max(0,b-k),P-v)}function w({top:k,bottom:v,horizontal:b}){let P=[];for(let N=0;N<b.length;N+=2)P.push(x(b[N],k,b[N+1],v));return P}function y(k,v,b){let P=1e9,N=-1e9,M=[];function U(G,V,K,L,R){let z=n.coordsAtPos(G,G==b.to?-2:2),J=n.coordsAtPos(K,K==b.from?2:-2);!z||!J||(P=Math.min(z.top,J.top,P),N=Math.max(z.bottom,J.bottom,N),R==Wt.LTR?M.push(s&&V?d:z.left,s&&L?f:J.right):M.push(!s&&L?d:J.left,!s&&V?f:z.right))}let I=k??b.from,A=v??b.to;for(let G of n.visibleRanges)if(G.to>I&&G.from<A)for(let V=Math.max(G.from,I),K=Math.min(G.to,A);;){let L=n.state.doc.lineAt(V);for(let R of n.bidiSpans(L)){let z=R.from+L.from,J=R.to+L.from;if(z>=K)break;J>V&&U(Math.max(z,V),k==null&&z<=I,Math.min(J,K),v==null&&J>=A,R.dir)}if(V=L.to+1,V>=K)break}return M.length==0&&U(I,k==null,A,v==null,n.textDirection),{top:P,bottom:N,horizontal:M}}function C(k,v){let b=i.top+(v?k.top:k.bottom);return{top:b,bottom:b,horizontal:[]}}}function ZT(n,e){return n.constructor==e.constructor&&n.eq(e)}var Fm=class{constructor(e,t){this.view=e,this.layer=t,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=e.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),t.above&&this.dom.classList.add("cm-layer-above"),t.class&&this.dom.classList.add(t.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(e.state),e.requestMeasure(this.measureReq),t.mount&&t.mount(this.dom,e)}update(e){e.startState.facet(Id)!=e.state.facet(Id)&&this.setOrder(e.state),(this.layer.update(e,this.dom)||e.geometryChanged)&&(this.scale(),e.view.requestMeasure(this.measureReq))}docViewUpdate(e){this.layer.updateOnDocViewUpdate!==!1&&e.requestMeasure(this.measureReq)}setOrder(e){let t=0,r=e.facet(Id);for(;t<r.length&&r[t]!=this.layer;)t++;this.dom.style.zIndex=String((this.layer.above?150:-1)-t)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:e,scaleY:t}=this.view;(e!=this.scaleX||t!=this.scaleY)&&(this.scaleX=e,this.scaleY=t,this.dom.style.transform=`scale(${1/e}, ${1/t})`)}draw(e){if(e.length!=this.drawn.length||e.some((t,r)=>!ZT(t,this.drawn[r]))){let t=this.dom.firstChild,r=0;for(let a of e)a.update&&t&&a.constructor&&this.drawn[r].constructor&&a.update(t,this.drawn[r])?(t=t.nextSibling,r++):this.dom.insertBefore(a.draw(),t);for(;t;){let a=t.nextSibling;t.remove(),t=a}this.drawn=e,we.webkit&&(this.dom.style.display=this.dom.firstChild?"":"none")}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}},Id=Me.define();function _S(n){return[cr.define(e=>new Fm(e,n)),Id.of(n)]}var Ui=Me.define({combine(n){return Ai(n,{cursorBlinkRate:1200,drawRangeCursor:!0,iosSelectionHandles:!0},{cursorBlinkRate:(e,t)=>Math.min(e,t),drawRangeCursor:(e,t)=>e||t})}});function HS(n={}){return[Ui.of(n),QT,eD,nD,fS.of(!0)]}function US(n){return n.startState.facet(Ui)!=n.state.facet(Ui)}var QT=_S({above:!0,markers(n){let{state:e}=n,t=e.facet(Ui),r=[];for(let a of e.selection.ranges){let s=a==e.selection.main;if(a.empty||t.drawRangeCursor&&!(s&&we.ios&&t.iosSelectionHandles)){let o=s?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",i=a.empty?a:se.cursor(a.head,a.assoc);for(let l of No.forRange(n,o,i))r.push(l)}}return r},update(n,e){n.transactions.some(r=>r.selection)&&(e.style.animationName=e.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let t=US(n);return t&&Gk(n.state,e),n.docChanged||n.selectionSet||t},mount(n,e){Gk(e.state,n)},class:"cm-cursorLayer"});function Gk(n,e){e.style.animationDuration=n.facet(Ui).cursorBlinkRate+"ms"}var eD=_S({above:!1,markers(n){let e=[],{main:t,ranges:r}=n.state.selection;for(let a of r)if(!a.empty)for(let s of No.forRange(n,"cm-selectionBackground",a))e.push(s);if(we.ios&&!t.empty&&n.state.facet(Ui).iosSelectionHandles){for(let a of No.forRange(n,"cm-selectionHandle cm-selectionHandle-start",se.cursor(t.from,1)))e.push(a);for(let a of No.forRange(n,"cm-selectionHandle cm-selectionHandle-end",se.cursor(t.to,1)))e.push(a)}return e},update(n,e){return n.docChanged||n.selectionSet||n.viewportChanged||US(n)},class:"cm-selectionLayer"}),tD=we.gecko&&we.gecko_version==153?"#ffffff01":"transparent",nD=Na.highest(Ie.theme({".cm-line":{"& ::selection, &::selection":{backgroundColor:`${tD} !important`},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}}));var A6=/x/.unicode!=null?"gu":"g";function GS(){return aD}var rD=Xe.line({class:"cm-activeLine"}),aD=cr.fromClass(class{constructor(n){this.decorations=this.getDeco(n)}update(n){(n.docChanged||n.selectionSet)&&(this.decorations=this.getDeco(n.view))}getDeco(n){let e=-1,t=[];for(let r of n.state.selection.ranges){let a=n.lineBlockAt(r.head);a.from>e&&(t.push(rD.range(a.from)),e=a.from)}return Xe.set(t)}},{decorations:n=>n.decorations}),Em=class extends Ir{constructor(e){super(),this.content=e}toDOM(e){let t=document.createElement("span");return t.className="cm-placeholder",t.style.pointerEvents="none",t.appendChild(typeof this.content=="string"?document.createTextNode(this.content):typeof this.content=="function"?this.content(e):this.content.cloneNode(!0)),t.setAttribute("aria-hidden","true"),t}coordsAt(e){let t=e.firstChild?fu(e.firstChild):[];if(!t.length)return null;let r=window.getComputedStyle(e.parentNode),a=Cu(t[0],r.direction!="rtl"),s=parseInt(r.lineHeight);return a.bottom-a.top>s*1.5?{left:a.left,right:a.right,top:a.top,bottom:a.top+s}:a}ignoreEvent(){return!1}};function zS(n){let e=cr.fromClass(class{constructor(t){this.view=t,this.placeholder=n?Xe.set([Xe.widget({widget:new Em(n),side:1}).range(0)]):Xe.none}get decorations(){return this.view.state.doc.length?Xe.none:this.placeholder}},{decorations:t=>t.decorations});return typeof n=="string"?[e,Ie.contentAttributes.of({"aria-placeholder":n})]:e}var On=class extends Pa{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}};On.prototype.elementClass="";On.prototype.toDOM=void 0;On.prototype.mapMode=ir.TrackBefore;On.prototype.startSide=On.prototype.endSide=-1;On.prototype.point=!0;var Ad=Me.define(),sD=Me.define(),oD={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>wt.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"},bu=Me.define();function Gi(n){return[WS(),bu.of({...oD,...n})]}var Bm=Me.define({combine:n=>n.some(e=>e)});function WS(n){let e=[iD];return n&&n.fixed===!1&&e.push(Bm.of(!0)),e}var iD=cr.fromClass(class{constructor(n){this.view=n,this.domAfter=null,this.prevViewport=n.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters cm-gutters-before",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=n.state.facet(bu).map(e=>new Ud(n,e)),this.fixed=!n.state.facet(Bm);for(let e of this.gutters)e.config.side=="after"?this.getDOMAfter().appendChild(e.dom):this.dom.appendChild(e.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),n.scrollDOM.insertBefore(this.dom,n.contentDOM)}getDOMAfter(){return this.domAfter||(this.domAfter=document.createElement("div"),this.domAfter.className="cm-gutters cm-gutters-after",this.domAfter.setAttribute("aria-hidden","true"),this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.domAfter.style.position=this.fixed?"sticky":"",this.view.scrollDOM.appendChild(this.domAfter)),this.domAfter}update(n){if(this.updateGutters(n)){let e=this.prevViewport,t=n.view.viewport,r=Math.min(e.to,t.to)-Math.max(e.from,t.from);this.syncGutters(r<(t.to-t.from)*.8)}if(n.geometryChanged){let e=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=e,this.domAfter&&(this.domAfter.style.minHeight=e)}this.view.state.facet(Bm)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=n.view.viewport}syncGutters(n){let e=this.dom.nextSibling;n&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let t=wt.iter(this.view.state.facet(Ad),this.view.viewport.from),r=[],a=this.gutters.map(s=>new _m(s,this.view.viewport,-this.view.documentPadding.top));for(let s of this.view.viewportLineBlocks)if(r.length&&(r=[]),Array.isArray(s.type)){let o=!0;for(let i of s.type)if(i.type==Bn.Text&&o){Om(t,r,i.from);for(let l of a)l.line(this.view,i,r);o=!1}else if(i.widget)for(let l of a)l.widget(this.view,i)}else if(s.type==Bn.Text){Om(t,r,s.from);for(let o of a)o.line(this.view,s,r)}else if(s.widget)for(let o of a)o.widget(this.view,s);for(let s of a)s.finish();n&&(this.view.scrollDOM.insertBefore(this.dom,e),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(n){let e=n.startState.facet(bu),t=n.state.facet(bu),r=n.docChanged||n.heightChanged||n.viewportChanged||!wt.eq(n.startState.facet(Ad),n.state.facet(Ad),n.view.viewport.from,n.view.viewport.to);if(e==t)for(let a of this.gutters)a.update(n)&&(r=!0);else{r=!0;let a=[];for(let s of t){let o=e.indexOf(s);o<0?a.push(new Ud(this.view,s)):(this.gutters[o].update(n),a.push(this.gutters[o]))}for(let s of this.gutters)s.dom.remove(),a.indexOf(s)<0&&s.destroy();for(let s of a)s.config.side=="after"?this.getDOMAfter().appendChild(s.dom):this.dom.appendChild(s.dom);this.gutters=a}return r}destroy(){for(let n of this.gutters)n.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:n=>Ie.scrollMargins.of(e=>{let t=e.plugin(n);if(!t||t.gutters.length==0||!t.fixed)return null;let r=t.dom.offsetWidth*e.scaleX,a=t.domAfter?t.domAfter.offsetWidth*e.scaleX:0;return e.textDirection==Wt.LTR?{left:r,right:a}:{right:r,left:a}})});function zk(n){return Array.isArray(n)?n:[n]}function Om(n,e,t){for(;n.value&&n.from<=t;)n.from==t&&e.push(n.value),n.next()}var _m=class{constructor(e,t,r){this.gutter=e,this.height=r,this.i=0,this.cursor=wt.iter(e.markers,t.from)}addElement(e,t,r){let{gutter:a}=this,s=(t.top-this.height)/e.scaleY,o=t.height/e.scaleY;if(this.i==a.elements.length){let i=new Gd(e,o,s,r);a.elements.push(i),a.dom.appendChild(i.dom)}else a.elements[this.i].update(e,o,s,r);this.height=t.bottom,this.i++}line(e,t,r){let a=[];Om(this.cursor,a,t.from),r.length&&(a=a.concat(r));let s=this.gutter.config.lineMarker(e,t,a);s&&a.unshift(s);let o=this.gutter;a.length==0&&!o.config.renderEmptyElements||this.addElement(e,t,a)}widget(e,t){let r=this.gutter.config.widgetMarker(e,t.widget,t),a=r?[r]:null;for(let s of e.state.facet(sD)){let o=s(e,t.widget,t);o&&(a||(a=[])).push(o)}a&&this.addElement(e,t,a)}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let t=e.elements.pop();e.dom.removeChild(t.dom),t.destroy()}}},Ud=class{constructor(e,t){this.view=e,this.config=t,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let r in t.domEventHandlers)this.dom.addEventListener(r,a=>{let s=a.target,o;if(s!=this.dom&&this.dom.contains(s)){for(;s.parentNode!=this.dom;)s=s.parentNode;let l=s.getBoundingClientRect();o=(l.top+l.bottom)/2}else o=a.clientY;let i=e.lineBlockAtHeight(o-e.documentTop);t.domEventHandlers[r](e,i,a)&&a.preventDefault()});this.markers=zk(t.markers(e)),t.initialSpacer&&(this.spacer=new Gd(e,0,0,[t.initialSpacer(e)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(e){let t=this.markers;if(this.markers=zk(this.config.markers(e.view)),this.spacer&&this.config.updateSpacer){let a=this.config.updateSpacer(this.spacer.markers[0],e);a!=this.spacer.markers[0]&&this.spacer.update(e.view,0,0,[a])}let r=e.view.viewport;return!wt.eq(this.markers,t,r.from,r.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(e):!1)}destroy(){for(let e of this.elements)e.destroy()}},Gd=class{constructor(e,t,r,a){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(e,t,r,a)}update(e,t,r,a){this.height!=t&&(this.height=t,this.dom.style.height=t+"px"),this.above!=r&&(this.dom.style.marginTop=(this.above=r)?r+"px":""),lD(this.markers,a)||this.setMarkers(e,a)}setMarkers(e,t){let r="cm-gutterElement",a=this.dom.firstChild;for(let s=0,o=0;;){let i=o,l=s<t.length?t[s++]:null,u=!1;if(l){let c=l.elementClass;c&&(r+=" "+c);for(let d=o;d<this.markers.length;d++)if(this.markers[d].compare(l)){i=d,u=!0;break}}else i=this.markers.length;for(;o<i;){let c=this.markers[o++];if(c.toDOM){c.destroy(a);let d=a.nextSibling;a.remove(),a=d}}if(!l)break;l.toDOM&&(u?a=a.nextSibling:this.dom.insertBefore(l.toDOM(e),a)),u&&o++}this.dom.className=r,this.markers=t}destroy(){this.setMarkers(null,[])}};function lD(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(!n[t].compare(e[t]))return!1;return!0}var uD=Me.define(),cD=Me.define(),Ti=Me.define({combine(n){return Ai(n,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(e,t){let r=Object.assign({},e);for(let a in t){let s=r[a],o=t[a];r[a]=s?(i,l,u)=>s(i,l,u)||o(i,l,u):o}return r}})}}),wu=class extends On{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}};function Kp(n,e){return n.state.facet(Ti).formatNumber(e,n.state)}var dD=bu.compute([Ti],n=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(uD)},lineMarker(e,t,r){return r.some(a=>a.toDOM)?null:new wu(Kp(e,e.state.doc.lineAt(t.from).number))},widgetMarker:(e,t,r)=>{for(let a of e.state.facet(cD)){let s=a(e,t,r);if(s)return s}return null},lineMarkerChange:e=>e.startState.facet(Ti)!=e.state.facet(Ti),initialSpacer(e){return new wu(Kp(e,Wk(e.state.doc.lines)))},updateSpacer(e,t){let r=Kp(t.view,Wk(t.view.state.doc.lines));return r==e.number?e:new wu(r)},domEventHandlers:n.facet(Ti).domEventHandlers,side:"before"}));function qd(n={}){return[Ti.of(n),WS(),dD]}function Wk(n){let e=9;for(;e<n;)e=e*10+9;return e}var fD=new class extends On{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},hD=Ad.compute(["selection"],n=>{let e=[],t=-1;for(let r of n.selection.ranges){let a=n.doc.lineAt(r.head).from;a>t&&(t=a,e.push(fD.range(a)))}return wt.of(e)});function jS(){return hD}var pD=0,Au=class{constructor(e,t){this.from=e,this.to=t}},lt=class{constructor(e={}){this.id=pD++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=e.combine||null}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof e!="function"&&(e=Ar.match(e)),t=>{let r=e(t);return r===void 0?null:[this,r]}}};lt.closedBy=new lt({deserialize:n=>n.split(" ")});lt.openedBy=new lt({deserialize:n=>n.split(" ")});lt.group=new lt({deserialize:n=>n.split(" ")});lt.isolate=new lt({deserialize:n=>{if(n&&n!="rtl"&&n!="ltr"&&n!="auto")throw new RangeError("Invalid value for isolate: "+n);return n||"auto"}});lt.contextHash=new lt({perNode:!0});lt.lookAhead=new lt({perNode:!0});lt.mounted=new lt({perNode:!0});var Do=class{constructor(e,t,r,a=!1){this.tree=e,this.overlay=t,this.parser=r,this.bracketed=a}static get(e){return e&&e.props&&e.props[lt.mounted.id]}},mD=Object.create(null),Ar=class n{constructor(e,t,r,a=0){this.name=e,this.props=t,this.id=r,this.flags=a}static define(e){let t=e.props&&e.props.length?Object.create(null):mD,r=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),a=new n(e.name||"",t,e.id,r);if(e.props){for(let s of e.props)if(Array.isArray(s)||(s=s(a)),s){if(s[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[s[0].id]=s[1]}}return a}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e=="string"){if(this.name==e)return!0;let t=this.prop(lt.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let r in e)for(let a of r.split(" "))t[a]=e[r];return r=>{for(let a=r.prop(lt.group),s=-1;s<(a?a.length:0);s++){let o=t[s<0?r.name:a[s]];if(o)return o}}}};Ar.none=new Ar("",Object.create(null),0,8);var Vd=new WeakMap,qS=new WeakMap,on;(function(n){n[n.ExcludeBuffers=1]="ExcludeBuffers",n[n.IncludeAnonymous=2]="IncludeAnonymous",n[n.IgnoreMounts=4]="IgnoreMounts",n[n.IgnoreOverlays=8]="IgnoreOverlays",n[n.EnterBracketed=16]="EnterBracketed"})(on||(on={}));var _n=class n{constructor(e,t,r,a,s){if(this.type=e,this.children=t,this.positions=r,this.length=a,this.props=null,s&&s.length){this.props=Object.create(null);for(let[o,i]of s)this.props[typeof o=="number"?o:o.id]=i}}toString(){let e=Do.get(this);if(e&&!e.overlay)return e.tree.toString();let t="";for(let r of this.children){let a=r.toString();a&&(t&&(t+=","),t+=a)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(t.length?"("+t+")":""):t}cursor(e=0){return new Ru(this.topNode,e)}cursorAt(e,t=0,r=0){let a=Vd.get(this)||this.topNode,s=new Ru(a);return s.moveTo(e,t),Vd.set(this,s._tree),s}get topNode(){return new Ta(this,0,0,null)}resolve(e,t=0){let r=Pu(Vd.get(this)||this.topNode,e,t,!1);return Vd.set(this,r),r}resolveInner(e,t=0){let r=Pu(qS.get(this)||this.topNode,e,t,!0);return qS.set(this,r),r}resolveStack(e,t=0){return gD(this,e,t)}iterate(e){let{enter:t,leave:r,from:a=0,to:s=this.length}=e,o=e.mode||0,i=(o&on.IncludeAnonymous)>0;for(let l=this.cursor(o|on.IncludeAnonymous);;){let u=!1;if(l.from<=s&&l.to>=a&&(!i&&l.type.isAnonymous||t(l)!==!1)){if(l.firstChild())continue;u=!0}for(;u&&r&&(i||!l.type.isAnonymous)&&r(l),!l.nextSibling();){if(!l.parent())return;u=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(e={}){return this.children.length<=8?this:eg(Ar.none,this.children,this.positions,0,this.children.length,0,this.length,(t,r,a)=>new n(this.type,t,r,a,this.propValues),e.makeTree||((t,r,a)=>new n(Ar.none,t,r,a)))}static build(e){return xD(e)}};_n.empty=new _n(Ar.none,[],[],0);var Km=class n{constructor(e,t){this.buffer=e,this.index=t}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new n(this.buffer,this.index)}},zs=class n{constructor(e,t,r){this.buffer=e,this.length=t,this.set=r}get type(){return Ar.none}toString(){let e=[];for(let t=0;t<this.buffer.length;)e.push(this.childString(t)),t=this.buffer[t+3];return e.join(",")}childString(e){let t=this.buffer[e],r=this.buffer[e+3],a=this.set.types[t],s=a.name;if(/\W/.test(s)&&!a.isError&&(s=JSON.stringify(s)),e+=4,r==e)return s;let o=[];for(;e<r;)o.push(this.childString(e)),e=this.buffer[e+3];return s+"("+o.join(",")+")"}findChild(e,t,r,a,s){let{buffer:o}=this,i=-1;for(let l=e;l!=t&&!(KS(s,a,o[l+1],o[l+2])&&(i=l,r>0));l=o[l+3]);return i}slice(e,t,r){let a=this.buffer,s=new Uint16Array(t-e),o=0;for(let i=e,l=0;i<t;){s[l++]=a[i++],s[l++]=a[i++]-r;let u=s[l++]=a[i++]-r;s[l++]=a[i++]-e,o=Math.max(o,u)}return new n(s,o,this.set)}};function KS(n,e,t,r){switch(n){case-2:return t<e;case-1:return r>=e&&t<e;case 0:return t<e&&r>e;case 1:return t<=e&&r>e;case 2:return r>e;case 4:return!0}}function Pu(n,e,t,r){for(var a;n.from==n.to||(t<1?n.from>=e:n.from>e)||(t>-1?n.to<=e:n.to<e);){let o=!r&&n instanceof Ta&&n.index<0?null:n.parent;if(!o)return n;n=o}let s=r?0:on.IgnoreOverlays;if(r)for(let o=n,i=o.parent;i;o=i,i=o.parent)o instanceof Ta&&o.index<0&&((a=i.enter(e,t,s))===null||a===void 0?void 0:a.from)!=o.from&&(n=i);for(;;){let o=n.enter(e,t,s);if(!o)return n;n=o}}var Kd=class{cursor(e=0){return new Ru(this,e)}getChild(e,t=null,r=null){let a=VS(this,e,t,r);return a.length?a[0]:null}getChildren(e,t=null,r=null){return VS(this,e,t,r)}resolve(e,t=0){return Pu(this,e,t,!1)}resolveInner(e,t=0){return Pu(this,e,t,!0)}matchContext(e){return Xm(this.parent,e)}enterUnfinishedNodesBefore(e){let t=this.childBefore(e),r=this;for(;t;){let a=t.lastChild;if(!a||a.to!=t.to)break;a.type.isError&&a.from==a.to?(r=t,t=a.prevSibling):t=a}return r}get node(){return this}get next(){return this.parent}},Ta=class n extends Kd{constructor(e,t,r,a){super(),this._tree=e,this.from=t,this.index=r,this._parent=a}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(e,t,r,a,s=0){for(let o=this;;){for(let{children:i,positions:l}=o._tree,u=t>0?i.length:-1;e!=u;e+=t){let c=i[e],d=l[e]+o.from,f;if(!(!(s&on.EnterBracketed&&c instanceof _n&&(f=Do.get(c))&&!f.overlay&&f.bracketed&&r>=d&&r<=d+c.length)&&!KS(a,r,d,d+c.length))){if(c instanceof zs){if(s&on.ExcludeBuffers)continue;let h=c.findChild(0,c.buffer.length,t,r-d,a);if(h>-1)return new Nu(new Ym(o,c,e,d),null,h)}else if(s&on.IncludeAnonymous||!c.type.isAnonymous||Qm(c)){let h;if(!(s&on.IgnoreMounts)&&(h=Do.get(c))&&!h.overlay)return new n(h.tree,d,e,o);let p=new n(c,d,e,o);return s&on.IncludeAnonymous||!p.type.isAnonymous?p:p.nextChild(t<0?c.children.length-1:0,t,r,a,s)}}}if(s&on.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?e=o.index+t:e=t<0?-1:o._parent._tree.children.length,o=o._parent,!o))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}prop(e){return this._tree.prop(e)}enter(e,t,r=0){let a;if(!(r&on.IgnoreOverlays)&&(a=Do.get(this._tree))&&a.overlay){let s=e-this.from,o=r&on.EnterBracketed&&a.bracketed;for(let{from:i,to:l}of a.overlay)if((t>0||o?i<=s:i<s)&&(t<0||o?l>=s:l>s))return new n(a.tree,a.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,t,r)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}};function VS(n,e,t,r){let a=n.cursor(),s=[];if(!a.firstChild())return s;if(t!=null){for(let o=!1;!o;)if(o=a.type.is(t),!a.nextSibling())return s}for(;;){if(r!=null&&a.type.is(r))return s;if(a.type.is(e)&&s.push(a.node),!a.nextSibling())return r==null?s:[]}}function Xm(n,e,t=e.length-1){for(let r=n;t>=0;r=r.parent){if(!r)return!1;if(!r.type.isAnonymous){if(e[t]&&e[t]!=r.name)return!1;t--}}return!0}var Ym=class{constructor(e,t,r,a){this.parent=e,this.buffer=t,this.index=r,this.start=a}},Nu=class n extends Kd{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,t,r){super(),this.context=e,this._parent=t,this.index=r,this.type=e.buffer.set.types[e.buffer.buffer[r]]}child(e,t,r){let{buffer:a}=this.context,s=a.findChild(this.index+4,a.buffer[this.index+3],e,t-this.context.start,r);return s<0?null:new n(this.context,this,s)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}prop(e){return this.type.prop(e)}enter(e,t,r=0){if(r&on.ExcludeBuffers)return null;let{buffer:a}=this.context,s=a.findChild(this.index+4,a.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return s<0?null:new n(this.context,this,s)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,t=e.buffer[this.index+3];return t<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new n(this.context,this._parent,t):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,t=this._parent?this._parent.index+4:0;return this.index==t?this.externalSibling(-1):new n(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],t=[],{buffer:r}=this.context,a=this.index+4,s=r.buffer[this.index+3];if(s>a){let o=r.buffer[this.index+1];e.push(r.slice(a,s,o)),t.push(0)}return new _n(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}};function XS(n){if(!n.length)return null;let e=0,t=n[0];for(let s=1;s<n.length;s++){let o=n[s];(o.from>t.from||o.to<t.to)&&(t=o,e=s)}let r=t instanceof Ta&&t.index<0?null:t.parent,a=n.slice();return r?a[e]=r:a.splice(e,1),new Jm(a,t)}var Jm=class{constructor(e,t){this.heads=e,this.node=t}get next(){return XS(this.heads)}};function gD(n,e,t){let r=n.resolveInner(e,t),a=null;for(let s=r instanceof Ta?r:r.context.parent;s;s=s.parent)if(s.index<0){let o=s.parent;(a||(a=[r])).push(o.resolve(e,t)),s=o}else{let o=Do.get(s.tree);if(o&&o.overlay&&o.overlay[0].from<=e&&o.overlay[o.overlay.length-1].to>=e){let i=new Ta(o.tree,o.overlay[0].from+s.from,-1,s);(a||(a=[r])).push(Pu(i,e,t,!1))}}return a?XS(a):r}var Ru=class{get name(){return this.type.name}constructor(e,t=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=t&~on.EnterBracketed,e instanceof Ta)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let r=e._parent;r;r=r._parent)this.stack.unshift(r.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,t){this.index=e;let{start:r,buffer:a}=this.buffer;return this.type=t||a.set.types[a.buffer[e]],this.from=r+a.buffer[e+1],this.to=r+a.buffer[e+2],!0}yield(e){return e?e instanceof Ta?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,r){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,r,this.mode));let{buffer:a}=this.buffer,s=a.findChild(this.index+4,a.buffer[this.index+3],e,t-this.buffer.start,r);return s<0?!1:(this.stack.push(this.index),this.yieldBuf(s))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,r=this.mode){return this.buffer?r&on.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,r))}parent(){if(!this.buffer)return this.yieldNode(this.mode&on.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&on.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:t}=this.buffer,r=this.stack.length-1;if(e<0){let a=r<0?0:this.stack[r]+4;if(this.index!=a)return this.yieldBuf(t.findChild(a,this.index,-1,0,4))}else{let a=t.buffer[this.index+3];if(a<(r<0?t.buffer.length:t.buffer[this.stack[r]+3]))return this.yieldBuf(a)}return r<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,r,{buffer:a}=this;if(a){if(e>0){if(this.index<a.buffer.buffer.length)return!1}else for(let s=0;s<this.index;s++)if(a.buffer.buffer[s+3]<this.index)return!1;({index:t,parent:r}=a)}else({index:t,_parent:r}=this._tree);for(;r;{index:t,_parent:r}=r)if(t>-1)for(let s=t+e,o=e<0?-1:r._tree.children.length;s!=o;s+=e){let i=r._tree.children[s];if(this.mode&on.IncludeAnonymous||i instanceof zs||!i.type.isAnonymous||Qm(i))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,t););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,t=null,r=0;if(e&&e.context==this.buffer)e:for(let a=this.index,s=this.stack.length;s>=0;){for(let o=e;o;o=o._parent)if(o.index==a){if(a==this.index)return o;t=o,r=s+1;break e}a=this.stack[--s]}for(let a=r;a<this.stack.length;a++)t=new Nu(this.buffer,t,this.stack[a]);return this.bufferNode=new Nu(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let r=0;;){let a=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){r++;continue}this.type.isAnonymous||(a=!0)}for(;;){if(a&&t&&t(this),a=this.type.isAnonymous,!r)return;if(this.nextSibling())break;this.parent(),r--,a=!0}}}matchContext(e){if(!this.buffer)return Xm(this.node.parent,e);let{buffer:t}=this.buffer,{types:r}=t.set;for(let a=e.length-1,s=this.stack.length-1;a>=0;s--){if(s<0)return Xm(this._tree,e,a);let o=r[t.buffer[this.stack[s]]];if(!o.isAnonymous){if(e[a]&&e[a]!=o.name)return!1;a--}}return!0}};function Qm(n){return n.children.some(e=>e instanceof zs||!e.type.isAnonymous||Qm(e))}function xD(n){var e;let{buffer:t,nodeSet:r,maxBufferLength:a=1024,reused:s=[],minRepeatType:o=r.types.length}=n,i=Array.isArray(t)?new Km(t,t.length):t,l=r.types,u=0,c=0;function d(k,v,b,P,N,M){let{id:U,start:I,end:A,size:G}=i,V=c,K=u;if(G<0)if(i.next(),G==-1){let Q=s[U];b.push(Q),P.push(I-k);return}else if(G==-3){u=U;return}else if(G==-4){c=U;return}else throw new RangeError(`Unrecognized record size: ${G}`);let L=l[U],R,z,J=I-k;if(A-I<=a&&(z=g(i.pos-v,N))){let Q=new Uint16Array(z.size-z.skip),re=i.pos-z.size,pe=Q.length;for(;i.pos>re;)pe=x(z.start,Q,pe);R=new zs(Q,A-z.start,r),J=z.start-k}else{let Q=i.pos-G;i.next();let re=[],pe=[],ee=U>=o?U:-1,ce=0,ue=A;for(;i.pos>Q;)ee>=0&&i.id==ee&&i.size>=0?(i.end<=ue-a&&(p(re,pe,I,ce,i.end,ue,ee,V,K),ce=re.length,ue=i.end),i.next()):M>2500?f(I,Q,re,pe):d(I,Q,re,pe,ee,M+1);if(ee>=0&&ce>0&&ce<re.length&&p(re,pe,I,ce,I,ue,ee,V,K),re.reverse(),pe.reverse(),ee>-1&&ce>0){let He=h(L,K);R=eg(L,re,pe,0,re.length,0,A-I,He,He)}else R=m(L,re,pe,A-I,V-A,K)}b.push(R),P.push(J)}function f(k,v,b,P){let N=[],M=0,U=-1;for(;i.pos>v;){let{id:I,start:A,end:G,size:V}=i;if(V>4)i.next();else{if(U>-1&&A<U)break;U<0&&(U=G-a),N.push(I,A,G),M++,i.next()}}if(M){let I=new Uint16Array(M*4),A=N[N.length-2];for(let G=N.length-3,V=0;G>=0;G-=3)I[V++]=N[G],I[V++]=N[G+1]-A,I[V++]=N[G+2]-A,I[V++]=V;b.push(new zs(I,N[2]-A,r)),P.push(A-k)}}function h(k,v){return(b,P,N)=>{let M=0,U=b.length-1,I,A;if(U>=0&&(I=b[U])instanceof _n){if(!U&&I.type==k&&I.length==N)return I;(A=I.prop(lt.lookAhead))&&(M=P[U]+I.length+A)}return m(k,b,P,N,M,v)}}function p(k,v,b,P,N,M,U,I,A){let G=[],V=[];for(;k.length>P;)G.push(k.pop()),V.push(v.pop()+b-N);k.push(m(r.types[U],G,V,M-N,I-M,A)),v.push(N-b)}function m(k,v,b,P,N,M,U){if(M){let I=[lt.contextHash,M];U=U?[I].concat(U):[I]}if(N>25){let I=[lt.lookAhead,N];U=U?[I].concat(U):[I]}return new _n(k,v,b,P,U)}function g(k,v){let b=i.fork(),P=0,N=0,M=0,U=b.end-a,I={size:0,start:0,skip:0};e:for(let A=b.pos-k;b.pos>A;){let G=b.size;if(b.id==v&&G>=0){I.size=P,I.start=N,I.skip=M,M+=4,P+=4,b.next();continue}let V=b.pos-G;if(G<0||V<A||b.start<U)break;let K=b.id>=o?4:0,L=b.start;for(b.next();b.pos>V;){if(b.size<0)if(b.size==-3||b.size==-4)K+=4;else break e;else b.id>=o&&(K+=4);b.next()}N=L,P+=G,M+=K}return(v<0||P==k)&&(I.size=P,I.start=N,I.skip=M),I.size>4?I:void 0}function x(k,v,b){let{id:P,start:N,end:M,size:U}=i;if(i.next(),U>=0&&P<o){let I=b;if(U>4){let A=i.pos-(U-4);for(;i.pos>A;)b=x(k,v,b)}v[--b]=I,v[--b]=M-k,v[--b]=N-k,v[--b]=P}else U==-3?u=P:U==-4&&(c=P);return b}let w=[],y=[];for(;i.pos>0;)d(n.start||0,n.bufferStart||0,w,y,-1,0);let C=(e=n.length)!==null&&e!==void 0?e:w.length?y[0]+w[0].length:0;return new _n(l[n.topID],w.reverse(),y.reverse(),C)}var $S=new WeakMap;function $d(n,e){if(!n.isAnonymous||e instanceof zs||e.type!=n)return 1;let t=$S.get(e);if(t==null){t=1;for(let r of e.children){if(r.type!=n||!(r instanceof _n)){t=1;break}t+=$d(n,r)}$S.set(e,t)}return t}function eg(n,e,t,r,a,s,o,i,l){let u=0;for(let p=r;p<a;p++)u+=$d(n,e[p]);let c=Math.ceil(u*1.5/8),d=[],f=[];function h(p,m,g,x,w){for(let y=g;y<x;){let C=y,k=m[y],v=$d(n,p[y]);for(y++;y<x;y++){let b=$d(n,p[y]);if(v+b>=c)break;v+=b}if(y==C+1){if(v>c){let b=p[C];h(b.children,b.positions,0,b.children.length,m[C]+w);continue}d.push(p[C])}else{let b=m[y-1]+p[y-1].length-k;d.push(eg(n,p,m,C,y,k,b,null,l))}f.push(k+w-s)}}return h(e,t,r,a,0),(i||l)(d,f,o)}var Fo=class n{constructor(e,t,r,a,s=!1,o=!1){this.from=e,this.to=t,this.tree=r,this.offset=a,this.open=(s?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(e,t=[],r=!1){let a=[new n(0,e.length,e,0,!1,r)];for(let s of t)s.to>e.length&&a.push(s);return a}static applyChanges(e,t,r=128){if(!t.length)return e;let a=[],s=1,o=e.length?e[0]:null;for(let i=0,l=0,u=0;;i++){let c=i<t.length?t[i]:null,d=c?c.fromA:1e9;if(d-l>=r)for(;o&&o.from<d;){let f=o;if(l>=f.from||d<=f.to||u){let h=Math.max(f.from,l)-u,p=Math.min(f.to,d)-u;f=h>=p?null:new n(h,p,f.tree,f.offset+u,i>0,!!c)}if(f&&a.push(f),o.to>d)break;o=s<e.length?e[s++]:null}if(!c)break;l=c.toA,u=c.toA-c.toB}return a}},Xd=class{startParse(e,t,r){return typeof e=="string"&&(e=new Zm(e)),r=r?r.length?r.map(a=>new Au(a.from,a.to)):[new Au(0,0)]:[new Au(0,e.length)],this.createParse(e,t||[],r)}parse(e,t,r){let a=this.startParse(e,t,r);for(;;){let s=a.advance();if(s)return s}}},Zm=class{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}};var F6=new lt({perNode:!0});var yD=0,da=class n{constructor(e,t,r,a){this.name=e,this.set=t,this.base=r,this.modified=a,this.id=yD++}toString(){let{name:e}=this;for(let t of this.modified)t.name&&(e=`${t.name}(${e})`);return e}static define(e,t){let r=typeof e=="string"?e:"?";if(e instanceof n&&(t=e),t?.base)throw new Error("Can not derive from a modified tag");let a=new n(r,[],null,[]);if(a.set.push(a),t)for(let s of t.set)a.set.push(s);return a}static defineModifier(e){let t=new Qd(e);return r=>r.modified.indexOf(t)>-1?r:Qd.get(r.base||r,r.modified.concat(t).sort((a,s)=>a.id-s.id))}},bD=0,Qd=class n{constructor(e){this.name=e,this.instances=[],this.id=bD++}static get(e,t){if(!t.length)return e;let r=t[0].instances.find(i=>i.base==e&&wD(t,i.modified));if(r)return r;let a=[],s=new da(e.name,a,e,t);for(let i of t)i.instances.push(s);let o=vD(t);for(let i of e.set)if(!i.modified.length)for(let l of o)a.push(n.get(i,l));return s}};function wD(n,e){return n.length==e.length&&n.every((t,r)=>t==e[r])}function vD(n){let e=[[]];for(let t=0;t<n.length;t++)for(let r=0,a=e.length;r<a;r++)e.push(e[r].concat(n[t]));return e.sort((t,r)=>r.length-t.length)}function ZS(n){let e=Object.create(null);for(let t in n){let r=n[t];Array.isArray(r)||(r=[r]);for(let a of t.split(" "))if(a){let s=[],o=2,i=a;for(let d=0;;){if(i=="..."&&d>0&&d+3==a.length){o=1;break}let f=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(i);if(!f)throw new RangeError("Invalid path: "+a);if(s.push(f[0]=="*"?"":f[0][0]=='"'?JSON.parse(f[0]):f[0]),d+=f[0].length,d==a.length)break;let h=a[d++];if(d==a.length&&h=="!"){o=0;break}if(h!="/")throw new RangeError("Invalid path: "+a);i=a.slice(d)}let l=s.length-1,u=s[l];if(!u)throw new RangeError("Invalid path: "+a);let c=new Bo(r,o,l>0?s.slice(0,l):null);e[u]=c.sort(e[u])}}return QS.add(e)}var QS=new lt({combine(n,e){let t,r,a;for(;n||e;){if(!n||e&&n.depth<=e.depth?(a=e,e=e.next):(a=n,n=n.next),t&&t.mode==a.mode&&!a.context&&!t.context)continue;let s=new Bo(a.tags,a.mode,a.context);t?t.next=s:r=s,t=s}return r}}),Bo=class{constructor(e,t,r,a){this.tags=e,this.mode=t,this.context=r,this.next=a}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}};Bo.empty=new Bo([],2,null);function ag(n,e){let t=Object.create(null);for(let s of n)if(!Array.isArray(s.tag))t[s.tag.id]=s.class;else for(let o of s.tag)t[o.id]=s.class;let{scope:r,all:a=null}=e||{};return{style:s=>{let o=a;for(let i of s)for(let l of i.set){let u=t[l.id];if(u){o=o?o+" "+u:u;break}}return o},scope:r}}function kD(n,e){let t=null;for(let r of n){let a=r.style(e);a&&(t=t?t+" "+a:a)}return t}function sg(n,e,t,r=0,a=n.length){let s=new ng(r,Array.isArray(e)?e:[e],t);s.highlightRange(n.cursor(),r,a,"",s.highlighters),s.flush(a)}var ng=class{constructor(e,t,r){this.at=e,this.highlighters=t,this.span=r,this.class=""}startSpan(e,t){t!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=t)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,t,r,a,s){let{type:o,from:i,to:l}=e;if(i>=r||l<=t)return;o.isTop&&(s=this.highlighters.filter(h=>!h.scope||h.scope(o)));let u=a,c=SD(e)||Bo.empty,d=kD(s,c.tags);if(d&&(u&&(u+=" "),u+=d,c.mode==1&&(a+=(a?" ":"")+d)),this.startSpan(Math.max(t,i),u),c.opaque)return;let f=e.tree&&e.tree.prop(lt.mounted);if(f&&f.overlay){let h=e.node.enter(f.overlay[0].from+i,1),p=this.highlighters.filter(g=>!g.scope||g.scope(f.tree.type)),m=e.firstChild();for(let g=0,x=i;;g++){let w=g<f.overlay.length?f.overlay[g]:null,y=w?w.from+i:l,C=Math.max(t,x),k=Math.min(r,y);if(C<k&&m)for(;e.from<k&&(this.highlightRange(e,C,k,a,s),this.startSpan(Math.min(k,e.to),u),!(e.to>=y||!e.nextSibling())););if(!w||y>r)break;x=w.to+i,x>t&&(this.highlightRange(h.cursor(),Math.max(t,w.from+i),Math.min(r,x),"",p),this.startSpan(Math.min(r,x),u))}m&&e.parent()}else if(e.firstChild()){f&&(a="");do if(!(e.to<=t)){if(e.from>=r)break;this.highlightRange(e,t,r,a,s),this.startSpan(Math.min(r,e.to),u)}while(e.nextSibling());e.parent()}}};function SD(n){let e=n.type.prop(QS);for(;e&&e.context&&!n.matchContext(e.context);)e=e.next;return e||null}var xe=da.define,Yd=xe(),Ws=xe(),YS=xe(Ws),JS=xe(Ws),js=xe(),Jd=xe(js),tg=xe(js),Ea=xe(),Eo=xe(Ea),Da=xe(),Fa=xe(),rg=xe(),Mu=xe(rg),Zd=xe(),be={comment:Yd,lineComment:xe(Yd),blockComment:xe(Yd),docComment:xe(Yd),name:Ws,variableName:xe(Ws),typeName:YS,tagName:xe(YS),propertyName:JS,attributeName:xe(JS),className:xe(Ws),labelName:xe(Ws),namespace:xe(Ws),macroName:xe(Ws),literal:js,string:Jd,docString:xe(Jd),character:xe(Jd),attributeValue:xe(Jd),number:tg,integer:xe(tg),float:xe(tg),bool:xe(js),regexp:xe(js),escape:xe(js),color:xe(js),url:xe(js),keyword:Da,self:xe(Da),null:xe(Da),atom:xe(Da),unit:xe(Da),modifier:xe(Da),operatorKeyword:xe(Da),controlKeyword:xe(Da),definitionKeyword:xe(Da),moduleKeyword:xe(Da),operator:Fa,derefOperator:xe(Fa),arithmeticOperator:xe(Fa),logicOperator:xe(Fa),bitwiseOperator:xe(Fa),compareOperator:xe(Fa),updateOperator:xe(Fa),definitionOperator:xe(Fa),typeOperator:xe(Fa),controlOperator:xe(Fa),punctuation:rg,separator:xe(rg),bracket:Mu,angleBracket:xe(Mu),squareBracket:xe(Mu),paren:xe(Mu),brace:xe(Mu),content:Ea,heading:Eo,heading1:xe(Eo),heading2:xe(Eo),heading3:xe(Eo),heading4:xe(Eo),heading5:xe(Eo),heading6:xe(Eo),contentSeparator:xe(Ea),list:xe(Ea),quote:xe(Ea),emphasis:xe(Ea),strong:xe(Ea),link:xe(Ea),monospace:xe(Ea),strikethrough:xe(Ea),inserted:xe(),deleted:xe(),changed:xe(),invalid:xe(),meta:Zd,documentMeta:xe(Zd),annotation:xe(Zd),processingInstruction:xe(Zd),definition:da.defineModifier("definition"),constant:da.defineModifier("constant"),function:da.defineModifier("function"),standard:da.defineModifier("standard"),local:da.defineModifier("local"),special:da.defineModifier("special")};for(let n in be){let e=be[n];e instanceof da&&(e.name=n)}var O6=ag([{tag:be.link,class:"tok-link"},{tag:be.heading,class:"tok-heading"},{tag:be.emphasis,class:"tok-emphasis"},{tag:be.strong,class:"tok-strong"},{tag:be.keyword,class:"tok-keyword"},{tag:be.atom,class:"tok-atom"},{tag:be.bool,class:"tok-bool"},{tag:be.url,class:"tok-url"},{tag:be.labelName,class:"tok-labelName"},{tag:be.inserted,class:"tok-inserted"},{tag:be.deleted,class:"tok-deleted"},{tag:be.literal,class:"tok-literal"},{tag:be.string,class:"tok-string"},{tag:be.number,class:"tok-number"},{tag:[be.regexp,be.escape,be.special(be.string)],class:"tok-string2"},{tag:be.variableName,class:"tok-variableName"},{tag:be.local(be.variableName),class:"tok-variableName tok-local"},{tag:be.definition(be.variableName),class:"tok-variableName tok-definition"},{tag:be.special(be.variableName),class:"tok-variableName2"},{tag:be.definition(be.propertyName),class:"tok-propertyName tok-definition"},{tag:be.typeName,class:"tok-typeName"},{tag:be.namespace,class:"tok-namespace"},{tag:be.className,class:"tok-className"},{tag:be.macroName,class:"tok-macroName"},{tag:be.propertyName,class:"tok-propertyName"},{tag:be.operator,class:"tok-operator"},{tag:be.comment,class:"tok-comment"},{tag:be.meta,class:"tok-meta"},{tag:be.invalid,class:"tok-invalid"},{tag:be.punctuation,class:"tok-punctuation"}]);var og,Du=new lt;var CD=new lt,$r=class{constructor(e,t,r=[],a=""){this.data=e,this.name=a,Ct.prototype.hasOwnProperty("tree")||Object.defineProperty(Ct.prototype,"tree",{get(){return os(this)}}),this.parser=t,this.extension=[qs.of(this),Ct.languageData.of((s,o,i)=>{let l=eC(s,o,i),u=l.type.prop(Du);if(!u)return[];let c=s.facet(u),d=l.type.prop(CD);if(d){let f=l.resolve(o-l.from,i);for(let h of d)if(h.test(f,s)){let p=s.facet(h.facet);return h.type=="replace"?p:p.concat(c)}}return c})].concat(r)}isActiveAt(e,t,r=-1){return eC(e,t,r).type.prop(Du)==this.data}findRegions(e){let t=e.facet(qs);if(t?.data==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let r=[],a=(s,o)=>{if(s.prop(Du)==this.data){r.push({from:o,to:o+s.length});return}let i=s.prop(lt.mounted);if(i){if(i.tree.prop(Du)==this.data){if(i.overlay)for(let l of i.overlay)r.push({from:l.from+o,to:l.to+o});else r.push({from:o,to:o+s.length});return}else if(i.overlay){let l=r.length;if(a(i.tree,i.overlay[0].from+o),r.length>l)return}}for(let l=0;l<s.children.length;l++){let u=s.children[l];u instanceof _n&&a(u,s.positions[l]+o)}};return a(os(e),0),r}get allowsNesting(){return!0}};$r.setState=xt.define();function eC(n,e,t){let r=n.facet(qs),a=os(n).topNode;if(!r||r.allowsNesting)for(let s=a;s;s=s.enter(e,t,on.ExcludeBuffers|on.EnterBracketed))s.type.isTop&&(a=s);return a}function os(n){let e=n.field($r.state,!1);return e?e.tree:_n.empty}var ug=class{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,t){let r=this.cursorPos-this.string.length;return e<r||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-r,t-r)}},Tu=null,cg=class n{constructor(e,t,r=[],a,s,o,i,l){this.parser=e,this.state=t,this.fragments=r,this.tree=a,this.treeLen=s,this.viewport=o,this.skipped=i,this.scheduleOn=l,this.parse=null,this.tempSkipped=[]}static create(e,t,r){return new n(e,t,[],_n.empty,0,r,[],null)}startParse(){return this.parser.startParse(new ug(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=_n.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var r;if(typeof e=="number"){let a=Date.now()+e;e=()=>Date.now()>a}for(this.parse||(this.parse=this.startParse()),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t<this.state.doc.length&&this.parse.stopAt(t);;){let a=this.parse.advance();if(a)if(this.fragments=this.withoutTempSkipped(Fo.addTree(a,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(r=this.parse.stoppedAt)!==null&&r!==void 0?r:this.state.doc.length,this.tree=a,this.parse=null,this.treeLen<(t??this.state.doc.length))this.parse=this.startParse();else return!0;if(e())return!1}})}takeTree(){let e,t;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(t=this.parse.advance()););}),this.treeLen=e,this.tree=t,this.fragments=this.withoutTempSkipped(Fo.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=Tu;Tu=this;try{return e()}finally{Tu=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=tC(e,t.from,t.to);return e}changes(e,t){let{fragments:r,tree:a,treeLen:s,viewport:o,skipped:i}=this;if(this.takeTree(),!e.empty){let l=[];if(e.iterChangedRanges((u,c,d,f)=>l.push({fromA:u,toA:c,fromB:d,toB:f})),r=Fo.applyChanges(r,l),a=_n.empty,s=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){i=[];for(let u of this.skipped){let c=e.mapPos(u.from,1),d=e.mapPos(u.to,-1);c<d&&i.push({from:c,to:d})}}}return new n(this.parser,t,r,a,s,o,i,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let t=this.skipped.length;for(let r=0;r<this.skipped.length;r++){let{from:a,to:s}=this.skipped[r];a<e.to&&s>e.from&&(this.fragments=tC(this.fragments,a,s),this.skipped.splice(r--,1))}return this.skipped.length>=t?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,t){this.skipped.push({from:e,to:t})}static getSkippingParser(e){return new class extends Xd{createParse(t,r,a){let s=a[0].from,o=a[a.length-1].to;return{parsedPos:s,advance(){let l=Tu;if(l){for(let u of a)l.tempSkipped.push(u);e&&(l.scheduleOn=l.scheduleOn?Promise.all([l.scheduleOn,e]):e)}return this.parsedPos=o,new _n(Ar.none,[],[],o-s)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let t=this.fragments;return this.treeLen>=e&&t.length&&t[0].from==0&&t[0].to>=e}static get(){return Tu}};function tC(n,e,t){return Fo.applyChanges(n,[{fromA:e,toA:t,fromB:e,toB:t}])}var Fu=class n{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let t=this.context.changes(e.changes,e.state),r=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,r)||t.takeTree(),new n(t)}static init(e){let t=Math.min(3e3,e.doc.length),r=cg.create(e.facet(qs).parser,e,{from:0,to:t});return r.work(20,t)||r.takeTree(),new n(r)}};$r.state=vn.define({create:Fu.init,update(n,e){for(let t of e.effects)if(t.is($r.setState))return t.value;return e.startState.facet(qs)!=e.state.facet(qs)?Fu.init(e.state):n.apply(e)}});var sC=n=>{let e=setTimeout(()=>n(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(sC=n=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(n,{timeout:400})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});var ig=typeof navigator<"u"&&(!((og=navigator.scheduling)===null||og===void 0)&&og.isInputPending)?()=>navigator.scheduling.isInputPending():null,LD=cr.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let t=this.view.state.field($r.state).context;(t.updateViewport(e.view.viewport)||this.view.viewport.to>t.treeLen)&&this.scheduleWork(),(e.docChanged||e.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(t)}scheduleWork(){if(this.working)return;let{state:e}=this.view,t=e.field($r.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=sC(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnd<t&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=t+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:r,viewport:{to:a}}=this.view,s=r.field($r.state);if(s.tree==s.context.tree&&s.context.isDone(a+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,e&&!ig?Math.max(25,e.timeRemaining()-5):1e9),i=s.context.treeLen<a&&r.doc.length>a+1e3,l=s.context.work(()=>ig&&ig()||Date.now()>o,a+(i?0:1e5));this.chunkBudget-=Date.now()-t,(l||this.chunkBudget<=0)&&(s.context.takeTree(),this.view.dispatch({effects:$r.setState.of(new Fu(s.context))})),this.chunkBudget>0&&!(l&&!i)&&this.scheduleWork(),this.checkAsyncSchedule(s.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(t=>la(this.view.state,t)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),qs=Me.define({combine(n){return n.length?n[0]:null},enables:n=>[$r.state,LD,Ie.contentAttributes.compute([n],e=>{let t=e.facet(n);return t&&t.name?{"data-language":t.name}:{}})]});var ID=Me.define(),ef=Me.define({combine:n=>{if(!n.length)return" ";let e=n[0];if(!e||/\S/.test(e)||Array.from(e).some(t=>t!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(n[0]));return e}});function Eu(n){let e=n.facet(ef);return e.charCodeAt(0)==9?n.tabSize*e.length:e.length}function Bu(n,e){let t="",r=n.tabSize,a=n.facet(ef)[0];if(a==" "){for(;e>=r;)t+=" ",e-=r;a=" "}for(let s=0;s<e;s++)t+=a;return t}function mg(n,e){n instanceof Ct&&(n=new Oo(n));for(let r of n.state.facet(ID)){let a=r(n,e);if(a!==void 0)return a}let t=os(n.state);return t.length>=e?PD(n,t,e):null}var Oo=class{constructor(e,t={}){this.state=e,this.options=t,this.unit=Eu(e)}lineAt(e,t=1){let r=this.state.doc.lineAt(e),{simulateBreak:a,simulateDoubleBreak:s}=this.options;return a!=null&&a>=r.from&&a<=r.to?s&&a==e?{text:"",from:e}:(t<0?a<e:a<=e)?{text:r.text.slice(a-r.from),from:a}:{text:r.text.slice(0,a-r.from),from:r.from}:r}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:r,from:a}=this.lineAt(e,t);return r.slice(e-a,Math.min(r.length,e+100-a))}column(e,t=1){let{text:r,from:a}=this.lineAt(e,t),s=this.countColumn(r,e-a),o=this.options.overrideIndentation?this.options.overrideIndentation(a):-1;return o>-1&&(s+=o-this.countColumn(r,r.search(/\S|$/))),s}countColumn(e,t=e.length){return Io(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:r,from:a}=this.lineAt(e,t),s=this.options.overrideIndentation;if(s){let o=s(a);if(o>-1)return o}return this.countColumn(r,r.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}},AD=new lt;function PD(n,e,t){let r=e.resolveStack(t),a=e.resolveInner(t,-1).resolve(t,0).enterUnfinishedNodesBefore(t);if(a!=r.node){let s=[];for(let o=a;o&&!(o.from<r.node.from||o.to>r.node.to||o.from==r.node.from&&o.type==r.node.type);o=o.parent)s.push(o);for(let o=s.length-1;o>=0;o--)r={node:s[o],next:r}}return oC(r,n,t)}function oC(n,e,t){for(let r=n;r;r=r.next){let a=RD(r.node);if(a)return a(dg.create(e,t,r))}return 0}function ND(n){return n.pos==n.options.simulateBreak&&n.options.simulateDoubleBreak}function RD(n){let e=n.type.prop(AD);if(e)return e;let t=n.firstChild,r;if(t&&(r=t.type.prop(lt.closedBy))){let a=n.lastChild,s=a&&r.indexOf(a.name)>-1;return o=>FD(o,!0,1,void 0,s&&!ND(o)?a.from:void 0)}return n.parent==null?MD:null}function MD(){return 0}var dg=class n extends Oo{constructor(e,t,r){super(e.state,e.options),this.base=e,this.pos=t,this.context=r}get node(){return this.context.node}static create(e,t,r){return new n(e,t,r)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let t=this.state.doc.lineAt(e.from);for(;;){let r=e.resolve(t.from);for(;r.parent&&r.parent.from==r.from;)r=r.parent;if(TD(r,e))break;t=this.state.doc.lineAt(r.from)}return this.lineIndent(t.from)}continue(){return oC(this.context.next,this.base,this.pos)}};function TD(n,e){for(let t=e;t;t=t.parent)if(n==t)return!0;return!1}function DD(n){let e=n.node,t=e.childAfter(e.from),r=e.lastChild;if(!t)return null;let a=n.options.simulateBreak,s=n.state.doc.lineAt(t.from),o=a==null||a<=s.from?s.to:Math.min(s.to,a);for(let i=t.to;;){let l=e.childAfter(i);if(!l||l==r)return null;if(!l.type.isSkipped){if(l.from>=o)return null;let u=/^ */.exec(s.text.slice(t.to-s.from))[0].length;return{from:t.from,to:t.to+u}}i=l.to}}function FD(n,e,t,r,a){let s=n.textAfter,o=s.match(/^\s*/)[0].length,i=r&&s.slice(o,o+r.length)==r||a==n.pos+o,l=e?DD(n):null;return l?i?n.column(l.from):n.column(l.to):n.baseIndent+(i?0:n.unit*t)}var fg=class n{constructor(e,t){this.specs=e;let r;function a(i){let l=lr.newName();return(r||(r=Object.create(null)))["."+l]=i,l}let s=typeof t.all=="string"?t.all:t.all?a(t.all):void 0,o=t.scope;this.scope=o instanceof $r?i=>i.prop(Du)==o.data:o?i=>i==o:void 0,this.style=ag(e.map(i=>({tag:i.tag,class:i.class||a(Object.assign({},i,{tag:null}))})),{all:s}).style,this.module=r?new lr(r):null,this.themeType=t.themeType}static define(e,t){return new n(e,t||{})}},ED=Me.define(),BD=Me.define({combine(n){return n.length?[n[0]]:null}});function OD(n){let e=n.facet(ED);return e.length?e:n.facet(BD)}function iC(n,e,t){let r=OD(n),a=null;if(r){for(let s of r)if(!s.scope||t&&s.scope(t)){let o=s.style(e);o&&(a=a?a+" "+o:o)}}return a}var V6=fg.define([{tag:be.meta,color:"#404740"},{tag:be.link,textDecoration:"underline"},{tag:be.heading,textDecoration:"underline",fontWeight:"bold"},{tag:be.emphasis,fontStyle:"italic"},{tag:be.strong,fontWeight:"bold"},{tag:be.strikethrough,textDecoration:"line-through"},{tag:be.keyword,color:"#708"},{tag:[be.atom,be.bool,be.url,be.contentSeparator,be.labelName],color:"#219"},{tag:[be.literal,be.inserted],color:"#164"},{tag:[be.string,be.deleted],color:"#a11"},{tag:[be.regexp,be.escape,be.special(be.string)],color:"#e40"},{tag:be.definition(be.variableName),color:"#00f"},{tag:be.local(be.variableName),color:"#30a"},{tag:[be.typeName,be.namespace],color:"#085"},{tag:be.className,color:"#167"},{tag:[be.special(be.variableName),be.macroName],color:"#256"},{tag:be.definition(be.propertyName),color:"#00c"},{tag:be.comment,color:"#940"},{tag:be.invalid,color:"#f00"}]);var _D=1e4,HD="()[]{}";var UD=new lt;function hg(n,e,t){let r=n.prop(e<0?lt.openedBy:lt.closedBy);if(r)return r;if(n.name.length==1){let a=t.indexOf(n.name);if(a>-1&&a%2==(e<0?1:0))return[t[a+e]]}return null}function pg(n){let e=n.type.prop(UD);return e?e(n.node):n}function _o(n,e,t,r={}){let a=r.maxScanDistance||_D,s=r.brackets||HD,o=os(n),i=o.resolveInner(e,t);for(let l=i;l;l=l.parent){let u=hg(l.type,t,s);if(u&&l.from<l.to){let c=pg(l);if(c&&(t>0?e>=c.from&&e<c.to:e>c.from&&e<=c.to))return GD(n,e,t,l,c,u,s)}}return zD(n,e,t,o,i.type,a,s)}function GD(n,e,t,r,a,s,o){let i=r.parent,l={from:a.from,to:a.to},u=0,c=i?.cursor();if(c&&(t<0?c.childBefore(r.from):c.childAfter(r.to)))do if(t<0?c.to<=r.from:c.from>=r.to){if(u==0&&s.indexOf(c.type.name)>-1&&c.from<c.to){let d=pg(c);return{start:l,end:d?{from:d.from,to:d.to}:void 0,matched:!0}}else if(hg(c.type,t,o))u++;else if(hg(c.type,-t,o)){if(u==0){let d=pg(c);return{start:l,end:d&&d.from<d.to?{from:d.from,to:d.to}:void 0,matched:!1}}u--}}while(t<0?c.prevSibling():c.nextSibling());return{start:l,matched:!1}}function zD(n,e,t,r,a,s,o){if(t<0?!e:e==n.doc.length)return null;let i=t<0?n.sliceDoc(e-1,e):n.sliceDoc(e,e+1),l=o.indexOf(i);if(l<0||l%2==0!=t>0)return null;let u={from:t<0?e-1:e,to:t>0?e+1:e},c=n.doc.iterRange(e,t>0?n.doc.length:0),d=0;for(let f=0;!c.next().done&&f<=s;){let h=c.value;t<0&&(f+=h.length);let p=e+f*t;for(let m=t>0?0:h.length-1,g=t>0?h.length:-1;m!=g;m+=t){let x=o.indexOf(h[m]);if(!(x<0||r.resolveInner(p+m,1).type!=a))if(x%2==0==t>0)d++;else{if(d==1)return{start:u,end:{from:p+m,to:p+m+1},matched:x>>1==l>>1};d--}}t>0&&(f+=h.length)}return c.done?{start:u,matched:!1}:null}var WD=Object.create(null),nC=[Ar.none];var rC=[],aC=Object.create(null),jD=Object.create(null);for(let[n,e]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])jD[n]=qD(WD,e);function lg(n,e){rC.indexOf(n)>-1||(rC.push(n),console.warn(e))}function qD(n,e){let t=[];for(let i of e.split(" ")){let l=[];for(let u of i.split(".")){let c=n[u]||be[u];c?typeof c=="function"?l.length?l=l.map(c):lg(u,`Modifier ${u} used at start of tag`):l.length?lg(u,`Tag ${u} used as modifier`):l=Array.isArray(c)?c:[c]:lg(u,`Unknown highlighting tag ${u}`)}for(let u of l)t.push(u)}if(!t.length)return 0;let r=e.replace(/ /g,"_"),a=r+" "+t.map(i=>i.id),s=aC[a];if(s)return s.id;let o=aC[a]=Ar.define({id:nC.length,name:r,props:[ZS({[r]:t})]});return nC.push(o),o.id}var $6={rtl:Xe.mark({class:"cm-iso",inclusive:!0,attributes:{dir:"rtl"},bidiIsolate:Wt.RTL}),ltr:Xe.mark({class:"cm-iso",inclusive:!0,attributes:{dir:"ltr"},bidiIsolate:Wt.LTR}),auto:Xe.mark({class:"cm-iso",inclusive:!0,attributes:{dir:"auto"},bidiIsolate:null})};var gn=class n{constructor(e,t,r,a){this.fromA=e,this.toA=t,this.fromB=r,this.toB=a}offset(e,t=e){return new n(this.fromA+e,this.toA+e,this.fromB+t,this.toB+t)}};function Uo(n,e,t,r,a,s){if(n==r)return[];let o=Lg(n,e,t,r,a,s),i=Ig(n,e+o,t,r,a+o,s);e+=o,t-=i,a+=o,s-=i;let l=t-e,u=s-a;if(!l||!u)return[new gn(e,t,a,s)];if(l>u){let d=n.slice(e,t).indexOf(r.slice(a,s));if(d>-1)return[new gn(e,e+d,a,a),new gn(e+d+u,t,s,s)]}else if(u>l){let d=r.slice(a,s).indexOf(n.slice(e,t));if(d>-1)return[new gn(e,e,a,a+d),new gn(t,t,a+d+l,s)]}if(l==1||u==1)return[new gn(e,t,a,s)];let c=PC(n,e,t,r,a,s);if(c){let[d,f,h]=c;return Uo(n,e,d,r,a,f).concat(Uo(n,d+h,t,r,f+h,s))}return VD(n,e,t,r,a,s)}var Ou=1e9,_u=0,Cg=!1;function VD(n,e,t,r,a,s){let o=t-e,i=s-a;if(Ou<1e9&&Math.min(o,i)>Ou*16||_u>0&&Date.now()>_u)return Math.min(o,i)>Ou*64?[new gn(e,t,a,s)]:lC(n,e,t,r,a,s);let l=Math.ceil((o+i)/2);gg.reset(l),xg.reset(l);let u=(h,p)=>n.charCodeAt(e+h)==r.charCodeAt(a+p),c=(h,p)=>n.charCodeAt(t-h-1)==r.charCodeAt(s-p-1),d=(o-i)%2!=0?xg:null,f=d?null:gg;for(let h=0;h<l;h++){if(h>Ou||_u>0&&!(h&63)&&Date.now()>_u)return lC(n,e,t,r,a,s);let p=gg.advance(h,o,i,l,d,!1,u)||xg.advance(h,o,i,l,f,!0,c);if(p)return $D(n,e,t,e+p[0],r,a,s,a+p[1])}return[new gn(e,t,a,s)]}var sf=class{constructor(){this.vec=[]}reset(e){this.len=e<<1;for(let t=0;t<this.len;t++)this.vec[t]=-1;this.vec[e+1]=0,this.start=this.end=0}advance(e,t,r,a,s,o,i){for(let l=-e+this.start;l<=e-this.end;l+=2){let u=a+l,c=l==-e||l!=e&&this.vec[u-1]<this.vec[u+1]?this.vec[u+1]:this.vec[u-1]+1,d=c-l;for(;c<t&&d<r&&i(c,d);)c++,d++;if(this.vec[u]=c,c>t)this.end+=2;else if(d>r)this.start+=2;else if(s){let f=a+(t-r)-l;if(f>=0&&f<this.len&&s.vec[f]!=-1)if(o){let h=s.vec[f];if(h>=t-c)return[h,a+h-f]}else{let h=t-s.vec[f];if(c>=h)return[c,d]}}}return null}},gg=new sf,xg=new sf;function $D(n,e,t,r,a,s,o,i){let l=!1;return!Wi(n,r)&&++r==t&&(l=!0),!Wi(a,i)&&++i==o&&(l=!0),l?[new gn(e,t,s,o)]:Uo(n,e,r,a,s,i).concat(Uo(n,r,t,a,i,o))}function AC(n,e){let t=1,r=Math.min(n,e);for(;t<r;)t=t<<1;return t}function Lg(n,e,t,r,a,s){if(e==t||e==s||n.charCodeAt(e)!=r.charCodeAt(a))return 0;let o=AC(t-e,s-a);for(let i=e,l=a;;){let u=i+o,c=l+o;if(u>t||c>s||n.slice(i,u)!=r.slice(l,c)){if(o==1)return i-e-(Wi(n,i)?0:1);o=o>>1}else{if(u==t||c==s)return u-e;i=u,l=c}}}function Ig(n,e,t,r,a,s){if(e==t||a==s||n.charCodeAt(t-1)!=r.charCodeAt(s-1))return 0;let o=AC(t-e,s-a);for(let i=t,l=s;;){let u=i-o,c=l-o;if(u<e||c<a||n.slice(u,i)!=r.slice(c,l)){if(o==1)return t-i-(Wi(n,i)?0:1);o=o>>1}else{if(u==e||c==a)return t-u;i=u,l=c}}}function yg(n,e,t,r,a,s,o,i){let l=r.slice(a,s),u=null;for(;;){if(u||o<i)return u;for(let c=e+o;;){Wi(n,c)||c++;let d=c+o;if(Wi(n,d)||(d+=d==c+1?1:-1),d>=t)break;let f=n.slice(c,d),h=-1;for(;(h=l.indexOf(f,h+1))!=-1;){let p=Lg(n,d,t,r,a+h+f.length,s),m=Ig(n,e,c,r,a,a+h),g=f.length+p+m;(!u||u[2]<g)&&(u=[c-m,a+h-m,g])}c=d}if(i<0)return u;o=o>>1}}function PC(n,e,t,r,a,s){let o=t-e,i=s-a;if(o<i){let l=PC(r,a,s,n,e,t);return l&&[l[1],l[0],l[2]]}return o<4||i*2<o?null:yg(n,e,t,r,a,s,Math.floor(o/4),-1)}function lC(n,e,t,r,a,s){Cg=!0;let o=t-e,i=s-a,l;if(o<i){let f=yg(r,a,s,n,e,t,Math.floor(o/6),50);l=f&&[f[1],f[0],f[2]]}else l=yg(n,e,t,r,a,s,Math.floor(i/6),50);if(!l)return[new gn(e,t,a,s)];let[u,c,d]=l;return Uo(n,e,u,r,a,c).concat(Uo(n,u+d,t,r,c+d,s))}function NC(n,e){for(let t=1;t<n.length;t++){let r=n[t-1],a=n[t];r.toA>a.fromA-e&&r.toB>a.fromB-e&&(n[t-1]=new gn(r.fromA,a.toA,r.fromB,a.toB),n.splice(t--,1))}}function KD(n,e,t){for(;;){NC(t,1);let r=!1;for(let a=0;a<t.length;a++){let s=t[a],o,i;(o=Lg(n,s.fromA,s.toA,e,s.fromB,s.toB))&&(s=t[a]=new gn(s.fromA+o,s.toA,s.fromB+o,s.toB)),(i=Ig(n,s.fromA,s.toA,e,s.fromB,s.toB))&&(s=t[a]=new gn(s.fromA,s.toA-i,s.fromB,s.toB-i));let l=s.toA-s.fromA,u=s.toB-s.fromB;if(l&&u)continue;let c=s.fromA-(a?t[a-1].toA:0),d=(a<t.length-1?t[a+1].fromA:n.length)-s.toA;if(!c||!d)continue;let f=l?n.slice(s.fromA,s.toA):e.slice(s.fromB,s.toB);c<=f.length&&n.slice(s.fromA-c,s.fromA)==f.slice(f.length-c)?(t[a]=new gn(s.fromA-c,s.toA-c,s.fromB-c,s.toB-c),r=!0):d<=f.length&&n.slice(s.toA,s.toA+d)==f.slice(0,d)&&(t[a]=new gn(s.fromA+d,s.toA+d,s.fromB+d,s.toB+d),r=!0)}if(!r)break}return t}function XD(n,e,t){for(let r=0,a=0;a<n.length;a++){let s=n[a],o=s.toA-s.fromA,i=s.toB-s.fromB;if(o&&i||o>3||i>3){let l=a==n.length-1?e.length:n[a+1].fromA,u=s.fromA-r,c=l-s.toA,d=cC(e,s.fromA,u),f=uC(e,s.toA,c),h=s.fromA-d,p=f-s.toA;if((!o||!i)&&h&&p){let m=Math.max(o,i),[g,x,w]=o?[e,s.fromA,s.toA]:[t,s.fromB,s.toB];m>h&&e.slice(d,s.fromA)==g.slice(w-h,w)?(s=n[a]=new gn(d,d+o,s.fromB-h,s.toB-h),d=s.fromA,f=uC(e,s.toA,l-s.toA)):m>p&&e.slice(s.toA,f)==g.slice(x,x+p)&&(s=n[a]=new gn(f-o,f,s.fromB+p,s.toB+p),f=s.toA,d=cC(e,s.fromA,s.fromA-r)),h=s.fromA-d,p=f-s.toA}if(h||p)s=n[a]=new gn(s.fromA-h,s.toA+p,s.fromB-h,s.toB+p);else if(o){if(!i){let m=fC(e,s.fromA,s.toA),g,x=m<0?-1:dC(e,s.toA,s.fromA);m>-1&&(g=m-s.fromA)<=c&&e.slice(s.fromA,m)==e.slice(s.toA,s.toA+g)?s=n[a]=s.offset(g):x>-1&&(g=s.toA-x)<=u&&e.slice(s.fromA-g,s.fromA)==e.slice(x,s.toA)&&(s=n[a]=s.offset(-g))}}else{let m=fC(t,s.fromB,s.toB),g,x=m<0?-1:dC(t,s.toB,s.fromB);m>-1&&(g=m-s.fromB)<=c&&t.slice(s.fromB,m)==t.slice(s.toB,s.toB+g)?s=n[a]=s.offset(g):x>-1&&(g=s.toB-x)<=u&&t.slice(s.fromB-g,s.fromB)==t.slice(x,s.toB)&&(s=n[a]=s.offset(-g))}}r=s.toA}return NC(n,3),n}var Ho;try{Ho=new RegExp("[\\p{Alphabetic}\\p{Number}]","u")}catch{}function RC(n){return n>48&&n<58||n>64&&n<91||n>96&&n<123}function MC(n,e){if(e==n.length)return 0;let t=n.charCodeAt(e);return t<192?RC(t)?1:0:Ho?!FC(t)||e==n.length-1?Ho.test(String.fromCharCode(t))?1:0:Ho.test(n.slice(e,e+2))?2:0:0}function TC(n,e){if(!e)return 0;let t=n.charCodeAt(e-1);return t<192?RC(t)?1:0:Ho?!EC(t)||e==1?Ho.test(String.fromCharCode(t))?1:0:Ho.test(n.slice(e-2,e))?2:0:0}var DC=8;function uC(n,e,t){if(e==n.length||!TC(n,e))return e;for(let r=e,a=e+t,s=0;s<DC;s++){let o=MC(n,r);if(!o||r+o>a)return r;r+=o}return e}function cC(n,e,t){if(!e||!MC(n,e))return e;for(let r=e,a=e-t,s=0;s<DC;s++){let o=TC(n,r);if(!o||r-o<a)return r;r-=o}return e}function dC(n,e,t){for(;e!=t;e--)if(n.charCodeAt(e-1)==10)return e;return-1}function fC(n,e,t){for(;e!=t;e++)if(n.charCodeAt(e)==10)return e;return-1}var FC=n=>n>=55296&&n<=56319,EC=n=>n>=56320&&n<=57343;function Wi(n,e){return!e||e==n.length||!FC(n.charCodeAt(e-1))||!EC(n.charCodeAt(e))}function YD(n,e,t){var r;let a=t?.override;return a?a(n,e):(Ou=((r=t?.scanLimit)!==null&&r!==void 0?r:1e9)>>1,_u=t?.timeout?Date.now()+t.timeout:0,Cg=!1,KD(n,e,Uo(n,0,n.length,e,0,e.length)))}function BC(){return!Cg}function OC(n,e,t){return XD(YD(n,e,t),n,e)}var dr=Me.define({combine:n=>n[0]}),bg=xt.define(),_C=Me.define(),nr=vn.define({create(n){return null},update(n,e){for(let t of e.effects)t.is(bg)&&(n=t.value);for(let t of e.state.facet(_C))n=t(n,e);return n}});var is=class n{constructor(e,t,r,a,s,o=!0){this.changes=e,this.fromA=t,this.toA=r,this.fromB=a,this.toB=s,this.precise=o}offset(e,t){return e||t?new n(this.changes,this.fromA+e,this.toA+e,this.fromB+t,this.toB+t,this.precise):this}get endA(){return Math.max(this.fromA,this.toA-1)}get endB(){return Math.max(this.fromB,this.toB-1)}static build(e,t,r){let a=OC(e.toString(),t.toString(),r);return HC(a,e,t,0,0,BC())}static updateA(e,t,r,a,s){return xC(gC(e,a,!0,r.length),e,t,r,s)}static updateB(e,t,r,a,s){return xC(gC(e,a,!1,t.length),e,t,r,s)}};function hC(n,e,t,r){let a=t.lineAt(n),s=r.lineAt(e);return a.to==n&&s.to==e&&n<t.length&&e<r.length?[n+1,e+1]:[a.from,s.from]}function pC(n,e,t,r){let a=t.lineAt(n),s=r.lineAt(e);return a.from==n&&s.from==e?[n,e]:[a.to+1,s.to+1]}function HC(n,e,t,r,a,s){let o=[];for(let i=0;i<n.length;i++){let l=n[i],[u,c]=hC(l.fromA+r,l.fromB+a,e,t),[d,f]=pC(l.toA+r,l.toB+a,e,t),h=[l.offset(-u+r,-c+a)];for(;i<n.length-1;){let p=n[i+1],[m,g]=hC(p.fromA+r,p.fromB+a,e,t);if(m>d+1&&g>f+1)break;h.push(p.offset(-u+r,-c+a)),[d,f]=pC(p.toA+r,p.toB+a,e,t),i++}o.push(new is(h,u,Math.max(u,d),c,Math.max(c,f),s))}return o}var tf=1e3;function mC(n,e,t,r){let a=0,s=n.length;for(;;){if(a==s){let c=0,d=0;a&&({toA:c,toB:d}=n[a-1]);let f=e-(t?c:d);return[c+f,d+f]}let o=a+s>>1,i=n[o],[l,u]=t?[i.fromA,i.toA]:[i.fromB,i.toB];if(l>e)s=o;else if(u<=e)a=o+1;else return r?[i.fromA,i.fromB]:[i.toA,i.toB]}}function gC(n,e,t,r){let a=[];return e.iterChangedRanges((s,o,i,l)=>{let u=0,c=t?e.length:r,d=0,f=t?r:e.length;s>tf&&([u,d]=mC(n,s-tf,t,!0)),o<e.length-tf&&([c,f]=mC(n,o+tf,t,!1));let h=l-i-(o-s),p,[m,g]=t?[h,0]:[0,h];a.length&&(p=a[a.length-1]).toA>=u?a[a.length-1]={fromA:p.fromA,fromB:p.fromB,toA:c,toB:f,diffA:p.diffA+m,diffB:p.diffB+g}:a.push({fromA:u,toA:c,fromB:d,toB:f,diffA:m,diffB:g})}),a}function xC(n,e,t,r,a){if(!n.length)return e;let s=[];for(let o=0,i=0,l=0,u=0;;o++){let c=o==n.length?null:n[o],d=c?c.fromA+i:t.length,f=c?c.fromB+l:r.length;for(;u<e.length;){let g=e[u];if(c&&(g.toA+i>d||g.toB+l>f))break;s.push(g.offset(i,l)),u++}if(!c)break;let h=c.toA+i+c.diffA,p=c.toB+l+c.diffB,m=OC(t.sliceString(d,h),r.sliceString(f,p),a);for(let g of HC(m,t,r,d,f,BC()))s.push(g);for(i+=c.diffA,l+=c.diffB;u<e.length;){let g=e[u];if(g.fromA+i>h&&g.fromB+l>p)break;u++}}return s}var UC={scanLimit:500},cf=cr.fromClass(class{constructor(n){({deco:this.deco,gutter:this.gutter}=wC(n))}update(n){(n.docChanged||n.viewportChanged||JD(n.startState,n.state)||ZD(n.startState,n.state))&&({deco:this.deco,gutter:this.gutter}=wC(n.view))}},{decorations:n=>n.deco}),nf=Na.low(Gi({class:"cm-changeGutter",markers:n=>{var e;return((e=n.plugin(cf))===null||e===void 0?void 0:e.gutter)||wt.empty}}));function JD(n,e){return n.field(nr,!1)!=e.field(nr,!1)}function ZD(n,e){return n.facet(dr)!=e.facet(dr)}var yC=Xe.line({class:"cm-changedLine"}),GC=Xe.mark({class:"cm-changedText"}),QD=Xe.mark({tagName:"ins",class:"cm-insertedLine"}),eF=Xe.mark({tagName:"del",class:"cm-deletedLine"}),bC=new class extends On{constructor(){super(...arguments),this.elementClass="cm-changedLineGutter"}};function tF(n,e,t,r,a,s){let o=t?n.fromA:n.fromB,i=t?n.toA:n.toB,l=0;if(o!=i){a.add(o,o,yC),a.add(o,i,t?eF:QD),s&&s.add(o,o,bC);for(let u=e.iterRange(o,i-1),c=o;!u.next().done;){if(u.lineBreak){c++,a.add(c,c,yC),s&&s.add(c,c,bC);continue}let d=c+u.value.length;if(r)for(;l<n.changes.length;){let f=n.changes[l],h=o+(t?f.fromA:f.fromB),p=o+(t?f.toA:f.toB),m=Math.max(c,h),g=Math.min(d,p);if(m<g&&a.add(m,g,GC),p<d)l++;else break}c=d}}}function wC(n){let e=n.state.field(nr),{side:t,highlightChanges:r,markGutter:a,overrideChunk:s}=n.state.facet(dr),o=t=="a",i=new jn,l=a?new jn:null,{from:u,to:c}=n.viewport;for(let d of e){if((o?d.fromA:d.fromB)>=c)break;(o?d.toA:d.toB)>u&&(!s||!s(n.state,d,i,l))&&tF(d,n.state.doc,o,r,i,l)}return{deco:i.finish(),gutter:l&&l.finish()}}var zi=class extends Ir{constructor(e){super(),this.height=e}eq(e){return this.height==e.height}toDOM(){let e=document.createElement("div");return e.className="cm-mergeSpacer",e.style.height=this.height+"px",e}updateDOM(e){return e.style.height=this.height+"px",!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}},of=xt.define({map:(n,e)=>n.map(e)}),Hu=vn.define({create:()=>Xe.none,update:(n,e)=>{for(let t of e.effects)if(t.is(of))return t.value;return n.map(e.changes)},provide:n=>Ie.decorations.from(n)}),rf=.01;function vC(n,e){if(n.size!=e.size)return!1;let t=n.iter(),r=e.iter();for(;t.value;){if(t.from!=r.from||Math.abs(t.value.spec.widget.height-r.value.spec.widget.height)>1)return!1;t.next(),r.next()}return!0}function nF(n,e,t){let r=new jn,a=new jn,s=n.state.field(Hu).iter(),o=e.state.field(Hu).iter(),i=0,l=0,u=0,c=0,d=n.viewport,f=e.viewport;for(let g=0;;g++){let x=g<t.length?t[g]:null,w=x?x.fromA:n.state.doc.length,y=x?x.fromB:e.state.doc.length;if(i<w){let C=n.lineBlockAt(i).top+u,k=e.lineBlockAt(l).top+c,v=C-k;v<-rf?(u-=v,r.add(i,i,Xe.widget({widget:new zi(-v),block:!0,side:-1}))):v>rf&&(c+=v,a.add(l,l,Xe.widget({widget:new zi(v),block:!0,side:-1})))}if(w>i+1e3&&i<d.from&&w>d.from&&l<f.from&&y>f.from){let C=Math.min(d.from-i,f.from-l);i+=C,l+=C,g--}else if(x)i=x.toA,l=x.toB;else break;for(;s.value&&s.from<i;)u-=s.value.spec.widget.height,s.next();for(;o.value&&o.from<l;)c-=o.value.spec.widget.height,o.next()}for(;s.value;)u-=s.value.spec.widget.height,s.next();for(;o.value;)c-=o.value.spec.widget.height,o.next();let h=n.contentHeight+u-(e.contentHeight+c);h<rf?r.add(n.state.doc.length,n.state.doc.length,Xe.widget({widget:new zi(-h),block:!0,side:1})):h>rf&&a.add(e.state.doc.length,e.state.doc.length,Xe.widget({widget:new zi(h),block:!0,side:1}));let p=r.finish(),m=a.finish();vC(p,n.state.field(Hu))||n.dispatch({effects:of.of(p)}),vC(m,e.state.field(Hu))||e.dispatch({effects:of.of(m)})}var wg=xt.define({map:(n,e)=>e.mapPos(n)});var vg=class extends Ir{constructor(e){super(),this.lines=e}eq(e){return this.lines==e.lines}toDOM(e){let t=document.createElement("div");return t.className="cm-collapsedLines",t.textContent=e.state.phrase("$ unchanged lines",this.lines),t.addEventListener("click",r=>{let a=e.posAtDOM(r.target);e.dispatch({effects:wg.of(a)});let{side:s,sibling:o}=e.state.facet(dr);o&&o().dispatch({effects:wg.of(rF(a,e.state.field(nr),s=="a"))})}),t}ignoreEvent(e){return e instanceof MouseEvent}get estimatedHeight(){return 27}get type(){return"collapsed-unchanged-code"}};function rF(n,e,t){let r=0,a=0;for(let s=0;;s++){let o=s<e.length?e[s]:null;if(!o||(t?o.fromA:o.fromB)>=n)return a+(n-r);[r,a]=t?[o.toA,o.toB]:[o.toB,o.toA]}}var aF=vn.define({create(n){return Xe.none},update(n,e){n=n.map(e.changes);for(let t of e.effects)t.is(wg)&&(n=n.update({filter:r=>r!=t.value}));if(n.size&&e.state.field(nr)!=e.startState.field(nr,!1)){let t=e.state.facet(dr).side=="a",r=[];for(let a of e.state.field(nr))n.between(t?a.fromA:a.fromB,t?a.toA:a.toB,s=>{r.push(s)});r.length&&(n=n.update({filter:a=>r.indexOf(a)<0}))}return n},provide:n=>Ie.decorations.from(n)});function kg({margin:n=3,minSize:e=4}){return aF.init(t=>sF(t,n,e))}function sF(n,e,t){let r=new jn,a=n.facet(dr).side=="a",s=n.field(nr),o=1;for(let i=0;;i++){let l=i<s.length?s[i]:null,u=i?o+e:1,c=l?n.doc.lineAt(a?l.fromA:l.fromB).number-1-e:n.doc.lines,d=c-u+1;if(d>=t&&r.add(n.doc.line(u).from,n.doc.line(c).to,Xe.replace({widget:new vg(d),block:!0})),!l)break;o=n.doc.lineAt(Math.min(n.doc.length,a?l.toA:l.toB)).number}return r.finish()}var oF=Ie.styleModule.of(new lr({".cm-mergeView":{overflowY:"auto"},".cm-mergeViewEditors":{display:"flex",alignItems:"stretch"},".cm-mergeViewEditor":{flexGrow:1,flexBasis:0,overflow:"hidden"},".cm-merge-revert":{width:"1.6em",flexGrow:0,flexShrink:0,position:"relative"},".cm-merge-revert button":{position:"absolute",display:"block",width:"100%",boxSizing:"border-box",textAlign:"center",background:"none",border:"none",font:"inherit",cursor:"pointer"}})),zC=Ie.baseTheme({".cm-mergeView & .cm-scroller, .cm-mergeView &":{height:"auto !important",overflowY:"visible !important"},"&.cm-merge-a .cm-changedLine, .cm-deletedChunk":{backgroundColor:"rgba(160, 128, 100, .08)"},"&.cm-merge-b .cm-changedLine, .cm-inlineChangedLine":{backgroundColor:"rgba(100, 160, 128, .08)"},"&light.cm-merge-a .cm-changedText, &light .cm-deletedChunk .cm-deletedText":{background:"linear-gradient(#ee443366, #ee443366) bottom/100% 2px no-repeat"},"&dark.cm-merge-a .cm-changedText, &dark .cm-deletedChunk .cm-deletedText":{background:"linear-gradient(#ffaa9966, #ffaa9966) bottom/100% 2px no-repeat"},"&light.cm-merge-b .cm-changedText":{background:"linear-gradient(#22bb22aa, #22bb22aa) bottom/100% 2px no-repeat"},"&dark.cm-merge-b .cm-changedText":{background:"linear-gradient(#88ff88aa, #88ff88aa) bottom/100% 2px no-repeat"},"&.cm-merge-b .cm-deletedText":{background:"#ff000033"},".cm-insertedLine, .cm-deletedLine, .cm-deletedLine del":{textDecoration:"none"},".cm-deletedChunk":{paddingLeft:"6px","& .cm-chunkButtons":{position:"absolute",insetInlineEnd:"5px"},"& button":{border:"none",cursor:"pointer",color:"white",margin:"0 2px",borderRadius:"3px","&[name=accept]":{background:"#2a2"},"&[name=reject]":{background:"#d43"}}},".cm-collapsedLines":{padding:"5px 5px 5px 10px",cursor:"pointer","&:before":{content:'"\u299A"',marginInlineEnd:"7px"},"&:after":{content:'"\u299A"',marginInlineStart:"7px"}},"&light .cm-collapsedLines":{color:"#444",background:"linear-gradient(to bottom, transparent 0, #f3f3f3 30%, #f3f3f3 70%, transparent 100%)"},"&dark .cm-collapsedLines":{color:"#ddd",background:"linear-gradient(to bottom, transparent 0, #222 30%, #222 70%, transparent 100%)"},".cm-changeGutter":{width:"3px",paddingLeft:"1px"},"&light.cm-merge-a .cm-changedLineGutter, &light .cm-deletedLineGutter":{background:"#e43"},"&dark.cm-merge-a .cm-changedLineGutter, &dark .cm-deletedLineGutter":{background:"#fa9"},"&light.cm-merge-b .cm-changedLineGutter":{background:"#2b2"},"&dark.cm-merge-b .cm-changedLineGutter":{background:"#8f8"},".cm-inlineChangedLineGutter":{background:"#75d"}}),kC=new zr,af=new zr,lf=class{constructor(e){this.revertDOM=null,this.revertToA=!1,this.revertToLeft=!1,this.measuring=-1,this.diffConf=e.diffConfig||UC;let t=[Na.low(cf),zC,oF,Hu,Ie.updateListener.of(d=>{this.measuring<0&&(d.heightChanged||d.viewportChanged)&&!d.transactions.some(f=>f.effects.some(h=>h.is(of)))&&this.measure()})],r=[dr.of({side:"a",sibling:()=>this.b,highlightChanges:e.highlightChanges!==!1,markGutter:e.gutter!==!1})];e.gutter!==!1&&r.push(nf);let a=Ct.create({doc:e.a.doc,selection:e.a.selection,extensions:[e.a.extensions||[],Ie.editorAttributes.of({class:"cm-merge-a"}),af.of(r),t]}),s=[dr.of({side:"b",sibling:()=>this.a,highlightChanges:e.highlightChanges!==!1,markGutter:e.gutter!==!1})];e.gutter!==!1&&s.push(nf);let o=Ct.create({doc:e.b.doc,selection:e.b.selection,extensions:[e.b.extensions||[],Ie.editorAttributes.of({class:"cm-merge-b"}),af.of(s),t]});this.chunks=is.build(a.doc,o.doc,this.diffConf);let i=[nr.init(()=>this.chunks),kC.of(e.collapseUnchanged?kg(e.collapseUnchanged):[])];a=a.update({effects:xt.appendConfig.of(i)}).state,o=o.update({effects:xt.appendConfig.of(i)}).state,this.dom=document.createElement("div"),this.dom.className="cm-mergeView",this.editorDOM=this.dom.appendChild(document.createElement("div")),this.editorDOM.className="cm-mergeViewEditors";let l=e.orientation||"a-b",u=document.createElement("div");u.className="cm-mergeViewEditor";let c=document.createElement("div");c.className="cm-mergeViewEditor",this.editorDOM.appendChild(l=="a-b"?u:c),this.editorDOM.appendChild(l=="a-b"?c:u),this.a=new Ie({state:a,parent:u,root:e.root,dispatchTransactions:d=>this.dispatch(d,this.a)}),this.b=new Ie({state:o,parent:c,root:e.root,dispatchTransactions:d=>this.dispatch(d,this.b)}),this.setupRevertControls(!!e.revertControls,e.revertControls=="b-to-a",e.renderRevertControl),e.parent&&e.parent.appendChild(this.dom),this.scheduleMeasure()}dispatch(e,t){if(e.some(r=>r.docChanged)){let r=e[e.length-1],a=e.reduce((o,i)=>o.compose(i.changes),Rn.empty(e[0].startState.doc.length));this.chunks=t==this.a?is.updateA(this.chunks,r.newDoc,this.b.state.doc,a,this.diffConf):is.updateB(this.chunks,this.a.state.doc,r.newDoc,a,this.diffConf),t.update([...e,r.state.update({effects:bg.of(this.chunks)})]);let s=t==this.a?this.b:this.a;s.update([s.state.update({effects:bg.of(this.chunks)})]),this.scheduleMeasure()}else t.update(e)}reconfigure(e){if("diffConfig"in e&&(this.diffConf=e.diffConfig),"orientation"in e){let s=e.orientation!="b-a";if(s!=(this.editorDOM.firstChild==this.a.dom.parentNode)){let o=this.a.dom.parentNode,i=this.b.dom.parentNode;o.remove(),i.remove(),this.editorDOM.insertBefore(s?o:i,this.editorDOM.firstChild),this.editorDOM.appendChild(s?i:o),this.revertToLeft=!this.revertToLeft,this.revertDOM&&(this.revertDOM.textContent="")}}if("revertControls"in e||"renderRevertControl"in e){let s=!!this.revertDOM,o=this.revertToA,i=this.renderRevert;"revertControls"in e&&(s=!!e.revertControls,o=e.revertControls=="b-to-a"),"renderRevertControl"in e&&(i=e.renderRevertControl),this.setupRevertControls(s,o,i)}let t="highlightChanges"in e,r="gutter"in e,a="collapseUnchanged"in e;if(t||r||a){let s=[],o=[];if(t||r){let i=this.a.state.facet(dr),l=r?e.gutter!==!1:i.markGutter,u=t?e.highlightChanges!==!1:i.highlightChanges;s.push(af.reconfigure([dr.of({side:"a",sibling:()=>this.b,highlightChanges:u,markGutter:l}),l?nf:[]])),o.push(af.reconfigure([dr.of({side:"b",sibling:()=>this.a,highlightChanges:u,markGutter:l}),l?nf:[]]))}if(a){let i=kC.reconfigure(e.collapseUnchanged?kg(e.collapseUnchanged):[]);s.push(i),o.push(i)}this.a.dispatch({effects:s}),this.b.dispatch({effects:o})}this.scheduleMeasure()}setupRevertControls(e,t,r){this.revertToA=t,this.revertToLeft=this.revertToA==(this.editorDOM.firstChild==this.a.dom.parentNode),this.renderRevert=r,!e&&this.revertDOM?(this.revertDOM.remove(),this.revertDOM=null):e&&!this.revertDOM?(this.revertDOM=this.editorDOM.insertBefore(document.createElement("div"),this.editorDOM.firstChild.nextSibling),this.revertDOM.addEventListener("mousedown",a=>this.revertClicked(a)),this.revertDOM.className="cm-merge-revert"):this.revertDOM&&(this.revertDOM.textContent="")}scheduleMeasure(){if(this.measuring<0){let e=this.dom.ownerDocument.defaultView||window;this.measuring=e.requestAnimationFrame(()=>{this.measuring=-1,this.measure()})}}measure(){nF(this.a,this.b,this.chunks),this.revertDOM&&this.updateRevertButtons()}updateRevertButtons(){let e=this.revertDOM,t=e.firstChild,r=this.a.viewport,a=this.b.viewport;for(let s=0;s<this.chunks.length;s++){let o=this.chunks[s];if(o.fromA>r.to||o.fromB>a.to)break;if(o.fromA<r.from||o.fromB<a.from)continue;let i=this.a.lineBlockAt(o.fromA).top+"px";for(;t&&+t.dataset.chunk<s;)t=SC(t);t&&t.dataset.chunk==String(s)?(t.style.top!=i&&(t.style.top=i),t=t.nextSibling):e.insertBefore(this.renderRevertButton(i,s),t)}for(;t;)t=SC(t)}renderRevertButton(e,t){let r;if(this.renderRevert)r=this.renderRevert();else{r=document.createElement("button");let a=this.a.state.phrase("Revert this chunk");r.setAttribute("aria-label",a),r.setAttribute("title",a),r.textContent=this.revertToLeft?"\u21DC":"\u21DD"}return r.style.top=e,r.setAttribute("data-chunk",String(t)),r}revertClicked(e){let t=e.target,r;for(;t&&t.parentNode!=this.revertDOM;)t=t.parentNode;if(t&&(r=this.chunks[t.dataset.chunk])){let[a,s,o,i,l,u]=this.revertToA?[this.b,this.a,r.fromB,r.toB,r.fromA,r.toA]:[this.a,this.b,r.fromA,r.toA,r.fromB,r.toB],c=a.state.sliceDoc(o,Math.max(o,i-1));o!=i&&u<=s.state.doc.length&&(c+=a.state.lineBreak),s.dispatch({changes:{from:l,to:Math.min(s.state.doc.length,u),insert:c},userEvent:"revert"}),e.preventDefault()}}destroy(){this.a.destroy(),this.b.destroy(),this.measuring>-1&&(this.dom.ownerDocument.defaultView||window).cancelAnimationFrame(this.measuring),this.dom.remove()}};function SC(n){let e=n.nextSibling;return n.remove(),e}var iF=new class extends On{constructor(){super(...arguments),this.elementClass="cm-deletedLineGutter"}},lF=Na.low(Gi({class:"cm-changeGutter",markers:n=>{var e;return((e=n.plugin(cf))===null||e===void 0?void 0:e.gutter)||wt.empty},widgetMarker:(n,e)=>e instanceof uf?iF:null}));function WC(n){var e;let t=typeof n.original=="string"?ct.of(n.original.split(/\r?\n/)):n.original,r=n.diffConfig||UC;return[Na.low(cf),fF,zC,Ie.editorAttributes.of({class:"cm-merge-b"}),_C.of((a,s)=>{let o=s.effects.find(i=>i.is(Ag));return o&&(a=is.updateA(a,o.value.doc,s.startState.doc,o.value.changes,r)),s.docChanged&&(a=is.updateB(a,s.state.field(ji),s.newDoc,s.changes,r)),a}),dr.of({highlightChanges:n.highlightChanges!==!1,markGutter:n.gutter!==!1,syntaxHighlightDeletions:n.syntaxHighlightDeletions!==!1,syntaxHighlightDeletionsMaxLength:3e3,mergeControls:(e=n.mergeControls)!==null&&e!==void 0?e:!0,overrideChunk:n.allowInlineDiffs?mF:void 0,side:"b"}),ji.init(()=>t),n.gutter!==!1?lF:[],n.collapseUnchanged?kg(n.collapseUnchanged):[],nr.init(a=>is.build(t,a.doc,r))]}var Ag=xt.define();var ji=vn.define({create:()=>ct.empty,update(n,e){for(let t of e.effects)t.is(Ag)&&(n=t.value.doc);return n}});var CC=new WeakMap,uf=class extends Ir{constructor(e){super(),this.buildDOM=e,this.dom=null}eq(e){return this.dom==e.dom}toDOM(e){return this.dom||(this.dom=this.buildDOM(e))}};function uF(n,e,t){let r=CC.get(e.changes);if(r)return r;let a=o=>{let{highlightChanges:i,syntaxHighlightDeletions:l,syntaxHighlightDeletionsMaxLength:u,mergeControls:c}=n.facet(dr),d=document.createElement("div");if(d.className="cm-deletedChunk",c){let C=d.appendChild(document.createElement("div"));C.className="cm-chunkButtons";let k=b=>{b.preventDefault(),cF(o,o.posAtDOM(d))},v=b=>{b.preventDefault(),dF(o,o.posAtDOM(d))};if(typeof c=="function")C.appendChild(c("accept",k)),C.appendChild(c("reject",v));else{let b=C.appendChild(document.createElement("button"));b.name="accept",b.textContent=n.phrase("Accept"),b.onmousedown=k;let P=C.appendChild(document.createElement("button"));P.name="reject",P.textContent=n.phrase("Reject"),P.onmousedown=v}}if(t||e.fromA>=e.toA)return d;let f=o.state.field(ji).sliceString(e.fromA,e.endA),h=l&&n.facet(qs),p=w(),m=e.changes,g=0,x=!1;function w(){let C=d.appendChild(document.createElement("div"));return C.className="cm-deletedLine",C.appendChild(document.createElement("del"))}function y(C,k,v){for(let b=C;b<k;){if(f.charAt(b)==`
42
- `){p.firstChild||p.appendChild(document.createElement("br")),p=w(),b++;continue}let P=k,N=v+(x?" cm-deletedText":""),M=!1,U=f.indexOf(`
43
- `,b);if(U>-1&&U<k&&(P=U),i&&g<m.length){let I=Math.max(0,x?m[g].toA:m[g].fromA);I<=P&&(P=I,x&&g++,M=!0)}if(P>b){let I=document.createTextNode(f.slice(b,P));if(N){let A=p.appendChild(document.createElement("span"));A.className=N,A.appendChild(I)}else p.appendChild(I);b=P}M&&(x=!x)}}if(h&&e.toA-e.fromA<=u){let C=h.parser.parse(f),k=0;sg(C,{style:v=>iC(n,v)},(v,b,P)=>{v>k&&y(k,v,""),y(v,b,P),k=b}),y(k,f.length,"")}else y(0,f.length,"");return p.firstChild||p.appendChild(document.createElement("br")),d},s=Xe.widget({block:!0,side:-1,widget:new uf(a)});return CC.set(e.changes,s),s}function cF(n,e){let{state:t}=n,r=e??t.selection.main.head,a=n.state.field(nr).find(l=>l.fromB<=r&&l.endB>=r);if(!a)return!1;let s=n.state.sliceDoc(a.fromB,Math.max(a.fromB,a.toB-1)),o=n.state.field(ji);a.fromB!=a.toB&&a.toA<=o.length&&(s+=n.state.lineBreak);let i=Rn.of({from:a.fromA,to:Math.min(o.length,a.toA),insert:s},o.length);return n.dispatch({effects:Ag.of({doc:i.apply(o),changes:i}),userEvent:"accept"}),!0}function dF(n,e){let{state:t}=n,r=e??t.selection.main.head,a=t.field(nr).find(i=>i.fromB<=r&&i.endB>=r);if(!a)return!1;let o=t.field(ji).sliceString(a.fromA,Math.max(a.fromA,a.toA-1));return a.fromA!=a.toA&&a.toB<=t.doc.length&&(o+=t.lineBreak),n.dispatch({changes:{from:a.fromB,to:Math.min(t.doc.length,a.toB),insert:o},userEvent:"revert"}),!0}function LC(n){let e=new jn;for(let t of n.field(nr)){let r=n.facet(dr).overrideChunk&&jC(n,t);e.add(t.fromB,t.fromB,uF(n,t,!!r))}return e.finish()}var fF=vn.define({create:n=>LC(n),update(n,e){return e.state.field(nr,!1)!=e.startState.field(nr,!1)?LC(e.state):n},provide:n=>Ie.decorations.from(n)}),IC=new WeakMap;function jC(n,e){let t=IC.get(e);if(t!==void 0)return t;t=null;let r=n.field(ji),a=n.doc,s=r.lineAt(e.endA).number-r.lineAt(e.fromA).number+1,o=a.lineAt(e.endB).number-a.lineAt(e.fromB).number+1;e:if(s==o&&s<10){let i=[],l=0,u=e.fromA,c=e.fromB;for(let d of e.changes){if(d.fromA<d.toA){l+=d.toA-d.fromA;let f=r.sliceString(u+d.fromA,u+d.toA);if(/\n/.test(f))break e;i.push(Xe.widget({widget:new Sg(f),side:-1}).range(c+d.fromB))}d.fromB<d.toB&&i.push(GC.range(c+d.fromB,c+d.toB))}l<e.endA-e.fromA-s*2&&(t=i)}return IC.set(e,t),t}var Sg=class extends Ir{constructor(e){super(),this.text=e}eq(e){return this.text==e.text}toDOM(e){let t=document.createElement("del");return t.className="cm-deletedText",t.textContent=this.text,t}},hF=new class extends On{constructor(){super(...arguments),this.elementClass="cm-inlineChangedLineGutter"}},pF=Xe.line({class:"cm-inlineChangedLine"});function mF(n,e,t,r){let a=jC(n,e),s=0;if(!a)return!1;for(let o=n.doc.lineAt(e.fromB);;){for(r&&r.add(o.from,o.from,hF),t.add(o.from,o.from,pF);s<a.length&&a[s].to<=o.to;){let i=a[s++];t.add(i.from,i.to,i.value)}if(o.to>=e.endB)break;o=n.doc.lineAt(o.to+1)}return!0}function qC(n,e){if(!n||!e)return!1;let t=n.getInternalStack(),r=e.getInternalStack();return!t||!r?!1:t.equals(r)}function gF(n,e){return{from:n,to:e,lines:null,startState:null,endState:null,final:!1,stateKnown:!1,lastUsed:0}}var df=class{constructor(e,t,r,a,s=64,o=4096){this.hl=e;this.lang=t;this.theme=r;this.targetLines=s;this.targetChars=o;this.chunks=[];this.tick=0;this.warned=!1;this.layoutDirty=!0;this.layout(a)}pieces(e,t,r){let a=[],s=t;for(;s<=r;){let o=e.line(s),i=o,l=1,u=o.length;for(;s+l<=r&&l<this.targetLines;){let c=e.line(s+l);if(u+1+c.length>this.targetChars)break;i=c,u+=1+c.length,l+=1}a.push(gF(o.from,i.to)),s+=l}return a}layout(e){this.chunks.length=0,this.chunks.push(...this.pieces(e,1,e.lines))}chunkIndexAt(e){let t=0,r=this.chunks.length-1;for(;t<r;){let a=t+r+1>>1;this.chunks[a].from<=e?t=a:r=a-1}return t}firstLineOf(e,t){return e.lineAt(t.from).number}tokensAt(e,t){return e.lines?.[t]??null}tokensForLine(e,t){let r=e.line(t),a=this.chunks[this.chunkIndexAt(r.from)];return{chunk:a,tokens:this.tokensAt(a,t-this.firstLineOf(e,a))}}lineCountOf(e,t){return e.lineAt(t.to).number-e.lineAt(t.from).number+1}hasPendingWork(e,t){let r=this.firstNonFinal(0);return r>=0&&r<=t||this.rebalanceTarget(e)!==null}firstNonFinal(e){for(let t=Math.max(0,e);t<this.chunks.length;t++)if(!this.chunks[t].final)return t;return-1}tokenize(e,t,r=!0){let a=this.chunks[t],s=t>0?this.chunks[t-1]:null,o=s?.endState??null,i=t===0||!!(s&&s.final&&s.stateKnown),l=e.sliceString(a.from,a.to),u=a.endState,c,d;try{let f=this.hl.codeToTokensBase(l,{lang:this.lang,theme:this.theme,includeExplanation:!1,tokenizeMaxLineLength:2e4,...o?{grammarState:o}:{}});d=this.hl.getLastGrammarState(f)??null,c=f}catch(f){this.warned||(this.warned=!0,console.warn("[Filesystem] shiki chunk tokenization failed",this.lang,f)),c=[],d=null}return a.lines=c,a.startState=o,a.endState=d,a.final=i,a.stateKnown=!0,r&&(a.lastUsed=++this.tick),this.trimWindow(),i&&qC(u,d)}ensureRange(e,t,r,a=16384){let s=!1,o=0,i=this.chunkIndexAt(t),l=Math.min(this.chunks.length-1,this.chunkIndexAt(r)+1);for(let u=i;u<=l;u++){let c=this.chunks[u];if(c.lines){c.lastUsed=++this.tick;continue}if(s&&o+(c.to-c.from)>a)break;this.tokenize(e,u,!0),o+=c.to-c.from,s=!0}return s}idleStep(e,t,r,a=()=>performance.now()){let s=a(),o=null,i=u=>{o=o?{from:Math.min(o.from,u.from),to:Math.max(o.to,u.to)}:{from:u.from,to:u.to}};this.rebalanceOnce(e);let l=this.firstNonFinal(0);for(;l>=0&&l<this.chunks.length&&l<=r;){let u=this.tokenize(e,l,!1);if(i(this.chunks[l]),u){let c=l+1;for(;c<this.chunks.length;c++){let d=this.chunks[c];if(!d.final)if(d.startState&&qC(d.startState,this.chunks[c-1].endState))d.final=!0;else break}l=this.firstNonFinal(c)}else{if(l+1<this.chunks.length&&(this.chunks[l+1].final=!1),l>=r)for(let c=l+2;c<this.chunks.length;c++)this.chunks[c].final=!1;l+=1}if(a()-s>=t)break}return{more:this.hasPendingWork(e,r),touched:o}}applyChanges(e,t){let r=new Set;if(e.iterChangedRanges((i,l)=>{let u=this.chunkIndexAt(i);for(;u<this.chunks.length&&this.chunks[u].from<=l;)r.add(this.chunks[u]),u++}),t.length===0){this.layout(t);return}let a=[],s=0;for(let i=0;i<this.chunks.length;i++){let l=this.chunks[i],u=e.mapPos(l.to,1);if(u>t.length&&(u=t.length),u=t.lineAt(u).to,u<s){let c=a[a.length-1];c&&r.add(c);continue}l.from=s,l.to=u,a.push(l),s=u+1}let o=a[a.length-1];o&&o.to<t.length&&(o.to=t.length,r.add(o));for(let i of r)i.lines=null,i.startState=null,i.final=!1,i.stateKnown=!1;this.chunks.length=0,this.chunks.push(...a),this.layoutDirty=!0,this.splitOversized(t,r)}splitOversized(e,t){for(let r=0;r<this.chunks.length;r++){let a=this.chunks[r];if(!t.has(a))continue;let s=e.lineAt(a.from).number,o=e.lineAt(a.to).number;if(o-s+1<=this.targetLines*2&&a.to-a.from<=this.targetChars*2)continue;let l=this.pieces(e,s,o);if(l.length<2)continue;let u=l[l.length-1];u.endState=a.endState,this.chunks.splice(r,1,...l),r+=l.length-1}}rebalanceTarget(e){if(!this.layoutDirty)return null;let t=this.targetLines;for(let r=0;r+1<this.chunks.length;r++){let a=this.chunks[r],s=this.chunks[r+1],o=this.lineCountOf(e,a),i=a.to-a.from;if(!(o>=t/2||i>=this.targetChars/2)&&!(o+this.lineCountOf(e,s)>t*2)&&!(s.to-a.from>this.targetChars*2))return r}return this.layoutDirty=!1,null}rebalanceOnce(e){let t=this.rebalanceTarget(e);if(t===null)return!1;let r=this.chunks[t],a=this.chunks[t+1];return r.to=a.to,r.endState=a.endState,r.lines=null,r.startState=null,r.final=!1,r.stateKnown=!1,this.chunks.splice(t+1,1),this.layoutDirty=!0,!0}trimWindow(){let e=this.chunks.filter(t=>t.lines);if(!(e.length<=32)){e.sort((t,r)=>t.lastUsed-r.lastUsed);for(let t=0;t<e.length-32;t++)e[t].lines=null}}};var Vs=Me.define({combine:n=>n.length?n[n.length-1]:{theme:"dark-plus"}}),KC=xt.define(),bF=8;function VC(n){setTimeout(()=>{try{n.dispatch({effects:KC.of(null)})}catch{}},0)}function wF(n){let e=globalThis;if(typeof e.requestIdleCallback=="function"){let r=e.requestIdleCallback(n,{timeout:250});return{cancel:()=>e.cancelIdleCallback?.(r)}}let t=setTimeout(n,0);return{cancel:()=>clearTimeout(t)}}var $C=new Map;function vF(n){let e=$C.get(n);return e||(e=Xe.mark({attributes:{style:`color:${n}`}}),$C.set(n,e)),e}var Pg=class{constructor(e){this.decorations=Xe.none;this.engine=null;this.engineKey="";this.idle=null;this.disposed=!1;this.loadKicked=null;this.horizon=0;this.decorations=this.build(e)}update(e){e.docChanged&&this.engine&&this.engine.applyChanges(e.changes,e.state.doc);let t=e.startState.facet(Vs),r=e.state.facet(Vs),a=t.lang!==r.lang||t.theme!==r.theme,s=e.transactions.some(o=>o.effects.some(i=>i.is(KC)));(e.docChanged||e.viewportChanged||a||s)&&(this.decorations=this.build(e.view))}destroy(){this.disposed=!0,this.idle?.cancel(),this.idle=null,this.engine=null}build(e){let t=e.state.facet(Vs),r=vi(t.lang);if(!r)return this.engine=null,Xe.none;let a=e.state.doc;if(a.length>2e6)return this.engine=null,Xe.none;let s=t1(r);if(!s)return this.loadKicked!==r&&(this.loadKicked=r,eu().then(()=>Jc(r)).then(c=>{c&&!this.disposed&&VC(e)})),Xe.none;let o=`${r} ${t.theme}`;(!this.engine||this.engineKey!==o)&&(this.engine=new df(s,r,t.theme,a),this.engineKey=o);let i=this.engine,l=new jn,u=0;for(let{from:c,to:d}of e.visibleRanges){i.ensureRange(a,c,d);let f=a.lineAt(c).number,h=a.lineAt(d).number,p=i.chunkIndexAt(d);u=Math.max(u,p+4);for(let m=i.chunkIndexAt(c);m<=p;m++){let g=i.chunks[m],x=i.firstLineOf(a,g),w=a.lineAt(g.to).number;for(let y=Math.max(f,x);y<=Math.min(h,w);y++){let C=i.tokensAt(g,y-x);if(!C)continue;let k=a.line(y);for(let v of C){if(!v.content||!v.color)continue;let b=g.from+v.offset,P=b+v.content.length;b<k.from||b>=P||P>k.to||l.add(b,P,vF(v.color))}}}}return this.horizon=u,i.hasPendingWork(a,u)&&this.scheduleIdle(e),l.finish()}scheduleIdle(e){this.idle||this.disposed||(this.idle=wF(()=>{if(this.idle=null,this.disposed||!this.engine)return;let t=this.engine.idleStep(e.state.doc,bF,this.horizon),r=t.touched;!!r&&e.visibleRanges.some(s=>r.from<=s.to&&r.to>=s.from)?VC(e):t.more&&this.scheduleIdle(e)}))}},ff=cr.fromClass(Pg,{decorations:n=>n.decorations});var hf=Ie.theme({"&":{backgroundColor:"transparent",color:"#d4d4d4",height:"100%"},"&.cm-focused":{outline:"none"},".cm-scroller":{fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace',fontSize:"12px",lineHeight:"18px"},".cm-content":{padding:"6px 0",caretColor:"#e5e7eb"},".cm-gutters":{backgroundColor:"transparent",border:"none",color:"rgba(255,255,255,0.25)"},".cm-lineNumbers .cm-gutterElement":{padding:"0 10px 0 12px",minWidth:"2ch"},".cm-activeLine":{backgroundColor:"rgba(255,255,255,0.035)"},".cm-activeLineGutter":{backgroundColor:"transparent",color:"rgba(255,255,255,0.5)"},".cm-cursor, .cm-dropCursor":{borderLeftColor:"#e5e7eb"},".cm-selectionBackground, .cm-content ::selection":{backgroundColor:"rgba(96,130,255,0.28)"},"&.cm-focused .cm-selectionBackground":{backgroundColor:"rgba(96,130,255,0.34)"},".cm-placeholder":{color:"rgba(255,255,255,0.22)"}},{dark:!0}),XC=Ie.theme({".cm-changedLine":{backgroundColor:"rgba(16,185,129,0.10)"},".cm-changedText":{background:"rgba(16,185,129,0.24)"},".cm-insertedLine":{backgroundColor:"rgba(16,185,129,0.12)"},".cm-deletedChunk":{backgroundColor:"rgba(244,63,94,0.10)"},".cm-deletedChunk .cm-deletedText, .cm-deletedText":{background:"rgba(244,63,94,0.30)"},".cm-changeGutter":{width:"3px"},".cm-changedLineGutter":{backgroundColor:"rgba(16,185,129,0.45)"},".cm-deletedLineGutter":{backgroundColor:"rgba(244,63,94,0.45)"},".cm-merge-a, .cm-merge-b":{backgroundColor:"transparent"},".cm-mergeSpacer":{backgroundColor:"rgba(255,255,255,0.02)"},".cm-merge-revert":{display:"none"}});var YC=W(le(),1);function Ng(n,e){return[qd(),Ct.readOnly.of(!0),Ie.editable.of(!1),hf,XC,Vs.of({lang:n,theme:e}),ff]}function Rg({oldContent:n,newContent:e,language:t,viewMode:r="unified",className:a,theme:s="dark-plus"}){let o=(0,pf.useRef)(null);return(0,pf.useEffect)(()=>{let i=o.current;if(!i)return;let l;if(r==="split"){let u=new lf({a:{doc:n,extensions:Ng(t,s)},b:{doc:e,extensions:Ng(t,s)},parent:i,gutter:!0,highlightChanges:!0,revertControls:void 0});l=()=>u.destroy()}else{let u=Ct.create({doc:e,extensions:[...Ng(t,s),WC({original:n,mergeControls:!1,gutter:!0,highlightChanges:!0,syntaxHighlightDeletions:!1})]}),c=new Ie({state:u,parent:i});l=()=>c.destroy()}return l},[n,e,t,r,s]),(0,YC.jsx)("div",{ref:o,className:a})}var Vn=W($e(),1);var kF=n=>{let{state:e}=n,t=e.doc.lineAt(e.selection.main.from),r=Og(n.state,t.from);return r.line?SF(n):r.block?LF(n):!1};function Bg(n,e){return({state:t,dispatch:r})=>{if(t.readOnly)return!1;let a=n(e,t);return a?(r(t.update(a)),!0):!1}}var SF=Bg(PF,0);var CF=Bg(sL,0);var LF=Bg((n,e)=>sL(n,e,AF(e)),0);function Og(n,e){let t=n.languageDataAt("commentTokens",e,1);return t.length?t[0]:{}}var Uu=50;function IF(n,{open:e,close:t},r,a){let s=n.sliceDoc(r-Uu,r),o=n.sliceDoc(a,a+Uu),i=/\s*$/.exec(s)[0].length,l=/^\s*/.exec(o)[0].length,u=s.length-i;if(s.slice(u-e.length,u)==e&&o.slice(l,l+t.length)==t)return{open:{pos:r-i,margin:i&&1},close:{pos:a+l,margin:l&&1}};let c,d;a-r<=2*Uu?c=d=n.sliceDoc(r,a):(c=n.sliceDoc(r,r+Uu),d=n.sliceDoc(a-Uu,a));let f=/^\s*/.exec(c)[0].length,h=/\s*$/.exec(d)[0].length,p=d.length-h-t.length;return c.slice(f,f+e.length)==e&&d.slice(p,p+t.length)==t?{open:{pos:r+f+e.length,margin:/\s/.test(c.charAt(f+e.length))?1:0},close:{pos:a-h-t.length,margin:/\s/.test(d.charAt(p-1))?1:0}}:null}function AF(n){let e=[];for(let t of n.selection.ranges){let r=n.doc.lineAt(t.from),a=t.to<=r.to?r:n.doc.lineAt(t.to);a.from>r.from&&a.from==t.to&&(a=t.to==r.to+1?r:n.doc.lineAt(t.to-1));let s=e.length-1;s>=0&&e[s].to>r.from?e[s].to=a.to:e.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:a.to})}return e}function sL(n,e,t=e.selection.ranges){let r=t.map(s=>Og(e,s.from).block);if(!r.every(s=>s))return null;let a=t.map((s,o)=>IF(e,r[o],s.from,s.to));if(n!=2&&!a.every(s=>s))return{changes:e.changes(t.map((s,o)=>a[o]?[]:[{from:s.from,insert:r[o].open+" "},{from:s.to,insert:" "+r[o].close}]))};if(n!=1&&a.some(s=>s)){let s=[];for(let o=0,i;o<a.length;o++)if(i=a[o]){let l=r[o],{open:u,close:c}=i;s.push({from:u.pos-l.open.length,to:u.pos+u.margin},{from:c.pos-c.margin,to:c.pos+l.close.length})}return{changes:s}}return null}function PF(n,e,t=e.selection.ranges){let r=[],a=-1;e:for(let{from:s,to:o}of t){let i=r.length,l=1e9,u;for(let c=s;c<=o;){let d=e.doc.lineAt(c);if(u==null&&(u=Og(e,d.from).line,!u))continue e;if(d.from>a&&(s==o||o>d.from)){a=d.from;let f=/^\s*/.exec(d.text)[0].length,h=f==d.length,p=d.text.slice(f,f+u.length)==u?f:-1;f<d.text.length&&f<l&&(l=f),r.push({line:d,comment:p,token:u,indent:f,empty:h,single:!1})}c=d.to+1}if(l<1e9)for(let c=i;c<r.length;c++)r[c].indent<r[c].line.text.length&&(r[c].indent=l);r.length==i+1&&(r[i].single=!0)}if(n!=2&&r.some(s=>s.comment<0&&(!s.empty||s.single))){let s=[];for(let{line:i,token:l,indent:u,empty:c,single:d}of r)(d||!c)&&s.push({from:i.from+u,insert:l+" "});let o=e.changes(s);return{changes:o,selection:e.selection.map(o,1)}}else if(n!=1&&r.some(s=>s.comment>=0)){let s=[];for(let{line:o,comment:i,token:l}of r)if(i>=0){let u=o.from+i,c=u+l.length;o.text[c-o.from]==" "&&c++,s.push({from:u,to:c})}return{changes:s}}return null}var Tg=Wr.define(),NF=Wr.define(),RF=Me.define(),oL=Me.define({combine(n){return Ai(n,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(r,a)=>e(r,a)||t(r,a)})}}),iL=vn.define({create(){return Go.empty},update(n,e){let t=e.state.facet(oL),r=e.annotation(Tg);if(r){let l=fa.fromTransaction(e,r.selection),u=r.side,c=u==0?n.undone:n.done;return l?c=gf(c,c.length,t.minDepth,l):c=dL(c,e.startState.selection),new Go(u==0?r.rest:c,u==0?c:r.rest)}let a=e.annotation(NF);if((a=="full"||a=="before")&&(n=n.isolate()),e.annotation(Pn.addToHistory)===!1)return e.changes.empty?n:n.addMapping(e.changes.desc);let s=fa.fromTransaction(e),o=e.annotation(Pn.time),i=e.annotation(Pn.userEvent);return s?n=n.addChanges(s,o,i,t,e):e.selection&&(n=n.addSelection(e.startState.selection,o,i,t.newGroupDelay)),(a=="full"||a=="after")&&(n=n.isolate()),n},toJSON(n){return{done:n.done.map(e=>e.toJSON()),undone:n.undone.map(e=>e.toJSON())}},fromJSON(n){return new Go(n.done.map(fa.fromJSON),n.undone.map(fa.fromJSON))}});function lL(n={}){return[iL,oL.of(n),Ie.domEventHandlers({beforeinput(e,t){let r=e.inputType=="historyUndo"?uL:e.inputType=="historyRedo"?Dg:null;return r?(e.preventDefault(),r(t)):!1}})]}function xf(n,e){return function({state:t,dispatch:r}){if(!e&&t.readOnly)return!1;let a=t.field(iL,!1);if(!a)return!1;let s=a.pop(n,t,e);return s?(r(s),!0):!1}}var uL=xf(0,!1),Dg=xf(1,!1),MF=xf(0,!0),TF=xf(1,!0);var fa=class n{constructor(e,t,r,a,s){this.changes=e,this.effects=t,this.mapped=r,this.startSelection=a,this.selectionsAfter=s}setSelAfter(e){return new n(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,t,r;return{changes:(e=this.changes)===null||e===void 0?void 0:e.toJSON(),mapped:(t=this.mapped)===null||t===void 0?void 0:t.toJSON(),startSelection:(r=this.startSelection)===null||r===void 0?void 0:r.toJSON(),selectionsAfter:this.selectionsAfter.map(a=>a.toJSON())}}static fromJSON(e){return new n(e.changes&&Rn.fromJSON(e.changes),[],e.mapped&&ts.fromJSON(e.mapped),e.startSelection&&se.fromJSON(e.startSelection),e.selectionsAfter.map(se.fromJSON))}static fromTransaction(e,t){let r=Kr;for(let a of e.startState.facet(RF)){let s=a(e);s.length&&(r=r.concat(s))}return!r.length&&e.changes.empty?null:new n(e.changes.invert(e.startState.doc),r,void 0,t||e.startState.selection,Kr)}static selection(e){return new n(void 0,Kr,void 0,void 0,e)}};function gf(n,e,t,r){let a=e+1>t+20?e-t-1:0,s=n.slice(a,e);return s.push(r),s}function DF(n,e){let t=[],r=!1;return n.iterChangedRanges((a,s)=>t.push(a,s)),e.iterChangedRanges((a,s,o,i)=>{for(let l=0;l<t.length;){let u=t[l++],c=t[l++];i>=u&&o<=c&&(r=!0)}}),r}function FF(n,e){return n.ranges.length==e.ranges.length&&n.ranges.filter((t,r)=>t.empty!=e.ranges[r].empty).length===0}function cL(n,e){return n.length?e.length?n.concat(e):n:e}var Kr=[],EF=200;function dL(n,e){if(n.length){let t=n[n.length-1],r=t.selectionsAfter.slice(Math.max(0,t.selectionsAfter.length-EF));return r.length&&r[r.length-1].eq(e)?n:(r.push(e),gf(n,n.length-1,1e9,t.setSelAfter(r)))}else return[fa.selection([e])]}function BF(n){let e=n[n.length-1],t=n.slice();return t[n.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),t}function Mg(n,e){if(!n.length)return n;let t=n.length,r=Kr;for(;t;){let a=OF(n[t-1],e,r);if(a.changes&&!a.changes.empty||a.effects.length){let s=n.slice(0,t);return s[t-1]=a,s}else e=a.mapped,t--,r=a.selectionsAfter}return r.length?[fa.selection(r)]:Kr}function OF(n,e,t){let r=cL(n.selectionsAfter.length?n.selectionsAfter.map(i=>i.map(e)):Kr,t);if(!n.changes)return fa.selection(r);let a=n.changes.map(e),s=e.mapDesc(n.changes,!0),o=n.mapped?n.mapped.composeDesc(s):s;return new fa(a,xt.mapEffects(n.effects,e),o,n.startSelection.map(s),r)}var _F=/^(input\.type|delete)($|\.)/,Go=class n{constructor(e,t,r=0,a=void 0){this.done=e,this.undone=t,this.prevTime=r,this.prevUserEvent=a}isolate(){return this.prevTime?new n(this.done,this.undone):this}addChanges(e,t,r,a,s){let o=this.done,i=o[o.length-1];return i&&i.changes&&!i.changes.empty&&e.changes&&(!r||_F.test(r))&&(!i.selectionsAfter.length&&t-this.prevTime<a.newGroupDelay&&a.joinToEvent(s,DF(i.changes,e.changes))||r=="input.type.compose")?o=gf(o,o.length-1,a.minDepth,new fa(e.changes.compose(i.changes),cL(xt.mapEffects(e.effects,i.changes),i.effects),i.mapped,i.startSelection,Kr)):o=gf(o,o.length,a.minDepth,e),new n(o,Kr,t,r)}addSelection(e,t,r,a){let s=this.done.length?this.done[this.done.length-1].selectionsAfter:Kr;return s.length>0&&t-this.prevTime<a&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&FF(s[s.length-1],e)?this:new n(dL(this.done,e),this.undone,t,r)}addMapping(e){return new n(Mg(this.done,e),Mg(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,t,r){let a=e==0?this.done:this.undone;if(a.length==0)return null;let s=a[a.length-1],o=s.selectionsAfter[0]||(s.startSelection?s.startSelection.map(s.changes.invertedDesc,1):t.selection);if(r&&s.selectionsAfter.length)return t.update({selection:s.selectionsAfter[s.selectionsAfter.length-1],annotations:Tg.of({side:e,rest:BF(a),selection:o}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(s.changes){let i=a.length==1?Kr:a.slice(0,a.length-1);return s.mapped&&(i=Mg(i,s.mapped)),t.update({changes:s.changes,selection:s.startSelection,effects:s.effects,annotations:Tg.of({side:e,rest:i,selection:o}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}};Go.empty=new Go(Kr,Kr);var fL=[{key:"Mod-z",run:uL,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:Dg,preventDefault:!0},{linux:"Ctrl-Shift-z",run:Dg,preventDefault:!0},{key:"Mod-u",run:MF,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:TF,preventDefault:!0}];function qi(n,e){return se.create(n.ranges.map(e),n.mainIndex)}function ha(n,e){return n.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function pa({state:n,dispatch:e},t){let r=qi(n.selection,t);return r.eq(n.selection,!0)?!1:(e(ha(n,r)),!0)}function yf(n,e){return se.cursor(e?n.to:n.from)}function hL(n,e){return pa(n,t=>t.empty?n.moveByChar(t,e):yf(t,e))}function qn(n){return n.textDirectionAt(n.state.selection.main.head)==Wt.LTR}var pL=n=>hL(n,!qn(n)),mL=n=>hL(n,qn(n));function gL(n,e){return pa(n,t=>t.empty?n.moveByGroup(t,e):yf(t,e))}var HF=n=>gL(n,!qn(n)),UF=n=>gL(n,qn(n));var Cj=typeof Intl<"u"&&Intl.Segmenter?new Intl.Segmenter(void 0,{granularity:"word"}):null;function GF(n,e,t){if(e.type.prop(t))return!0;let r=e.to-e.from;return r&&(r>2||/[^\s,.;:]/.test(n.sliceDoc(e.from,e.to)))||e.firstChild}function bf(n,e,t){let r=os(n).resolveInner(e.head),a=t?lt.closedBy:lt.openedBy;for(let l=e.head;;){let u=t?r.childAfter(l):r.childBefore(l);if(!u)break;GF(n,u,a)?r=u:l=t?u.to:u.from}let s=r.type.prop(a),o,i;return s&&(o=t?_o(n,r.from,1):_o(n,r.to,-1))&&o.matched?i=t?o.end.to:o.end.from:i=t?r.to:r.from,se.cursor(i,t?-1:1)}var zF=n=>pa(n,e=>bf(n.state,e,!qn(n))),WF=n=>pa(n,e=>bf(n.state,e,qn(n)));function xL(n,e){return pa(n,t=>{if(!t.empty)return yf(t,e);let r=n.moveVertically(t,e);return r.head!=t.head?r:n.moveToLineBoundary(t,e)})}var yL=n=>xL(n,!1),bL=n=>xL(n,!0);function wL(n){let e=n.scrollDOM.clientHeight<n.scrollDOM.scrollHeight-2,t=0,r=0,a;if(e){for(let s of n.state.facet(Ie.scrollMargins)){let o=s(n);o?.top&&(t=Math.max(o?.top,t)),o?.bottom&&(r=Math.max(o?.bottom,r))}a=n.scrollDOM.clientHeight-t-r}else a=(n.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:t,marginBottom:r,selfScroll:e,height:Math.max(n.defaultLineHeight,a-5)}}function vL(n,e){let t=wL(n),{state:r}=n,a=qi(r.selection,o=>o.empty?n.moveVertically(o,e,t.height):yf(o,e));if(a.eq(r.selection))return!1;let s;if(t.selfScroll){let o=n.coordsAtPos(r.selection.main.head),i=n.scrollDOM.getBoundingClientRect(),l=i.top+t.marginTop,u=i.bottom-t.marginBottom;o&&o.top>l&&o.bottom<u&&(s=Ie.scrollIntoView(a.main.head,{y:"start",yMargin:o.top-l}))}return n.dispatch(ha(r,a),{effects:s}),!0}var JC=n=>vL(n,!1),Fg=n=>vL(n,!0);function $s(n,e,t){let r=n.lineBlockAt(e.head),a=n.moveToLineBoundary(e,t);if(a.head==e.head&&a.head!=(t?r.to:r.from)&&(a=n.moveToLineBoundary(e,t,!1)),!t&&a.head==r.from&&r.length){let s=/^\s*/.exec(n.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;s&&e.head!=r.from+s&&(a=se.cursor(r.from+s))}return a}var jF=n=>pa(n,e=>$s(n,e,!0)),qF=n=>pa(n,e=>$s(n,e,!1)),VF=n=>pa(n,e=>$s(n,e,!qn(n))),$F=n=>pa(n,e=>$s(n,e,qn(n))),KF=n=>pa(n,e=>n.moveToLineBoundary(e,!1,!1)),XF=n=>pa(n,e=>n.moveToLineBoundary(e,!0,!1));function YF(n,e,t){let r=!1,a=qi(n.selection,s=>{let o=_o(n,s.head,-1)||_o(n,s.head,1)||s.head>0&&_o(n,s.head-1,1)||s.head<n.doc.length&&_o(n,s.head+1,-1);if(!o||!o.end)return s;r=!0;let i=o.start.from==s.head?o.end.to:o.end.from;return t?se.range(s.anchor,i):se.cursor(i)});return r?(e(ha(n,a)),!0):!1}var JF=({state:n,dispatch:e})=>YF(n,e,!1);function Xr(n,e,t){let r=qi(n.state.selection,a=>{a.undirectional&&a.head>=a.anchor!=e&&(a=se.range(a.head,a.anchor));let s=t(a);return se.range(a.anchor,s.head,s.goalColumn,s.bidiLevel||void 0,s.assoc)});return r.eq(n.state.selection)?!1:(n.dispatch(ha(n.state,r)),!0)}function kL(n,e){return Xr(n,e,t=>n.moveByChar(t,e))}var SL=n=>kL(n,!qn(n)),CL=n=>kL(n,qn(n));function LL(n,e){return Xr(n,e,t=>n.moveByGroup(t,e))}var ZF=n=>LL(n,!qn(n)),QF=n=>LL(n,qn(n));var e5=n=>{let e=!qn(n);return Xr(n,e,t=>bf(n.state,t,e))},t5=n=>{let e=qn(n);return Xr(n,e,t=>bf(n.state,t,e))};function IL(n,e){return Xr(n,e,t=>n.moveVertically(t,e))}var AL=n=>IL(n,!1),PL=n=>IL(n,!0);function NL(n,e){return Xr(n,e,t=>n.moveVertically(t,e,wL(n).height))}var ZC=n=>NL(n,!1),QC=n=>NL(n,!0),n5=n=>Xr(n,!0,e=>$s(n,e,!0)),r5=n=>Xr(n,!1,e=>$s(n,e,!1)),a5=n=>{let e=!qn(n);return Xr(n,e,t=>$s(n,t,e))},s5=n=>{let e=qn(n);return Xr(n,e,t=>$s(n,t,e))},o5=n=>Xr(n,!1,e=>se.cursor(n.lineBlockAt(e.head).from)),i5=n=>Xr(n,!0,e=>se.cursor(n.lineBlockAt(e.head).to)),eL=({state:n,dispatch:e})=>(e(ha(n,{anchor:0})),!0),tL=({state:n,dispatch:e})=>(e(ha(n,{anchor:n.doc.length})),!0),nL=({state:n,dispatch:e})=>(e(ha(n,{anchor:n.selection.main.anchor,head:0})),!0),rL=({state:n,dispatch:e})=>(e(ha(n,{anchor:n.selection.main.anchor,head:n.doc.length})),!0),l5=({state:n,dispatch:e})=>(e(n.update({selection:{anchor:0,head:n.doc.length},userEvent:"select"})),!0),u5=({state:n,dispatch:e})=>{let t=wf(n).map(({from:r,to:a})=>se.undirectionalRange(r,Math.min(a+1,n.doc.length)));return e(n.update({selection:se.create(t),userEvent:"select"})),!0},c5=({state:n,dispatch:e})=>{let t=qi(n.selection,r=>{let a=os(n),s=a.resolveStack(r.from,1);if(r.empty){let o=a.resolveStack(r.from,-1);o.node.from>=s.node.from&&o.node.to<=s.node.to&&(s=o)}for(let o=s;o;o=o.next){let{node:i}=o;if((i.from<r.from&&i.to>=r.to||i.to>r.to&&i.from<=r.from)&&o.next)return se.undirectionalRange(i.from,i.to)}return r});return t.eq(n.selection)?!1:(e(ha(n,t)),!0)};function RL(n,e){let{state:t}=n,r=t.selection,a=t.selection.ranges.slice();for(let s of t.selection.ranges){let o=t.doc.lineAt(s.head);if(e?o.to<n.state.doc.length:o.from>0)for(let i=s;;){let l=n.moveVertically(i,e);if(l.head<o.from||l.head>o.to){a.some(u=>u.head==l.head)||a.push(l);break}else{if(l.head==i.head)break;i=l}}}return a.length==r.ranges.length?!1:(n.dispatch(ha(t,se.create(a,a.length-1))),!0)}var d5=n=>RL(n,!1),f5=n=>RL(n,!0),h5=({state:n,dispatch:e})=>{let t=n.selection,r=null;return t.ranges.length>1?r=se.create([t.main]):t.main.empty||(r=se.create([se.cursor(t.main.head)])),r?(e(ha(n,r)),!0):!1};function Gu(n,e){if(n.state.readOnly)return!1;let t="delete.selection",{state:r}=n,a=r.changeByRange(s=>{let{from:o,to:i}=s;if(o==i){let l=e(s);l<o?(t="delete.backward",l=mf(n,l,!1)):l>o&&(t="delete.forward",l=mf(n,l,!0)),o=Math.min(o,l),i=Math.max(i,l)}else o=mf(n,o,!1),i=mf(n,i,!0);return o==i?{range:s}:{changes:{from:o,to:i},range:se.cursor(o,o<s.head?-1:1)}});return a.changes.empty?!1:(n.dispatch(r.update(a,{scrollIntoView:!0,userEvent:t,effects:t=="delete.selection"?Ie.announce.of(r.phrase("Selection deleted")):void 0})),!0)}function mf(n,e,t){if(n instanceof Ie)for(let r of n.state.facet(Ie.atomicRanges).map(a=>a(n)))r.between(e,e,(a,s)=>{a<e&&s>e&&(e=t?s:a)});return e}var ML=(n,e,t)=>Gu(n,r=>{let a=r.from,{state:s}=n,o=s.doc.lineAt(a),i,l;if(t&&!e&&a>o.from&&a<o.from+200&&!/[^ \t]/.test(i=o.text.slice(0,a-o.from))){if(i[i.length-1]==" ")return a-1;let u=Io(i,s.tabSize),c=u%Eu(s)||Eu(s);for(let d=0;d<c&&i[i.length-1-d]==" ";d++)a--;l=a}else l=Nn(o.text,a-o.from,e,e)+o.from,l==a&&o.number!=(e?s.doc.lines:1)?l+=e?1:-1:!e&&/[\ufe00-\ufe0f]/.test(o.text.slice(l-o.from,a-o.from))&&(l=Nn(o.text,l-o.from,!1,!1)+o.from);return l}),Eg=n=>ML(n,!1,!0);var TL=n=>ML(n,!0,!1),DL=(n,e)=>Gu(n,t=>{let r=t.head,{state:a}=n,s=a.doc.lineAt(r),o=a.charCategorizer(r);for(let i=null;;){if(r==(e?s.to:s.from)){r==t.head&&s.number!=(e?a.doc.lines:1)&&(r+=e?1:-1);break}let l=Nn(s.text,r-s.from,e)+s.from,u=s.text.slice(Math.min(r,l)-s.from,Math.max(r,l)-s.from),c=o(u);if(i!=null&&c!=i)break;(u!=" "||r!=t.head)&&(i=c),r=l}return r}),FL=n=>DL(n,!1),p5=n=>DL(n,!0);var m5=n=>Gu(n,e=>{let t=n.lineBlockAt(e.head).to;return e.head<t?t:Math.min(n.state.doc.length,e.head+1)});var g5=n=>Gu(n,e=>{let t=n.moveToLineBoundary(e,!1).head;return e.head>t?t:Math.max(0,e.head-1)}),x5=n=>Gu(n,e=>{let t=n.moveToLineBoundary(e,!0).head;return e.head<t?t:Math.min(n.state.doc.length,e.head+1)});var y5=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=n.changeByRange(r=>({changes:{from:r.from,to:r.to,insert:ct.of(["",""])},range:se.cursor(r.from)}));return e(n.update(t,{scrollIntoView:!0,userEvent:"input"})),!0},b5=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=n.changeByRange(r=>{if(!r.empty||r.from==0||r.from==n.doc.length)return{range:r};let a=r.from,s=n.doc.lineAt(a),o=a==s.from?a-1:Nn(s.text,a-s.from,!1)+s.from,i=a==s.to?a+1:Nn(s.text,a-s.from,!0)+s.from;return{changes:{from:o,to:i,insert:n.doc.slice(a,i).append(n.doc.slice(o,a))},range:se.cursor(i)}});return t.changes.empty?!1:(e(n.update(t,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function wf(n){let e=[],t=-1;for(let r of n.selection.ranges){let a=n.doc.lineAt(r.from),s=n.doc.lineAt(r.to);if(!r.empty&&r.to==s.from&&(s=n.doc.lineAt(r.to-1)),t>=a.number){let o=e[e.length-1];o.to=s.to,o.ranges.push(r)}else e.push({from:a.from,to:s.to,ranges:[r]});t=s.number+1}return e}function EL(n,e,t){if(n.readOnly)return!1;let r=[],a=[];for(let s of wf(n)){if(t?s.to==n.doc.length:s.from==0)continue;let o=n.doc.lineAt(t?s.to+1:s.from-1),i=o.length+1;if(t){r.push({from:s.to,to:o.to},{from:s.from,insert:o.text+n.lineBreak});for(let l of s.ranges)a.push(se.range(Math.min(n.doc.length,l.anchor+i),Math.min(n.doc.length,l.head+i)))}else{r.push({from:o.from,to:s.from},{from:s.to,insert:n.lineBreak+o.text});for(let l of s.ranges)a.push(se.range(l.anchor-i,l.head-i))}}return r.length?(e(n.update({changes:r,scrollIntoView:!0,selection:se.create(a,n.selection.mainIndex),userEvent:"move.line"})),!0):!1}var w5=({state:n,dispatch:e})=>EL(n,e,!1),v5=({state:n,dispatch:e})=>EL(n,e,!0);function BL(n,e,t){if(n.readOnly)return!1;let r=[];for(let s of wf(n))t?r.push({from:s.from,insert:n.doc.slice(s.from,s.to)+n.lineBreak}):r.push({from:s.to,insert:n.lineBreak+n.doc.slice(s.from,s.to)});let a=n.changes(r);return e(n.update({changes:a,selection:n.selection.map(a,t?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}var k5=({state:n,dispatch:e})=>BL(n,e,!1),S5=({state:n,dispatch:e})=>BL(n,e,!0),C5=n=>{if(n.state.readOnly)return!1;let{state:e}=n,t=e.changes(wf(e).map(({from:a,to:s})=>(a>0?a--:s<e.doc.length&&s++,{from:a,to:s}))),r=qi(e.selection,a=>{let s;if(n.lineWrapping){let o=n.lineBlockAt(a.head),i=n.coordsAtPos(a.head,a.assoc||1);i&&(s=o.bottom+n.documentTop-i.bottom+n.defaultLineHeight/2)}return n.moveVertically(a,!0,s)}).map(t);return n.dispatch({changes:t,selection:r,scrollIntoView:!0,userEvent:"delete.line"}),!0};function L5(n,e){if(/\(\)|\[\]|\{\}/.test(n.sliceDoc(e-1,e+1)))return{from:e,to:e};let t=os(n).resolveInner(e),r=t.childBefore(e),a=t.childAfter(e),s;return r&&a&&r.to<=e&&a.from>=e&&(s=r.type.prop(lt.closedBy))&&s.indexOf(a.name)>-1&&n.doc.lineAt(r.to).from==n.doc.lineAt(a.from).from&&!/\S/.test(n.sliceDoc(r.to,a.from))?{from:r.to,to:a.from}:null}var aL=OL(!1),I5=OL(!0);function OL(n){return({state:e,dispatch:t})=>{if(e.readOnly)return!1;let r=e.changeByRange(a=>{let{from:s,to:o}=a,i=e.doc.lineAt(s),l=!n&&s==o&&L5(e,s);n&&(s=o=(o<=i.to?i:e.doc.lineAt(o)).to);let u=new Oo(e,{simulateBreak:s,simulateDoubleBreak:!!l}),c=mg(u,s);for(c==null&&(c=Io(/^\s*/.exec(e.doc.lineAt(s).text)[0],e.tabSize));o<i.to&&/\s/.test(i.text[o-i.from]);)o++;l?{from:s,to:o}=l:s>i.from&&s<i.from+100&&!/\S/.test(i.text.slice(0,s))&&(s=i.from);let d=["",Bu(e,c)];return l&&d.push(Bu(e,u.lineIndent(i.from,-1))),{changes:{from:s,to:o,insert:ct.of(d)},range:se.cursor(s+1+d[1].length)}});return t(e.update(r,{scrollIntoView:!0,userEvent:"input"})),!0}}function _g(n,e){let t=-1;return n.changeByRange(r=>{let a=[];for(let o=r.from;o<=r.to;){let i=n.doc.lineAt(o);i.number>t&&(r.empty||r.to>i.from)&&(e(i,a,r),t=i.number),o=i.to+1}let s=n.changes(a);return{changes:a,range:se.range(s.mapPos(r.anchor,1),s.mapPos(r.head,1))}})}var A5=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=Object.create(null),r=new Oo(n,{overrideIndentation:s=>{let o=t[s];return o??-1}}),a=_g(n,(s,o,i)=>{let l=mg(r,s.from);if(l==null)return;/\S/.test(s.text)||(l=0);let u=/^\s*/.exec(s.text)[0],c=Bu(n,l);(u!=c||i.from<s.from+u.length)&&(t[s.from]=l,o.push({from:s.from,to:s.from+u.length,insert:c}))});return a.changes.empty||e(n.update(a,{userEvent:"indent"})),!0},_L=({state:n,dispatch:e})=>n.readOnly?!1:(e(n.update(_g(n,(t,r)=>{r.push({from:t.from,insert:n.facet(ef)})}),{userEvent:"input.indent"})),!0),HL=({state:n,dispatch:e})=>n.readOnly?!1:(e(n.update(_g(n,(t,r)=>{let a=/^\s*/.exec(t.text)[0];if(!a)return;let s=Io(a,n.tabSize),o=0,i=Bu(n,Math.max(0,s-Eu(n)));for(;o<a.length&&o<i.length&&a.charCodeAt(o)==i.charCodeAt(o);)o++;r.push({from:t.from+o,to:t.from+a.length,insert:i.slice(o)})}),{userEvent:"delete.dedent"})),!0),P5=n=>(n.setTabFocusMode(),!0);var N5=[{key:"Ctrl-b",run:pL,shift:SL,preventDefault:!0},{key:"Ctrl-f",run:mL,shift:CL},{key:"Ctrl-p",run:yL,shift:AL},{key:"Ctrl-n",run:bL,shift:PL},{key:"Ctrl-a",run:KF,shift:o5},{key:"Ctrl-e",run:XF,shift:i5},{key:"Ctrl-d",run:TL},{key:"Ctrl-h",run:Eg},{key:"Ctrl-k",run:m5},{key:"Ctrl-Alt-h",run:FL},{key:"Ctrl-o",run:y5},{key:"Ctrl-t",run:b5},{key:"Ctrl-v",run:Fg}],R5=[{key:"ArrowLeft",run:pL,shift:SL,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:HF,shift:ZF,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:VF,shift:a5,preventDefault:!0},{key:"ArrowRight",run:mL,shift:CL,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:UF,shift:QF,preventDefault:!0},{mac:"Cmd-ArrowRight",run:$F,shift:s5,preventDefault:!0},{key:"ArrowUp",run:yL,shift:AL,preventDefault:!0},{mac:"Cmd-ArrowUp",run:eL,shift:nL},{mac:"Ctrl-ArrowUp",run:JC,shift:ZC},{key:"ArrowDown",run:bL,shift:PL,preventDefault:!0},{mac:"Cmd-ArrowDown",run:tL,shift:rL},{mac:"Ctrl-ArrowDown",run:Fg,shift:QC},{key:"PageUp",run:JC,shift:ZC},{key:"PageDown",run:Fg,shift:QC},{key:"Home",run:qF,shift:r5,preventDefault:!0},{key:"Mod-Home",run:eL,shift:nL},{key:"End",run:jF,shift:n5,preventDefault:!0},{key:"Mod-End",run:tL,shift:rL},{key:"Enter",run:aL,shift:aL},{key:"Mod-a",run:l5},{key:"Backspace",run:Eg,shift:Eg,preventDefault:!0},{key:"Delete",run:TL,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:FL,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:p5,preventDefault:!0},{mac:"Mod-Backspace",run:g5,preventDefault:!0},{mac:"Mod-Delete",run:x5,preventDefault:!0}].concat(N5.map(n=>({mac:n.key,run:n.run,shift:n.shift}))),UL=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:zF,shift:e5},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:WF,shift:t5},{key:"Alt-ArrowUp",run:w5},{key:"Shift-Alt-ArrowUp",run:k5},{key:"Alt-ArrowDown",run:v5},{key:"Shift-Alt-ArrowDown",run:S5},{key:"Mod-Alt-ArrowUp",run:d5},{key:"Mod-Alt-ArrowDown",run:f5},{key:"Escape",run:h5},{key:"Mod-Enter",run:I5},{key:"Alt-l",mac:"Ctrl-l",run:u5},{key:"Mod-i",run:c5,preventDefault:!0},{key:"Mod-[",run:HL},{key:"Mod-]",run:_L},{key:"Mod-Alt-\\",run:A5},{key:"Shift-Mod-k",run:C5},{key:"Shift-Mod-\\",run:JF},{key:"Mod-/",run:kF},{key:"Alt-A",mac:"Ctrl-A",run:CF},{key:"Ctrl-m",mac:"Shift-Alt-m",run:P5}].concat(R5),GL={key:"Tab",run:_L,shift:HL};var M5={lines:new Map,deletedBefore:new Set},zL=xt.define(),WL=vn.define({create:()=>M5,update(n,e){for(let t of e.effects)if(t.is(zL))return t.value;return n}}),zu=class extends On{constructor(t){super();this.kind=t}eq(t){return t.kind===this.kind}toDOM(){let t=document.createElement("div");return this.kind==="deleted"?t.style.cssText="width:0;height:0;margin-left:2px;border-left:4px solid rgba(244,63,94,0.85);border-top:3px solid transparent;border-bottom:3px solid transparent;":t.style.cssText=`width:2px;height:100%;margin-left:3px;border-radius:1px;background:${this.kind==="added"?"rgba(16,185,129,0.9)":"rgba(59,130,246,0.9)"};`,t}},T5=new zu("added"),D5=new zu("modified"),F5=new zu("deleted"),E5=Gi({class:"nrs-cm-git-gutter",lineMarker(n,e){let t=n.state.field(WL,!1);if(!t)return null;let r=n.state.doc.lineAt(e.from).number,a=t.lines.get(r);return a==="added"?T5:a==="modified"?D5:t.deletedBefore.has(r)?F5:null},lineMarkerChange:n=>n.transactions.some(e=>e.effects.some(t=>t.is(zL)))});function jL(n){return[WL.init(()=>n),E5]}var qL=W(le(),1);function Hg({value:n,language:e,readOnly:t=!1,wrap:r=!1,onChange:a,className:s,placeholder:o,ariaLabel:i,theme:l="dark-plus",gitLineStatus:u}){let c=(0,Vn.useRef)(null),d=(0,Vn.useRef)(null),f=(0,Vn.useRef)(a),h=(0,Vn.useRef)(!1),p=(0,Vn.useRef)(new zr),m=(0,Vn.useRef)(new zr),g=(0,Vn.useRef)(new zr),x=(0,Vn.useRef)(new zr);return f.current=a,(0,Vn.useEffect)(()=>{let w=c.current;if(!w)return;let y=Ct.create({doc:n,extensions:[qd(),GS(),jS(),HS(),lL(),$m.of([...UL,...fL,GL]),hf,p.current.of(Vs.of({lang:e,theme:l})),ff,m.current.of([Ct.readOnly.of(t),Ie.editable.of(!t)]),g.current.of(r?Ie.lineWrapping:[]),x.current.of([]),o?zS(o):[],Ie.updateListener.of(k=>{k.docChanged&&!h.current&&f.current?.(k.state.doc.toString())}),Ie.contentAttributes.of(i?{"aria-label":i}:{})]}),C=new Ie({state:y,parent:w});return d.current=C,()=>{C.destroy(),d.current=null}},[]),(0,Vn.useEffect)(()=>{let w=d.current;if(!w)return;let y=w.state.doc.toString();n!==y&&(h.current=!0,w.dispatch({changes:{from:0,to:y.length,insert:n}}),h.current=!1)},[n]),(0,Vn.useEffect)(()=>{let w=d.current;w&&w.dispatch({effects:p.current.reconfigure(Vs.of({lang:e,theme:l}))})},[e,l]),(0,Vn.useEffect)(()=>{let w=d.current;w&&w.dispatch({effects:m.current.reconfigure([Ct.readOnly.of(t),Ie.editable.of(!t)])})},[t]),(0,Vn.useEffect)(()=>{let w=d.current;w&&w.dispatch({effects:g.current.reconfigure(r?Ie.lineWrapping:[])})},[r]),(0,Vn.useEffect)(()=>{let w=d.current;if(!w)return;let y=u&&!sd(u)?jL(u):[];w.dispatch({effects:x.current.reconfigure(y)})},[u]),(0,qL.jsx)("div",{ref:c,className:s})}var Vi=W($e(),1);var VL=W(le(),1);function Ug({target:n,agentId:e,projectId:t}){let[r,a]=(0,Vi.useState)(!1),s=B(i=>i.sourceChangeRevision[n.source]??0);(0,Vi.useEffect)(()=>{let i=!0;return a(!1),e&&Xo({agentId:e,...t?{projectId:t}:{},source:n.source}).then(l=>{i&&a(l.repos.find(u=>u.rel===(n.repo??""))?.canWrite===!0)}).catch(()=>{i&&a(!1)}),()=>{i=!1}},[e,t,n.source,n.repo,s]);let o=(0,Vi.useMemo)(()=>$v(n),[n]);return(0,VL.jsx)(bo,{source:n.source,repo:n.repo??"",path:n.path,mode:o,agentId:e,projectId:t,variant:"tab",canWrite:r,revision:s})}var Ba=W($e(),1);var ft=W(le(),1),$L="brain://docs",Gg=q("h-7 w-full rounded-md px-2 text-[10px] outline-none transition font-mono","bg-white/[0.04] border border-white/[0.08] text-white/86","focus:border-white/[0.18] focus:bg-white/[0.06]","placeholder:text-white/28"),B5=q(Gg,"pr-6");function zg(n){let{agentId:e,projectId:t}=n,r=B(b=>b.workspacePanels.upload),a=B(b=>b.setWorkspacePanelOpen),s=B(b=>b.uploading),o=B(b=>b.uploadMany),i=B(b=>b.files),l=B(b=>b.activeFolderPath),u=B(b=>b.setActiveFolderPath),[c,d]=(0,Ba.useState)(""),[f,h]=(0,Ba.useState)(""),[p,m]=(0,Ba.useState)(!1),[g,x]=(0,Ba.useState)(!1),w=(0,Ba.useRef)(null),y=(0,Ba.useMemo)(()=>{let b=c.trim();return b||l||$L},[l,c]),C=(0,Ba.useMemo)(()=>{let b=new Set;for(let P of Object.values(i||{})){if(P?.type!=="folder")continue;let N=String(P.uri||"");N&&b.add(N)}return b.add($L),Array.from(b).sort((P,N)=>P.localeCompare(N))},[i]),k=b=>{let P=b.trim();P&&(d(P),u(P))},v=async b=>{if(b.length!==0)try{await o({agentId:e,projectId:t,files:b,uri:y})}finally{w.current&&(w.current.value=""),m(!1),a("upload",!1)}};return r?(0,ft.jsxs)("div",{className:"w-full px-5 pt-3 pb-6 text-white/85",children:[(0,ft.jsx)("input",{ref:w,type:"file",multiple:!0,className:"hidden",onChange:async b=>{let P=Array.from(b.target.files||[]);await v(P)}}),(0,ft.jsxs)("div",{className:"flex items-center justify-between gap-2 pb-2 border-b border-white/[0.06]",children:[(0,ft.jsxs)("div",{className:"flex items-center gap-2",children:[s?(0,ft.jsx)(ze,{className:"h-4 w-4 animate-spin text-cyan-300/70 shrink-0"}):(0,ft.jsx)(Sa,{className:"h-4 w-4 text-cyan-300/70 shrink-0"}),(0,ft.jsx)("span",{className:"text-sm font-semibold tracking-wide text-white/92",children:"Upload"}),(0,ft.jsx)("span",{className:"rounded px-1.5 py-0.5 text-[10px] font-medium text-white/45 bg-white/[0.04] font-mono truncate max-w-[160px]",children:y})]}),(0,ft.jsx)("button",{type:"button",onClick:()=>a("upload",!1),className:"h-7 px-2.5 rounded-md text-[10px] font-medium text-white/50 hover:text-white/80 hover:bg-white/[0.05] transition",children:"Close"})]}),(0,ft.jsx)("div",{className:q("mt-2 rounded-md border border-dashed px-4 py-5 text-center transition",p?"border-cyan-300/40 bg-cyan-400/[0.04]":"border-white/[0.10] bg-white/[0.02]",s&&"opacity-60"),onDragEnter:b=>{s||(b.preventDefault(),m(!0))},onDragOver:b=>{s||(b.preventDefault(),b.dataTransfer.dropEffect="copy",m(!0))},onDragLeave:b=>{b.currentTarget.contains(b.relatedTarget)||m(!1)},onDrop:async b=>{s||(b.preventDefault(),await v(Array.from(b.dataTransfer.files||[])))},children:(0,ft.jsxs)("div",{className:"flex items-center justify-center gap-3",children:[s?(0,ft.jsx)(ze,{className:"h-4 w-4 animate-spin text-cyan-200/80"}):(0,ft.jsx)(Sa,{className:"h-4 w-4 text-cyan-200/70"}),(0,ft.jsx)("span",{className:"text-[11px] text-white/60",children:s?"Uploading...":"Drop files here"}),(0,ft.jsxs)("button",{type:"button",onClick:()=>w.current?.click(),disabled:s,className:"h-6 px-2.5 rounded-md bg-cyan-500/12 border border-cyan-400/20 text-[9px] font-semibold text-cyan-200/90 hover:bg-cyan-500/20 transition disabled:opacity-40 disabled:cursor-not-allowed inline-flex items-center gap-1",children:[(0,ft.jsx)(Pl,{className:"h-2.5 w-2.5"}),"Choose files"]})]})}),(0,ft.jsxs)("div",{className:"mt-1",children:[(0,ft.jsxs)("button",{type:"button",onClick:()=>x(b=>!b),className:"w-full flex items-center gap-2 py-1.5 text-left hover:bg-white/[0.02] rounded-md px-1 transition",children:[(0,ft.jsx)(wr,{className:"h-3.5 w-3.5 text-violet-400/70 shrink-0"}),(0,ft.jsx)("span",{className:"text-[11px] font-semibold text-white/88",children:"Destination"}),(0,ft.jsx)("span",{className:"text-[9px] text-white/35 font-mono truncate",children:y}),(0,ft.jsx)(Tt,{className:q("ml-auto h-3 w-3 text-white/25 shrink-0 transition-transform",g&&"rotate-180")})]}),(0,ft.jsx)("div",{className:q("overflow-hidden transition-all duration-200",g?"max-h-[300px] opacity-100":"max-h-0 opacity-0"),children:(0,ft.jsxs)("div",{className:"rounded-md bg-white/[0.02] p-2.5 ml-5 mb-1 space-y-2",children:[(0,ft.jsxs)("div",{className:"space-y-1",children:[(0,ft.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Folder"}),(0,ft.jsx)("select",{value:y,onChange:b=>k(b.target.value),disabled:s,className:B5,children:C.map(b=>(0,ft.jsx)("option",{value:b,className:"bg-[#1a1a1f]",children:b},b))})]}),(0,ft.jsxs)("div",{className:"space-y-1",children:[(0,ft.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Override"}),(0,ft.jsx)("input",{value:c,onChange:b=>d(b.target.value),placeholder:y,disabled:s,className:Gg})]}),(0,ft.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,ft.jsx)("input",{value:f,onChange:b=>h(b.target.value),onKeyDown:b=>{b.key==="Enter"&&(b.preventDefault(),k(f),h(""))},placeholder:"brain://docs/new-folder",disabled:s,className:q(Gg,"flex-1")}),(0,ft.jsxs)("button",{type:"button",disabled:s||!f.trim(),onClick:()=>{k(f),h("")},className:"h-7 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-white/60 hover:text-white/85 transition disabled:opacity-35 disabled:cursor-not-allowed inline-flex items-center gap-1 shrink-0",children:[(0,ft.jsx)(wr,{className:"h-2.5 w-2.5"}),"Use"]})]})]})})]})]}):null}var Se=W($e(),1);var Xg=W(mr(),1);function O5(n){let e=n?.configSchema??{};return{required:Array.isArray(e.required)?e.required:[],properties:e.properties&&typeof e.properties=="object"?e.properties:{}}}var _5=new Set(["path","container-path","host-path"]);function KL(n){let e=O5(n),t=e.properties.root,r=t?.["x-neuralis"]?.ui,a=typeof r?.control=="string"?r.control:void 0;return{needed:!!(t&&(e.required.includes("root")||a&&_5.has(a))),container:a!=="host-path",label:typeof r?.label=="string"?r.label:"Path",placeholder:typeof r?.placeholder=="string"?r.placeholder:""}}var ln=W($e(),1);var XL=W(mr(),1);var ke=W(le(),1),$i={gc:{label:"GC",explainer:"Removes records marked as deleted, older than the retention window.",tooltip:"Garbage-collect deleted records past the retention threshold (default 24h). Keeps recent deletions in case you want to restore.",destructive:!0},"repair-orphans":{label:"Repair",explainer:"Removes chunks whose parent document no longer exists or is deleted.",tooltip:"Drops orphaned chunks (parent file gone / deleted). Safe to run anytime \u2014 these chunks have no path back to a real file.",destructive:!0},"repair-pending":{label:"Repair pending",explainer:"Discards your pending changes whose file is gone with nothing to restore; counts older changes that need a review in Changes.",tooltip:"Run with Dry run first to see the counts. Only your own visible pending changes are touched; older changes with an unknown original are only reported \u2014 confirm them in the Changes panel. Nothing is reindexed.",destructive:!0},deduplicate:{label:"Deduplicate",explainer:"Reports document groups with identical content hash (read-only \u2014 no delete).",tooltip:"Lists documents that share a content hash. Read-only; nothing is removed.",destructive:!1}};function YL({agentId:n,projectId:e}){let t=hn(),r=Xa({grantedFeatures:[...t.grantedFeatures??[]]},"drive.write"),[a,s]=(0,ln.useState)(null),[o,i]=(0,ln.useState)(null),[l,u]=(0,ln.useState)(!1),[c,d]=(0,ln.useState)(!1),[f,h]=(0,ln.useState)(null),[p,m]=(0,ln.useState)(null),[g,x]=(0,ln.useState)(null),[w,y]=(0,ln.useState)(null),[C,k]=(0,ln.useState)(!1),[v,b]=(0,ln.useState)(!1),[P,N]=(0,ln.useState)(24),[M,U]=(0,ln.useState)(null),I=(0,ln.useRef)(null),A=(0,ln.useCallback)(async()=>{u(!0),x(null);try{let[L,R]=await Promise.all([ix({agentId:n,...e?{projectId:e}:{}}),yx({agentId:n,...e?{projectId:e}:{}}).catch(()=>[])]),z=new Map;for(let Q of R)z.set(Q.source,{...Q.last_sync?{last_sync:Q.last_sync}:{},sync_status:Q.sync_status});let J=L;J.perSource&&(J.perSource=J.perSource.map(Q=>{let re=z.get(Q.source);return re?{...Q,...re}:Q})),s(J)}catch(L){x(L instanceof Error?L.message:"Failed to fetch health report")}finally{u(!1)}},[n,e]),G=(0,ln.useCallback)(async()=>{k(!0),x(null);try{let L=await lx({agentId:n,...e?{projectId:e}:{}});y({orphanChunkCount:L.orphanChunkCount??0,duplicateGroups:L.duplicateGroups??0})}catch(L){x(L instanceof Error?L.message:"Scan failed")}finally{k(!1)}},[n,e]),V=(0,ln.useCallback)(async L=>{if(!v&&$i[L].destructive&&M!==L){U(L),I.current&&clearTimeout(I.current),I.current=setTimeout(()=>U(null),3e3);return}I.current&&(clearTimeout(I.current),I.current=null),U(null),d(!0),h(null),m(L),x(null),i(v?null:a);try{let R=await ux({agentId:n,...e?{projectId:e}:{},action:L,dryRun:v,retentionHours:P});h(R),v||(A(),w&&G())}catch(R){x(R instanceof Error?R.message:"Action failed")}finally{d(!1)}},[n,e,v,P,A,M,a,w,G]);(0,ln.useEffect)(()=>{A()},[A]),(0,ln.useEffect)(()=>()=>{I.current&&clearTimeout(I.current)},[]);function K(L){if(!o||!a)return null;let R=o[L]??0,z=a[L]??0;if(R===z)return null;let J=R-z,Q=J>0?"\u2212":"+";return`${R} \u2192 ${z} (${Q}${Math.abs(J)})`}return(0,ke.jsxs)("div",{className:"space-y-3 px-2 pb-2",children:[(0,ke.jsxs)("div",{className:"text-[10px] text-white/40 italic leading-relaxed",children:["Cleanup tool for the vector index. Removes leftover records:"," ",(0,ke.jsx)("span",{className:"text-white/60",children:"deleted documents past retention"}),","," ",(0,ke.jsx)("span",{className:"text-white/60",children:"orphaned chunks (no parent file)"}),", and reports"," ",(0,ke.jsx)("span",{className:"text-white/60",children:"duplicate documents"})," (same content hash). To clear ALL vectors of a single source, use the"," ",(0,ke.jsx)("span",{className:"text-rose-300/80",children:"Delete"})," button on that source instead."]}),l&&(0,ke.jsxs)("div",{className:"text-[10px] text-white/40 flex items-center gap-1.5",children:[(0,ke.jsx)(Ht,{className:"h-3 w-3 animate-spin text-blue-400"})," Loading..."]}),g&&(0,ke.jsx)("div",{className:"rounded-md bg-red-500/8 px-2.5 py-1.5 text-[10px] text-red-200/80",children:g}),a&&(0,ke.jsxs)(ke.Fragment,{children:[(0,ke.jsx)("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-1.5",children:[{label:"Documents",value:a.documentCount??0,color:"text-emerald-400",delta:null},{label:"Chunks",value:a.chunkCount??0,color:"text-cyan-400",delta:null},{label:"Deleted",value:a.deletedCount??0,color:(a.deletedCount??0)>0?"text-red-400":"text-white/60",delta:p==="gc"?K("deletedCount"):null},{label:"Orphans",value:w?w.orphanChunkCount??0:"\u2014",color:(w?.orphanChunkCount??0)>0?"text-amber-400":"text-white/60",delta:null}].map(L=>(0,ke.jsxs)("div",{className:"bg-white/[0.04] border border-white/[0.06] rounded-lg px-2 py-1.5 text-center",children:[(0,ke.jsx)("div",{className:q("text-sm font-semibold",L.color),children:L.value}),(0,ke.jsx)("div",{className:"text-[9px] text-white/40",children:L.label}),L.delta&&(0,ke.jsx)("div",{className:"text-[8px] text-emerald-300/70 mt-0.5 tabular-nums",children:L.delta})]},L.label))}),(0,ke.jsxs)("div",{className:"flex items-center gap-3 text-[9px] text-white/35",children:[(0,ke.jsxs)("span",{children:["Total points: ",a.totalPoints??"-"]}),(0,ke.jsxs)("span",{children:["Duplicate groups: ",w?w.duplicateGroups??0:"\u2014"]}),a.generatedAt&&(()=>{let L=Date.now()-new Date(a.generatedAt).getTime(),R=Math.floor(L/6e4),z=Math.floor(R/60),J=R<1?"just now":z<1?`${R}m ago`:`${z}h ${R%60}m ago`,Q=z<1?"text-emerald-400/60":"text-amber-400/60";return(0,ke.jsxs)("span",{className:Q,children:["Generated: ",J]})})()]}),a.perSource&&a.perSource.length>0&&(0,ke.jsx)("div",{className:"bg-white/[0.04] border border-white/[0.06] rounded-lg overflow-hidden",children:(0,ke.jsxs)("table",{className:"w-full text-[10px]",children:[(0,ke.jsx)("thead",{children:(0,ke.jsxs)("tr",{className:"border-b border-white/[0.06]",children:[(0,ke.jsx)("th",{className:"text-left px-2 py-1.5 text-white/40 font-medium",children:"Source"}),(0,ke.jsx)("th",{className:"text-right px-2 py-1.5 text-white/40 font-medium",children:"Docs"}),(0,ke.jsx)("th",{className:"text-right px-2 py-1.5 text-white/40 font-medium",children:"Chunks"}),(0,ke.jsx)("th",{className:"text-right px-2 py-1.5 text-white/40 font-medium",children:"Deleted"}),(0,ke.jsx)("th",{className:"text-right px-2 py-1.5 text-white/40 font-medium",children:"Last sync"})]})}),(0,ke.jsx)("tbody",{children:a.perSource.map((L,R)=>{let z=L.source.includes(":")?L.source.split(":")[0]:L.source,J=z==="local"?"text-cyan-400/60":z==="github"?"text-amber-400/60":"text-violet-400/60",Q=(()=>{if(!L.last_sync)return L.sync_status==="idle"?"\u2014":L.sync_status??"\u2014";let pe=new Date(L.last_sync).getTime();if(Number.isNaN(pe))return L.last_sync;let ee=Math.floor((Date.now()-pe)/6e4);if(ee<1)return"just now";if(ee<60)return`${ee}m ago`;let ce=Math.floor(ee/60);return ce<24?`${ce}h ago`:`${Math.floor(ce/24)}d ago`})(),re=L.last_sync?L.sync_status==="error"?"text-rose-300/60":L.sync_status==="paused"?"text-amber-300/60":"text-emerald-300/60":"text-white/35";return(0,ke.jsxs)("tr",{className:q("border-b border-white/[0.03] last:border-0",R%2===1&&"bg-white/[0.02]"),children:[(0,ke.jsxs)("td",{className:"px-2 py-1 text-white/70 font-mono flex items-center gap-1.5",children:[(0,ke.jsx)(Gn,{className:q("h-2.5 w-2.5 shrink-0",J)}),L.source]}),(0,ke.jsx)("td",{className:"px-2 py-1 text-right text-emerald-300/60",children:L.documents}),(0,ke.jsx)("td",{className:"px-2 py-1 text-right text-cyan-300/60",children:L.chunks}),(0,ke.jsx)("td",{className:q("px-2 py-1 text-right",L.deleted>0?"text-red-300/60":"text-white/40"),children:L.deleted}),(0,ke.jsx)("td",{className:q("px-2 py-1 text-right",re),title:L.last_sync??`status: ${L.sync_status??"unknown"}`,children:Q})]},L.source)})})]})}),(0,ke.jsxs)("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[(0,ke.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,ke.jsxs)("button",{type:"button",onClick:()=>{A()},disabled:l,title:"Refresh the cheap count stats for this project.",className:"px-2 py-1 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[10px] text-white/70 transition inline-flex items-center gap-1 disabled:opacity-40",children:[(0,ke.jsx)(Ht,{className:q("h-3 w-3 text-blue-400",l&&"animate-spin")}),"Refresh"]}),(0,ke.jsxs)("button",{type:"button",onClick:()=>{G()},disabled:C,title:"Scan the whole index for orphan chunks and duplicate documents. Expensive \u2014 walks every point, so it runs only when you ask.",className:"px-2 py-1 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[10px] text-white/70 transition inline-flex items-center gap-1 disabled:opacity-40",children:[(0,ke.jsx)(Ka,{className:q("h-3 w-3 text-amber-400",C&&"animate-pulse")}),w?"Re-scan":"Scan for problems"]}),(0,ke.jsx)("span",{className:"text-white/10",children:"|"}),["gc","repair-orphans",...r?["repair-pending"]:[],"deduplicate"].map(L=>{let R=$i[L],z=L==="gc"?It:L==="repair-orphans"?Al:L==="repair-pending"?ys:ra,J=L==="gc"?"text-amber-400":L==="repair-orphans"?"text-cyan-400":L==="repair-pending"?"text-rose-300":"text-violet-400",Q=M===L;return(0,ke.jsxs)("button",{type:"button",onClick:()=>{V(L)},disabled:c,title:R.tooltip,className:q("px-2 py-1 rounded-md text-[10px] transition inline-flex items-center gap-1 disabled:opacity-40",Q?"bg-rose-500/15 hover:bg-rose-500/25 text-rose-100 border border-rose-400/40":"bg-white/[0.04] hover:bg-white/[0.08] text-white/70"),children:[(0,ke.jsx)(z,{className:q("h-3 w-3",J)}),Q?"Click again to confirm":R.label]},L)}),(0,ke.jsx)("span",{className:"text-white/10",children:"|"}),(0,ke.jsx)(XL.SkillLauncher,{variant:"icon",size:"sm",skill:"manage-sources",packageId:"@neuralis/brain-core",scripts:["scripts/sync-status.sh","scripts/reindex.sh"],label:"Inspect sync status or reindex a source with the agent",icon:"Database"})]}),(0,ke.jsxs)("div",{className:"flex items-center gap-3",children:[(0,ke.jsxs)("label",{className:"inline-flex items-center gap-1 text-[10px] text-white/60 cursor-pointer",title:"Preview only \u2014 nothing will be deleted.",children:[(0,ke.jsx)("input",{type:"checkbox",checked:v,onChange:L=>b(L.target.checked),className:"accent-emerald-400 h-3 w-3"}),"Dry run"]}),(0,ke.jsxs)("label",{className:"inline-flex items-center gap-1 text-[10px] text-white/60",title:"Records marked as deleted within this many hours are kept (GC ignores them).",children:["Retention:",(0,ke.jsx)("input",{type:"number",min:1,value:P,onChange:L=>N(Math.max(1,Number(L.target.value)||24)),className:"w-12 h-5 rounded px-1 text-[10px] bg-white/[0.04] border border-white/[0.08] text-white/80 outline-none"}),"h"]})]})]}),(0,ke.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-1.5 text-[9px] text-white/40 leading-snug",children:[(0,ke.jsxs)("div",{children:[(0,ke.jsx)("span",{className:"text-amber-300/70 font-medium",children:"GC:"})," ",$i.gc.explainer]}),(0,ke.jsxs)("div",{children:[(0,ke.jsx)("span",{className:"text-cyan-300/70 font-medium",children:"Repair:"})," ",$i["repair-orphans"].explainer]}),(0,ke.jsxs)("div",{children:[(0,ke.jsx)("span",{className:"text-violet-300/70 font-medium",children:"Deduplicate:"})," ",$i.deduplicate.explainer]}),r?(0,ke.jsxs)("div",{children:[(0,ke.jsx)("span",{className:"text-rose-300/70 font-medium",children:"Repair pending:"})," ",$i["repair-pending"].explainer]}):null]}),f&&(0,ke.jsxs)("div",{className:"bg-white/[0.04] border border-white/[0.06] rounded-lg px-2.5 py-2 text-[10px] text-white/60 space-y-0.5",children:[(0,ke.jsxs)("div",{className:"text-[10px] text-white/50 font-medium mb-1 flex items-center justify-between",children:[(0,ke.jsx)("span",{children:"Last Action Result"}),typeof f.removed=="number"&&(0,ke.jsxs)("span",{className:q("font-mono tabular-nums",f.dryRun?"text-amber-300/80":"text-emerald-300/85"),children:[f.dryRun?"Would remove":"Removed",": ",f.removed]})]}),Object.entries(f).map(([L,R])=>(0,ke.jsxs)("div",{className:"flex justify-between",children:[(0,ke.jsx)("span",{className:"text-white/40",children:L}),(0,ke.jsx)("span",{className:"text-white/70 font-mono",children:typeof R=="object"?JSON.stringify(R):String(R)})]},L))]})]})]})}var nn=W($e(),1);var Be=W(le(),1),H5=["member","owner","admin"],vf=["read","write","exec"];function U5(n){return{default:{...n.default},...n.byRole?{byRole:Wg(n.byRole)}:{},...n.byUser?{byUser:Wg(n.byUser)}:{},...n.byAgent?{byAgent:Wg(n.byAgent)}:{},paths:(n.paths??[]).map(e=>({...e,permissions:{...e.permissions},...e.roles?{roles:[...e.roles]}:{},...e.agents?{agents:[...e.agents]}:{},...e.users?{users:[...e.users]}:{}}))}}function Wg(n){let e={};for(let[t,r]of Object.entries(n))e[t]={...r};return e}function G5(n){return{pattern:`${n}://`,permissions:{read:!0,write:!1,exec:!1}}}function jg({letter:n,state:e,onClick:t,disabled:r,title:a}){let s=e===!0?"bg-emerald-500/20 text-emerald-200 border-emerald-400/30":e===!1?"bg-rose-500/15 text-rose-200/80 border-rose-400/25":"bg-white/[0.04] text-white/35 border-white/[0.08]";return(0,Be.jsx)("button",{type:"button",title:a??`${n} \u2014 ${e===!0?"allow":e===!1?"deny":"inherit"}`,disabled:r,onClick:t,className:q("inline-flex items-center justify-center w-5 h-5 rounded text-[9px] font-bold tabular-nums border transition disabled:cursor-default",s,!r&&"hover:brightness-125"),children:n})}function qg(n){return n==="read"?"R":n==="write"?"W":"X"}function JL(n,e){if(!e)return!n;if(n===void 0)return!0;if(n===!0)return!1}function Vg({source:n,permissions:e,mode:t,onSave:r,knownRoles:a=H5}){let[s,o]=(0,nn.useState)(()=>U5(e)),[i,l]=(0,nn.useState)(!1),[u,c]=(0,nn.useState)(null),[d,f]=(0,nn.useState)(""),[h,p]=(0,nn.useState)(""),[m,g]=(0,nn.useState)(""),x=(0,nn.useMemo)(()=>JSON.stringify(s)!==JSON.stringify(e),[s,e]),w=t==="view",y=(0,nn.useCallback)((L,R)=>{o(z=>({...z,default:{...z.default,[L]:R}}))},[]),C=L=>L,k=(0,nn.useCallback)((L,R)=>{let z=R.trim();z&&o(J=>{let Q={...J[C(L)]??{}};return z in Q?J:(Q[z]={},{...J,[C(L)]:Q})})},[]),v=(0,nn.useCallback)((L,R)=>{o(z=>{let J={...z[C(L)]??{}};return delete J[R],Object.keys(J).length===0?{...z,[C(L)]:void 0}:{...z,[C(L)]:J}})},[]),b=(0,nn.useCallback)((L,R,z)=>{o(J=>{let Q={...J[C(L)]??{}},re=Q[R]??{},pe=JL(re[z],!0),ee={...re};return pe===void 0?delete ee[z]:ee[z]=pe,Q[R]=ee,{...J,[C(L)]:Q}})},[]),P=(0,nn.useCallback)((L,R)=>{o(z=>{let J=[...z.paths??[]];return J[L]={...J[L],...R},{...z,paths:J}})},[]),N=(0,nn.useCallback)((L,R)=>{o(z=>{let J=[...z.paths??[]],Q=J[L],re=JL(Q.permissions[R],!0),pe={...Q.permissions};return re===void 0?delete pe[R]:pe[R]=re,J[L]={...Q,permissions:pe},{...z,paths:J}})},[]),M=(0,nn.useCallback)((L,R)=>{o(z=>{let J=[...z.paths??[]],Q=J[L],re=new Set(Q.roles??[]);return re.has(R)?re.delete(R):re.add(R),J[L]=re.size>0?{...Q,roles:[...re]}:{...Q,roles:void 0},{...z,paths:J}})},[]),U=(0,nn.useCallback)((L,R,z)=>{let J=z.trim();J&&o(Q=>{let re=[...Q.paths??[]],pe=re[L],ee=new Set(pe[R]??[]);return ee.add(J),re[L]={...pe,[R]:[...ee]},{...Q,paths:re}})},[]),I=(0,nn.useCallback)((L,R,z)=>{o(J=>{let Q=[...J.paths??[]],re=Q[L],pe=(re[R]??[]).filter(ee=>ee!==z);return Q[L]={...re,[R]:pe.length>0?pe:void 0},{...J,paths:Q}})},[]),A=(0,nn.useCallback)(()=>{o(L=>({...L,paths:[G5(n),...L.paths??[]]}))},[n]),G=(0,nn.useCallback)(L=>{o(R=>({...R,paths:(R.paths??[]).filter((z,J)=>J!==L)}))},[]),V=(0,nn.useCallback)(async()=>{if(r){l(!0),c(null);try{await r(s)}catch(L){c(L instanceof Error?L.message:String(L))}finally{l(!1)}}},[s,r]),K=(L,R,z,J,Q)=>{let re=s[C(L)]??{},pe=Object.entries(re),[ee,ce]=Q;return(0,Be.jsxs)("div",{className:"space-y-1",children:[(0,Be.jsxs)("div",{className:"flex items-center gap-2",children:[(0,Be.jsx)("span",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/40",children:R}),(0,Be.jsx)("span",{className:"text-[9px] text-white/30 italic flex-1 truncate",children:z})]}),pe.length===0&&w?(0,Be.jsx)("div",{className:"text-[9px] text-white/25 italic",children:"No overrides."}):null,pe.map(([ue,He])=>(0,Be.jsxs)("div",{className:"flex items-center gap-1.5 text-[10px]",children:[(0,Be.jsx)("span",{className:"font-mono text-white/70 truncate min-w-[72px]",children:ue}),vf.map(De=>(0,Be.jsx)(jg,{letter:qg(De),state:He[De],onClick:w?void 0:()=>b(L,ue,De),disabled:w},De)),!w&&(0,Be.jsx)("button",{type:"button",onClick:()=>v(L,ue),className:"ml-auto text-white/30 hover:text-rose-300 transition",title:"Remove override",children:(0,Be.jsx)(It,{className:"w-3 h-3"})})]},ue)),!w&&(0,Be.jsxs)("div",{className:"flex items-center gap-1.5 pt-0.5",children:[(0,Be.jsx)("input",{type:"text",value:ee,onChange:ue=>ce(ue.target.value),onKeyDown:ue=>{ue.key==="Enter"&&(ue.preventDefault(),k(L,ee),ce(""))},placeholder:J,className:"h-6 flex-1 rounded bg-white/[0.04] border border-white/[0.08] px-2 text-[10px] text-white/80 placeholder:text-white/25 outline-none focus:border-white/20"}),(0,Be.jsxs)("button",{type:"button",onClick:()=>{k(L,ee),ce("")},className:"h-6 px-2 rounded bg-white/[0.05] border border-white/[0.08] text-[9px] font-semibold text-white/65 hover:text-white/90 hover:bg-white/[0.08] transition inline-flex items-center gap-1",children:[(0,Be.jsx)(Fn,{className:"w-2.5 h-2.5"}),"Add"]})]})]})};return(0,Be.jsxs)("div",{className:"flex flex-col gap-3 text-[10px]",children:[(0,Be.jsx)("div",{className:"space-y-1",children:(0,Be.jsxs)("div",{className:"flex items-center gap-2",children:[(0,Be.jsx)("span",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/40",children:"Default"}),(0,Be.jsxs)("span",{className:"text-[9px] text-white/30 italic flex-1 truncate",children:["Base access for ",n,"://*"]}),(0,Be.jsx)("div",{className:"flex items-center gap-1",children:vf.map(L=>(0,Be.jsx)(jg,{letter:qg(L),state:s.default[L],onClick:w?void 0:()=>y(L,!s.default[L]),disabled:w},L))})]})}),K("byRole","By Role","Override default for specific roles.","role (e.g. admin)",[d,f]),K("byUser","By User","Override for specific users (highest priority after paths).","userId",[h,p]),K("byAgent","By Agent","$self = the agent owning the file.","$self or agentId",[m,g]),(0,Be.jsxs)("div",{className:"space-y-1",children:[(0,Be.jsxs)("div",{className:"flex items-center gap-2",children:[(0,Be.jsx)("span",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/40",children:"Path Rules"}),(0,Be.jsx)("span",{className:"text-[9px] text-white/30 italic flex-1 truncate",children:"Fine-grained rules per path/glob \u2014 first match wins."}),!w&&(0,Be.jsxs)("button",{type:"button",onClick:A,className:"h-6 px-2 rounded bg-white/[0.05] border border-white/[0.08] text-[9px] font-semibold text-white/65 hover:text-white/90 hover:bg-white/[0.08] transition inline-flex items-center gap-1",children:[(0,Be.jsx)(Fn,{className:"w-2.5 h-2.5"}),"Rule"]})]}),(s.paths??[]).length===0?(0,Be.jsx)("div",{className:"text-[9px] text-white/25 italic",children:"No rules \u2014 Default applies everywhere."}):(0,Be.jsx)("ul",{className:"space-y-1",children:(s.paths??[]).map((L,R)=>(0,Be.jsxs)("li",{className:"rounded bg-white/[0.02] border border-white/[0.05] px-2 py-1.5 space-y-1.5",children:[(0,Be.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,Be.jsx)("input",{type:"text",disabled:w,value:L.pattern,onChange:z=>P(R,{pattern:z.target.value}),placeholder:`${n}://path/**`,className:"flex-1 min-w-0 h-6 rounded bg-white/[0.04] border border-white/[0.08] px-2 text-[10px] font-mono text-white/85 outline-none focus:border-white/20 disabled:opacity-70"}),vf.map(z=>(0,Be.jsx)(jg,{letter:qg(z),state:L.permissions[z],onClick:w?void 0:()=>N(R,z),disabled:w},z)),(0,Be.jsx)("button",{type:"button",disabled:w,onClick:()=>P(R,{override:L.override?void 0:!0}),title:"Override deny-wins precedence",className:q("h-5 px-1.5 rounded text-[8px] font-semibold border transition disabled:cursor-default",L.override?"bg-amber-500/15 text-amber-200 border-amber-400/30":"bg-white/[0.04] text-white/35 border-white/[0.08] hover:text-white/65"),children:"OVR"}),!w&&(0,Be.jsx)("button",{type:"button",onClick:()=>G(R),title:"Remove rule",className:"text-white/30 hover:text-rose-300 transition",children:(0,Be.jsx)(It,{className:"w-3 h-3"})})]}),(0,Be.jsxs)("div",{className:"flex flex-wrap items-center gap-1 text-[9px] text-white/50",children:[(0,Be.jsx)("span",{className:"text-white/35 mr-0.5",children:"Roles:"}),a.map(z=>{let J=(L.roles??[]).includes(z);return(0,Be.jsx)("button",{type:"button",disabled:w,onClick:()=>M(R,z),className:q("h-5 px-1.5 rounded border text-[9px] font-medium capitalize transition disabled:cursor-default",J?"bg-cyan-500/15 text-cyan-200 border-cyan-400/30":"bg-white/[0.04] text-white/40 border-white/[0.08] hover:text-white/70"),children:z},z)}),(L.roles??[]).length===0&&(0,Be.jsx)("span",{className:"italic text-white/30",children:"all roles"})]}),(0,Be.jsx)(ZL,{label:"Agents",values:L.agents??[],emptyLabel:"any agent",placeholder:"$self / agentId",readOnly:w,onAdd:z=>U(R,"agents",z),onRemove:z=>I(R,"agents",z)}),(0,Be.jsx)(ZL,{label:"Users",values:L.users??[],emptyLabel:"any user",placeholder:"$owner / userId",readOnly:w,onAdd:z=>U(R,"users",z),onRemove:z=>I(R,"users",z)}),(L.users??[]).length>0&&!z5(L)&&(0,Be.jsx)("div",{className:"text-[9px] text-amber-200/80",children:"Users apply only to an allow rule: turn on OVR and set every bit to allow."})]},R))})]}),!w&&(0,Be.jsxs)("div",{className:"flex items-center justify-between gap-2 pt-1",children:[u&&(0,Be.jsx)("span",{className:"text-[9px] text-rose-300/80",children:u}),(0,Be.jsxs)("button",{type:"button",onClick:V,disabled:!x||i,className:q("ml-auto inline-flex items-center gap-1 h-6 px-2.5 rounded bg-emerald-500/15 border border-emerald-400/30 text-[10px] font-semibold text-emerald-200 hover:bg-emerald-500/25 transition",(!x||i)&&"opacity-40 cursor-default"),children:[(0,Be.jsx)(io,{className:"w-3 h-3"}),i?"Saving\u2026":"Save policy"]})]})]})}function z5(n){let e=vf.map(t=>n.permissions[t]).filter(t=>t!==void 0);return n.override===!0&&e.length>0&&e.every(t=>t===!0)}function ZL({label:n,values:e,emptyLabel:t,placeholder:r,readOnly:a,onAdd:s,onRemove:o}){return(0,Be.jsxs)("div",{className:"flex flex-wrap items-center gap-1 text-[9px] text-white/50",children:[(0,Be.jsxs)("span",{className:"text-white/35 mr-0.5",children:[n,":"]}),e.map(i=>(0,Be.jsxs)("span",{className:"inline-flex items-center gap-1 h-5 px-1.5 rounded bg-violet-500/12 text-violet-200 border border-violet-400/25",children:[(0,Be.jsx)("span",{className:"font-mono",children:i}),!a&&(0,Be.jsx)("button",{type:"button",onClick:()=>o(i),className:"text-violet-200/60 hover:text-rose-300",title:`Remove ${i}`,children:"\xD7"})]},i)),e.length===0&&(0,Be.jsx)("span",{className:"italic text-white/30",children:t}),!a&&(0,Be.jsx)(W5,{placeholder:r,onAdd:s})]})}function W5({placeholder:n,onAdd:e}){let[t,r]=(0,nn.useState)("");return(0,Be.jsxs)("div",{className:"inline-flex items-center gap-1",children:[(0,Be.jsx)("input",{type:"text",value:t,onChange:a=>r(a.target.value),onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),e(t),r(""))},placeholder:n,className:"h-5 rounded bg-white/[0.04] border border-white/[0.08] px-1.5 text-[9px] font-mono text-white/75 placeholder:text-white/25 outline-none focus:border-white/20 w-[120px]"}),(0,Be.jsx)("button",{type:"button",onClick:()=>{e(t),r("")},className:"text-white/40 hover:text-white/80 transition",title:"Add",children:(0,Be.jsx)(Fn,{className:"w-3 h-3"})})]})}var QL=W($e(),1);var $t=W(le(),1);function eI({source:n,vectorCount:e,isDockerMount:t,busy:r,onCancel:a,onConfirm:s}){let[o,i]=(0,QL.useState)(!1);return(0,$t.jsxs)("div",{className:"rounded-md border border-rose-400/30 bg-rose-500/5 p-2.5 mt-1.5 ml-5 mb-1 space-y-2",children:[(0,$t.jsxs)("div",{className:"flex items-start gap-2",children:[(0,$t.jsx)(dt,{className:"h-3.5 w-3.5 text-rose-300 shrink-0 mt-0.5"}),(0,$t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,$t.jsxs)("div",{className:"text-[11px] font-semibold text-white/90",children:["Delete ",(0,$t.jsx)("span",{className:"font-mono text-rose-200",children:n}),"?"]}),(0,$t.jsxs)("div",{className:"text-[10px] text-white/55 mt-0.5",children:["The source config and connector binding are removed."," ",(0,$t.jsx)("span",{className:"text-white/75",children:"The host folder is not touched"})," ","\u2014 your files stay where they are."]})]})]}),(0,$t.jsxs)("label",{className:"flex items-start gap-2 cursor-pointer rounded px-1.5 py-1 hover:bg-white/[0.03]",children:[(0,$t.jsx)("input",{type:"checkbox",checked:o,onChange:l=>i(l.target.checked),className:"accent-rose-400 h-3 w-3 mt-0.5"}),(0,$t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,$t.jsxs)("div",{className:"text-[10px] font-medium text-white/80",children:["Purge vector index entries",e!==null&&(0,$t.jsxs)("span",{className:"text-white/40 ml-1.5 tabular-nums",children:["(~",e," point",e===1?"":"s",")"]})]}),(0,$t.jsxs)("div",{className:"text-[9px] text-white/40 leading-relaxed",children:["Removes every Qdrant point whose URI maps back to"," ",(0,$t.jsxs)("code",{className:"font-mono text-white/55",children:[n,"://"]}),". Otherwise the vectors stay and Vector Health \u2192 Repair will mop them up later."]})]})]}),t&&(0,$t.jsxs)("div",{className:"rounded bg-amber-500/8 border border-amber-400/20 px-2 py-1.5 text-[9px] italic text-amber-100/70 leading-relaxed",children:["Docker bind-mount source. This deletes the source config (and vectors, if checked). To also drop the underlying compose bind, run the infra-only:"," ",(0,$t.jsxs)("code",{className:"font-mono not-italic text-amber-100/90",children:["pnpm neuralis:mount remove ",n]})]}),(0,$t.jsxs)("div",{className:"flex items-center justify-end gap-1.5 pt-0.5",children:[(0,$t.jsxs)("button",{type:"button",onClick:a,disabled:r,className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[10px] font-medium text-white/70 transition disabled:opacity-40 inline-flex items-center gap-1",children:[(0,$t.jsx)(Ut,{className:"h-2.5 w-2.5"}),"Cancel"]}),(0,$t.jsxs)("button",{type:"button",onClick:()=>s({purgeVectors:o}),disabled:r,className:q("h-6 px-2.5 rounded-md text-[10px] font-semibold transition disabled:opacity-40 inline-flex items-center gap-1","bg-rose-500/20 hover:bg-rose-500/30 border border-rose-400/40 text-rose-100"),children:[r?(0,$t.jsx)(ze,{className:"h-2.5 w-2.5 animate-spin"}):(0,$t.jsx)(It,{className:"h-2.5 w-2.5"}),"Delete",o?" + Purge":""]})]})]})}var S=W(le(),1),$g={exclude:[],trigger:"manual"},j5=[{value:"manual",label:"Manual"},{value:"auto",label:"Auto (watch + reconcile)"},{value:"interval",label:"On schedule"}],q5=[{value:"s",label:"sec"},{value:"m",label:"min"},{value:"h",label:"hr"},{value:"d",label:"day"}],Yg="Mounted (user-added)";function V5(n){return n&&n.trim().length>0?n:Yg}function $5(n){return n.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,24)||"agent"}function Lf(n){return n.toLowerCase().replace(/[^a-z0-9-]+/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"").slice(0,40)}function K5(n){return n.split(/[/\\]/).filter(Boolean).pop()??null}function X5(n){if(n?.name){let e=Lf(n.name);if(e)return e}if(n?.email){let e=Lf(n.email.split("@")[0]??"");if(e)return e}return"user"}function rI(n){let{baseName:e,meta:t,scope:r,ids:a}=n,o=(e?Lf(e):"")||(t?.urlScheme||t?.kind||"source").toLowerCase().replace(/[^a-z0-9-]+/g,"-");return r==="project"?o:r==="user"?`${o}-${a.userSlug||"user"}`:`${o}-${a.agentSlug||$5(a.agentId)}`}function Y5(n){return n?.allowedScopes?.length?n.allowedScopes:["project","user","agent"]}function Jg(n){return!!n?.capabilities.includes("scanDelta")}function Zg(n){let e=n?.configSchema??{};return{required:Array.isArray(e.required)?e.required:[],properties:e.properties&&typeof e.properties=="object"?e.properties:{}}}function J5(n){let e=Zg(n),t={};for(let[r,a]of Object.entries(e.properties)){if(r==="root")continue;let s=a.default;(typeof s=="string"||typeof s=="number"||typeof s=="boolean")&&(t[r]=s)}return t}function aI(n){let e=n?.defaultPermissions?.default;return{read:typeof e?.read=="boolean"?e.read:!0,write:typeof e?.write=="boolean"?e.write:!1,exec:typeof e?.exec=="boolean"?e.exec:!1}}function Wu(n,e){let t=n?.defaultScope??"project",r=aI(n);return{key:rI({baseName:null,meta:n,scope:t,ids:e}),path:"",scope:t,...r,syncEnabled:Jg(n),exclude:Sf(n?.defaultSyncExcludes??[]),include:"",trigger:"manual",description:"",config:J5(n),policies:[],recognizesPackages:!1}}function ju(n){return n.split(/\r?\n|,/).map(e=>e.trim()).filter(Boolean)}function Sf(n){return Array.isArray(n)?n.join(`
44
- `):""}function Z5(n){return n&&n.default&&typeof n.default=="object"?n:n&&typeof n.read=="boolean"?{default:{read:n.read,write:n.write??!1,exec:n.exec??!1}}:{default:{read:!0,write:!1,exec:!1}}}function Ki(n){return{source:n.source,permissions:Z5(n.permissions),description:n.description??"",recognizesPackages:n.recognizesPackages??!1,...n.sync?{sync:{exclude:[...n.sync.exclude??[]],trigger:n.sync.trigger??"manual",...n.sync.include&&n.sync.include.length>0?{include:[...n.sync.include]}:{},...n.sync.alwaysActive!==void 0?{alwaysActive:n.sync.alwaysActive}:{},...n.sync.maxScanFiles!==void 0?{maxScanFiles:n.sync.maxScanFiles}:{},...n.sync.media?{media:{...n.sync.media}}:{}}}:{}}}var Q5=[{key:"images",label:"Images",on:!0},{key:"pdf",label:"PDF pages",on:!0},{key:"video",label:"Video",on:!1},{key:"audio",label:"Audio",on:!1}];function tI(n){if(!n)return null;let e=[];return n.textOnlyModel>0&&e.push(`${n.textOnlyModel} media file${n.textOnlyModel===1?"":"s"} not embedded \u2014 the active embedding model is text-only`),n.off>0&&e.push(`${n.off} off in media settings`),n.tooLarge>0&&e.push(`${n.tooLarge} over the media size limit`),n.invalid>0&&e.push(`${n.invalid} structurally invalid PNG file${n.invalid===1?"":"s"}`),n.unavailable>0&&e.push(`${n.unavailable} unreadable as media`),e.length>0?e.join(" \xB7 "):null}function eE(n,e,t){if(t)return!0;let r=n.sync,a=e.sync;if(!r||!a)return!!r!=!!a;let s=o=>(o??[]).join(`
45
- `);return s(r.exclude)!==s(a.exclude)||s(r.include)!==s(a.include)||r.maxScanFiles!==a.maxScanFiles}function sI(n){if(n==="auto"||n==="on_change")return{mode:"auto",val:"5",unit:"m"};let e=/^interval:(\d+)([smhd])$/.exec(n);return e?{mode:"interval",val:e[1],unit:e[2]}:{mode:"manual",val:"5",unit:"m"}}function Cf(n){return n==="s"?30:1}function Kg(n,e,t){if(n!=="interval")return n;let r=Number.parseInt(e,10);return`interval:${Number.isFinite(r)?Math.max(r,Cf(t)):5}${t}`}function tE(n){let e=sI(n);return e.mode==="manual"?"Manual":e.mode==="auto"?"Auto":`Every ${e.val}${e.unit}`}function nE(n,e){let t=n.connection.config??{};for(let[r,a]of Object.entries(t)){if(typeof a=="string"&&a.length>0)return a;if(typeof a=="number")return String(a)}return e?.label??n.connection.kind}function rE(n,e){let t=n.permissions??aI(e);return{source:Ve(n.uri_root),source_kind:n.source_kind,scope:{kind:"project"},createdBy:"runtime",connection:{kind:n.source_kind,config:{}},permissions:{default:t},sync_status:n.sync_status,last_updated:n.last_updated,kind_label:e?.label??n.source_kind,kind_trust:e?.trust??null,observed:!0,...n.origin_package?{origin_package:n.origin_package}:{},...n.live!==void 0?{live:n.live}:{},...n.live_reason?{live_reason:n.live_reason}:{}}}function aE(n,e){return JSON.stringify(Ki(n))!==JSON.stringify(e)}function nI(n){if(!n)return"never";let e=Date.now()-new Date(n).getTime();return e<6e4?"just now":e<36e5?`${Math.floor(e/6e4)}m ago`:e<864e5?`${Math.floor(e/36e5)}h ago`:`${Math.floor(e/864e5)}d ago`}var zo=q("h-7 w-full rounded-md px-2 text-[10px] outline-none transition","bg-white/[0.04] border border-white/[0.08] text-white/86","focus:border-white/[0.18] focus:bg-white/[0.06]","placeholder:text-white/28"),kf=q(zo,"pr-6 font-mono"),qu=q("w-full rounded-md px-2 py-1.5 text-[10px] font-mono outline-none resize-y transition","bg-white/[0.04] border border-white/[0.08] text-white/86","focus:border-white/[0.18] focus:bg-white/[0.06]","placeholder:text-white/28");function oI(n){let{agentId:e,projectId:t,isDocker:r}=n,a=B(T=>T.workspacePanels.sources),s=B(T=>T.setWorkspacePanelOpen),o=B(T=>T.pendingSourceSuggestion),i=B(T=>T.setPendingSourceSuggestion),l=B(T=>T.refresh),u=B(T=>T.sources),c=hn(),d=c.useAgents(),f=(0,Se.useMemo)(()=>X5(c.currentUser),[c.currentUser]),h=(c.currentRole?.priority??99)<=2,p=(0,Se.useMemo)(()=>oi({grantedFeatures:[...c.grantedFeatures??[]]},{features:["drive.mount"]}),[c.grantedFeatures]),m=(0,Se.useMemo)(()=>{let T=d.byId[e]?.name;return T?Lf(T):void 0},[d,e]),g=(0,Se.useMemo)(()=>({userSlug:f,agentSlug:m,agentId:e}),[f,m,e]),[x,w]=(0,Se.useState)([]),[y,C]=(0,Se.useState)({}),[k,v]=(0,Se.useState)({}),[b,P]=(0,Se.useState)({}),[N,M]=(0,Se.useState)(new Set),[U,I]=(0,Se.useState)({}),[A,G]=(0,Se.useState)(!1),[V,K]=(0,Se.useState)(null),[L,R]=(0,Se.useState)(null),[z,J]=(0,Se.useState)(null),[Q,re]=(0,Se.useState)(null),[pe,ee]=(0,Se.useState)(null),[ce,ue]=(0,Se.useState)(null),[He,De]=(0,Se.useState)(null),[je,et]=(0,Se.useState)(null),[Dt,at]=(0,Se.useState)(null),[vt,Pt]=(0,Se.useState)(null),[Ye,Ne]=(0,Se.useState)("source"),[tt,Je]=(0,Se.useState)(""),[Ft,Mt]=(0,Se.useState)(!0),[Te,oe]=(0,Se.useState)(null),[jt,Kt]=(0,Se.useState)(!1),de=(0,Se.useRef)(0);(0,Se.useEffect)(()=>{de.current++,Pt(null),oe(null)},[e,t]);let[fe,qe]=(0,Se.useState)(null),[Re,Fe]=(0,Se.useState)(!1),[Lt,st]=(0,Se.useState)("project"),[Le,Ee]=(0,Se.useState)(()=>Wu(null,g)),Et=(0,Se.useRef)(Le.key),qt=(0,Se.useRef)(!0);(0,Se.useEffect)(()=>(qt.current=!0,()=>{qt.current=!1}),[]);let[Tn,te]=(0,Se.useState)(!1),[Ce,Ge]=(0,Se.useState)(!1),[Ke,Ae]=(0,Se.useState)(!1),[he,ut]=(0,Se.useState)(!1),[Qt,xn]=(0,Se.useState)([]),[yn,Nr]=(0,Se.useState)("/"),[Kn,Xn]=(0,Se.useState)(!1),[Rr,Yn]=(0,Se.useState)(null),[Mr,j]=(0,Se.useState)([]),[ie,Ue]=(0,Se.useState)(!1),[Bt,Xt]=(0,Se.useState)([]),[dn,Sn]=(0,Se.useState)("local"),[hr,Ua]=(0,Se.useState)(null),[Jr,Ys]=(0,Se.useState)([]);(0,Se.useEffect)(()=>{let T=!1;return bx().then(Z=>{if(T)return;Xt(Z.kinds??[]),Ua(null);let F=Z.kinds?.find(ge=>ge.kind==="local")??Z.kinds?.[0]??null;if(F){Sn(F.kind);let ge=Wu(F,g);Et.current=ge.key,Ee(ge)}}).catch(Z=>{T||Ua(Z instanceof Error?Z.message:"Failed to load source kinds")}),()=>{T=!0}},[e]);let Hn=(0,Se.useMemo)(()=>{let T=new Map;for(let Z of Bt)T.set(Z.kind,Z);return T},[Bt]),rn=Hn.get(dn)??null,Jn=Jg(rn),pr=KL(rn),E=pr.needed,ne=E&&pr.container,O=(0,Se.useCallback)(T=>{let Z=Wu(Hn.get(T.suggestedKind)??null,g),F=T.suggestedConfig.root??"",ge=T.suggestedConfig.hostRoot;Sn(T.suggestedKind),Et.current=T.suggestedScheme,Ee({...Z,key:T.suggestedScheme,path:F,...T.suggestedScope?{scope:T.suggestedScope}:{},...T.syncDisabled?{syncEnabled:!1}:{},...T.suggestedSync?.include?{include:Sf(T.suggestedSync.include)}:{},...T.suggestedSync?.trigger?{trigger:T.suggestedSync.trigger}:{},...T.suggestedPolicies?.length?{policies:T.suggestedPolicies}:{},...T.description?{description:T.description}:{},...T.suggestedAccess??{},config:{...Z.config,...ge&&Zg(Hn.get(T.suggestedKind)??null).properties.hostRoot?{hostRoot:ge}:{}}}),Fe(!0)},[Hn,g]);(0,Se.useEffect)(()=>{o&&Hn.size!==0&&(i(null),O(o))},[o,Hn,O,i]);let Pe=(0,Se.useCallback)((T,Z)=>rI({baseName:Z?K5(Z):null,meta:rn,scope:T,ids:g}),[rn,g]),D=T=>T===""||T===Et.current,me=(0,Se.useCallback)(async()=>{if(t){G(!0),K(null);try{let[T,Z]=await Promise.all([F0({agentId:e,projectId:t,scope:Lt}),Zu({agentId:e,projectId:t}).catch(()=>({suggestions:[]}))]);w(T),C(Object.fromEntries(T.map(F=>[F.source,Ki(F)]))),v(F=>Object.fromEntries(T.map(ge=>[ge.source,F[ge.source]??!1]))),Ys(Z.suggestions??[])}catch(T){K(T instanceof Error?T.message:"Failed to load sources")}finally{G(!1)}}},[Lt,e,t]);(0,Se.useEffect)(()=>{a&&me()},[a,me]),(0,Se.useEffect)(()=>{a&&e&&l({agentId:e,projectId:t})},[a,e,t,l]);let Yt=(0,Se.useCallback)(async T=>{if(!e||b[T])return;let Z=!1;if(M(F=>{if(F.has(T))return Z=!0,F;let ge=new Set(F);return ge.add(T),ge}),!Z)try{let F=await D0(e,t??void 0,T);F&&P(ge=>({...ge,[T]:F}))}catch{}finally{M(F=>{if(!F.has(T))return F;let ge=new Set(F);return ge.delete(T),ge})}},[e,t,b]),Ot=(0,Se.useCallback)(T=>{P(Z=>{if(!(T in Z))return Z;let F={...Z};return delete F[T],F})},[]),Cn=(0,Se.useCallback)(T=>{v(Z=>{let F=!Z[T];return F&&Yt(T),{...Z,[T]:F}})},[Yt]);(0,Se.useEffect)(()=>{if(!He)return;let T=setTimeout(()=>De(null),4e3);return()=>clearTimeout(T)},[He]),(0,Se.useEffect)(()=>{!Re||!r||!p||(Ue(!0),Zf({path:"/mounts",agentId:e,...t?{projectId:t}:{}}).then(T=>{let Z=new Set(x.map(ge=>ge.source)),F=T.entries.filter(ge=>!Z.has(ge.name));j(F)}).catch(()=>j([])).finally(()=>Ue(!1)))},[Re,r,p,e,t,x]);let Tr=(0,Se.useMemo)(()=>{let T=new Set,Z=x.map(F=>{T.add(F.source);let ge=u.find(fn=>Ve(fn.uri_root)===F.source),an=b[F.source]??ge;return{...F,connector_count:an?.on_disk,connector_truncated:an?.truncated,indexed_count:an?.indexed_count,unindexed_count:an?.unindexed,last_updated:ge?.last_updated??F.last_updated,sync_status:F.sync?.status??ge?.sync_status??F.sync_status,live:ge?.live,live_reason:ge?.live_reason,kind_icon:ge?.kind_icon}});if(Lt==="project")for(let F of u){let ge=Ve(F.uri_root);if(!ge||T.has(ge))continue;let an=Hn.get(F.source_kind)??null,fn=b[ge]??F;Z.push({...rE(F,an),connector_count:fn.on_disk,connector_truncated:fn.truncated,indexed_count:fn.indexed_count,unindexed_count:fn.unindexed,kind_icon:F.kind_icon})}return Z},[Lt,x,Hn,u,b]),Gf=(0,Se.useMemo)(()=>{let T=new Map;for(let Z of Tr){let F=V5(Z.origin_package),ge=T.get(F);ge?ge.push(Z):T.set(F,[Z])}return[...T.entries()].sort(([Z],[F])=>Z===Yg?1:F===Yg?-1:Z.localeCompare(F))},[Tr]),Zr=(T,Z)=>{C(F=>({...F,[T]:Z(F[T])}))},zf=(T,Z)=>{I(F=>({...F,[T]:{...F[T]??{},[Z]:!(F[T]?.[Z]??!1)}}))},f2=async(T,Z)=>{R(T.source),K(null);try{let F=!Z.sync&&!!T.sync,ge=h&&T.connection.kind==="local",{recognizesPackages:an,...fn}=Z,us=await Yf({agentId:e,...t?{projectId:t}:{},config:{...ge?Z:fn,...F?{clearSync:!0}:{}}});w(Ga=>Ga.map(za=>za.source===us.source?us:za)),C(Ga=>({...Ga,[us.source]:Ki(us)})),eE(T,Z,F)?(await l({agentId:e,projectId:t,withCounts:!0}),Ot(T.source)):await l({agentId:e,projectId:t})}catch(F){K(F instanceof Error?F.message:"Save failed")}finally{R(null)}},h2=(0,Se.useCallback)(async(T,Z)=>{let F=y[T.source]??Ki(T);R(T.source),K(null);try{let ge=await Yf({agentId:e,...t?{projectId:t}:{},config:{...F,permissions:Z}});w(an=>an.map(fn=>fn.source===ge.source?ge:fn)),C(an=>({...an,[ge.source]:Ki(ge)})),await l({agentId:e,projectId:t})}catch(ge){throw K(ge instanceof Error?ge.message:"Save failed"),ge}finally{R(null)}},[e,y,t,l]),f0=(0,Se.useCallback)(async T=>{for(let ge=0;ge<2400;ge++){if(await new Promise(qo=>setTimeout(qo,1500)),!qt.current)return;let fn=(await B0({agentId:e,...t?{projectId:t}:{},source:T})).job;if(!fn)return;if(!(fn.status==="pending"||fn.status==="running")){if(fn.status==="failed")throw new Error(fn.error??fn.result?.error??"Sync failed");return}}},[e,t]);if(!a)return null;let p2=async T=>{J(T),K(null);try{await E0({agentId:e,...t?{projectId:t}:{},source:T}),await f0(T),await me(),await l({agentId:e,projectId:t,withCounts:!0}),Ot(T)}catch(Z){K(Z instanceof Error?Z.message:"Sync failed")}finally{J(null)}},m2=async T=>{try{await xx({agentId:e,...t?{projectId:t}:{},...T?{source:T}:{}}),J(null),re(null)}catch(Z){K(Z instanceof Error?Z.message:"Cancel failed")}},h0=async(T,Z,F)=>{re(T),K(null);try{await Z(),await f0(T),await me(),await l({agentId:e,projectId:t,withCounts:!0}),Ot(T)}catch(ge){K(ge instanceof Error?ge.message:F)}finally{re(null)}},g2=T=>h0(T,()=>hx({agentId:e,...t?{projectId:t}:{},source:T}),"Rescan failed"),p0=async(T,Z)=>{let F=++de.current,ge=Ye==="source"?{kind:"source"}:{kind:Ye,uri:tt};Kt(!0),K(null);try{let an=await px({agentId:e,...t?{projectId:t}:{},source:T,selector:ge,mode:Z,obsoleteOnly:Ft});if(F!==de.current)return;Z==="estimate"?oe(an):(Pt(null),oe(null),Ot(T),await me(),await l({agentId:e,projectId:t,withCounts:!0}))}catch(an){F===de.current&&K(an instanceof Error?an.message:"Index cleanup failed")}finally{F===de.current&&Kt(!1)}},x2=async T=>{et(T),K(null);try{await fx({agentId:e,...t?{projectId:t}:{},source:T}),await me()}catch(Z){K(Z instanceof Error?Z.message:"Reset failed")}finally{et(null)}},y2=async(T,Z)=>{qe(T),K(null);try{await O0({agentId:e,...t?{projectId:t}:{},source:T,enabled:Z}),await me()}catch(F){K(F instanceof Error?F.message:"Toggle failed")}finally{qe(null)}},b2=async(T,Z)=>{ee(T),K(null);try{let F=await dx({agentId:e,...t?{projectId:t}:{},source:T,...Z.purgeVectors?{purgeVectors:!0}:{}});await me(),await l({agentId:e,projectId:t}),Ot(T),De(Z.purgeVectors&&F?.purgeJob?`Deleted "${T}" (vector purge running in background)`:`Deleted "${T}"`),ue(null)}catch(F){K(F instanceof Error?F.message:"Delete failed")}finally{ee(null)}},Wf=async T=>{ut(!0),Xn(!0),Yn(null);try{let Z=await Zf({path:T,agentId:e,...t?{projectId:t}:{}});xn(Z.entries),Nr(T)}catch{Yn("That path is not available."),xn([])}finally{Xn(!1)}},m0=T=>{Ee(Z=>{if(!D(Z.key))return{...Z,path:T};let F=Pe(Z.scope,T);return Et.current=F,{...Z,path:T,key:F}}),ut(!1)},w2=async()=>{if(!(!Le.key||E&&!Le.path)){te(!0),K(null);try{let T={...Le.config,...E?{root:Le.path}:{}};await cx({agentId:e,...t?{projectId:t}:{},source:Le.key,scope:Le.scope,connection:{kind:dn,config:T},permissions:{default:{read:Le.read,write:Le.write,exec:Le.exec},...Le.policies.length>0?{paths:Le.policies}:{}},...Le.description.trim()?{description:Le.description.trim()}:{},...Jn&&Le.syncEnabled?{sync:{exclude:ju(Le.exclude),trigger:Le.trigger,...ju(Le.include).length>0?{include:ju(Le.include)}:{}}}:{},...h&&dn==="local"&&Le.recognizesPackages?{recognizesPackages:!0}:{}}),Fe(!1);{let Z=Wu(rn,g);Et.current=Z.key,Ee(Z)}await me(),await l({agentId:e,projectId:t})}catch(T){K(T instanceof Error?T.message:"Add source failed")}finally{te(!1)}}},v2=T=>T==="data"||T==="packages";return(0,S.jsxs)("div",{className:"w-full px-5 pt-3 pb-6 text-white/85",children:[(0,S.jsxs)("div",{className:"flex items-center justify-between gap-2 pb-2 border-b border-white/[0.06]",children:[(0,S.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,S.jsx)(br,{className:"h-4 w-4 text-cyan-400 shrink-0"}),(0,S.jsx)("span",{className:"text-sm font-semibold tracking-wide text-white/92",children:"Sources"}),(0,S.jsx)("span",{className:"rounded px-1.5 py-0.5 text-[10px] font-medium text-cyan-300 bg-cyan-500/20",children:Tr.length})]}),(0,S.jsxs)("div",{className:"flex items-center gap-1",children:[(0,S.jsxs)("div",{className:"inline-flex items-center gap-0.5",children:[(0,S.jsxs)("button",{type:"button",onClick:()=>Fe(T=>!T),className:"h-7 px-2 rounded-l-md rounded-r-none text-cyan-300 hover:text-cyan-200 hover:bg-white/[0.05] transition inline-flex items-center gap-1 text-[10px] font-medium",title:"Add source",children:[(0,S.jsx)(Fn,{className:"h-3 w-3"}),"Source"]}),(0,S.jsx)(Xg.SkillLauncher,{variant:"icon",attached:"left",skill:"manage-sources",packageId:"@neuralis/brain-core",scripts:["scripts/sync.sh","scripts/reindex.sh","scripts/set-enabled.sh"],label:"Manage sources with the agent"})]}),(0,S.jsx)("button",{type:"button",onClick:()=>{me()},disabled:A,className:"h-7 w-7 rounded-md text-white/35 hover:text-white/70 hover:bg-white/[0.05] transition",title:"Refresh",children:(0,S.jsx)(Ht,{className:q("mx-auto h-3 w-3",A&&"animate-spin")})}),(0,S.jsx)("button",{type:"button",onClick:()=>s("sources",!1),className:"h-7 px-2.5 rounded-md text-[10px] font-medium text-white/50 hover:text-white/80 hover:bg-white/[0.05] transition",children:"Close"})]})]}),(0,S.jsxs)("div",{className:"mt-2 text-[10px] text-white/35 italic",children:["Add filesystem-style sources from Neuralis packages. A source URI such as ",(0,S.jsx)("code",{className:"font-mono",children:"neuralis://"})," or ",(0,S.jsx)("code",{className:"font-mono",children:"machine-user://"})," is the stable handle agents use with fs_* tools."]}),(0,S.jsx)("div",{className:"mt-2 flex items-center gap-1 rounded-md bg-white/[0.025] p-1",children:[{id:"project",label:"Project"},{id:"user",label:"User"},{id:"agent",label:"Agent"}].map(T=>(0,S.jsx)("button",{type:"button",onClick:()=>st(T.id),className:q("h-6 rounded px-2 text-[9px] font-semibold transition",Lt===T.id?"bg-cyan-500/15 text-cyan-200 border border-cyan-400/20":"text-white/35 hover:text-white/65 hover:bg-white/[0.04]"),children:T.label},T.id))}),V&&(0,S.jsx)("div",{className:"mt-2 rounded-md bg-red-500/8 px-3 py-2 text-[10px] text-red-200/80",children:V}),Re&&(0,S.jsxs)("div",{className:"mt-2 rounded-lg bg-white/[0.03] border border-white/[0.08] p-3 space-y-2",children:[(0,S.jsx)("div",{className:"text-[11px] font-semibold text-white/80",children:"Add Source"}),hr&&(0,S.jsxs)("div",{className:"text-[9px] text-rose-300/80 bg-rose-500/10 rounded px-2 py-1",children:["Could not load source kinds: ",hr,'. Falling back to "local".']}),Bt.length>1&&(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Kind"}),(0,S.jsx)("select",{value:dn,onChange:T=>{let Z=T.target.value,F=Hn.get(Z)??null;Sn(Z);let ge=Wu(F,g);Et.current=ge.key,Ee(ge)},className:kf,children:Bt.map(T=>(0,S.jsxs)("option",{value:T.kind,children:[T.label," \u2014 ",T.trust," (",T.packageId,")"]},T.kind))}),(0,S.jsx)("div",{className:"text-[9px] text-white/30 italic",children:rn?.description??""})]}),rn?.scopeSelectable&&(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Scope"}),(0,S.jsx)("select",{value:Le.scope,onChange:T=>{let Z=T.target.value;Ee(F=>{if(!D(F.key))return{...F,scope:Z};let ge=Pe(Z,F.path);return Et.current=ge,{...F,scope:Z,key:ge}})},className:kf,children:Y5(rn).map(T=>(0,S.jsx)("option",{value:T,children:T},T))})]}),ne&&r?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)("div",{className:"text-[10px] text-amber-300/70 bg-amber-500/8 rounded px-2 py-1.5",children:["Docker mode: host folders still need the CLI mount script:"," ",(0,S.jsx)("code",{className:"text-amber-200/90 font-mono",children:"pnpm neuralis:mount add"})," ","on the host, then restart the container. Package sources like Machine do not require a host path here."]}),ie?(0,S.jsxs)("div",{className:"flex items-center gap-1.5 py-1",children:[(0,S.jsx)(ze,{className:"h-3 w-3 animate-spin text-white/30"}),(0,S.jsx)("span",{className:"text-[9px] text-white/35",children:"Scanning volume mounts..."})]}):Mr.length>0?(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Available volume mounts (not yet configured)"}),Mr.map(T=>(0,S.jsxs)("div",{className:"flex items-center gap-2 rounded px-2 py-1.5 bg-white/[0.02] hover:bg-white/[0.04] transition",children:[(0,S.jsx)(Br,{className:"h-3 w-3 text-cyan-400/70 shrink-0"}),(0,S.jsx)("span",{className:"text-[10px] text-white/75 font-medium flex-1 truncate",children:T.name}),(0,S.jsx)("span",{className:"text-[9px] text-white/30 font-mono truncate max-w-[120px]",children:T.path}),(0,S.jsx)("button",{type:"button",onClick:()=>{Ee(Z=>({...Z,key:T.name,path:T.path}))},className:"px-2 py-0.5 rounded text-[8px] font-semibold text-cyan-300/80 bg-cyan-500/10 hover:bg-cyan-500/20 border border-cyan-400/20 transition shrink-0",children:"+ Add"})]},T.path))]}):(0,S.jsx)("div",{className:"text-[9px] text-white/30 italic",children:"All volume mounts are configured as sources."})]}):(0,S.jsx)("div",{className:"text-[10px] text-white/35 italic",children:E?pr.container?"Mount any folder from your system. The path must be accessible to the server process.":"A path on the operator\u2019s host machine, reached through the host broker. It needs no volume mount here, and the broker ceiling still clamps what is reachable.":"This connector does not need a local path. Choose the scope and URI scheme; the package owns the runtime binding."}),(0,S.jsxs)("div",{className:"space-y-2",children:[(0,S.jsxs)("div",{className:q("grid gap-2",E?"grid-cols-2":"grid-cols-1"),children:[(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"URI scheme"}),(0,S.jsx)("input",{type:"text",value:Le.key,onChange:T=>Ee(Z=>({...Z,key:T.target.value})),placeholder:Pe(Le.scope,Le.path),className:zo}),(0,S.jsxs)("div",{className:"text-[8px] text-white/25 font-mono",children:[Le.key||Pe(Le.scope,Le.path),"://"]})]}),E&&(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:pr.label}),(0,S.jsxs)("div",{className:"flex gap-1",children:[(0,S.jsx)("input",{type:"text",value:Le.path,onChange:T=>Ee(Z=>({...Z,path:T.target.value})),placeholder:pr.placeholder,className:q(zo,"flex-1")}),pr.container&&!r&&p&&(0,S.jsx)("button",{type:"button",onClick:()=>{Wf(Le.path||"/")},className:"h-7 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] border border-white/[0.08] text-white/60 hover:text-white/90 transition shrink-0",title:"Browse directories",children:(0,S.jsx)(Ss,{className:"h-3.5 w-3.5"})})]})]})]}),Object.entries(Zg(rn).properties).filter(([T])=>T!=="root").map(([T,Z])=>(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:Z?.["x-neuralis"]?.ui?.label??T}),(0,S.jsx)("input",{type:Z.type==="number"||Z.type==="integer"?"number":"text",value:String(Le.config[T]??""),onChange:F=>Ee(ge=>({...ge,config:{...ge.config,[T]:F.target.value}})),placeholder:Z?.["x-neuralis"]?.ui?.placeholder??Z?.description??T,className:zo})]},T)),ne&&!r&&he&&(0,S.jsxs)("div",{className:"rounded-md bg-white/[0.03] border border-white/[0.1] overflow-hidden",children:[(0,S.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1.5 bg-white/[0.02] border-b border-white/[0.06]",children:[(0,S.jsx)(Ss,{className:"h-3 w-3 text-cyan-400 shrink-0"}),(0,S.jsx)("span",{className:"text-[9px] font-mono text-white/60 truncate flex-1",children:yn}),(0,S.jsx)("button",{type:"button",onClick:()=>ut(!1),className:"text-[9px] text-white/40 hover:text-white/70 px-1",children:"Close"})]}),Rr&&(0,S.jsx)("div",{className:"px-2 py-1 text-[9px] text-red-300/80",children:Rr}),Kn?(0,S.jsx)("div",{className:"flex items-center justify-center py-3",children:(0,S.jsx)(ze,{className:"h-3 w-3 animate-spin text-white/30"})}):(0,S.jsxs)("div",{className:"max-h-[180px] overflow-y-auto",children:[yn!=="/"&&(0,S.jsxs)("button",{type:"button",onClick:()=>{let T=yn.replace(/[/\\][^/\\]+$/,"")||"/";Wf(T)},className:"w-full flex items-center gap-1.5 px-2 py-1 text-left hover:bg-white/[0.04] transition",children:[(0,S.jsx)(ja,{className:"h-3 w-3 text-white/30"}),(0,S.jsx)("span",{className:"text-[10px] text-white/50",children:".."})]}),Qt.length===0&&!Kn&&(0,S.jsx)("div",{className:"px-2 py-2 text-[9px] text-white/30 italic",children:"No subdirectories"}),Qt.map(T=>(0,S.jsxs)("div",{className:"flex items-center gap-0.5 hover:bg-white/[0.04] transition",children:[(0,S.jsxs)("button",{type:"button",onClick:()=>{Wf(T.path)},className:"flex items-center gap-1.5 px-2 py-1 flex-1 text-left min-w-0",children:[(0,S.jsx)(Br,{className:"h-3 w-3 text-cyan-400/70 shrink-0"}),(0,S.jsx)("span",{className:"text-[10px] text-white/75 truncate",children:T.name})]}),(0,S.jsx)("button",{type:"button",onClick:()=>m0(T.path),className:"px-2 py-1 text-[8px] font-medium text-cyan-300/70 hover:text-cyan-200 shrink-0",children:"Select"})]},T.path)),(0,S.jsxs)("button",{type:"button",onClick:()=>m0(yn),className:"w-full flex items-center gap-1.5 px-2 py-1.5 text-left bg-cyan-500/5 hover:bg-cyan-500/10 border-t border-white/[0.06] transition",children:[(0,S.jsx)(ea,{className:"h-3 w-3 text-cyan-400 shrink-0"}),(0,S.jsx)("span",{className:"text-[10px] font-medium text-cyan-300/80",children:"Select this folder"}),(0,S.jsx)("span",{className:"text-[9px] text-white/30 font-mono truncate ml-auto",children:yn})]})]})]})]}),(0,S.jsxs)("div",{className:"flex items-center gap-2",children:[(0,S.jsx)("span",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35 w-16 shrink-0",children:"Access"}),[{key:"read",label:"Read",icon:wl},{key:"write",label:"Write",icon:ao},{key:"exec",label:"Exec",icon:si}].map(({key:T,label:Z,icon:F})=>(0,S.jsxs)("label",{className:q("inline-flex items-center gap-1 rounded px-2 py-1 text-[9px] cursor-pointer transition",Le[T]?"bg-white/[0.06] text-white/85":"bg-white/[0.02] text-white/40"),children:[(0,S.jsx)("input",{type:"checkbox",className:"sr-only",checked:Le[T],onChange:ge=>Ee(an=>({...an,[T]:ge.target.checked}))}),(0,S.jsx)(F,{className:"h-2.5 w-2.5"}),Z,(0,S.jsx)("span",{className:q("h-1.5 w-1.5 rounded-full",Le[T]?"bg-emerald-300/80":"bg-white/20")})]},T))]}),(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsxs)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:["Description ",(0,S.jsx)("span",{className:"text-white/20 normal-case font-normal",children:"(optional \u2014 shown to the agent)"})]}),(0,S.jsx)("input",{value:Le.description,onChange:T=>Ee(Z=>({...Z,description:T.target.value})),className:zo,placeholder:rn?.description??"What this source is for\u2026",maxLength:200})]}),Jn&&(0,S.jsx)("div",{className:"flex items-center gap-2",children:(0,S.jsxs)("label",{className:"inline-flex items-center gap-1.5 text-[10px] text-white/80 cursor-pointer",children:[(0,S.jsx)("input",{type:"checkbox",checked:Le.syncEnabled,onChange:T=>Ee(Z=>({...Z,syncEnabled:T.target.checked})),className:"accent-emerald-400 h-3 w-3"}),"Enable sync"]})}),Jn&&Le.syncEnabled&&(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Exclude patterns"}),(0,S.jsx)("textarea",{value:Le.exclude,onChange:T=>Ee(Z=>({...Z,exclude:T.target.value})),rows:2,className:qu,placeholder:"node_modules/**"})]}),Jn&&Le.syncEnabled&&(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Include (allowlist)"}),(0,S.jsx)("textarea",{value:Le.include,onChange:T=>Ee(Z=>({...Z,include:T.target.value})),rows:2,className:q(qu,"font-mono"),placeholder:`# empty = everything
46
- skills/**`}),(0,S.jsx)("div",{className:"text-[8px] text-white/25 italic",children:"Non-empty: only matching files sync. Excludes always win \u2014 an excluded path can never be re-included. This narrows the INDEX, not what the agent can read: the source root does that."})]}),dn==="local"&&h&&(0,S.jsx)("div",{className:"space-y-1",children:(0,S.jsxs)("label",{className:"inline-flex items-start gap-1.5 text-[10px] text-white/80 cursor-pointer",children:[(0,S.jsx)("input",{type:"checkbox",checked:Le.recognizesPackages,onChange:T=>Ee(Z=>({...Z,recognizesPackages:T.target.checked})),className:"accent-emerald-400 h-3 w-3 mt-0.5"}),(0,S.jsxs)("span",{children:["Recognize packages",(0,S.jsxs)("span",{className:"block text-[9px] text-white/35 normal-case font-normal",children:["Load WASM packages dropped in this folder (in addition to ",(0,S.jsx)("code",{children:"_packages/"}),"). Advertised only within this source's scope."]})]})]})}),(0,S.jsxs)("div",{className:"flex items-center gap-1.5 pt-1",children:[(0,S.jsx)("button",{type:"button",onClick:()=>Fe(!1),className:"h-6 px-2.5 rounded-md text-[9px] font-medium text-white/50 hover:text-white/80 hover:bg-white/[0.05] transition",children:"Cancel"}),(0,S.jsxs)("button",{type:"button",onClick:()=>{w2()},disabled:Tn||!Le.key||E&&!Le.path,className:"h-6 px-2.5 rounded-md bg-cyan-500/12 border border-cyan-400/25 text-[9px] font-semibold text-cyan-200/90 hover:bg-cyan-500/20 transition disabled:opacity-35 inline-flex items-center gap-1",children:[Tn?(0,S.jsx)(ze,{className:"h-2.5 w-2.5 animate-spin"}):(0,S.jsx)(Fn,{className:"h-2.5 w-2.5"}),"Create source"]})]})]}),Tr.length===0&&!A?(0,S.jsx)("div",{className:"mt-3 text-[10px] text-white/40",children:"No sources configured."}):null,(0,S.jsx)("div",{className:"mt-1 space-y-3",children:Gf.map(([T,Z])=>(0,S.jsxs)("div",{children:[(0,S.jsxs)("div",{className:"-ml-0.5 mb-0.5 flex items-center gap-1.5 px-1",children:[(0,S.jsx)(vr,{className:"h-3 w-3 shrink-0 text-white/30"}),(0,S.jsx)("span",{className:"truncate font-mono text-[10px] font-medium text-white/40",children:T}),(0,S.jsx)("span",{className:"text-[9px] tabular-nums text-white/25",children:Z.length})]}),(0,S.jsx)("div",{className:"space-y-0.5 pl-2",children:Z.map(F=>{let ge=y[F.source]??Ki(F),an=L===F.source,fn=z===F.source,qo=Q===F.source,us=pe===F.source,Ga=Hn.get(F.connection.kind)??null,za=Jg(Ga),Ju=za&&!!ge.sync,Un=ge.sync??$g,g0=(0,sr.resolveIconWithFallback)(F.kind_icon??Ga?.icon??void 0,Gn),x0=bc(F),y0=F.live===!1,k2=y0||F.enabled===!1||F.enabled==="auto"&&F.enabled_effective===!1,b0=!!k[F.source],cs=!F.observed,jf=cs&&aE(F,ge),Dr=sI(Un.trigger),Js=U[F.source]??{};return(0,S.jsxs)("div",{className:"rounded-sm",children:[(0,S.jsxs)("button",{type:"button",onClick:()=>Cn(F.source),title:y0?Sh(F.live_reason):void 0,className:"w-full flex items-center gap-2 py-2 text-left group hover:bg-white/[0.02] rounded-md px-1 transition",children:[F.git?.isRepo?(0,S.jsxs)("span",{className:"relative inline-flex shrink-0 items-center justify-center",children:[(0,S.jsx)(g0,{className:q("h-4 w-4",x0.iconClassName)}),(0,S.jsx)(Ln,{className:"absolute -right-1.5 -top-1.5 h-2.5 w-2.5 rounded-full bg-black/80 p-[1px] text-violet-300/90"})]}):(0,S.jsx)(g0,{className:q("h-4 w-4 shrink-0",x0.iconClassName)}),(0,S.jsx)("span",{className:q("min-w-0 flex-1 truncate text-[12.5px] font-semibold",k2?"text-white/45":"text-white/90"),children:F.source}),F.git?.isRepo&&F.git.branch?(0,S.jsxs)("span",{className:"inline-flex max-w-[96px] shrink-0 items-center gap-0.5 text-[10px] text-violet-300/70",title:`Git branch: ${F.git.branch}`,children:[(0,S.jsx)(Ln,{className:"h-2.5 w-2.5 shrink-0"}),(0,S.jsx)("span",{className:"truncate",children:F.git.branch})]}):null,F.observed&&(0,S.jsx)("span",{className:"shrink-0 rounded px-1 py-0.5 text-[8px] font-medium text-orange-200/90 bg-orange-500/5 ring-1 ring-orange-300/30",children:"observed"}),F.orphan&&(0,S.jsx)("span",{className:"shrink-0 rounded px-1 py-0.5 text-[8px] font-medium text-rose-300/80 bg-rose-500/15",title:F.orphan_hint??"Package missing",children:"orphan"}),jf&&(0,S.jsx)("span",{className:"shrink-0 rounded px-1 py-0.5 text-[8px] font-medium text-amber-300/80 bg-amber-500/10",children:"unsaved"}),(()=>{let We=F.enabled??!0,_t=F.enabled_effective??We===!0,Zn=(Ga?.kind??F.connection.kind)==="webtop",Zs=fe===F.source,S2=()=>Zn?We===!0?!1:We===!1?"auto":!0:We===!1,w0=We==="auto"?`Auto \xB7 ${_t?"Live":"Stopped"}`:We===!1?"Off":"On",C2=We===!1?"text-rose-300/85 bg-rose-500/10 border-rose-400/25":We==="auto"?"text-amber-200/85 bg-amber-500/10 border-amber-400/25":"text-emerald-300/85 bg-emerald-500/10 border-emerald-400/25";return(0,S.jsx)("button",{type:"button",title:`Source ${w0} \u2014 click to cycle`,onClick:L2=>{L2.stopPropagation(),!Zs&&y2(F.source,S2())},disabled:Zs||!!F.observed,className:q("shrink-0 rounded px-1 py-0.5 text-[8px] font-semibold border transition disabled:opacity-50",C2),children:Zs?"\u2026":w0})})(),(0,S.jsx)("span",{className:"text-[9px] text-white/30 truncate max-w-[140px] hidden sm:inline",children:nE(F,Ga)}),(0,S.jsx)(Tt,{className:q("h-3 w-3 text-white/25 shrink-0 transition-transform",b0&&"rotate-180")})]}),(0,S.jsx)("div",{className:q("transition-all duration-200",b0?"opacity-100":"max-h-0 opacity-0 overflow-hidden"),children:(0,S.jsxs)("div",{className:"rounded-md bg-white/[0.02] p-3 ml-5 mb-1 space-y-2.5",children:[(0,S.jsxs)("div",{className:"flex items-center gap-3 text-[9px] text-white/40",children:[N.has(F.source)&&typeof F.indexed_count!="number"&&(0,S.jsx)("span",{className:"text-white/30",children:"Loading counts\u2026"}),typeof F.connector_count=="number"&&(0,S.jsxs)("span",{children:[(0,S.jsxs)("span",{className:"text-white/60 tabular-nums",children:[F.connector_count,F.connector_truncated?"+":""]})," connector"]}),typeof F.indexed_count=="number"&&(0,S.jsxs)("span",{children:[(0,S.jsx)("span",{className:"text-cyan-300/70 tabular-nums",children:F.indexed_count})," indexed"]}),typeof F.unindexed_count=="number"&&F.unindexed_count>0&&(0,S.jsxs)("span",{children:[(0,S.jsx)("span",{className:"text-amber-300/70 tabular-nums",children:F.unindexed_count})," unindexed"]}),za&&F.sync?.lastSync&&(0,S.jsxs)("span",{children:["Last sync: ",nI(F.sync.lastSync)]}),F.updatedAt&&(0,S.jsxs)("span",{children:["Updated: ",nI(F.updatedAt)]})]}),za&&!F.sync?.lastSync?(0,S.jsx)("div",{className:"rounded-md border border-sky-300/15 bg-sky-500/5 px-2 py-1.5 text-[10px] text-sky-100/70",children:"Never synced \u2014 run a sync to index this source and load its packages (skills, rules, instructions) for agents."}):null,F.observed?(0,S.jsx)("div",{className:"rounded-md border border-orange-300/15 bg-orange-500/5 px-2 py-1.5 text-[10px] text-orange-100/70",children:"Runtime-observed source. Create a source config to edit permissions, sync, or persistence settings."}):null,(0,S.jsxs)("div",{children:[(0,S.jsxs)("button",{type:"button",onClick:()=>zf(F.source,"description"),className:"flex items-center gap-1.5 py-1 w-full text-left",children:[(0,S.jsx)(ba,{className:"h-3 w-3 text-violet-400 shrink-0"}),(0,S.jsx)("span",{className:"text-[10px] font-semibold text-white/70 flex-1",children:"Description"}),!Js.description&&((ge.description??"").trim()||F.description_effective)&&(0,S.jsx)("span",{className:q("text-[9px] truncate max-w-[200px]",(ge.description??"").trim()?"text-white/35":"text-white/25 italic"),children:(ge.description??"").trim()||`${F.description_effective} (from the package)`}),(0,S.jsx)(un,{className:q("h-2.5 w-2.5 text-white/25 transition-transform",Js.description&&"rotate-90")})]}),Js.description&&(0,S.jsxs)("div",{className:"pl-5 pt-1 space-y-1",children:[(0,S.jsx)("div",{className:"text-[10px] text-white/35 italic",children:"A one-line summary shown to the agent in its runtime source list."}),cs?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("textarea",{value:ge.description??"",onChange:We=>Zr(F.source,_t=>({..._t,description:We.target.value})),rows:2,className:qu,placeholder:F.description_effective??"What this source is for\u2026",maxLength:200}),!(ge.description??"").trim()&&F.description_effective&&(0,S.jsx)("div",{className:"text-[9px] text-white/25 italic",children:"Shown above from the package. Leave this empty to keep following it."})]}):(0,S.jsx)("div",{className:"text-[10px] text-white/70",children:(ge.description??"").trim()||(F.description_effective?(0,S.jsxs)("span",{className:"text-white/40 italic",children:[F.description_effective," ",(0,S.jsx)("span",{className:"text-white/25 not-italic",children:"(from the package)"})]}):(0,S.jsx)("span",{className:"text-white/30 italic",children:"No description"}))})]})]}),cs&&h&&(Ga?.kind??F.connection.kind)==="local"&&(0,S.jsx)("div",{className:"pl-0",children:(0,S.jsxs)("label",{className:"flex items-start gap-1.5 py-1 cursor-pointer",children:[(0,S.jsx)(vr,{className:"h-3 w-3 text-cyan-400 shrink-0 mt-0.5"}),(0,S.jsx)("input",{type:"checkbox",checked:ge.recognizesPackages??!1,onChange:We=>Zr(F.source,_t=>({..._t,recognizesPackages:We.target.checked})),className:"accent-cyan-400 h-3 w-3 mt-0.5"}),(0,S.jsxs)("span",{className:"text-[10px] text-white/70 leading-tight",children:["Recognize packages",(0,S.jsxs)("span",{className:"block text-[9px] text-white/35 normal-case font-normal",children:["Load WASM packages dropped here (additive to ",(0,S.jsx)("code",{children:"_packages/"}),"); advertised only within this source's scope. Save to apply."]})]})]})}),(0,S.jsxs)("div",{children:[(0,S.jsxs)("div",{className:"flex items-center gap-1.5 py-1",children:[(0,S.jsxs)("button",{type:"button",onClick:()=>zf(F.source,"perms"),className:"flex items-center gap-1.5 flex-1 text-left",children:[(0,S.jsx)(Is,{className:"h-3 w-3 text-emerald-400 shrink-0"}),(0,S.jsx)("span",{className:"text-[10px] font-semibold text-white/70 flex-1",children:"Permissions"}),(0,S.jsx)(un,{className:q("h-2.5 w-2.5 text-white/25 transition-transform",Js.perms&&"rotate-90")})]}),(0,S.jsx)(Xg.SkillLauncher,{variant:"icon",size:"sm",skill:"manage-uri-policy",packageId:"@neuralis/brain-core",scripts:["scripts/show-uri.sh","scripts/set-uri.sh","scripts/manifests.sh"],label:`Edit URI policy for "${F.source}" with the agent`,icon:"shield"})]}),Js.perms&&(0,S.jsx)("div",{className:"pl-5 pt-1",children:(0,S.jsx)(Vg,{source:F.source,permissions:F.permissions,mode:cs?"edit":"view",onSave:cs?We=>h2(F,We):void 0})})]}),za&&(0,S.jsxs)("div",{children:[(0,S.jsxs)("button",{type:"button",onClick:()=>zf(F.source,"sync"),className:"flex items-center gap-1.5 py-1 w-full text-left",children:[(0,S.jsx)(Ht,{className:"h-3 w-3 text-blue-400 shrink-0"}),(0,S.jsx)("span",{className:"text-[10px] font-semibold text-white/70 flex-1",children:"Sync"}),Ju&&(0,S.jsx)("span",{className:"text-[9px] text-white/35",children:tE(Un.trigger)}),(0,S.jsx)(un,{className:q("h-2.5 w-2.5 text-white/25 transition-transform",Js.sync&&"rotate-90")})]}),Js.sync&&(0,S.jsxs)("div",{className:"pl-5 space-y-2 pt-1",children:[(0,S.jsx)("div",{className:"text-[10px] text-white/35 italic",children:"Sync indexes files for AI search. Excluded patterns (logs/, node_modules/) are skipped automatically."}),(0,S.jsxs)("label",{className:"inline-flex items-center gap-1.5 text-[10px] text-white/80 cursor-pointer",children:[(0,S.jsx)("input",{type:"checkbox",checked:Ju,onChange:We=>Zr(F.source,_t=>({..._t,...We.target.checked?{sync:{...$g,exclude:[...F.defaultSyncExclude??$g.exclude]}}:{sync:void 0}})),className:"accent-emerald-400 h-3 w-3"}),"Enable sync"]}),Ju&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsxs)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35 flex items-center gap-1",children:[(0,S.jsx)(ya,{className:"h-2.5 w-2.5 text-cyan-300/60"})," Trigger"]}),(0,S.jsx)("select",{value:Dr.mode,onChange:We=>{let _t=We.target.value;Zr(F.source,Zn=>({...Zn,sync:{...Un,trigger:Kg(_t,Dr.val,Dr.unit)}}))},className:kf,children:j5.map(We=>(0,S.jsx)("option",{value:We.value,children:We.label},We.value))}),Dr.mode==="interval"&&(0,S.jsxs)("div",{className:"flex gap-1",children:[(0,S.jsx)("input",{type:"number",min:Cf(Dr.unit),value:Dr.val,onChange:We=>{let _t=We.target.value.replace(/\D/g,"")||String(Cf(Dr.unit));Zr(F.source,Zn=>({...Zn,sync:{...Un,trigger:Kg("interval",_t,Dr.unit)}}))},className:q(zo,"w-16")}),(0,S.jsx)("select",{value:Dr.unit,onChange:We=>{let _t=We.target.value,Zn=String(Math.max(Number.parseInt(Dr.val,10)||1,Cf(_t)));Zr(F.source,Zs=>({...Zs,sync:{...Un,trigger:Kg("interval",Zn,_t)}}))},className:q(kf,"flex-1"),children:q5.map(We=>(0,S.jsx)("option",{value:We.value,children:We.label},We.value))})]}),(0,S.jsx)("div",{className:"text-[8px] text-white/35 italic leading-relaxed",children:Dr.mode==="manual"?"Manual: nothing triggers it automatically \u2014 indexes only when you click Sync below.":Dr.mode==="auto"?"Auto: re-indexes on file changes (host edits, git, shell \u2014 anything) + a periodic full reconcile.":"Scheduled: runs a full reconcile every interval above."})]}),(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Exclude"}),(0,S.jsx)("textarea",{value:Sf(Un.exclude),onChange:We=>{let _t=ju(We.target.value);Zr(F.source,Zn=>({...Zn,sync:{...Un,exclude:_t}}))},rows:5,className:q(qu,"font-mono"),placeholder:`# .gitignore syntax
29
+ `}function Vv(t,e){if(!t)return{files:[],truncated:e,hunkPatches:null};let n=[];try{n=cv(t)}catch{n=[]}return{files:n,truncated:e,hunkPatches:zv(t)}}function Jc(t,e){let n=Rv(t,e);return n<=0?null:{start:t?t.oldStart+t.oldLines:1,end:e.oldStart,lines:n}}function ru(t,e){if(!t)return null;let n=t.oldStart+t.oldLines;if(e===null)return{start:n,end:n,lines:null};let r=e-n+1;return r<=0?null:{start:n,end:e+1,lines:r}}function qv(t,e){let n=[];for(let a=0;a<t.length;a++){let s=Jc(a===0?null:t[a-1],t[a]);s&&n.push({start:s.start,end:s.end})}let r=ru(t[t.length-1]??null,e);return r&&r.lines!==null&&n.push({start:r.start,end:r.end}),n}function nM(t){let e=t.split(`
30
+ `);return e.length>1&&e[e.length-1]===""&&e.pop(),e}function Zc(t,e){let n=nM(e);if(t.length===0)return n.slice();let r=t[t.length-1],a=Math.max(r.oldStart+r.oldLines,1),s=Math.max(r.newStart+r.newLines,1),i=Math.max(n.length-s+1,0),o=Math.max(a-1+i,0),l=new Array(o).fill(""),u=1,c=1,d=f=>{for(let h=u,p=c;h<f;h++,p++)l[h-1]=n[p-1]??""};for(let f of t)d(f.oldStart),u=Math.max(f.oldStart+f.oldLines,1),c=Math.max(f.newStart+f.newLines,1);return d(o+1),l}function $v(t,e,n){return n.reduce((r,a)=>Nv(r,e,a.start,a.end),t)}function Kv(t,e){let n=t.oldStart,r=t.oldStart+t.oldLines,a=[];for(let s=0;s<e.length;s++){let i=e[s];i.oldStart>=n&&i.oldStart+i.oldLines<=r&&a.push(s)}return a}function Xv(t){return"commit"in t?{kind:"commit",sha:t.commit}:"base"in t?{kind:"range",base:t.base,head:t.head}:{kind:"working",staged:t.staged}}function Yv(t){return t.kind==="working"?{staged:t.staged}:t.kind==="commit"?{commit:t.sha}:{base:t.base,head:t.head}}function Jv(t){return t.kind==="working"?t.staged?{type:"show",rev:"index"}:{type:"worktree"}:t.kind==="commit"?{type:"show",rev:t.sha}:{type:"show",rev:t.head}}function tn(t){return t.slice(0,7)}function Zv(t){return t.kind==="working"?t.staged?"Index \u2194 HEAD":"Working \u2194 Index":t.kind==="commit"?`${tn(t.sha)}^ \u2194 ${tn(t.sha)}`:`${tn(t.base)} \u2194 ${tn(t.head)}`}function Qv(t){return t.kind==="working"?t.staged?"No staged changes for this file.":"No working-tree changes for this file.":t.kind==="commit"?"No changes for this file in this commit.":"No changes for this file in this range."}function e1(t){return"commit"in t?`commit ${tn(t.commit)}`:"base"in t?`${tn(t.base)}..${tn(t.head)}`:t.staged?"staged":"working tree"}function xi(t,e){return t?`${t} \xB7 ${e}`:e}function t1(t){return!!t&&/uri.?policy.?denied/i.test(t)}var s1=j($e(),1);var tp={typescript:()=>import("./chunks/typescript-NEWOAB5Z.js"),tsx:()=>import("./chunks/tsx-S73GAE2L.js"),javascript:()=>import("./chunks/javascript-IH374YWG.js"),jsx:()=>import("./chunks/jsx-OTXJQD32.js"),json:()=>import("./chunks/json-WGGVVXSB.js"),markdown:()=>import("./chunks/markdown-LMWF6MQR.js"),python:()=>import("./chunks/python-CFG4FTQW.js"),bash:()=>import("./chunks/bash-KY6SAQTH.js"),yaml:()=>import("./chunks/yaml-UMWKDTK7.js"),html:()=>import("./chunks/html-F6FWTBSG.js"),css:()=>import("./chunks/css-MANZBYA4.js"),go:()=>import("./chunks/go-5UCPEC6S.js"),rust:()=>import("./chunks/rust-X7A37WU3.js"),sql:()=>import("./chunks/sql-B55MH6JJ.js"),toml:()=>import("./chunks/toml-ETQRDILP.js"),c:()=>import("./chunks/c-OBOPYVZ7.js"),cpp:()=>import("./chunks/cpp-TVWVOTEQ.js"),csharp:()=>import("./chunks/csharp-HQWR4N52.js"),java:()=>import("./chunks/java-ANIVV5H5.js"),kotlin:()=>import("./chunks/kotlin-MNR6XOEQ.js"),ruby:()=>import("./chunks/ruby-42NMJWAL.js"),php:()=>import("./chunks/php-AYGJ5WYZ.js"),swift:()=>import("./chunks/swift-PE7VNYW5.js"),scala:()=>import("./chunks/scala-OYHJSUG2.js"),r:()=>import("./chunks/r-4YFCFA4B.js"),powershell:()=>import("./chunks/powershell-7GSBBEFF.js"),ini:()=>import("./chunks/ini-BJIVD5MK.js"),xml:()=>import("./chunks/xml-UXKAGLDR.js"),scss:()=>import("./chunks/scss-XD7VU2CU.js"),less:()=>import("./chunks/less-KA5JURX6.js"),graphql:()=>import("./chunks/graphql-UGOPR3WU.js"),lua:()=>import("./chunks/lua-4CRZ64PU.js"),dart:()=>import("./chunks/dart-FO4TTVO2.js"),elm:()=>import("./chunks/elm-5WUUSTNB.js"),latex:()=>import("./chunks/latex-QCZNITGN.js"),clojure:()=>import("./chunks/clojure-4QCN4GHG.js"),elixir:()=>import("./chunks/elixir-S725Z7EH.js"),haskell:()=>import("./chunks/haskell-25PJ3OSG.js"),nix:()=>import("./chunks/nix-QGWLUUMZ.js"),perl:()=>import("./chunks/perl-BHTX7F5B.js"),proto:()=>import("./chunks/proto-7KDX5Z2U.js"),docker:()=>import("./chunks/docker-VX55HTDS.js"),mdx:()=>import("./chunks/mdx-WPMNN5BS.js"),vue:()=>import("./chunks/vue-CCDS4VZK.js"),svelte:()=>import("./chunks/svelte-WR3QPIJU.js"),astro:()=>import("./chunks/astro-B2J4AS2D.js"),diff:()=>import("./chunks/diff-SHANV4YC.js"),make:()=>import("./chunks/make-LPD5KOCO.js"),nginx:()=>import("./chunks/nginx-V4CYS7WR.js"),prisma:()=>import("./chunks/prisma-FPMPQISO.js")},rM=["typescript","tsx","javascript","jsx","json","markdown","python","bash","yaml","html","css","go","rust","sql","toml"];function So(t){if(!t)return;let e=t.toLowerCase(),r={js:"javascript",ts:"typescript","c++":"cpp","c#":"csharp",cs:"csharp",shell:"bash",sh:"bash",zsh:"bash",yml:"yaml",protobuf:"proto",dockerfile:"docker",md:"markdown",htm:"html",py:"python",rs:"rust",kt:"kotlin",rb:"ruby"}[e]??e;return r in tp?r:void 0}var Qc=null,yi=null,n1=new Map;function au(){return Qc||(Qc=Promise.all([import("./chunks/core-ZHTX3P2Q.js"),import("./chunks/dist-WSDF34DM.js"),import("./chunks/dark-plus-GYPKKZES.js"),import("./chunks/light-plus-QXH2UUWZ.js"),Promise.all(rM.map(t=>tp[t]()))]).then(([t,e,n,r,a])=>t.createHighlighterCore({themes:[n.default,r.default],langs:a.map(s=>s.default),engine:e.createJavaScriptRegexEngine()})).then(t=>(yi=t,t),t=>{throw Qc=null,t})),Qc}function ed(t,e){return t.getLoadedLanguages().includes(e)}function td(t){return!!yi&&ed(yi,t)}function r1(t){return yi&&ed(yi,t)?yi:null}async function nd(t){let e=await au();if(ed(e,t))return!0;let n=tp[t];if(!n)return!1;let r=n1.get(t);return r||(r=n().then(a=>e.loadLanguage(a.default)).then(()=>!0).catch(()=>!1),n1.set(t,r)),r}var ko=null;function a1(t,e,n){let r=yi;if(!r||!ed(r,e))return null;if(ko&&ko.text===t&&ko.lang===e&&ko.theme===n)return ko.lines;try{let a=r.codeToTokensBase(t,{lang:e,theme:n,includeExplanation:!1});return ko={text:t,lang:e,theme:n,lines:a},a}catch{return null}}function aM(t){return{highlight(e,n){let r=a1(e,n,t);if(!r)return[{type:"text",value:e}];let a=[];return r.forEach((s,i)=>{for(let o of s){if(!o.content)continue;let l={type:"element",tagName:"span",properties:{},color:o.color,children:[{type:"text",value:o.content}]};a.push(l)}i<r.length-1&&a.push({type:"text",value:`
31
+ `})}),a}}}function i1(t,e,n="dark-plus"){let r=So(e);if(r&&td(r))try{return Wv(t,{highlight:!0,refractor:aM(n),language:r})}catch{return}}var o1=(t,e,n)=>{let r=t.color;return t.type==="element"&&typeof r=="string"?(0,s1.createElement)("span",{key:n,style:{color:r}},t.children?.map((a,s)=>e(a,s))):e(t,n)};function rd(t){let e=gt(String(t||"")).toLowerCase().trim();if(!e)return;let n=e;if(n==="dockerfile")return"docker";let r=n.includes(".")?n.split(".").pop():"";if(!r)return;let a={js:"javascript",jsx:"jsx",ts:"typescript",tsx:"tsx",json:"json",jsonl:"json",py:"python",rb:"ruby",php:"php",java:"java",kt:"kotlin",go:"go",rs:"rust",c:"c",h:"c",cpp:"cpp",cc:"cpp",cxx:"cpp",hpp:"cpp",cs:"csharp",swift:"swift",scala:"scala",r:"r",sql:"sql",sh:"bash",bash:"bash",zsh:"bash",fish:"bash",ps1:"powershell",yaml:"yaml",yml:"yaml",toml:"toml",ini:"ini",xml:"xml",html:"html",css:"css",scss:"scss",less:"less",graphql:"graphql",gql:"graphql",lua:"lua",dart:"dart",elm:"elm",tex:"latex",clj:"clojure",ex:"elixir",exs:"elixir",hs:"haskell",nim:"nim",pl:"perl",proto:"protobuf",md:"markdown",mdx:"mdx"};return r==="env"?"bash":a[r]??r}var l1=j(Wn(),1);var ad=j(ie(),1),sM=[{key:"auto",label:"Auto",Icon:Rs},{key:"unified",label:"Unified",Icon:Ns},{key:"split",label:"Split",Icon:ys}];function sd({className:t}){let e=H(r=>r.diffViewMode),n=H(r=>r.setDiffViewMode);return(0,ad.jsx)("div",{className:$("inline-flex items-center gap-0.5 rounded-md bg-white/5 p-0.5",t),children:sM.map(({key:r,label:a,Icon:s})=>(0,ad.jsx)("button",{type:"button",onClick:()=>n(r),className:$("inline-flex items-center justify-center rounded p-1 transition",e===r?"bg-white/12 text-white/90":"text-white/40 hover:text-white/70 hover:bg-white/[0.06]"),title:`Diff layout: ${a}${r==="auto"?" (by width)":""}`,"aria-label":`Diff layout ${a}`,"aria-pressed":e===r,children:(0,ad.jsx)(s,{className:"w-3 h-3"})},r))})}var Xe=j(ie(),1),iM={"--diff-background-color":"transparent","--diff-text-color":"rgba(255,255,255,0.82)","--diff-font-family":"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace","--diff-selection-background-color":"rgba(139,92,246,0.35)","--diff-gutter-insert-background-color":"rgba(16,185,129,0.16)","--diff-gutter-delete-background-color":"rgba(244,63,94,0.16)","--diff-gutter-selected-background-color":"rgba(139,92,246,0.22)","--diff-code-insert-background-color":"rgba(16,185,129,0.10)","--diff-code-delete-background-color":"rgba(244,63,94,0.10)","--diff-code-insert-edit-background-color":"rgba(16,185,129,0.30)","--diff-code-delete-edit-background-color":"rgba(244,63,94,0.32)","--diff-code-selected-background-color":"rgba(139,92,246,0.16)","--diff-omit-gutter-line-color":"transparent"};function np(t,e,n,r){let a=r.kind==="working"?{kind:r.kind,staged:r.staged}:r.kind==="commit"?{kind:r.kind,sha:r.sha}:{kind:r.kind,base:r.base,head:r.head};return`diff\0${t}\0${e}\0${n}\0${JSON.stringify(a)}`}function bi({source:t,repo:e="",path:n,mode:r,agentId:a,projectId:s,variant:i="tab",revision:o=0,canWrite:l=!1,runContent:u,peekContent:c}){let d=H(ee=>ee.client),[f]=(0,ht.useState)(()=>c?.(`${np(t,e,n,r)}\0${o}`,np(t,e,n,r))),[h,p]=(0,ht.useState)(()=>f===void 0?null:f&&f.ok!==!1?f.diff:""),[g,m]=(0,ht.useState)(!1),[x,y]=(0,ht.useState)(null),[b,C]=(0,ht.useState)(()=>f!==void 0&&f.ok!==!1&&f.truncated===!0),[L,P]=(0,ht.useState)(()=>f!==void 0&&f.ok===!1),[w,k]=(0,ht.useState)(0),[_,M]=(0,ht.useState)(null),[R,U]=(0,ht.useState)(null),[v,T]=(0,ht.useState)([]),[V,Y]=(0,ht.useState)(null),[N,A]=(0,ht.useState)(!1),B=(0,ht.useRef)(new Map),K=(0,ht.useRef)(0),te=H(ee=>ee.loadGitStatus),ne=r.kind,pe=r.kind==="working"?r.staged:!1,Se=r.kind==="commit"?r.sha:null,le=r.kind==="range"?r.base:null,re=r.kind==="range"?r.head:null,he=(0,ht.useMemo)(()=>ne==="working"?{kind:ne,staged:pe}:ne==="commit"?{kind:ne,sha:Se??""}:{kind:ne,base:le??"",head:re??""},[ne,pe,Se,le,re]),Ne=(0,ht.useMemo)(()=>Jv(he),[he]),Ee=H(ee=>ee.diffViewMode),ze=(0,ht.useRef)(null),ct=(0,l1.useContainerWidth)(ze),it=Ee==="auto"?ct?"split":"unified":Ee,Qe=(0,ht.useMemo)(()=>rd(n),[n]),[Ye,Lt]=(0,ht.useState)(!1);(0,ht.useEffect)(()=>{let ee=So(Qe);if(!ee){Lt(!1);return}if(td(ee)){Lt(!0);return}let oe=!1;return Lt(!1),au().then(()=>nd(ee)).then(He=>{oe||Lt(He)}),()=>{oe=!0}},[Qe]),(0,ht.useEffect)(()=>{if(B.current.clear(),T([]),Y(null),A(!1),!a||!t||!n){C(!1),P(!1),p(null),y(null),m(!1);return}let ee=++K.current;return m(!0),y(null),(async()=>{try{let oe=()=>lc({agentId:a,...s?{projectId:s}:{},source:t,...e?{repo:e}:{},path:n,...Yv(he)},d),He=np(t,e,n,he),Ve={key:`${He}\0${o}`,family:He,bytes:ce=>ce&&ce.ok!==!1?ce.diff.length*2:64,fresh:w>0},Ae=u?await u(oe,()=>ee===K.current,Ve):await oe();if(!Ae||ee!==K.current)return;Ae&&Ae.ok===!1?(p(""),P(!0),C(!1)):(p(typeof Ae?.diff=="string"?Ae.diff:""),P(!1),C(Ae?.truncated===!0)),m(!1)}catch(oe){if(ee!==K.current)return;y(oe instanceof Error?oe.message:"Diff failed"),p(null),P(!1),C(!1),m(!1)}})(),()=>{K.current++}},[a,s,t,e,n,he,w,o,u]);let{files:Le,truncated:at,hunkPatches:ft}=(0,ht.useMemo)(()=>Vv(h,b),[h,b]),bt=Le.some(ee=>ee.hunks.length>0),At=gt(n)||n,Tt=t1(x),Ue=Le.length===1?Le[0]:null,me=l&&ne==="working"&&!!a&&!!Ue&&Ue.type==="modify"&&!at&&!!ft&&ft.hunks.length===Ue.hunks.length,Ot=!!a&&!!Ue&&!at&&Ue.hunks.length>0,Jt=(0,ht.useCallback)(async()=>{if(!a)return null;let ee=K.current,oe=Ne.type==="worktree"?"wt":Ne.rev,He=`${t}\0${e}\0${n}\0${oe}`,Ve=B.current.get(He),Ae=ce=>(B.current.set(He,ce),ee===K.current&&(ce.ok?Y(ce.content):A(!0)),ce.ok?ce.content:null);if(Ve)return Ae(Ve);try{if(Ne.type==="show"){let Zt=()=>F0({agentId:a,...s?{projectId:s}:{},source:t,...e?{repo:e}:{},path:n,rev:Ne.rev},d),dn=u?await u(Zt,()=>ee===K.current):await Zt();return!dn||ee!==K.current?null:Ae(dn.ok?{ok:!0,content:dn.content}:{ok:!1})}let ce=()=>$i({agentId:a,...s?{projectId:s}:{},files:[`${t}://${e?`${e}/`:""}${n}`]},d),Pt=u?await u(ce,()=>ee===K.current):await ce();if(!Pt||ee!==K.current)return null;let Ft=Yi(Pt)[0];return!Ft||typeof Ft.error=="string"?Ae({ok:!1}):Ae({ok:!0,content:Ji(Ft)})}catch{return Ae({ok:!1})}},[a,s,t,e,n,Ne,u]),ue=(0,ht.useMemo)(()=>Ue&&V!==null?Zc(Ue.hunks,V):null,[Ue,V]),be=(0,ht.useMemo)(()=>Le.map(ee=>ee!==Ue||!ue||v.length===0?ee.hunks:$v(ee.hunks,ue,v)),[Le,Ue,ue,v]),Ge=ue?ue.length:null,Re=(0,ht.useMemo)(()=>Ye?Le.map((ee,oe)=>i1(be[oe]??ee.hunks,Qe)):Le.map(()=>{}),[Le,be,Qe,Ye]),Te=(0,ht.useCallback)(async ee=>{if(!Ot)return;let oe=K.current,He=V??await Jt();if(He===null||oe!==K.current||!Ue)return;let Ve;if(ee.lines===null){let Ae=ru(Ue.hunks[Ue.hunks.length-1]??null,Zc(Ue.hunks,He).length);if(!Ae||Ae.lines===null)return;Ve={start:Ae.start,end:Ae.end}}else Ve={start:ee.start,end:ee.end};T(Ae=>[...Ae,Ve])},[Ot,V,Jt,Ue]),vt=(0,ht.useCallback)(async()=>{if(!Ot||!Ue)return;let ee=K.current,oe=V??await Jt();if(oe===null||ee!==K.current)return;let He=qv(Ue.hunks,Zc(Ue.hunks,oe).length);He.length>0&&T(Ve=>[...Ve,...He])},[Ot,Ue,V,Jt]),mt=(0,ht.useMemo)(()=>{if(!Ot||!Ue)return!1;let ee=Le.indexOf(Ue),oe=be[ee]??Ue.hunks;for(let He=0;He<oe.length;He++)if(Jc(He===0?null:oe[He-1],oe[He]))return!0;return ru(oe[oe.length-1]??null,Ge)!==null},[Ot,Ue,Le,be,Ge]),Gt=(0,ht.useCallback)(async ee=>{if(g||!me||!ft||!a)return;let oe=jv(ft.header,ft.hunks[ee]);if(!oe){U("Could not build a hunk patch for this change.");return}M(ee),U(null);try{pe?await _0({agentId:a,...s?{projectId:s}:{},source:t,...e?{repo:e}:{},hunk:oe},d):await B0({agentId:a,...s?{projectId:s}:{},source:t,...e?{repo:e}:{},hunk:oe},d),B.current.clear(),te({agentId:a,projectId:s}),k(He=>He+1)}catch(He){U(He instanceof Error?He.message:"Hunk apply failed")}finally{M(null)}},[g,me,ft,a,s,t,e,pe,te]),je=ee=>{let oe=ee.lines===null?"Expand to end of file":`${ee.lines} hidden ${ee.lines===1?"line":"lines"}`;return N?ee.lines===null?null:(0,Xe.jsx)(Yc,{children:(0,Xe.jsxs)("div",{className:"px-3 py-0.5 font-mono text-[10px] text-white/30",children:["\u22EF ",oe]})},`gap-${ee.start}`):(0,Xe.jsx)(Yc,{children:(0,Xe.jsxs)("button",{type:"button",onClick:()=>{Te(ee)},className:"block w-full px-3 py-0.5 text-left font-mono text-[10px] text-violet-300/70 transition-colors hover:bg-violet-500/10 hover:text-violet-200/90",title:"Expand this hidden region",children:["\u22EF ",oe]})},`gap-${ee.start}`)},kt=(ee,oe)=>oe.length===0?null:(0,Xe.jsx)(Yc,{children:(0,Xe.jsx)("div",{className:"flex items-center justify-end gap-2 px-2 py-1",children:oe.map(He=>(0,Xe.jsxs)("button",{type:"button",onClick:()=>{Gt(He)},disabled:_!==null||g,className:$("inline-flex items-center gap-1 rounded-md border px-2 py-0.5 text-[10px] transition-colors disabled:opacity-40",pe?"border-white/12 bg-white/[0.04] text-white/70 hover:bg-white/[0.09]":"border-emerald-500/25 bg-emerald-500/12 text-emerald-100/90 hover:bg-emerald-500/18"),title:pe?"Unstage this hunk":"Stage this hunk",children:[_===He?(0,Xe.jsx)(rp.LiveSpinner,{className:"h-3 w-3"}):pe?(0,Xe.jsx)(ai,{className:"h-3 w-3"}):(0,Xe.jsx)(Fn,{className:"h-3 w-3"}),pe?"Unstage hunk":"Stage hunk",oe.length>1?(0,Xe.jsxs)("span",{className:"font-mono text-white/45",children:["@",Ue?.hunks[He]?.oldStart]}):null]},He))})},`stage-${ee.oldStart}`),on=(0,Xe.jsxs)("button",{type:"button",onClick:()=>{vt()},className:"inline-flex shrink-0 items-center gap-1 rounded-md border border-white/10 px-1.5 py-0.5 text-[10px] text-white/55 transition-colors hover:bg-white/[0.06] hover:text-white/80",title:"Expand all hidden regions",children:[(0,Xe.jsx)(Wl,{className:"h-3 w-3"}),"Expand all"]}),Oe=x?Tt?(0,Xe.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-[11px] text-white/40",children:[(0,Xe.jsx)(ri,{className:"h-3.5 w-3.5 shrink-0 text-white/35"}),(0,Xe.jsx)("span",{children:"You don't have permission to view this file's changes."})]}):(0,Xe.jsx)("div",{className:"px-3 py-4 text-[11px] text-rose-300/70",children:x}):g&&!h?(0,Xe.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-[11px] text-white/40",children:[(0,Xe.jsx)(rp.LiveSpinner,{className:"h-3.5 w-3.5"}),"Loading diff\u2026"]}):L?(0,Xe.jsxs)("div",{className:"flex items-center justify-center gap-1.5 px-3 py-6 text-center text-[11px] text-amber-200/70",children:[(0,Xe.jsx)(ot,{className:"h-3.5 w-3.5 shrink-0"}),(0,Xe.jsx)("span",{children:"Diff too large to display \u2014 the change exceeds the server output bound."})]}):bt?(0,Xe.jsx)("div",{style:iM,className:$("nrs-git-diff px-1 py-1 text-[12px] leading-[18px]"),children:Le.map((ee,oe)=>{let He=ee===Ue&&Ot;return(0,Xe.jsx)(Bv,{viewType:it,diffType:ee.type,hunks:be[oe]??ee.hunks,tokens:Re[oe],renderToken:o1,children:Ve=>{let Ae=[],ce=Pt=>{Pt&&Ae.push(Pt)};if(Ve.forEach((Pt,Ft)=>{if(He){let Zt=Jc(Ft===0?null:Ve[Ft-1],Pt);Zt&&ce(je(Zt))}me&&ee===Ue&&ce(kt(Pt,Kv(Pt,ee.hunks))),Ae.push((0,Xe.jsx)(Qh,{hunk:Pt},`h-${Pt.oldStart}-${Pt.oldLines}`))}),He){let Pt=ru(Ve[Ve.length-1]??null,Ge);Pt&&ce(je(Pt))}return Ae}},`${ee.oldRevision??""}-${ee.newRevision??""}-${oe}`)})}):(0,Xe.jsx)("div",{className:"px-3 py-6 text-center text-[11px] text-white/35",children:Qv(he)});return(0,Xe.jsxs)("div",{ref:ze,className:$("flex w-full flex-col",i==="tab"&&"h-full min-h-0"),children:[i==="tab"?(0,Xe.jsxs)("div",{className:"flex shrink-0 items-center gap-2 px-3 py-1.5 text-[11px]",style:{borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[(0,Xe.jsx)(or,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/80"}),(0,Xe.jsx)("span",{className:"shrink-0 font-medium text-white/85",children:At}),(0,Xe.jsx)("span",{className:"truncate font-mono text-white/40",children:n}),(0,Xe.jsx)("span",{className:"ml-auto shrink-0 rounded-full border border-white/10 px-2 py-0.5 text-[9px] uppercase tracking-wider text-white/45",children:Zv(he)}),(0,Xe.jsx)(sd,{}),mt&&!N?on:null]}):mt&&!N?(0,Xe.jsx)("div",{className:"flex shrink-0 items-center justify-end px-2 pt-1",children:on}):null,at?(0,Xe.jsxs)("div",{className:"flex shrink-0 items-center gap-1.5 px-3 py-1 text-[10px] text-amber-200/70",children:[(0,Xe.jsx)(ot,{className:"h-3 w-3 shrink-0"}),(0,Xe.jsx)("span",{children:"Diff truncated by the server (2 MB cap) \u2014 showing the leading hunks; hunk staging is disabled."})]}):null,R?(0,Xe.jsxs)("div",{className:"flex shrink-0 items-center gap-1.5 px-3 py-1 text-[10px] text-rose-300/75",children:[(0,Xe.jsx)(ot,{className:"h-3 w-3 shrink-0"}),(0,Xe.jsx)("span",{className:"truncate",children:R})]}):null,i==="tab"?(0,Xe.jsx)("div",{className:"min-h-0 flex-1 overflow-auto",children:Oe}):Oe]})}var Je=j(ie(),1),ap={M:"text-amber-400",A:"text-emerald-400",D:"text-rose-400",R:"text-sky-400",C:"text-sky-400",T:"text-white/60"},id={M:"Modified",A:"Added",D:"Deleted",R:"Renamed",C:"Copied",T:"Type changed"};function oM(t){let e=new Date(t);return Number.isNaN(e.getTime())?t:e.toLocaleString()}var lM=(0,ns.memo)(function({file:e,mode:n,source:r,repo:a,agentId:s,projectId:i,defaultExpanded:o,queue:l}){let[u,c]=(0,ns.useState)(o),d=(e.status[0]??"M").toUpperCase(),f=e.path.includes("/")?e.path.slice(0,e.path.lastIndexOf("/")):"",h=e.path.includes("/")?e.path.slice(e.path.lastIndexOf("/")+1):e.path;return(0,Je.jsxs)("div",{ref:p=>l.register(e.path,p),className:"overflow-hidden rounded-lg border border-white/8 bg-black/20",children:[(0,Je.jsxs)("button",{type:"button",onClick:()=>c(p=>!p),className:"flex w-full items-center gap-2 px-2.5 py-1.5 text-left transition-colors hover:bg-white/[0.03]",title:e.path,"aria-expanded":u,children:[u?(0,Je.jsx)(Et,{className:"h-3.5 w-3.5 shrink-0 text-white/40"}):(0,Je.jsx)(un,{className:"h-3.5 w-3.5 shrink-0 text-white/40"}),(0,Je.jsx)("span",{className:$("shrink-0 text-[10px] font-bold leading-none tabular-nums",ap[d]??"text-white/60"),title:id[d]??"Changed","aria-label":`Status: ${id[d]??"Changed"}`,children:d}),(0,Je.jsxs)("span",{className:"min-w-0 flex-1 truncate text-xs text-white/85",children:[h,f?(0,Je.jsxs)("span",{className:"ml-1.5 font-mono text-[10px] text-white/30",children:[f,"/"]}):null]}),e.renamedFrom?(0,Je.jsxs)("span",{className:"shrink-0 truncate font-mono text-[10px] text-white/35",title:`Renamed from ${e.renamedFrom}`,children:["\u2190 ",e.renamedFrom]}):null,(0,Je.jsx)(Aa,{added:e.added,removed:e.removed,binary:e.binary,className:"shrink-0"})]}),u&&l.visible.has(e.path)?(0,Je.jsx)("div",{className:"border-t border-white/5",children:(0,Je.jsx)("div",{className:"max-h-96 overflow-auto",style:{scrollbarGutter:"auto"},children:(0,Je.jsx)(bi,{variant:"card",canWrite:!1,runContent:l.run,source:r,repo:a,path:e.path,mode:n,agentId:s,projectId:i})})}):null]})});function sp({target:t,agentId:e,projectId:n}){let r=H(x=>x.client),[a,s]=(0,ns.useState)(null),i=Pc(a),[o,l]=(0,ns.useState)({phase:"loading"}),[u,c]=(0,ns.useState)(null),{source:d}=t,f=t.repo??"",h=t.kind==="commit"?`c:${f}:${t.sha}`:`o:${f}:${t.base}..${t.head}`;(0,ns.useEffect)(()=>{if(l({phase:"loading"}),c(null),!e||!d)return;let x=!1;return(async()=>{try{if(t.kind==="commit"){let y=await cc({agentId:e,...n?{projectId:n}:{},source:d,...f?{repo:f}:{},sha:t.sha},r);if(x)return;y.ok===!1?l({phase:"unavailable"}):l({phase:"ready",files:y.files,range:null});try{let b=await uc({agentId:e,...n?{projectId:n}:{},source:d,...f?{repo:f}:{},maxCount:1,ref:t.sha},r),C=Array.isArray(b?.commits)?b.commits[0]:void 0;!x&&C&&c({author:C.author,date:C.date})}catch{}}else{let y=await cl({agentId:e,...n?{projectId:n}:{},source:d,...f?{repo:f}:{}},r);if(x)return;!y.ok||!y.baseSha||!y.headSha?l({phase:"no-upstream"}):l({phase:"ready",files:Array.isArray(y.files)?y.files:[],range:{base:y.baseSha,head:y.headSha}})}}catch(y){if(x)return;l({phase:"error",message:y instanceof Error?y.message:"Change-set failed"})}})(),()=>{x=!0}},[e,n,d,h]);let p=t.kind==="commit"?t:null,g=p!==null,m=o.phase==="ready"&&o.range?`${tn(o.range.base)}..${tn(o.range.head)}`:t.kind==="outgoing"?`${tn(t.base)}..${tn(t.head)}`:"";return(0,Je.jsxs)("div",{className:"flex h-full w-full min-h-0 flex-col",children:[(0,Je.jsx)("div",{className:"flex shrink-0 items-center gap-2 px-3 py-1.5 text-[11px]",style:{borderBottom:"1px solid rgba(255,255,255,0.05)"},children:p?(0,Je.jsxs)(Je.Fragment,{children:[(0,Je.jsx)(Dr,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/80"}),(0,Je.jsx)("span",{className:"shrink-0 rounded bg-white/[0.06] px-1.5 py-0.5 font-mono text-[10px] text-violet-200/90",children:tn(p.sha)}),(0,Je.jsx)("span",{className:"min-w-0 truncate font-medium text-white/85",children:p.subject}),u?(0,Je.jsxs)("span",{className:"ml-auto shrink-0 text-[10px] text-white/40",children:[u.author," \xB7 ",oM(u.date)]}):null]}):(0,Je.jsxs)(Je.Fragment,{children:[(0,Je.jsx)(Mr,{className:"h-3.5 w-3.5 shrink-0 text-blue-300/80"}),(0,Je.jsx)("span",{className:"shrink-0 font-medium text-white/85",children:"Outgoing changes"}),(0,Je.jsx)("span",{className:"truncate font-mono text-[10px] text-white/40",children:m}),(0,Je.jsx)("span",{className:"ml-auto shrink-0 text-[10px] text-white/35",title:"Computed from local refs (last fetch) \u2014 fetching/pulling remotes lands in a later increment.",children:"Local refs only \u2014 fetch lands later"})]})}),(0,Je.jsx)("div",{ref:s,className:"min-h-0 flex-1 overflow-auto px-2 py-2",children:o.phase==="loading"?(0,Je.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-[11px] text-white/40",children:[(0,Je.jsx)(We,{className:"h-3.5 w-3.5 animate-spin"}),"Loading changes\u2026"]}):o.phase==="error"?(0,Je.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-4 text-[11px] text-rose-300/70",children:[(0,Je.jsx)(ot,{className:"h-3.5 w-3.5 shrink-0"}),(0,Je.jsx)("span",{className:"truncate",children:o.message})]}):o.phase==="unavailable"?(0,Je.jsx)("div",{className:"px-3 py-6 text-center text-[11px] text-white/35",children:"Commit details unavailable \u2014 the commit may no longer exist in this repository."}):o.phase==="no-upstream"?(0,Je.jsx)("div",{className:"px-3 py-6 text-center text-[11px] text-white/35",children:"No upstream to compare against \u2014 everything here is local."}):o.files.length===0?(0,Je.jsx)("div",{className:"px-3 py-6 text-center text-[11px] text-white/35",children:g?"This commit changed no files.":"Nothing outgoing \u2014 the upstream is up to date."}):(0,Je.jsx)("div",{className:"flex flex-col gap-1.5",children:o.files.map(x=>(0,Je.jsx)(lM,{file:x,mode:p?{kind:"commit",sha:p.sha}:{kind:"range",base:o.range?.base??"",head:o.range?.head??""},source:d,repo:f,agentId:e,projectId:n,defaultExpanded:!0,queue:i},x.path))})})]})}var ae=j(ie(),1),Er=30,p1=16,up=14,u1=4.5,od=["#cba6f7","#a6e3a1","#f9e2af","#f38ba8","#94e2d5","#fab387","#b4befe","#89b4fa"];function op(t){return od[(t%od.length+od.length)%od.length]}var lp=t=>up+t*p1;function uM(){let t=null,e=new Set;return{get:()=>t,set:n=>{let r=typeof n=="function"?n(t):n;if(r!==t){t=r;for(let a of e)a()}},subscribe:n=>(e.add(n),()=>{e.delete(n)})}}var cM=null,dM=()=>cM;function fM({store:t,commits:e,expandedShas:n}){let r=nt.default.useSyncExternalStore(t.subscribe,t.get,dM);if(!r||n.has(r.sha))return null;let a=e.find(s=>s.sha===r.sha);return a?(0,ae.jsxs)("div",{className:"pointer-events-none absolute z-30 overflow-hidden rounded-md border border-white/10 bg-[#1b1b26] px-2.5 py-2 shadow-lg shadow-black/50",style:{left:up,right:8,maxHeight:"55%",...r.flip?{bottom:r.above}:{top:r.below}},children:[(0,ae.jsx)("div",{className:"whitespace-pre-wrap break-words text-[11px] font-medium leading-snug text-white/90",children:a.subject||"(no message)"}),a.body?(0,ae.jsx)("div",{className:"mt-1 whitespace-pre-wrap break-words text-[10px] leading-snug text-white/55",children:a.body}):null,(0,ae.jsxs)("div",{className:"mt-1.5 flex items-center gap-2 text-[10px] text-white/40",children:[(0,ae.jsx)("span",{className:"font-mono",children:tn(a.sha)}),(0,ae.jsx)("span",{className:"min-w-0 truncate",children:a.author}),(0,ae.jsx)("span",{children:Ah(a.date)})]})]}):null}function c1(t){let e=lp(t.fromLane),n=lp(t.toLane),r=t.fromY==="edge"?0:Er/2,a=t.toY==="edge"?Er:Er/2;if(e===n)return`M${e} ${r} L${n} ${a}`;if(t.toY==="edge"){let i=2*n-e;return`M${e} ${r} C ${e} ${(r+a)/2} ${(3*e+i)/4} ${(r+3*a)/4} ${n} ${a}`}let s=2*e-n;return`M${e} ${r} C ${(s+3*n)/4} ${(3*r+a)/4} ${n} ${(r+a)/2} ${n} ${a}`}function hM(t){return(t.split("->").pop()??t).replace(/^tag:\s*/,"").trim()}function d1(t,e){(t.key==="Enter"||t.key===" ")&&(t.preventDefault(),e())}function pM({file:t,onClick:e,showCounts:n}){let r=t.path.lastIndexOf("/"),a=r<0?t.path:t.path.slice(r+1),s=r<0?"":t.path.slice(0,r),i=(t.status[0]??"M").toUpperCase(),o=fo(t.path);return(0,ae.jsxs)("button",{type:"button",onClick:()=>e(t),className:"flex w-full min-w-0 items-center gap-1.5 overflow-hidden rounded-md py-1 pl-2 pr-1.5 text-left transition-colors hover:bg-white/[0.05]",title:t.renamedFrom?`${t.renamedFrom} \u2192 ${t.path}`:t.path,children:[(0,ae.jsx)(o,{className:"h-4 w-4 shrink-0 text-white/55"}),(0,ae.jsx)("span",{className:"shrink-0 truncate text-xs text-white/85",children:a}),s?(0,ae.jsx)("span",{className:"min-w-0 flex-1 truncate text-[10px] text-white/35",children:s}):(0,ae.jsx)("span",{className:"flex-1"}),n?(0,ae.jsx)(Aa,{added:t.added,removed:t.removed,binary:t.binary,className:"mr-1"}):null,(0,ae.jsx)("span",{className:$("shrink-0 text-[10px] font-bold leading-none tabular-nums",ap[i]??"text-white/60"),"aria-label":`Status: ${id[i]??"Changed"}`,children:i})]})}function f1({entry:t,emptyText:e,unavailableText:n,onFileClick:r,showCounts:a}){return t.status==="loading"?(0,ae.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 text-[10px] text-white/40",children:[(0,ae.jsx)(h1.LiveSpinner,{className:"h-3 w-3"}),"Loading files\u2026"]}):t.status==="error"?(0,ae.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 text-[10px] text-rose-300/70",children:[(0,ae.jsx)(ot,{className:"h-3 w-3 shrink-0"}),(0,ae.jsx)("span",{className:"truncate",children:t.message})]}):t.status==="unavailable"?(0,ae.jsx)("div",{className:"px-2 py-1 text-[10px] text-white/35",children:n}):t.files.length===0?(0,ae.jsx)("div",{className:"px-2 py-1 text-[10px] text-white/35",children:e}):(0,ae.jsx)("div",{className:"space-y-px",children:t.files.map(s=>(0,ae.jsx)(pM,{file:s,onClick:r,showCounts:a},s.path))})}function m1({source:t,repo:e="",agentId:n,projectId:r,repoName:a,showCounts:s=!0,onOutgoingStat:i}){let o=H(ue=>ue.client),[l,u]=(0,nt.useState)(Ih),[c,d]=(0,nt.useState)(!1),[f,h]=(0,nt.useState)(null),p=(0,nt.useRef)(0),g=(0,nt.useRef)(!1),m=(0,nt.useRef)(!1),x=(0,nt.useRef)(l);x.current=l;let[y,b]=(0,nt.useState)(()=>new Set),[C,L]=(0,nt.useState)(!1),[P,w]=(0,nt.useState)(()=>new Map),[k,_]=(0,nt.useState)({status:"idle"}),M=(0,nt.useRef)(null),R=(0,nt.useRef)(null);R.current===null&&(R.current=uM());let U=R.current,v=(0,nt.useRef)(0),T=(0,nt.useRef)(0),V=H(ue=>ue.gitLogNonce),Y=H(ue=>ue.setGitDiffTarget),N=H(ue=>ue.setGitCommitTarget),A=H(ue=>ue.setActiveWorkspaceTab),[B,K]=(0,nt.useState)(null),[te,ne]=(0,nt.useState)(null),[pe,Se]=(0,nt.useState)({}),le=(0,nt.useRef)(s);le.current=s;let re=(0,nt.useRef)(i);re.current=i;let he=(0,nt.useCallback)(async(ue,be,Ge)=>{if(!n||!t)return;let Re=++p.current;g.current=!0,d(!0),h(null);try{let Te=await uc({agentId:n,...r?{projectId:r}:{},source:t,...e?{repo:e}:{},maxCount:be,skip:ue},o);if(Re!==p.current)return;let vt={commits:Array.isArray(Te?.commits)?Te.commits:[],hasMore:Te?.hasMore===!0,outgoing:Array.isArray(Te?.outgoing)?Te.outgoing:void 0};u(mt=>Ge==="append"?ww(mt,vt):vw(vt)),le.current&&D0({agentId:n,...r?{projectId:r}:{},source:t,...e?{repo:e}:{},maxCount:be,skip:ue},o).then(mt=>{Re===p.current&&(Se(Gt=>Ge==="append"?{...Gt,...mt.stats}:{...mt.stats}),Ge==="replace"&&re.current?.(mt.outgoingStat??null))}).catch(()=>{}),Ge==="replace"&&(T.current++,_(mt=>mt.status==="idle"?mt:{status:"idle"})),d(!1)}catch(Te){if(Re!==p.current)return;h(Te instanceof Error?Te.message:"Git log failed"),d(!1)}finally{Re===p.current&&(g.current=!1)}},[n,r,t,e]);(0,nt.useEffect)(()=>{if(p.current++,g.current=!1,v.current++,T.current++,u(Ih),h(null),b(new Set),L(!1),w(new Map),_({status:"idle"}),!n||!t){d(!1);return}he(0,200,"replace")},[n,r,t,he]);let Ne=(0,nt.useRef)(V);(0,nt.useEffect)(()=>{V!==Ne.current&&(Ne.current=V,!(!n||!t)&&he(0,Lh(x.current.commits.length),"replace"))},[V,n,t,he]),(0,nt.useEffect)(()=>{if(!B||!te||(m.current=!1,typeof IntersectionObserver>"u"))return;let ue=new IntersectionObserver(be=>{for(let Re of be)m.current=Re.isIntersecting;if(!m.current)return;let Ge=x.current;!Ge.hasMore||g.current||he(Ge.nextSkip,200,"append")},{root:B,rootMargin:"120px"});return ue.observe(te),()=>ue.disconnect()},[B,te,he]),(0,nt.useEffect)(()=>{c||f!==null||!m.current||g.current||l.hasMore&&he(l.nextSkip,200,"append")},[l,c,f,he]);let Ee=(0,nt.useCallback)(async ue=>{if(!n||!t)return;let be=v.current;w(Ge=>new Map(Ge).set(ue,{status:"loading"}));try{let Ge=await cc({agentId:n,...r?{projectId:r}:{},source:t,...e?{repo:e}:{},sha:ue},o);if(be!==v.current)return;w(Re=>new Map(Re).set(ue,Ge.ok===!1?{status:"unavailable"}:{status:"ready",files:Array.isArray(Ge.files)?Ge.files:[]}))}catch(Ge){if(be!==v.current)return;w(Re=>new Map(Re).set(ue,{status:"error",message:Ge instanceof Error?Ge.message:"Commit files failed"}))}},[n,r,t,e]),ze=l.commits,ct=Fs(t,a),it=(0,nt.useMemo)(()=>xw(ze),[ze]),Qe=Math.max(40,up+it.laneCount*p1+8),Ye=(0,nt.useMemo)(()=>kw(ze,l.outgoing),[ze,l.outgoing]),Lt=(0,nt.useMemo)(()=>new Set(l.outgoing??[]),[l.outgoing]),Le=(0,nt.useMemo)(()=>Ye.some(ue=>ue.kind==="outgoing-divider"),[Ye]);(0,nt.useEffect)(()=>{if(!C||k.status!=="idle"||!Le||!n||!t)return;let ue=++T.current;_({status:"loading"}),(async()=>{try{let be=await cl({agentId:n,...r?{projectId:r}:{},source:t,...e?{repo:e}:{}},o);if(ue!==T.current)return;!be.ok||!be.baseSha||!be.headSha?_({status:"no-upstream"}):_({status:"ready",base:be.baseSha,head:be.headSha,files:Array.isArray(be.files)?be.files:[]})}catch(be){if(ue!==T.current)return;_({status:"error",message:be instanceof Error?be.message:"Outgoing changes failed"})}})()},[C,k.status,Le,n,r,t,e]);let at=lo({count:Ye.length,getScrollElement:()=>B,estimateSize:()=>Er,overscan:12,getItemKey:ue=>Sw(Ye[ue],ze)}),ft=()=>{!n||!t||he(0,Lh(x.current.commits.length),"replace")},bt=(ue,be)=>{if(y.has(ue)){at.resizeItem(be,Er),b(Re=>{let Te=new Set(Re);return Te.delete(ue),Te});return}b(Re=>new Set(Re).add(ue));let Ge=P.get(ue);(!Ge||Ge.status==="error")&&Ee(ue)},At=ue=>{let be=!C;be||at.resizeItem(ue,Er),be&&k.status==="error"&&_({status:"idle"}),L(be)},Tt=e?{repo:e}:{},Ue=(ue,be)=>{t&&(Y({source:t,...Tt,path:be.path,commit:ue}),A("git-diff"))},me=ue=>{t&&(N({source:t,...Tt,kind:"commit",sha:ue.sha,subject:ue.subject}),A("git-commit"))},Ot=ue=>{!t||k.status!=="ready"||(Y({source:t,...Tt,path:ue.path,base:k.base,head:k.head}),A("git-diff"))},Jt=()=>{if(!t||!n)return;if(k.status==="ready"){N({source:t,...Tt,kind:"outgoing",base:k.base,head:k.head}),A("git-commit");return}let ue=++T.current;_({status:"loading"}),(async()=>{try{let be=await cl({agentId:n,...r?{projectId:r}:{},source:t,...e?{repo:e}:{}},o);if(ue!==T.current)return;if(!be.ok||!be.baseSha||!be.headSha){_({status:"no-upstream"});return}_({status:"ready",base:be.baseSha,head:be.headSha,files:Array.isArray(be.files)?be.files:[]}),N({source:t,...Tt,kind:"outgoing",base:be.baseSha,head:be.headSha}),A("git-commit")}catch(be){if(ue!==T.current)return;_({status:"error",message:be instanceof Error?be.message:"Outgoing changes failed"})}})()};return(0,ae.jsxs)("div",{ref:M,className:"relative flex h-full w-full min-h-0 flex-col",children:[(0,ae.jsxs)("div",{className:"flex shrink-0 items-center gap-2 px-3 py-1.5 text-[11px]",style:{borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[(0,ae.jsx)(Dr,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/80"}),(0,ae.jsx)("span",{className:"shrink-0 font-medium text-white/85",children:"Commit graph"}),ct.prefix?(0,ae.jsxs)(ae.Fragment,{children:[(0,ae.jsx)("span",{className:"shrink-0 font-mono text-white/40",children:ct.prefix}),(0,ae.jsx)("span",{className:"truncate font-medium text-white/85",children:ct.name})]}):(0,ae.jsx)("span",{className:"truncate font-mono text-white/40",children:ct.name}),(0,ae.jsxs)("span",{className:"ml-auto shrink-0 tabular-nums text-white/40",children:[ze.length,l.hasMore?"+":""," commit",ze.length===1?"":"s"]}),(0,ae.jsx)("button",{type:"button",onClick:ft,className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded text-white/40 transition-colors hover:bg-white/[0.06] hover:text-white/70",title:"Refresh commit graph","aria-label":"Refresh commit graph",children:(0,ae.jsx)(_t,{className:$("h-3 w-3",c&&"animate-spin")})})]}),f&&ze.length>0?(0,ae.jsxs)("div",{className:"flex shrink-0 items-center gap-1.5 border-b border-white/[0.05] px-3 py-1 text-[10px] text-rose-300/70",children:[(0,ae.jsx)(ot,{className:"h-3 w-3 shrink-0"}),(0,ae.jsx)("span",{className:"truncate",children:f})]}):null,(0,ae.jsx)("div",{ref:K,className:"min-h-0 flex-1 overflow-auto",children:f&&ze.length===0?(0,ae.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-4 text-[11px] text-rose-300/70",children:[(0,ae.jsx)(ot,{className:"h-3 w-3 shrink-0"}),f]}):c&&ze.length===0?(0,ae.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-[11px] text-white/40",children:[(0,ae.jsx)(We,{className:"h-3.5 w-3.5 animate-spin"}),"Loading commit graph\u2026"]}):ze.length===0?(0,ae.jsx)("div",{className:"px-3 py-6 text-center text-[11px] text-white/35",children:"No commits yet."}):(0,ae.jsxs)(ae.Fragment,{children:[(0,ae.jsx)("div",{style:{height:at.getTotalSize(),width:"100%",position:"relative"},children:at.getVirtualItems().map(ue=>{let be=Ye[ue.index];if(!be)return null;if(be.kind==="outgoing-divider"){let ee=k.status==="ready"?{status:"ready",files:k.files}:k.status==="error"?k:{status:"loading"},oe=Ye[ue.index+1],He=yw(it.rowSegments,oe?.kind==="commit"?oe.row:-1);return(0,ae.jsxs)("div",{"data-index":ue.index,ref:C?at.measureElement:void 0,className:"absolute left-0 top-0 w-full",style:{transform:`translateY(${ue.start}px)`},children:[(0,ae.jsxs)("div",{role:"button",tabIndex:0,onClick:()=>At(ue.index),onKeyDown:Ve=>d1(Ve,()=>At(ue.index)),className:$("group flex w-full min-w-0 cursor-pointer items-center gap-1.5 text-[11px] transition-colors hover:bg-white/[0.04]",He.length>0?"pr-2":"px-2"),style:{height:Er},title:"The blue hollow dots mark commits not yet pushed to origin (local refs only, from the last known upstream). On a diverged/interleaved history this divider is an approximate boundary \u2014 the dots are the source of truth.",children:[He.length>0?(0,ae.jsx)("svg",{"data-divider-lanes":!0,width:Qe,height:Er,className:"shrink-0",style:{display:"block"},"aria-hidden":!0,children:He.map((Ve,Ae)=>(0,ae.jsx)("path",{d:c1(Ve),fill:"none",stroke:op(Ve.colorLane),strokeWidth:1.5,strokeOpacity:.55,strokeLinecap:"round"},Ae))}):null,C?(0,ae.jsx)(Et,{className:"h-3 w-3 shrink-0 text-white/40"}):(0,ae.jsx)(un,{className:"h-3 w-3 shrink-0 text-white/40"}),(0,ae.jsx)(Mr,{className:"h-3 w-3 shrink-0 text-blue-300/80"}),(0,ae.jsx)("span",{className:"shrink-0 text-[9px] font-bold uppercase tracking-wider text-blue-200/85",children:"Outgoing changes"}),(0,ae.jsx)("span",{className:"shrink-0 rounded bg-blue-400/15 px-1 py-0.5 text-[9px] leading-none tabular-nums text-blue-100/80",children:l.outgoing?.length??0}),(0,ae.jsx)("span",{className:"h-px min-w-0 flex-1 bg-blue-400/20","aria-hidden":!0}),(0,ae.jsx)("button",{type:"button",onClick:Ve=>{Ve.stopPropagation(),Jt()},className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded text-white/40 opacity-0 transition group-hover:opacity-100 focus-visible:opacity-100 hover:bg-white/10 hover:text-white/75",title:"Open Changes (all outgoing files)","aria-label":"Open outgoing changes",children:(0,ae.jsx)(ro,{className:"h-3 w-3"})})]}),C?(0,ae.jsx)("div",{className:"border-t border-white/[0.05] pb-1.5 pl-1 pr-2 pt-1",children:k.status==="no-upstream"?(0,ae.jsx)("div",{className:"px-2 py-1 text-[10px] text-white/35",children:"No upstream to compare against."}):(0,ae.jsx)(f1,{entry:ee,emptyText:"Nothing outgoing \u2014 the upstream is up to date.",unavailableText:"Outgoing changes unavailable.",onFileClick:Ot,showCounts:s})}):null]},ue.key)}let Ge=it.nodes[be.row];if(!Ge)return null;let Re=Ge.commit,Te=it.rowSegments[be.row]??[],vt=lp(Ge.lane),mt=op(Ge.lane),Gt=Re.refs??[],je=y.has(Re.sha),kt=Iw(Ge.isMerge,Lt.has(Re.sha)),on=Lw(kt,mt),Oe=P.get(Re.sha);return(0,ae.jsxs)("div",{"data-index":ue.index,ref:je?at.measureElement:void 0,className:"absolute left-0 top-0 w-full",style:{transform:`translateY(${ue.start}px)`},children:[(0,ae.jsxs)("div",{role:"button",tabIndex:0,"data-sha":Re.sha,onClick:()=>bt(Re.sha,ue.index),onKeyDown:ee=>d1(ee,()=>bt(Re.sha,ue.index)),onMouseEnter:ee=>{if(je)return;let oe=M.current;if(!oe)return;let He=oe.getBoundingClientRect(),Ve=ee.currentTarget.getBoundingClientRect(),Ae=Ve.bottom-He.top,ce=He.bottom-Ve.top;U.set({sha:Re.sha,below:Ae,above:ce,flip:Ae>He.height*.55})},onMouseLeave:()=>U.set(ee=>ee&&ee.sha===Re.sha?null:ee),className:"group/commit relative flex min-w-0 cursor-pointer items-center text-[11px] transition-colors hover:bg-white/[0.04]",style:{height:Er},children:[(0,ae.jsxs)("svg",{width:Qe,height:Er,className:"shrink-0",style:{display:"block"},"aria-hidden":!0,children:[Te.map((ee,oe)=>(0,ae.jsx)("path",{d:c1(ee),fill:"none",stroke:op(ee.colorLane),strokeWidth:1.5,strokeOpacity:ee.kind==="stub"?.3:.55,strokeDasharray:ee.kind==="stub"?"2 3":void 0,strokeLinecap:"round"},oe)),Ge.isHead?(0,ae.jsx)("circle",{cx:vt,cy:Er/2,r:u1+2.5,fill:"none",stroke:on,strokeWidth:1.5,strokeOpacity:.7}):null,(0,ae.jsx)("circle",{cx:vt,cy:Er/2,r:u1,fill:kt==="outgoing"?"transparent":kt==="merge"?"rgba(0,0,0,0.35)":mt,stroke:on,strokeWidth:kt==="filled"?1:1.5,fillOpacity:kt==="filled"?.9:1})]}),(0,ae.jsxs)("div",{className:"flex min-w-0 flex-1 items-center gap-2 pr-1",children:[je?(0,ae.jsx)(Et,{className:"h-3 w-3 shrink-0 text-white/35"}):(0,ae.jsx)(un,{className:"h-3 w-3 shrink-0 text-white/25"}),Gt.length?(0,ae.jsx)("span",{className:"flex shrink-0 items-center gap-1",children:Gt.slice(0,3).map(ee=>{let oe=Cw(ee);return(0,ae.jsxs)("span",{className:$("flex max-w-[120px] items-center gap-0.5 rounded px-1 py-0.5 text-[9px] font-medium leading-none",oe==="tag"?"bg-amber-400/15 text-amber-100/80":oe==="remote"?"border border-white/20 bg-transparent text-white/55":"bg-violet-400/20 text-violet-100/90"),children:[oe==="remote"?(0,ae.jsx)(vl,{className:"h-2 w-2 shrink-0","aria-hidden":!0}):null,(0,ae.jsx)("span",{className:"truncate",children:hM(ee)})]},ee)})}):null,(0,ae.jsx)("span",{className:"min-w-0 flex-1 truncate text-white/82",children:Re.subject||"(no message)"}),(0,ae.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/35 transition-opacity group-hover/commit:opacity-0",children:tn(Re.sha)}),(0,ae.jsx)("span",{className:"hidden shrink-0 max-w-[120px] truncate text-[10px] text-white/40 transition-opacity group-hover/commit:opacity-0 sm:inline",children:Re.author}),s&&pe[Re.sha]?(0,ae.jsx)(Aa,{...pe[Re.sha],compact:!0,className:"transition-opacity group-hover/commit:opacity-0"}):null,(0,ae.jsx)("button",{type:"button",onClick:ee=>{ee.stopPropagation(),me(Re)},className:"absolute right-1 top-1/2 inline-flex h-5 w-5 -translate-y-1/2 items-center justify-center rounded bg-white/10 text-white/50 opacity-0 transition group-hover/commit:opacity-100 focus-visible:opacity-100 hover:bg-white/20 hover:text-white/85",title:"Open Changes (all files in this commit)","aria-label":`Open changes of commit ${tn(Re.sha)}`,children:(0,ae.jsx)(ro,{className:"h-3 w-3"})})]})]}),je?(0,ae.jsxs)("div",{className:"pb-1.5 pl-1 pr-2 pt-0.5",children:[(0,ae.jsxs)("div",{className:"flex items-center gap-2 px-2 text-[10px] text-white/40",children:[(0,ae.jsx)("span",{className:"font-mono",children:tn(Re.sha)}),(0,ae.jsx)("span",{className:"min-w-0 truncate",children:Re.author}),(0,ae.jsx)("span",{title:Re.date,children:Ah(Re.date)})]}),(0,ae.jsx)("div",{className:"mt-1 border-t border-white/[0.05] pt-1",children:(0,ae.jsx)(f1,{entry:Oe??{status:"loading"},emptyText:"This commit changed no files.",unavailableText:"Commit details unavailable \u2014 the commit may no longer exist.",onFileClick:ee=>Ue(Re.sha,ee),showCounts:s})})]}):null]},ue.key)})}),l.hasMore?(0,ae.jsxs)("div",{ref:ne,className:"flex items-center justify-center gap-1.5 px-3 py-2 text-[11px] text-white/40",children:[(0,ae.jsx)(We,{className:$("h-3 w-3",c&&"animate-spin")}),"Loading more commits\u2026"]}):null]})}),(0,ae.jsx)(fM,{store:U,commits:ze,expandedShas:y})]})}var pn=j($e(),1);function su(t){return Number.isFinite(t)?Math.min(20,Math.max(.05,t)):1}function g1(t){return t>0&&t<1?1/t:1}function x1(t){if(!t)return{};try{let e=JSON.parse(t);if(!e||typeof e!="object"||Array.isArray(e))return{};let n={};for(let[r,a]of Object.entries(e)){if(!a||typeof a!="object"||Array.isArray(a))continue;let s=a;typeof s.collapsed!="boolean"||typeof s.weight!="number"||(n[r]={collapsed:s.collapsed,weight:su(s.weight)})}return n}catch{return{}}}function y1(t){return JSON.stringify(t)}function iu(t,e,n,r=1){return t[e]??{collapsed:n,weight:su(r)}}function b1(t,e,n,r,a=1){let s=iu(t,e,r,a),i=!n&&s.weight<.15?su(a):s.weight;return{...t,[e]:{collapsed:n,weight:i}}}function w1(t){let e=t.minBodyPx??72,n=t.heightAbove+t.heightBelow,r=t.weightAbove+t.weightBelow;if(!(n>0)||!(r>0)||n<e*2)return{above:t.weightAbove,below:t.weightBelow};let a=Math.min(n-e,Math.max(e,t.heightAbove+t.deltaY)),s=su(r*(a/n)),i=su(r-s);return{above:s,below:i}}var Or=j(ie(),1),mM=4;function gM(t){if(typeof window>"u")return{};try{return x1(window.localStorage.getItem(t))}catch{return{}}}function v1({sections:t,storageKey:e}){let[n,r]=(0,pn.useState)(()=>gM(e)),[a,s]=(0,pn.useState)(!1),i=(0,pn.useRef)(n);i.current=n;let o=(0,pn.useRef)(new Map),l=(0,pn.useRef)(null),u=(0,pn.useRef)(!1),c=(0,pn.useCallback)(w=>{if(typeof window<"u")try{window.localStorage.setItem(e,y1(w))}catch{}},[e]),d=(0,pn.useCallback)((w,k,_)=>{r(M=>{let R=iu(M,w,k,_),U=b1(M,w,!R.collapsed,k,_);return c(U),U})},[c]),f=(0,pn.useCallback)((w,k,_,M,R,U,v)=>{let T=o.current.get(k),V=o.current.get(_);U&&w.preventDefault(),l.current={aboveId:k,belowId:_,startY:w.clientY,weightAbove:M,weightBelow:R,heightAbove:T?.getBoundingClientRect().height??0,heightBelow:V?.getBoundingClientRect().height??0,engaged:U,belowCollapsed:v,expanded:!1,rebaselined:!1},u.current=!1,s(U),w.currentTarget.setPointerCapture(w.pointerId)},[]),h=(0,pn.useCallback)((w,k,_,M,R,U)=>{f(w,k,_,M,R,!0,U)},[f]),p=(0,pn.useCallback)((w,k,_,M,R,U)=>{w.button===0&&f(w,k,_,M,R,!1,U)},[f]),g=(0,pn.useCallback)(()=>{l.current&&(l.current=null,s(!1),c(i.current))},[c]);(0,pn.useEffect)(()=>{if(a)return window.addEventListener("pointerup",g),window.addEventListener("pointercancel",g),()=>{window.removeEventListener("pointerup",g),window.removeEventListener("pointercancel",g)}},[a,g]);let m=(0,pn.useCallback)(w=>{let k=l.current;if(!k)return;if((w.buttons&1)===0){g();return}let _=w.clientY-k.startY;if(!k.engaged){if(Math.abs(_)<mM)return;k.engaged=!0,u.current=!0,s(!0)}if(k.belowCollapsed&&!k.expanded){k.expanded=!0,r(U=>({...U,[k.belowId]:{collapsed:!1,weight:k.weightBelow}}));return}if(k.belowCollapsed&&!k.rebaselined){let U=o.current.get(k.belowId);if(!U)return;let v=o.current.get(k.aboveId);k.heightAbove=v?.getBoundingClientRect().height??k.heightAbove,k.heightBelow=U.getBoundingClientRect().height,k.startY=w.clientY,k.weightAbove=i.current[k.aboveId]?.weight??k.weightAbove,k.weightBelow=i.current[k.belowId]?.weight??k.weightBelow,k.rebaselined=!0;return}let{above:M,below:R}=w1({weightAbove:k.weightAbove,weightBelow:k.weightBelow,heightAbove:k.heightAbove,heightBelow:k.heightBelow,deltaY:_});r(U=>({...U,[k.aboveId]:{...U[k.aboveId]??{collapsed:!1,weight:1},weight:M},[k.belowId]:{...U[k.belowId]??{collapsed:!1,weight:1},weight:R}}))},[g]),x=(0,pn.useCallback)(w=>{w.currentTarget.hasPointerCapture(w.pointerId)&&w.currentTarget.releasePointerCapture(w.pointerId),g()},[g]),y=(0,pn.useCallback)((w,k,_,M)=>{let R=l.current?.engaged??!1,U=l.current!=null;w.currentTarget.hasPointerCapture(w.pointerId)&&w.currentTarget.releasePointerCapture(w.pointerId),g(),U&&!R&&d(k,_,M)},[g,d]),b=t.reduce((w,k)=>{let _=iu(n,k.id,k.defaultCollapsed??!1,k.defaultWeight??1);return _.collapsed?w:w+_.weight},0),C=g1(b),L=[],P=null;for(let w of t){let k=w.defaultCollapsed??!1,_=w.defaultWeight??1,M=iu(n,w.id,k,_),R=P&&!P.collapsed?P:null,U=M.collapsed?_:M.weight;R&&L.push((0,Or.jsx)("div",{role:"separator","aria-orientation":"horizontal",onPointerDown:v=>h(v,R.id,w.id,R.weight,U,M.collapsed),onPointerMove:m,onPointerUp:x,onPointerCancel:g,onLostPointerCapture:g,className:"relative h-1.5 shrink-0 cursor-row-resize touch-none bg-white/0 transition hover:bg-white/[0.06]",children:(0,Or.jsx)("div",{className:"absolute inset-x-6 top-1/2 h-[2px] -translate-y-1/2 rounded-full bg-white/[0.07]"})},`h:${R.id}:${w.id}`)),L.push((0,Or.jsxs)("div",{onPointerDown:R?v=>{v.target.closest("[data-section-actions]")||p(v,R.id,w.id,R.weight,U,M.collapsed)}:void 0,onPointerMove:R?m:void 0,onPointerUp:R?v=>y(v,w.id,k,_):void 0,onPointerCancel:R?g:void 0,onLostPointerCapture:R?g:void 0,className:$("group/section flex h-7 shrink-0 items-center gap-1.5 border-t border-white/[0.04] px-1 first:border-t-0",R&&"touch-none"),children:[(0,Or.jsxs)("button",{type:"button",onClick:v=>{R&&v.detail!==0||d(w.id,k,_)},"aria-expanded":!M.collapsed,className:"flex h-full min-w-0 flex-1 items-center gap-1 rounded px-1 text-left transition-colors hover:bg-white/[0.04]",children:[(0,Or.jsx)(un,{className:$("h-3 w-3 shrink-0 text-white/40 transition-transform",!M.collapsed&&"rotate-90")}),(0,Or.jsx)("span",{className:"truncate text-[10px] font-bold uppercase tracking-wider text-white/40",children:w.title}),typeof w.count=="number"?(0,Or.jsx)("span",{className:"text-[9px] tabular-nums text-white/30",children:w.count}):null,w.badge]}),w.actions?(0,Or.jsx)("div",{"data-section-actions":!0,className:"ml-auto flex shrink-0 items-center gap-1 opacity-0 transition-opacity focus-within:opacity-100 group-hover/section:opacity-100",children:w.actions}):null]},`s:${w.id}`)),M.collapsed||L.push((0,Or.jsx)("div",{ref:v=>{v?o.current.set(w.id,v):o.current.delete(w.id)},className:"min-h-0 overflow-auto",style:{flexGrow:M.weight*C,flexBasis:0},children:w.content},`b:${w.id}`)),P={id:w.id,collapsed:M.collapsed,weight:M.weight}}return(0,Or.jsx)("div",{className:$("flex min-h-0 flex-1 flex-col overflow-hidden",a&&"cursor-row-resize select-none"),children:L})}var G=j(ie(),1);function cp(t,e,n){(0,we.useEffect)(()=>{if(!t)return;let r=a=>{let s=a.target;s instanceof Node&&e.current?.contains(s)||n()};return document.addEventListener("mousedown",r,!0),()=>document.removeEventListener("mousedown",r,!0)},[t,e,n])}var xM="neuralis.filesystem.gitPanel.sections",k1="neuralis.filesystem.gitPanel.commitOpen",S1="neuralis.filesystem.gitPanel.diffCounts";function yM(t){return typeof t!="string"||!t?"":t.includes("://")?qe(t):t}function bM(t){let e=t.lastIndexOf("/");return e<0?{name:t,dir:""}:{name:t.slice(e+1),dir:t.slice(0,e)}}function wM(t){let e={name:"",path:"",children:new Map};for(let n of t){let r=n.path.split("/").filter(Boolean),a=e,s="";for(let i=0;i<r.length;i++){let o=r[i];s=s?`${s}/${o}`:o;let l=a.children.get(o);l||(l={name:o,path:s,children:new Map},a.children.set(o,l)),a=l,i===r.length-1&&(a.change=n)}}return e}function N1(t,e){let n=[],r=[...t.children.values()].sort((a,s)=>{let i=a.children.size>0,o=s.children.size>0;return i!==o?i?-1:1:a.name.localeCompare(s.name)});for(let a of r)n.push({node:a,depth:e}),a.children.size>0&&n.push(...N1(a,e+1));return n}var C1=Object.freeze({}),I1=we.default.memo(function({change:e,onClick:n,actions:r,busy:a,showCounts:s}){let{name:i,dir:o}=bM(e.path),l=fo(e.path),u=d=>d.stopPropagation(),c=!!(r.onDiscard||r.onUnstage||r.onStage);return(0,G.jsxs)("div",{className:"group/row relative flex w-full items-center rounded-md pr-1.5 transition-colors hover:bg-white/[0.05]",children:[(0,G.jsxs)("button",{type:"button",onClick:()=>n(e),title:e.origPath?`${e.origPath} \u2192 ${e.path}`:e.path,className:"flex min-w-0 flex-1 items-center gap-1.5 overflow-hidden py-1 pl-2 pr-1 text-left",children:[(0,G.jsx)(l,{className:"h-4 w-4 shrink-0 text-white/55"}),(0,G.jsx)("span",{className:"shrink-0 truncate text-xs text-white/85",children:i}),o?(0,G.jsx)("span",{className:"min-w-0 flex-1 truncate text-[10px] text-white/35",children:o}):(0,G.jsx)("span",{className:"flex-1"})]}),s?(0,G.jsx)(Aa,{added:e.added,removed:e.removed,binary:e.binary,className:"mr-1 transition-opacity group-hover/row:opacity-0"}):null,(0,G.jsx)("span",{className:"flex w-3.5 shrink-0 items-center justify-center",children:(0,G.jsx)(Ac,{code:e.code})}),c?(0,G.jsxs)("div",{className:"absolute right-6 top-1/2 flex -translate-y-1/2 items-center gap-0.5 rounded bg-gradient-to-r from-transparent via-black/30 to-black/45 pl-4 opacity-0 transition-opacity group-hover/row:opacity-100 focus-within:opacity-100",children:[r.onDiscard?(0,G.jsx)("button",{type:"button",onClick:d=>{u(d),r.onDiscard(e)},disabled:a,className:"inline-flex h-5 w-5 items-center justify-center rounded text-rose-300/70 transition-colors hover:bg-rose-500/15 hover:text-rose-200 disabled:opacity-40",title:"Discard changes (destructive)","aria-label":`Discard changes to ${i}`,children:(0,G.jsx)(Nt,{className:"h-3 w-3"})}):null,r.onUnstage?(0,G.jsx)("button",{type:"button",onClick:d=>{u(d),r.onUnstage(e)},disabled:a,className:"inline-flex h-5 w-5 items-center justify-center rounded text-white/50 transition-colors hover:bg-white/10 hover:text-white/80 disabled:opacity-40",title:"Unstage","aria-label":`Unstage ${i}`,children:(0,G.jsx)(ai,{className:"h-3 w-3"})}):null,r.onStage?(0,G.jsx)("button",{type:"button",onClick:d=>{u(d),r.onStage(e)},disabled:a,className:"inline-flex h-5 w-5 items-center justify-center rounded text-emerald-300/80 transition-colors hover:bg-emerald-500/15 hover:text-emerald-200 disabled:opacity-40",title:"Stage","aria-label":`Stage ${i}`,children:(0,G.jsx)(Fn,{className:"h-3 w-3"})}):null]}):null]})});function L1({changes:t,viewMode:e,staged:n,onRowClick:r,actionsFor:a,busy:s,showCounts:i}){let o=(0,we.useMemo)(()=>e==="tree"?N1(wM(t),0):[],[t,e]),l=(0,we.useCallback)(u=>r(u,n),[r,n]);return(0,G.jsx)("div",{className:"px-1 py-0.5",children:e==="list"?(0,G.jsx)("div",{className:"space-y-px",children:t.map(u=>(0,G.jsx)(I1,{change:u,onClick:l,actions:a(u),busy:s,showCounts:i},`${u.code}:${u.path}`))}):(0,G.jsx)("div",{className:"space-y-px",children:o.map(({node:u,depth:c})=>u.change?(0,G.jsx)("div",{style:{paddingLeft:`${c*12}px`},children:(0,G.jsx)(I1,{change:u.change,onClick:l,actions:a(u.change),busy:s,showCounts:i})},`f:${u.path}`):(0,G.jsxs)("div",{style:{paddingLeft:`${c*12}px`},className:"flex items-center gap-1.5 px-2 py-1 text-[11px] text-white/45",children:[(0,G.jsx)(Tr,{className:"h-3.5 w-3.5 shrink-0 text-white/35"}),(0,G.jsx)("span",{className:"truncate",children:u.name})]},`d:${u.path}`))})})}function dp({tone:t,onClick:e,disabled:n,title:r,children:a}){return(0,G.jsx)("button",{type:"button",onClick:e,disabled:n,className:$("rounded px-1 py-0.5 text-[9px] transition-colors disabled:opacity-40",t==="discard"?"text-rose-300/70 hover:bg-rose-500/15 hover:text-rose-200":t==="unstage"?"text-white/55 hover:bg-white/10 hover:text-white/85":"text-emerald-300/80 hover:bg-emerald-500/15 hover:text-emerald-200"),title:r,children:a})}function R1({agentId:t}){let e=H(D=>D.client),n=H(D=>D.sources),r=H(D=>D.activeProjectId),a=H(D=>D.activeSource),s=H(D=>D.activeRepoRel),i=H(D=>D.setActiveSource),o=H(D=>D.gitStatus),l=H(D=>D.gitTotals),u=H(D=>D.gitOutgoingStat),c=H(D=>D.setGitOutgoingStat),d=H(D=>D.gitLoading),f=H(D=>D.gitError),h=H(D=>D.gitViewMode),p=H(D=>D.setGitViewMode),g=H(D=>D.gitBranches),m=H(D=>D.loadGitStatus),x=H(D=>D.loadGitBranches),y=H(D=>D.setGitDiffTarget),b=H(D=>D.setActiveWorkspaceTab),C=H(D=>D.gitLogNonce),[L,P]=(0,we.useState)(!1),[w,k]=(0,we.useState)(!1),_=(0,we.useRef)(null),M=(0,we.useRef)(null),[R,U]=(0,we.useState)(!1),[v,T]=(0,we.useState)(!1),[V,Y]=(0,we.useState)(null),[N,A]=(0,we.useState)(""),[B,K]=(0,we.useState)(!1),[te,ne]=(0,we.useState)(()=>Ph(k1,!1)),[pe,Se]=(0,we.useState)(()=>Ph(S1,!0)),le=(0,we.useCallback)(()=>{Se(D=>{let xe=!D;return Nh(S1,xe),xe})},[]),[re,he]=(0,we.useState)(null),[Ne,Ee]=(0,we.useState)(null),[ze,ct]=(0,we.useState)(!1),it=(0,we.useCallback)(()=>P(!1),[]),Qe=(0,we.useCallback)(()=>{k(!1),ct(!1)},[]),Ye=(0,we.useCallback)(()=>U(!1),[]);cp(L,_,it),cp(w,M,Qe),cp(R,M,Ye);let[Lt,Le]=(0,we.useState)(""),[at,ft]=(0,we.useState)(""),bt=(0,we.useMemo)(()=>n.filter(D=>D.git?.isRepo||D.git?.containsRepos),[n]),At=(0,we.useMemo)(()=>bt.map(D=>D.uri_root).join("|"),[bt]),Tt=(0,we.useMemo)(()=>yM(a),[a]),Ue=(0,we.useMemo)(()=>bt.find(D=>qe(D.uri_root)===Tt)??bt[0]??null,[bt,Tt]),me=Ue?qe(Ue.uri_root):"",Ot=bt.length>1||bt.some(D=>!D.git?.isRepo&&D.git?.containsRepos),Jt=(0,we.useRef)(new Map),[ue,be]=(0,we.useState)(()=>new Map),Ge=(0,we.useCallback)(async(D,xe)=>{if(!t||!D)return[];let Mt=Jt.current.get(D);if(Mt&&(Mt instanceof Promise||!xe?.force))return Mt;let zt=(async()=>{try{let yn=await Ki({agentId:t,...r?{projectId:r}:{},source:D},e),Sn=Array.isArray(yn?.repos)?yn.repos:[];return Jt.current.set(D,Sn),be(nc=>new Map(nc).set(D,Sn)),Sn}catch{return Jt.current.delete(D),be(yn=>yn.has(D)?yn:new Map(yn).set(D,[])),[]}})();return Jt.current.set(D,zt),zt},[t,r]),Re=(0,we.useMemo)(()=>s?ue.get(me)?.find(D=>D.rel===s)??null:null,[s,ue,me]),Te=s?Re?.canWrite===!0:Ue?.git?.canWrite===!0,vt=s?Re?.canExec===!0:Ue?.git?.canExec===!0,mt=o?.staged.length??0,Gt=Fs(me,s?Re?.name??s:Ue?.git?.repoName),je=(0,we.useMemo)(()=>Aw(o),[o]);(0,we.useEffect)(()=>{me&&me!==Tt&&i(me)},[t,r,me,At]),(0,we.useEffect)(()=>{let D=Ue?.git;if(!me||!D||D.isRepo||!D.containsRepos)return;let xe=!1;return Ge(me).then(Mt=>{xe||s||Mt.length===0||i(me,Mt[0].rel)}),()=>{xe=!0}},[me,Ue,s,Ge,i]);let kt=(0,we.useRef)(C);(0,we.useEffect)(()=>{if(C===kt.current)return;kt.current=C;let D=Ue?.git;!me||!D||D.isRepo||!D.containsRepos||Ge(me,{force:!0})},[C,me,Ue,Ge]),(0,we.useEffect)(()=>{me&&m({agentId:t,projectId:r??null,source:me,repo:s})},[t,r,me,s,At]),(0,we.useEffect)(()=>{if(!Ne)return;let D=setTimeout(()=>Ee(null),9e3);return()=>clearTimeout(D)},[Ne]);let on=(0,we.useCallback)((D,xe)=>{P(!1),i(D,xe)},[i]),Oe=(0,we.useCallback)(()=>{k(!1),ct(!1),U(!1),P(D=>{let xe=!D;if(xe)for(let Mt of bt){let zt=Mt.git;zt&&!zt.isRepo&&zt.containsRepos&&Ge(qe(Mt.uri_root),{force:!0})}return xe})},[bt,Ge]),ee=(0,we.useCallback)(()=>{ne(D=>{let xe=!D;return Nh(k1,xe),xe})},[]),He=(0,we.useCallback)(()=>{me&&m({agentId:t,projectId:r??null,source:me,repo:s})},[t,r,me,s,m]),Ve=(0,we.useCallback)((D,xe)=>{me&&(y({source:me,...s?{repo:s}:{},path:D.path,staged:xe}),b("git-diff"))},[me,s,y,b]),Ae=(0,we.useCallback)(async D=>{if(me){T(!0),Y(null);try{let xe=await D();return m({agentId:t,projectId:r??null,source:me,repo:s}),xe}catch(xe){Y(xe instanceof Error?xe.message:"Git operation failed");return}finally{T(!1)}}},[me,s,t,r,m]),ce=(0,we.useMemo)(()=>({...r?{projectId:r}:{},...s?{repo:s}:{}}),[r,s]),Pt=(0,we.useCallback)(D=>{D.length!==0&&Ae(()=>E0({agentId:t,...ce,source:me,paths:D},e))},[Ae,t,ce,me]),Ft=(0,we.useCallback)(D=>{D.length!==0&&Ae(()=>O0({agentId:t,...ce,source:me,paths:D},e))},[Ae,t,ce,me]),Zt=(0,we.useCallback)(D=>{(async()=>{let xe=await Ae(()=>H0({agentId:t,...ce,source:me,paths:D},e));xe&&xe.rescue&&Ee({message:`Discarded ${D.length} file${D.length===1?"":"s"} \u2014 recoverable`,rescue:xe.rescue})})()},[Ae,t,ce,me]),dn=(0,we.useCallback)(D=>{D.length!==0&&he({title:"Discard changes",message:`Overwrite the working-tree version of ${D.length} file${D.length===1?"":"s"} with the last committed/indexed content? A rescue snapshot is saved server-side so it can be recovered.`,confirmLabel:"Discard",onConfirm:()=>{he(null),Zt(D)}})},[Zt]),rr=(0,we.useCallback)(D=>Pt([D.path]),[Pt]),qr=(0,we.useCallback)(D=>Ft([D.path]),[Ft]),Mn=(0,we.useCallback)(D=>dn([D.path]),[dn]),Yn=(0,we.useMemo)(()=>({onStage:rr}),[rr]),$r=(0,we.useMemo)(()=>({onStage:rr,onDiscard:Mn}),[rr,Mn]),ar=(0,we.useMemo)(()=>({onUnstage:qr}),[qr]),Pr=(0,we.useCallback)(D=>Te?D.code==="??"?Yn:$r:C1,[Te,Yn,$r]),Kr=(0,we.useCallback)(()=>Te?ar:C1,[Te,ar]),ln=(0,we.useCallback)(()=>{let D=N.trim();D&&(async()=>{let xe=await Ae(()=>U0({agentId:t,...ce,source:me,message:D,amend:B},e));xe&&xe.ok&&(A(""),K(!1))})()},[N,B,Ae,t,ce,me]),Jn=(0,we.useCallback)(()=>{P(!1),U(!1),k(D=>{let xe=!D;return xe&&me&&x({agentId:t,projectId:r??null,source:me,repo:s}),xe}),ct(!1)},[me,s,t,r,x]),Wt=(0,we.useCallback)(D=>{k(!1),(async()=>await Ae(()=>Qf({agentId:t,...ce,source:me,ref:D},e))&&x({agentId:t,projectId:r??null,source:me,repo:s}))()},[Ae,t,ce,me,s,x,r]),gr=(0,we.useCallback)(()=>{let D=Lt.trim();if(!D)return;let xe=at.trim();k(!1),ct(!1),Le(""),ft(""),(async()=>await Ae(()=>G0({agentId:t,...ce,source:me,name:D,...xe?{startPoint:xe}:{}},e))&&(await Ae(()=>Qf({agentId:t,...ce,source:me,ref:D},e)),x({agentId:t,projectId:r??null,source:me,repo:s})))()},[Lt,at,Ae,t,ce,me,s,x,r]),Un=(0,we.useCallback)(D=>{(async()=>{let xe=await Ae(()=>W0({agentId:t,...ce,source:me,name:D},e));xe&&xe.rescue&&Ee({message:`Deleted branch "${D}" \u2014 recoverable`,rescue:xe.rescue}),x({agentId:t,projectId:r??null,source:me,repo:s})})()},[Ae,t,ce,me,s,x,r]),Nr=(0,we.useCallback)(D=>{k(!1),he({title:"Delete branch",message:`Delete the local branch "${D.name}"? A rescue ref is saved so it can be recreated (git will refuse if it has unmerged commits).`,confirmLabel:"Delete branch",onConfirm:()=>{he(null),Un(D.name)}})},[Un]),pa=(0,we.useCallback)(()=>{if(!Ne)return;let D=Ne.rescue;Ee(null),Ae(()=>z0({agentId:t,...ce,source:me,rescue:D},e))},[Ne,Ae,t,ce,me]),fn=(0,we.useCallback)(()=>{U(!1),Ae(()=>j0({agentId:t,...ce,source:me},e))},[Ae,t,ce,me]),Xr=(0,we.useCallback)(()=>{U(!1),Ae(()=>V0({agentId:t,...ce,source:me},e))},[Ae,t,ce,me]),ma=(0,we.useCallback)(()=>{U(!1),Ae(()=>q0({agentId:t,...ce,source:me},e))},[Ae,t,ce,me]),xn=o?.unstaged??[],Tn=o?.staged??[],z=o?.untracked??[],I=(0,we.useMemo)(()=>[...xn,...z].sort((D,xe)=>D.path.localeCompare(xe.path)),[xn,z]);if(bt.length===0)return(0,G.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 px-4 py-10 text-center",children:[(0,G.jsx)(Cn,{className:"h-5 w-5 text-white/25"}),(0,G.jsx)("div",{className:"text-xs text-white/40",children:"No git repositories"}),(0,G.jsx)("div",{className:"max-w-[200px] text-[10px] text-white/30",children:"Sources whose root is \u2014 or whose folders contain \u2014 a git checkout appear here."})]});let q=Te&&N.trim().length>0&&(mt>0||B)&&!v,F=f?(0,G.jsx)("div",{className:"px-2 py-3 text-[11px] text-rose-300/70",children:f}):d&&!o?(0,G.jsx)("div",{className:"px-2 py-3 text-[11px] text-white/35",children:"Loading git status\u2026"}):I.length===0?(0,G.jsx)("div",{className:"px-2 py-4 text-center text-[11px] text-white/35",children:"No changes"}):(0,G.jsx)(L1,{changes:I,viewMode:h,staged:!1,showCounts:pe,onRowClick:Ve,actionsFor:Pr,busy:v}),de=[{id:"changes",title:"Changes",count:I.length,badge:l?(0,G.jsx)(Aa,{...l.changes,compact:!0,className:"ml-auto pr-1"}):void 0,actions:Te&&I.length>0?(0,G.jsxs)(G.Fragment,{children:[xn.length>0?(0,G.jsx)(dp,{tone:"discard",onClick:()=>dn(xn.map(D=>D.path)),disabled:v,title:"Discard all tracked changes in this group (destructive)",children:"Discard all"}):null,(0,G.jsx)(dp,{tone:"stage",onClick:()=>Pt(I.map(D=>D.path)),disabled:v,title:"Stage all",children:"Stage all"})]}):void 0,content:F},...Tn.length>0?[{id:"staged",title:"Staged Changes",count:Tn.length,badge:l?(0,G.jsx)(Aa,{...l.staged,compact:!0,className:"ml-auto pr-1"}):void 0,actions:Te?(0,G.jsx)(dp,{tone:"unstage",onClick:()=>Ft(Tn.map(D=>D.path)),disabled:v,title:"Unstage all",children:"Unstage all"}):void 0,content:(0,G.jsx)(L1,{changes:Tn,viewMode:h,staged:!0,showCounts:pe,onRowClick:Ve,actionsFor:Kr,busy:v})}]:[],{id:"graph",title:"Graph",badge:u?(0,G.jsx)(Aa,{added:u.added,removed:u.removed,unknown:u.commits-u.covered,compact:!0,className:"ml-auto pr-1"}):void 0,defaultCollapsed:!0,defaultWeight:2,content:(0,G.jsx)(m1,{showCounts:pe,onOutgoingStat:c,source:me,repo:s,agentId:t,projectId:r??null,repoName:s?Re?.name??s:Ue?.git?.repoName},`${me}\0${s}`)}];return(0,G.jsxs)("div",{className:"flex h-full min-h-0 flex-col",children:[(0,G.jsxs)("div",{ref:_,className:"relative px-2 pt-1 pb-1.5",children:[(0,G.jsxs)("div",{className:"flex items-center gap-1",children:[(0,G.jsxs)("button",{type:"button",onClick:Oe,disabled:!Ot,className:$("flex min-w-0 flex-1 items-center gap-1.5 rounded-md px-2 py-1 text-left transition-colors","bg-white/[0.03] hover:bg-white/[0.06] disabled:hover:bg-white/[0.03]"),title:me?Gt.title:"Select a repository",children:[(0,G.jsx)(Cn,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/80"}),Gt.prefix?(0,G.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/40",children:Gt.prefix}):null,(0,G.jsx)("span",{className:"min-w-0 flex-1 truncate text-xs font-medium text-white/85",children:Gt.name||"Select repository"}),Ot?(0,G.jsx)(Et,{className:"h-3 w-3 shrink-0 text-white/40"}):null]}),(0,G.jsx)("button",{type:"button",onClick:He,className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-white/40 transition-colors hover:bg-white/[0.06] hover:text-white/70",title:"Refresh git status","aria-label":"Refresh git status",children:(0,G.jsx)(_t,{className:$("h-3.5 w-3.5",d&&"animate-spin")})}),(0,G.jsx)(P1.SkillLauncher,{variant:"icon",size:"sm",skill:"git",packageId:"@neuralis/brain-core",scripts:["scripts/git.sh"],label:"Status, diff, commit, branch, fetch or push with the agent",icon:"GitBranch"})]}),L&&Ot?(0,G.jsx)(G.Fragment,{children:(0,G.jsx)("div",{className:"absolute left-2 right-2 z-50 mt-1 max-h-56 overflow-auto rounded-md border border-white/10 bg-[rgba(var(--w-bg-rgb),0.96)] py-1 shadow-lg",children:bt.map(D=>{let xe=qe(D.uri_root);if(D.git?.isRepo){let zt=xe===me&&!s,yn=Fs(xe,D.git?.repoName);return(0,G.jsxs)("button",{type:"button",onClick:()=>on(xe,""),className:$("flex w-full items-center gap-1.5 px-2 py-1.5 text-left text-xs transition-colors hover:bg-white/[0.06]",zt?"text-white/90":"text-white/65"),children:[(0,G.jsx)(Cn,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/70"}),yn.prefix?(0,G.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/40",children:yn.prefix}):null,(0,G.jsx)("span",{className:"min-w-0 flex-1 truncate",children:yn.name}),D.git?.branch?(0,G.jsx)("span",{className:"shrink-0 truncate text-[10px] text-white/35",children:D.git.branch}):null,zt?(0,G.jsx)(Dn,{className:"h-3 w-3 shrink-0 text-violet-300/80"}):null]},D.uri_root)}let Mt=ue.get(xe);return Mt?Mt.length===0?(0,G.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1.5 text-[11px] text-white/35",children:[(0,G.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/40",children:`${xe}://`}),(0,G.jsx)("span",{className:"truncate",children:"No repositories found."})]},D.uri_root):Mt.map(zt=>{let yn=xe===me&&s===zt.rel,Sn=Fs(xe,zt.name||zt.rel);return(0,G.jsxs)("button",{type:"button",onClick:()=>on(xe,zt.rel),className:$("flex w-full items-center gap-1.5 px-2 py-1.5 text-left text-xs transition-colors hover:bg-white/[0.06]",yn?"text-white/90":"text-white/65"),children:[(0,G.jsx)(Cn,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/70"}),Sn.prefix?(0,G.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/40",children:Sn.prefix}):null,(0,G.jsx)("span",{className:"min-w-0 flex-1 truncate",children:Sn.name}),zt.branch?(0,G.jsx)("span",{className:"shrink-0 truncate text-[10px] text-white/35",children:zt.branch}):null,yn?(0,G.jsx)(Dn,{className:"h-3 w-3 shrink-0 text-violet-300/80"}):null]},`${D.uri_root}\0${zt.rel}`)}):(0,G.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1.5 text-[11px] text-white/35",children:[(0,G.jsx)(We,{className:"h-3 w-3 shrink-0 animate-spin"}),(0,G.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/40",children:`${xe}://`}),(0,G.jsx)("span",{className:"truncate",children:"Scanning repositories\u2026"})]},D.uri_root)})})}):null]}),(0,G.jsxs)("div",{ref:M,className:"relative flex items-center justify-between gap-2 px-2 pb-1.5",children:[(0,G.jsxs)("div",{className:"flex min-w-0 items-center gap-1",children:[(0,G.jsxs)("button",{type:"button",onClick:Jn,className:"flex min-w-0 items-center gap-1.5 rounded-md px-1.5 py-0.5 text-[11px] text-white/55 transition-colors hover:bg-white/[0.05] hover:text-white/80",title:"Switch or create branch","aria-haspopup":"menu","aria-expanded":w,children:[(0,G.jsx)(Cn,{className:"h-3 w-3 shrink-0 text-white/40"}),(0,G.jsx)("span",{className:"truncate",children:o?.branch??"\u2014"}),(0,G.jsx)(Et,{className:"h-3 w-3 shrink-0 text-white/30"})]}),Te?(0,G.jsx)("button",{type:"button",onClick:()=>{P(!1),k(!1),ct(!1),U(D=>!D)},className:"flex shrink-0 items-center gap-1.5 rounded bg-white/[0.05] px-1.5 py-0.5 text-[10px] leading-none tabular-nums text-white/60 transition-colors hover:bg-white/[0.08] hover:text-white/85",title:"Fetch / pull / push","aria-haspopup":"menu","aria-expanded":R,children:je?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)("span",{className:"flex items-center gap-0.5","aria-label":`${je.ahead} commits ahead of ${je.upstream}`,children:[(0,G.jsx)("span",{className:"text-blue-300/60",children:"\u2191"}),(0,G.jsx)("span",{className:"text-blue-200/90",children:je.ahead})]}),(0,G.jsxs)("span",{className:"flex items-center gap-0.5","aria-label":`${je.behind} commits behind ${je.upstream}`,children:[(0,G.jsx)("span",{className:"text-white/40",children:"\u2193"}),(0,G.jsx)("span",{className:"text-white/70",children:je.behind})]})]}):(0,G.jsx)(gl,{className:"h-3 w-3 text-white/40"})}):je?(0,G.jsxs)("span",{className:"flex shrink-0 cursor-default items-center gap-1.5 rounded bg-white/[0.05] px-1 py-0.5 text-[10px] leading-none tabular-nums",title:`${je.upstream}: ahead/behind vs the tracked upstream (local refs)`,children:[(0,G.jsxs)("span",{className:"flex items-center gap-0.5","aria-label":`${je.ahead} commits ahead of ${je.upstream}`,children:[(0,G.jsx)("span",{className:"text-blue-300/60",children:"\u2191"}),(0,G.jsx)("span",{className:"text-blue-200/90",children:je.ahead})]}),(0,G.jsxs)("span",{className:"flex items-center gap-0.5","aria-label":`${je.behind} commits behind ${je.upstream}`,children:[(0,G.jsx)("span",{className:"text-white/40",children:"\u2193"}),(0,G.jsx)("span",{className:"text-white/70",children:je.behind})]})]}):null,Te?(0,G.jsxs)("button",{type:"button",onClick:ee,className:"flex shrink-0 items-center gap-1 rounded-md px-1.5 py-0.5 text-[11px] text-white/55 transition-colors hover:bg-white/[0.05] hover:text-white/80",title:te?"Hide the commit box":"Show the commit box","aria-expanded":te,children:[(0,G.jsx)("span",{children:"Commit"}),mt>0?(0,G.jsx)("span",{className:"rounded bg-white/[0.08] px-1 py-0.5 text-[9px] leading-none tabular-nums text-white/70",children:mt}):null,te?(0,G.jsx)(qa,{className:"h-3 w-3 shrink-0 text-white/30"}):(0,G.jsx)(Et,{className:"h-3 w-3 shrink-0 text-white/30"})]}):null]}),(0,G.jsxs)("div",{className:"flex shrink-0 items-center gap-0.5 rounded-md bg-white/[0.03] p-0.5",children:[(0,G.jsx)("button",{type:"button",onClick:()=>p("list"),className:$("inline-flex h-5 w-5 items-center justify-center rounded transition-colors",h==="list"?"bg-white/10 text-white/85":"text-white/40 hover:text-white/70"),title:"Flat list","aria-label":"Flat list view","aria-pressed":h==="list",children:(0,G.jsx)(ni,{className:"h-3 w-3"})}),(0,G.jsx)("button",{type:"button",onClick:()=>p("tree"),className:$("inline-flex h-5 w-5 items-center justify-center rounded transition-colors",h==="tree"?"bg-white/10 text-white/85":"text-white/40 hover:text-white/70"),title:"Folder tree","aria-label":"Folder tree view","aria-pressed":h==="tree",children:(0,G.jsx)(Al,{className:"h-3 w-3"})})]}),(0,G.jsx)("button",{type:"button",onClick:le,className:$("inline-flex h-5 w-5 shrink-0 items-center justify-center rounded transition-colors",pe?"text-white/85":"text-white/35 hover:text-white/60"),title:pe?"Hide per-row diff counts":"Show per-row diff counts","aria-label":"Toggle per-row diff counts","aria-pressed":pe,children:(0,G.jsx)(Hl,{className:"h-3 w-3"})}),w?(0,G.jsx)(G.Fragment,{children:(0,G.jsxs)("div",{className:"absolute left-2 right-2 top-full z-50 mt-1 max-h-72 overflow-auto rounded-md border border-white/10 bg-[rgba(var(--w-bg-rgb),0.97)] py-1 shadow-lg",children:[(0,G.jsx)("div",{className:"px-2 py-1 text-[9px] font-bold uppercase tracking-wider text-white/35",children:"Branches"}),g.length===0?(0,G.jsx)("div",{className:"px-2 py-1.5 text-[11px] text-white/35",children:"No branches loaded."}):g.map(D=>(0,G.jsxs)("div",{className:"group flex items-center gap-1.5 pr-1",children:[(0,G.jsxs)("button",{type:"button",onClick:()=>!D.current&&Wt(D.name),disabled:D.current||v,className:$("flex min-w-0 flex-1 items-center gap-1.5 px-2 py-1.5 text-left text-xs transition-colors",D.current?"text-violet-200/90":"text-white/70 hover:bg-white/[0.06]"),title:D.current?`${D.name} (current)`:`Switch to ${D.name}`,children:[(0,G.jsx)(Cn,{className:"h-3.5 w-3.5 shrink-0 text-white/40"}),(0,G.jsx)("span",{className:"min-w-0 flex-1 truncate",children:D.name}),D.current?(0,G.jsx)(Dn,{className:"h-3 w-3 shrink-0 text-violet-300/80"}):null]}),Te&&!D.current?(0,G.jsx)("button",{type:"button",onClick:()=>Nr(D),disabled:v,className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded text-rose-300/60 opacity-0 transition group-hover:opacity-100 hover:bg-rose-500/15 hover:text-rose-200 disabled:opacity-40",title:`Delete branch ${D.name}`,"aria-label":`Delete branch ${D.name}`,children:(0,G.jsx)(Nt,{className:"h-3 w-3"})}):null]},D.name)),Te?(0,G.jsx)("div",{className:"mt-1 border-t border-white/[0.06] pt-1",children:ze?(0,G.jsxs)("div",{className:"px-2 py-1.5",children:[(0,G.jsx)("input",{value:Lt,onChange:D=>Le(D.target.value),onKeyDown:D=>{D.key==="Enter"&&gr()},placeholder:"new-branch-name",autoFocus:!0,className:"mb-1 h-6 w-full rounded border border-white/[0.12] bg-white/[0.04] px-1.5 text-[11px] text-white/85 outline-none placeholder:text-white/25 focus:border-white/25"}),(0,G.jsx)("input",{value:at,onChange:D=>ft(D.target.value),onKeyDown:D=>{D.key==="Enter"&&gr()},placeholder:"from (optional ref \u2014 default HEAD)",className:"mb-1.5 h-6 w-full rounded border border-white/[0.12] bg-white/[0.04] px-1.5 text-[11px] text-white/85 outline-none placeholder:text-white/25 focus:border-white/25"}),(0,G.jsxs)("div",{className:"flex items-center gap-1",children:[(0,G.jsxs)("button",{type:"button",onClick:gr,disabled:v||Lt.trim().length===0,className:"inline-flex items-center gap-1 rounded bg-violet-500/20 px-2 py-1 text-[10px] text-violet-100/90 transition-colors hover:bg-violet-500/30 disabled:opacity-40",children:[(0,G.jsx)(Fn,{className:"h-3 w-3"})," Create & switch"]}),(0,G.jsx)("button",{type:"button",onClick:()=>{ct(!1),Le(""),ft("")},className:"rounded px-2 py-1 text-[10px] text-white/50 transition-colors hover:bg-white/[0.06] hover:text-white/80",children:"Cancel"})]})]}):(0,G.jsxs)("button",{type:"button",onClick:()=>ct(!0),className:"flex w-full items-center gap-1.5 px-2 py-1.5 text-left text-xs text-white/70 transition-colors hover:bg-white/[0.06]",children:[(0,G.jsx)(Fn,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/70"}),(0,G.jsx)("span",{children:"Create new branch\u2026"})]})}):null]})}):null,R?(0,G.jsx)(G.Fragment,{children:(0,G.jsxs)("div",{className:"absolute right-2 top-full z-50 mt-1 w-52 max-w-[calc(100%-1rem)] overflow-auto rounded-md border border-white/10 bg-[rgba(var(--w-bg-rgb),0.97)] py-1 shadow-lg",children:[(0,G.jsx)("div",{className:"px-2 py-1 text-[9px] font-bold uppercase tracking-wider text-white/35",children:"Remote"}),vt?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)("button",{type:"button",onClick:Xr,disabled:v,className:"flex w-full items-center gap-2 px-2 py-1.5 text-left text-xs text-white/75 transition-colors hover:bg-white/[0.06] disabled:opacity-40",title:"Fetch + fast-forward merge (git pull, ff-only)",children:[(0,G.jsx)(ml,{className:"h-3.5 w-3.5 shrink-0 text-white/45"}),(0,G.jsx)("span",{className:"min-w-0 flex-1",children:"Pull"}),je&&je.behind>0?(0,G.jsxs)("span",{className:"shrink-0 tabular-nums text-[10px] text-white/50",children:["\u2193",je.behind]}):null]}),(0,G.jsxs)("button",{type:"button",onClick:ma,disabled:v,className:"flex w-full items-center gap-2 px-2 py-1.5 text-left text-xs text-white/75 transition-colors hover:bg-white/[0.06] disabled:opacity-40",title:"Push the current branch (git push origin HEAD)",children:[(0,G.jsx)(xl,{className:"h-3.5 w-3.5 shrink-0 text-blue-300/60"}),(0,G.jsx)("span",{className:"min-w-0 flex-1",children:"Push"}),je&&je.ahead>0?(0,G.jsxs)("span",{className:"shrink-0 tabular-nums text-[10px] text-blue-200/80",children:["\u2191",je.ahead]}):null]}),(0,G.jsxs)("button",{type:"button",onClick:fn,disabled:v,className:"flex w-full items-center gap-2 px-2 py-1.5 text-left text-xs text-white/75 transition-colors hover:bg-white/[0.06] disabled:opacity-40",title:"Fetch remote refs (git fetch origin)",children:[(0,G.jsx)(_t,{className:"h-3.5 w-3.5 shrink-0 text-white/45"}),(0,G.jsx)("span",{className:"min-w-0 flex-1",children:"Fetch"})]})]}):(0,G.jsxs)("div",{className:"flex items-start gap-1.5 px-2 py-2",children:[(0,G.jsx)(ri,{className:"mt-0.5 h-3 w-3 shrink-0 text-amber-300/70"}),(0,G.jsxs)("div",{className:"min-w-0 text-[11px] leading-snug text-white/55",children:["Remote git operations need ",(0,G.jsx)("span",{className:"font-medium text-white/75",children:"exec"})," permission on this source. Ask an owner to grant it."]})]})]})}):null]}),Ne?(0,G.jsxs)("div",{className:"mx-2 mb-1 flex items-start gap-1.5 rounded-md border border-amber-500/20 bg-amber-500/[0.07] px-2 py-1.5",children:[(0,G.jsx)(ot,{className:"mt-0.5 h-3 w-3 shrink-0 text-amber-300/80"}),(0,G.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,G.jsx)("div",{className:"text-[11px] text-amber-100/85",children:Ne.message}),(0,G.jsxs)("div",{className:"truncate font-mono text-[9px] text-amber-100/45",title:Ne.rescue.ref,children:["rescue: ",Ne.rescue.ref]})]}),(0,G.jsx)("button",{type:"button",onClick:pa,disabled:v,className:"shrink-0 rounded px-1.5 py-0.5 text-[10px] font-semibold text-amber-100 transition-colors hover:bg-amber-500/20 disabled:opacity-40",children:"Undo"}),(0,G.jsx)("button",{type:"button",onClick:()=>Ee(null),className:"shrink-0 rounded p-0.5 text-amber-200/60 transition-colors hover:bg-amber-500/15 hover:text-amber-100","aria-label":"Dismiss recovery notice",children:(0,G.jsx)(Ht,{className:"h-3 w-3"})})]}):null,V?(0,G.jsxs)("div",{className:"mx-2 mb-1 flex items-start gap-1.5 rounded-md border border-rose-500/20 bg-rose-500/[0.06] px-2 py-1.5",children:[(0,G.jsx)(ot,{className:"mt-0.5 h-3 w-3 shrink-0 text-rose-300/80"}),(0,G.jsx)("div",{className:"min-w-0 flex-1 text-[11px] text-rose-200/85",children:V}),(0,G.jsx)("button",{type:"button",onClick:()=>Y(null),className:"shrink-0 rounded p-0.5 text-rose-200/60 transition-colors hover:bg-rose-500/15 hover:text-rose-100","aria-label":"Dismiss error",children:(0,G.jsx)(Ht,{className:"h-3 w-3"})})]}):null,Te&&te?(0,G.jsxs)("div",{className:"mx-2 mb-1.5 rounded-md border border-white/[0.07] bg-white/[0.02] p-1",children:[(0,G.jsx)("textarea",{value:N,onChange:D=>A(D.target.value),onKeyDown:D=>{D.key==="Enter"&&(D.metaKey||D.ctrlKey)&&!D.nativeEvent.isComposing&&q&&(D.preventDefault(),ln())},placeholder:mt>0?`Commit message (${mt} staged)`:"Commit message",rows:2,className:"w-full resize-none rounded bg-transparent px-1 text-[11px] text-white/85 outline-none placeholder:text-white/30"}),(0,G.jsxs)("div",{className:"mt-0.5 flex items-center justify-end gap-2",children:[(0,G.jsxs)("label",{className:"flex cursor-pointer select-none items-center gap-1 text-[10px] text-white/50",children:[(0,G.jsx)("input",{type:"checkbox",checked:B,onChange:D=>K(D.target.checked),className:"h-3 w-3 accent-violet-400"}),"Amend"]}),(0,G.jsxs)("button",{type:"button",onClick:ln,disabled:!q,className:"inline-flex items-center gap-1 rounded-md bg-violet-500/20 px-2.5 py-1 text-[11px] font-medium text-violet-100/90 transition-colors hover:bg-violet-500/30 disabled:opacity-40",title:B?"Amend the last commit":"Commit the staged changes",children:[v?(0,G.jsx)(We,{className:"h-3 w-3 animate-spin"}):(0,G.jsx)(Dn,{className:"h-3 w-3"}),B?"Amend":"Commit"]})]})]}):null,(0,G.jsx)(v1,{storageKey:xM,sections:de}),re&&typeof document<"u"?(0,A1.createPortal)((0,G.jsxs)("div",{className:"fixed inset-0 z-[100000] flex items-center justify-center p-4",children:[(0,G.jsx)("button",{type:"button","aria-hidden":!0,tabIndex:-1,onClick:()=>he(null),className:"absolute inset-0 cursor-default bg-black/50"}),(0,G.jsxs)("div",{className:"relative z-10 w-full max-w-xs rounded-lg border border-white/10 bg-[rgba(var(--w-bg-rgb),0.98)] p-4 shadow-xl",children:[(0,G.jsxs)("div",{className:"mb-1 flex items-center gap-2",children:[(0,G.jsx)(ot,{className:"h-4 w-4 shrink-0 text-rose-300/80"}),(0,G.jsx)("span",{className:"text-sm font-semibold text-white/90",children:re.title})]}),(0,G.jsx)("p",{className:"mb-3 text-[11px] leading-relaxed text-white/55",children:re.message}),(0,G.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,G.jsx)("button",{type:"button",onClick:()=>he(null),className:"rounded-md px-3 py-1.5 text-[11px] text-white/60 transition-colors hover:bg-white/[0.06] hover:text-white/85",children:"Cancel"}),(0,G.jsxs)("button",{type:"button",onClick:re.onConfirm,className:"inline-flex items-center gap-1 rounded-md border border-rose-500/30 bg-rose-500/15 px-3 py-1.5 text-[11px] font-semibold text-rose-100 transition-colors hover:bg-rose-500/25",children:[(0,G.jsx)(Nt,{className:"h-3 w-3"}),re.confirmLabel]})]})]})]}),document.body):null]})}var Ct=j(ie(),1),M1={},T1="brain://",vM=32,kM=28,SM=114;function CM(t){return t==="header"?vM:t==="empty"?SM:kM}function IM(t){return t!=="node"}function D1(t,e){return t.type===e.type?t.name.localeCompare(e.name):t.type==="folder"?-1:1}function LM(t){let e=new Map,n=new Set;for(let a of t)n.add(a.uri);for(let a of t){let s=a.parentUri??et(a.uri);if(!s||a.uri===s)continue;let i=e.get(s);i?i.push(a):e.set(s,[a])}for(let a of e.values())a.sort(D1);let r=new Map;for(let a of t){let s=sr(a.uri);if(!s||a.uri===s)continue;let i=a.parentUri??et(a.uri);if(!(!i||i===s||!n.has(i)))continue;let l=r.get(s);l?l.push(a):r.set(s,[a])}for(let a of r.values())a.sort(D1);return{childrenByParent:e,rootsBySource:r}}function AM(t,e,n){let r=[],a=(i,o)=>{r.push({node:i,depth:o});let l=i.storeKey||Va(i);if(i.type==="folder"&&n.has(l)){let u=t.childrenByParent.get(i.uri);if(u)for(let c=0;c<u.length;c++)a(u[c],o+1)}},s=t.rootsBySource.get(e);if(s)for(let i=0;i<s.length;i++)a(s[i],0);return r}function fp(t){let{agentId:e,sidebarView:n="tree"}=t,r=hn(),a=ti(),s=H(I=>I.files),i=H(I=>I.folderBadges),o=H(I=>I.expandedFolders),l=H(I=>I.activeFile),u=H(I=>I.toggleFolder),c=H(I=>I.openFile),d=H(I=>I.activeProjectId),f=H(I=>I.setActiveFolderPath),h=H(I=>I.activeFolderPath),p=H(I=>I.uploadMany),g=H(I=>I.moveFileToFolder),m=H(I=>I.uploading),x=H(I=>I.sources),y=H(I=>I.sourcesLoading),b=H(I=>I.hydrationState),C=H(I=>I.dirtySources),L=H(I=>I.organizeError),P=H(I=>I.clearOrganizeError),w=H(I=>I.snapshotError),k=H(I=>I.clearSnapshotError),_=H(I=>I.loadList),M=H(I=>I.pendingReviewPaths),R=H(I=>I.renameNode),U=H(I=>I.deleteNodes),v=H(I=>I.createNode),T=H(I=>I.pasteNodes),[V,Y]=(0,_e.useState)(null),[N,A]=(0,_e.useState)({}),[B,K]=(0,_e.useState)(()=>new Set),[te,ne]=(0,_e.useState)(null),[pe,Se]=(0,_e.useState)(null),[le,re]=(0,_e.useState)(null),[he,Ne]=(0,_e.useState)(null),[Ee,ze]=(0,_e.useState)(null),[ct,it]=(0,_e.useState)(null),[Qe,Ye]=(0,_e.useState)(!1),[Lt,Le]=(0,_e.useState)(!1),at=H(I=>I.setPendingSourceSuggestion),ft=H(I=>I.setWorkspacePanelOpen);(0,_e.useEffect)(()=>{if(!l)return;let I=`${qe(l)}://`;A(q=>q[I]?q:{...q,[I]:!0})},[l]);let bt=r.useFileMarks(e),At=r.useAgents(),Tt=r.usePackageIconBySlug?.()??M1,Ue=(0,_e.useMemo)(()=>bt||M1,[bt]),me=(0,_e.useMemo)(()=>Ms(At),[At]),Ot=(0,_e.useMemo)(()=>me.byId.get(e)??null,[me,e]),Jt=(0,_e.useMemo)(()=>{let I={};for(let q of M){let F=xa(q);for(let de of F)I[de]=(I[de]||0)+1}return I},[M]),ue=x.length>0,be=(0,_e.useMemo)(()=>Object.values(s),[s]),Ge=(0,_e.useMemo)(()=>LM(be),[be]),Re=(0,_e.useMemo)(()=>{let I={uri_root:T1,source_kind:"brain",writable:!0};return ue?x.length>0?x:[I]:[I]},[ue,x]),Te=n==="search",vt=(0,_e.useMemo)(()=>{let I=h?sr(h):null;return I&&Re.some(F=>F.uri_root===I)?I:Re.find(F=>F.source_kind!=="brain")?.uri_root??Re[0]?.uri_root??T1},[h,Re]),mt=(0,_e.useMemo)(()=>{if(Te)return[];let I=[];for(let q of Re){let F=N[q.uri_root]??!1;if(I.push({kind:"header",key:`h:${q.uri_root}`,info:q,expanded:F}),!F)continue;let de=AM(Ge,q.uri_root,o);if(de.length===0)I.push({kind:"empty",key:`e:${q.uri_root}`,sourceRoot:q.uri_root});else for(let D of de)I.push({kind:"node",key:`n:${D.node.uri}`,node:D.node,depth:D.depth})}if(le){let q=le.parentUri,F=-1,de=0;if(q.endsWith("://"))F=I.findIndex(D=>D.kind==="header"&&D.info.uri_root===q),de=0;else{let D=I.findIndex(xe=>xe.kind==="node"&&xe.node.uri===q);D>=0&&(F=D,de=I[D].depth+1)}F>=0&&I.splice(F+1,0,{kind:"creating",key:"creating-row",parentUri:q,createKind:le.kind,depth:de})}return I},[Ge,o,Re,N,Te,le]),Gt=(0,_e.useMemo)(()=>mt.filter(I=>I.kind==="node").map(I=>I.node.uri),[mt]),je=(0,_e.useCallback)(({node:I,additive:q,range:F})=>{K(de=>{if(F&&te){let D=Gt.indexOf(te),xe=Gt.indexOf(I.uri);if(D>=0&&xe>=0){let[Mt,zt]=D<=xe?[D,xe]:[xe,D];return new Set(Gt.slice(Mt,zt+1))}}if(q){let D=new Set(de);return D.has(I.uri)?D.delete(I.uri):D.add(I.uri),D}return new Set([I.uri])}),F||ne(I.uri)},[Gt,te]),kt=(0,_e.useCallback)(({node:I,x:q,y:F})=>{K(de=>de.has(I.uri)&&de.size>1?de:new Set([I.uri])),ne(I.uri),ze({kind:"node",node:I,x:q,y:F})},[]),on=(0,_e.useCallback)((I,q)=>{q.preventDefault(),q.stopPropagation(),A(F=>F[I]?F:{...F,[I]:!0}),ze({kind:"source",sourceRoot:I,x:q.clientX,y:q.clientY})},[]),Oe=(0,_e.useCallback)(I=>{I.target.closest('button, input, textarea, [role="menu"]')||on(vt,I)},[vt,on]),ee=(0,_e.useMemo)(()=>Ee?.kind!=="node"?[]:(B.has(Ee.node.uri)&&B.size>0?[...B]:[Ee.node.uri]).map(q=>s[q]).filter(Boolean),[Ee,B,s]),oe=(0,_e.useMemo)(()=>oo({grantedFeatures:[...r.grantedFeatures??[]]},{features:["drive.sync"]}),[r.grantedFeatures]),[He,Ve]=(0,_e.useState)(null),Ae=(0,_e.useMemo)(()=>{if(Ee?.kind==="source")return{"new-file":!0,"new-folder":qe(Ee.sourceRoot)!=="brain"};let I=ee.length===1?ee[0]:null,q=I??ee[0],F=q?q.type==="folder"?q.uri:et(q.uri):null;return{"copy-path":!!I,"copy-relative-path":!!I,reembed:!!I&&oe&&qe(I.uri)!=="brain",rename:!!I,delete:ee.length>0,"new-file":!!I,"new-folder":!!I&&qe(I.uri)!=="brain",cut:ee.length>0,copy:ee.length>0,paste:!!he&&he.uris.length>0&&!!F}},[Ee,ee,he,oe]),ce=(0,_e.useCallback)(I=>{if(Ee?.kind==="source"){(I==="new-file"||I==="new-folder")&&re({parentUri:Ee.sourceRoot,kind:I==="new-file"?"file":"folder"});return}let q=ee,F=q.length===1?q[0]:null;if(I==="copy-path"&&F)navigator.clipboard?.writeText(F.uri);else if(I==="copy-relative-path"&&F)navigator.clipboard?.writeText(F.uri.replace(/^[a-z0-9_-]+:\/\//i,""));else if(I==="reembed"&&F){let de=qe(F.uri);de&&Ve({source:de,...F.type==="folder"?{folder:F.uri}:{uri:F.uri},label:F.type==="folder"?`${F.name}/`:F.name})}else if(I==="rename"&&F)Se(F.uri);else if(I==="delete")q.length&&it({targets:q.map(de=>({uri:de.uri,id:de.id,name:de.name}))});else if(I==="cut"||I==="copy")q.length&&Ne({op:I,uris:q.map(de=>de.uri)});else if(I==="paste"){let de=F??q[0];if(de&&he){let D=de.type==="folder"?de.uri:et(de.uri);D&&(T({agentId:e,projectId:d??null,targetFolderUri:D,op:he.op,uris:he.uris}),he.op==="cut"&&Ne(null))}}else if(I==="new-file"||I==="new-folder"){let de=I==="new-file"?"file":"folder",D=F??q[0];if(!D)return;let xe=D.type==="folder"?D.uri:et(D.uri);if(!xe)return;!xe.endsWith("://")&&!o.has(xe)&&(u(xe),a.getState().ensureFolderLoaded({agentId:e,projectId:d,uri:xe})),re({parentUri:xe,kind:de})}},[Ee,ee,o,u,e,d,he,T,a]),Pt=(0,_e.useCallback)(async I=>{let q=le;if(re(null),!q)return;let F=(I??"").trim();F&&await v({agentId:e,projectId:d??null,parentUri:q.parentUri,name:F,kind:q.kind})},[le,v,e,d]),Ft=(0,_e.useCallback)(()=>re(null),[]),Zt=(0,_e.useCallback)(async({node:I,newName:q})=>{Se(null);let F=(q??"").trim();!F||F===I.name||await R({agentId:e,projectId:d??null,uri:I.uri,id:I.id,newName:F})},[R,e,d]),dn=(0,_e.useCallback)(()=>Se(null),[]),rr=(0,_e.useCallback)(async()=>{if(ct){Ye(!0);try{await U({agentId:e,projectId:d??null,targets:ct.targets.map(I=>({uri:I.uri,id:I.id}))}),K(new Set)}finally{Ye(!1),it(null)}}},[ct,U,e,d]),qr=(0,_e.useCallback)(I=>{if(!pe)if(I.key==="F2"){let q=B.size===1?[...B][0]:null;q&&s[q]&&(I.preventDefault(),Se(q))}else if(I.key==="Delete"||I.key==="Backspace"){let q=[...B].map(F=>s[F]).filter(F=>!!F);q.length&&(I.preventDefault(),it({targets:q.map(F=>({uri:F.uri,id:F.id,name:F.name}))}))}else I.key==="Escape"&&K(new Set)},[pe,B,s]),Mn=(0,_e.useCallback)(async I=>{let q=o.has(I.key);f(I.key),u(I.key),!q&&await a.getState().ensureFolderLoaded({agentId:e,projectId:d,uri:I.key})},[e,o,d,f,u,a]),Yn=(0,_e.useCallback)(I=>{I.uri&&f(et(I.uri)),c(I)},[f,c]),$r=(0,_e.useCallback)(I=>{r.clearFileMark(I)},[r]),ar=(0,_e.useCallback)(I=>{A(q=>({...q,[I]:!q[I]}))},[]),Pr=(0,_e.useCallback)(async I=>{if(!e)return;let q=a.getState();if(A(F=>F[I]?F:{...F,[I]:!0}),q.loadedFolders?.[I]){let F=qe(I);F&&await q.reconcileSourceFolders({agentId:e,projectId:d,source:F});return}await q.ensureFolderLoaded({agentId:e,projectId:d,uri:I,force:!0})},[e,d,a]);(0,_e.useEffect)(()=>{if(!e)return;let I=a.getState(),q=[];for(let F of Re)N[F.uri_root]&&q.push(F.uri_root);for(let F of o)q.push(F);for(let F of q){if(I.loadedFolders?.[F])continue;let de=I.hydrationState?.[F];de&&de!=="idle"||I.ensureFolderLoaded({agentId:e,projectId:d,uri:F})}},[e,d,Re,N,o,a]);let Kr=(0,_e.useCallback)(async({fromUri:I,id:q,toFolderUri:F})=>{await g({agentId:e,projectId:d??null,fromUri:I,toFolderUri:F,id:q})},[e,d,g]),ln=(0,_e.useMemo)(()=>Re.every(I=>!N[I.uri_root]),[Re,N]),Jn=(0,_e.useMemo)(()=>oo({grantedFeatures:[...r.grantedFeatures??[]]},{features:["drive.mount"]}),[r.grantedFeatures]),Wt=qb({agentId:e,projectId:d??void 0,enabled:Jn&&ln}),gr=ln&&Jn&&Wt.length>0,Un=(0,_e.useCallback)(I=>{at(I),ft("sources",!0)},[at,ft]),Nr=(0,_e.useCallback)(()=>Le(I=>!I),[]),pa=(0,_e.useRef)(null),fn=(0,_e.useRef)(mt);fn.current=mt;let Xr=(0,_e.useCallback)(I=>CM(fn.current[I]?.kind??"node"),[]),ma=(0,_e.useCallback)(I=>fn.current[I]?.key??I,[]),xn=lo({count:mt.length,getScrollElement:()=>pa.current,estimateSize:Xr,overscan:8,getItemKey:ma});if(n==="git")return(0,Ct.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:(0,Ct.jsx)(R1,{agentId:e})});if(y&&!ue&&!Te)return(0,Ct.jsx)("div",{className:"p-4 text-center text-xs text-white/40 animate-pulse",children:"Loading sources"});let Tn=w&&!Te?(0,Ct.jsxs)("div",{role:"status",className:"mx-2 mb-1 mt-1 flex items-start gap-2 rounded-md border border-rose-400/30 bg-rose-500/10 px-2 py-1.5 text-[11px] text-rose-100/90",children:[(0,Ct.jsx)("span",{className:"min-w-0 flex-1 break-words",children:w}),(0,Ct.jsx)("button",{type:"button",onClick:()=>{e&&_({agentId:e,projectId:d??null})},className:"shrink-0 rounded px-1 font-medium text-rose-200/80 transition-colors hover:text-rose-100",children:"Retry"}),(0,Ct.jsx)("button",{type:"button",onClick:k,"aria-label":"Dismiss",className:"shrink-0 rounded px-1 text-rose-200/70 transition-colors hover:text-rose-100",children:"\xD7"})]}):null;if(!be.length&&!Te&&!ue)return Tn??(0,Ct.jsx)("div",{className:"p-4 text-center text-xs text-white/30",children:"Empty Drive"});let z=(I,q)=>{let F=I.type==="folder",de=I.storeKey||Va(I);return(0,Ct.jsx)(iw,{node:I,depth:q,agentId:e,projectId:d,isActive:!F&&l===de,isExpanded:F&&o.has(de),badgeCount:F?i[de]:void 0,isDrop:V===de,isSelectedFolder:F&&h===de,mark:Ue[I.uri],agentIndex:me,fallbackAgent:Ot,uploading:m,packageIconBySlug:Tt,onToggleFolder:Mn,onOpenFile:Yn,onClearFileMark:$r,onSetDropTarget:Y,onUploadMany:p,onMoveFileToFolder:Kr,pendingReviewCount:F?Jt[de]:void 0,isSelected:B.has(I.uri),isCut:he?.op==="cut"&&he.uris.includes(I.uri),renaming:pe===I.uri,onNodeClick:je,onNodeContextMenu:kt,onRenameCommit:Zt,onRenameCancel:dn})};return(0,Ct.jsxs)("div",{className:"relative flex min-h-0 flex-1 flex-col",children:[(0,Ct.jsxs)("div",{ref:pa,tabIndex:0,onKeyDown:qr,onContextMenu:Oe,className:"min-h-0 flex-1 overflow-auto pt-0 pb-2 outline-none",children:[Tn,L&&!Te?(0,Ct.jsxs)("div",{role:"status",className:"mx-2 mb-1 mt-1 flex items-start gap-2 rounded-md border border-amber-400/30 bg-amber-500/10 px-2 py-1.5 text-[11px] text-amber-100/90",children:[(0,Ct.jsx)("span",{className:"min-w-0 flex-1 break-words",children:L}),(0,Ct.jsx)("button",{type:"button",onClick:P,"aria-label":"Dismiss",className:"shrink-0 rounded px-1 text-amber-200/70 transition-colors hover:text-amber-100",children:"\xD7"})]}):null,Te?(0,Ct.jsx)(gw,{agentId:e}):null,Te?null:(0,Ct.jsx)("div",{style:{height:xn.getTotalSize(),width:"100%",position:"relative"},children:xn.getVirtualItems().map(I=>{let q=mt[I.index];if(!q)return null;let F=IM(q.kind);return(0,Ct.jsx)("div",{"data-index":I.index,ref:F?xn.measureElement:void 0,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${I.start}px)`},children:q.kind==="header"?(0,Ct.jsx)(mw,{info:q.info,expanded:q.expanded,onToggle:ar,onContextMenu:on,onRefresh:Pr,hydration:b[q.info.uri_root]??"idle",dirty:!!C[qe(q.info.uri_root)],hideChevron:!0,compact:!0}):q.kind==="empty"?(0,Ct.jsxs)("div",{className:"flex flex-col items-start gap-1.5 px-4 py-2",onContextMenu:de=>on(q.sourceRoot,de),children:[(0,Ct.jsxs)("span",{className:"text-xs text-white/35",children:["No files for ",qe(q.sourceRoot)]}),(0,Ct.jsx)(F1.SkillLauncher,{variant:"label",skill:"manage-files",packageId:"@neuralis/brain-core",scripts:["scripts/upload.sh","scripts/modify.sh"],label:"Populate this source with the agent"})]}):q.kind==="creating"?(0,Ct.jsx)(PM,{kind:q.createKind,depth:q.depth,onCommit:Pt,onCancel:Ft}):z(q.node,q.depth)},I.key)})}),Ee?(0,Ct.jsx)(lw,{x:Ee.x,y:Ee.y,variant:Ee.kind==="source"?"source":"node",enabled:Ae,onAction:ce,onClose:()=>ze(null)}):null,He?(0,Ct.jsx)(Xl,{agentId:e,...d?{projectId:d}:{},target:He,onClose:()=>Ve(null)}):null,ct?(0,Ct.jsx)(dw,{names:ct.targets.map(I=>I.name),busy:Qe,onCancel:()=>{Qe||it(null)},onConfirm:rr}):null]}),gr&&!Te?(0,Ct.jsx)(Zb,{suggestions:Wt,expanded:Lt,onToggleExpanded:Nr,onPick:Un,overlay:Lt}):null]})}function PM({kind:t,depth:e,onCommit:n,onCancel:r}){let a=(0,_e.useRef)(!1),s=t==="folder"?br:Cs;return(0,Ct.jsxs)("div",{className:"flex h-7 items-center gap-1.5 px-2",style:{paddingLeft:`${e*12+8}px`},children:[(0,Ct.jsx)("span",{className:"w-3.5 h-3.5 inline-block shrink-0"}),(0,Ct.jsx)(s,{className:"w-4 h-4 shrink-0 text-sky-300/80"}),(0,Ct.jsx)("input",{autoFocus:!0,spellCheck:!1,placeholder:t==="folder"?"Folder name":"File name",onClick:i=>i.stopPropagation(),onMouseDown:i=>i.stopPropagation(),onKeyDown:i=>{i.stopPropagation(),i.key==="Enter"?a.current||(a.current=!0,n(i.currentTarget.value)):i.key==="Escape"&&(a.current||(a.current=!0,r()))},onBlur:i=>{if(a.current)return;a.current=!0;let o=i.currentTarget.value.trim();o?n(o):r()},className:"min-w-0 flex-1 rounded border border-sky-400/60 bg-black/50 px-1 py-0 text-xs text-white outline-none placeholder:text-white/30"})]})}var yt=j($e(),1);var ZL=j(Wn(),1);function E1(t){if(!t)return{lines:new Map,deletedBefore:new Set};let e=new Map,n=new Set,r=0,a=!1,s=0,i=0,o=()=>{s>0&&i===0&&n.add(r),s=0,i=0};for(let l of t.split(`
32
+ `)){if(l.startsWith("@@")){o();let u=/^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(l);r=u?parseInt(u[1],10):0,a=r>0;continue}a&&(l.startsWith("+")&&!l.startsWith("+++")?(e.set(r,s>0?"modified":"added"),i++,r++):l.startsWith("-")&&!l.startsWith("---")?s++:(o(),l.startsWith(" ")&&r++))}return o(),{lines:e,deletedBefore:n}}function ld(t){return t.lines.size===0&&t.deletedBefore.size===0}var jn=j($e(),1),B1=j(Za(),1);var ou=j(ie(),1);function hp({sourceType:t,className:e}){return t==="blob"?(0,ou.jsx)("span",{title:"Blob + Vector",children:(0,ou.jsx)(zn,{className:$("w-3 h-3",e)})}):(0,ou.jsx)("span",{title:"Vector only",children:(0,ou.jsx)(ir,{className:$("w-3 h-3",e)})})}var Br=j(ie(),1);function pp({node:t,active:e,mark:n,isDirty:r,hasPendingReview:a,preview:s,pinned:i,onTogglePin:o}){let l=H(h=>h.setActiveFile),u=H(h=>h.closeFile),c=H(h=>h.activeAgentId),d=hn(),f=t.status==="deleted";return(0,Br.jsxs)("div",{className:$("group flex items-center gap-1.5 px-3 py-2 text-xs cursor-pointer min-w-[120px] max-w-[240px] rounded-lg",e?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>{l(t.storeKey||t.path),c&&n&&d.clearFileMark({agentId:c,path:t.path})},onDoubleClick:()=>o?.(),title:t.path,children:[(0,Br.jsx)(hp,{sourceType:t.sourceType,className:$("shrink-0",t.sourceType==="blob"?"text-sky-400/60":"text-violet-400/60")}),(0,Br.jsxs)("span",{className:$("truncate flex-1",s&&"italic",f&&"line-through text-white/45"),children:[t.name,r?(0,Br.jsx)("span",{className:"ml-1",style:{color:"var(--warning)"},children:"*"}):null]}),a?(0,Br.jsx)("span",{className:"inline-flex items-center rounded-full px-1.5 py-0.5 text-[9px] font-semibold bg-amber-500/15 text-amber-200",children:"REVIEW"}):n?(0,Br.jsx)("span",{className:$("inline-flex items-center rounded-full px-1.5 py-0.5 text-[9px] font-semibold",n==="new"?"bg-emerald-500/15 text-emerald-200":"bg-blue-500/15 text-blue-200"),children:n==="new"?"NEW":"MOD"}):null,i?(0,Br.jsx)("button",{onClick:h=>{h.stopPropagation(),o?.()},className:"p-0.5 rounded text-amber-300/80 hover:bg-white/10",title:"Unpin tab",children:(0,Br.jsx)(ii,{className:"w-3 h-3 fill-current"})}):(0,Br.jsx)("button",{onClick:h=>{h.stopPropagation(),u(t.storeKey||t.path)},className:$("opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-white/10"),title:"Close (double-click tab to pin)",children:(0,Br.jsx)(Ht,{className:"w-3 h-3"})})]})}var Ln=j(ie(),1),ud="data-tab-scroller",O1="data-tab-active";function NM(t,e){return e.left<t.left?e.left-t.left:e.right>t.right?Math.min(e.right-t.right,e.left-t.left):0}function RM(t,e){return e.scrollWidth<=e.clientWidth||Math.abs(t.deltaX)>=Math.abs(t.deltaY)?0:t.deltaY}function _1(){let t=H(b=>b.openFiles),e=H(b=>b.activeFile),n=H(b=>b.files),r=H(b=>b.tabMeta),a=H(b=>b.fileContentByPath),s=H(b=>b.fileBaseContentByPath),i=H(b=>b.filePrevByPath),o=H(b=>b.activeAgentId),l=H(b=>b.reorderOpenFiles),u=H(b=>b.toggleTabPin),d=hn().useFileMarks(o??void 0)||{},[f,h]=(0,jn.useState)(null),[p,g]=(0,jn.useState)(null),m=(0,jn.useRef)(null),x=t.length>0,y=(0,jn.useCallback)(()=>{let b=m.current,C=b?.closest(`[${ud}]`),L=b?.querySelector(`[${O1}="true"]`);if(!C||!L)return;let P=NM(C.getBoundingClientRect(),L.getBoundingClientRect());P!==0&&(C.scrollLeft+=P)},[]);return(0,jn.useLayoutEffect)(()=>{y()},[e,t,y]),(0,jn.useEffect)(()=>{let b=m.current?.closest(`[${ud}]`);if(!b)return;let C=P=>{let w=RM(P,b);w!==0&&(P.preventDefault(),b.scrollLeft+=w)};b.addEventListener("wheel",C,{passive:!1});let L=typeof ResizeObserver<"u"?new ResizeObserver(()=>{b.clientWidth>0&&y()}):null;return L?.observe(b),()=>{b.removeEventListener("wheel",C),L?.disconnect()}},[x,y]),t.length===0?null:(0,Ln.jsx)("div",{ref:m,className:"flex items-center",children:t.map(b=>{let C=n[b],L=r[b],P=C?.uri??b,w=C?.name??L?.name??gt(b),k=C?.status??L?.status,_=a[b]??"",M=s[b],R=typeof M=="string"&&M!==_,v=!!i[b]&&k==="pending_review";return(0,Ln.jsx)("div",{draggable:!0,[O1]:e===b?"true":void 0,onDragStart:T=>{h(b),T.dataTransfer.effectAllowed="move";try{T.dataTransfer.setData("text/plain",b)}catch{}},onDragOver:T=>{T.preventDefault(),T.dataTransfer.dropEffect="move",p!==b&&g(b)},onDrop:T=>{T.preventDefault(),f&&f!==b&&l(f,b),h(null),g(null)},onDragEnd:()=>{h(null),g(null)},className:$("shrink-0 rounded-lg",p===b&&f&&f!==b?"ring-1 ring-violet-400/50":"",f===b?"opacity-50":""),children:(0,Ln.jsx)(pp,{node:{storeKey:C?.storeKey??b,path:P,name:w,status:k,sourceAgentId:C?.sourceAgentId??L?.sourceAgentId,sourceType:C?.sourceType},active:e===b,mark:d[P]?.kind,isDirty:R,hasPendingReview:v,preview:!!L?.preview,pinned:!!L?.pinned,onTogglePin:()=>u(b)})},b)})})}function H1(){let t=H(p=>p.openFiles),e=H(p=>p.activeFile),n=H(p=>p.closeAllFiles),r=H(p=>p.closeSavedFiles),a=H(p=>p.closeOtherFiles),s=H(p=>p.previewEditorsEnabled),i=H(p=>p.setPreviewEditorsEnabled),[o,l]=(0,jn.useState)(!1),[u,c]=(0,jn.useState)(null),d=(0,jn.useRef)(null),f=(0,jn.useRef)(null);return(0,jn.useEffect)(()=>{if(!o)return;let p=x=>{let y=x.target;d.current?.contains(y)||f.current?.contains(y)||l(!1)},g=x=>{x.key==="Escape"&&l(!1)},m=()=>l(!1);return document.addEventListener("mousedown",p),document.addEventListener("keydown",g),window.addEventListener("resize",m),window.addEventListener("scroll",m,!0),()=>{document.removeEventListener("mousedown",p),document.removeEventListener("keydown",g),window.removeEventListener("resize",m),window.removeEventListener("scroll",m,!0)}},[o]),t.length===0?null:(0,Ln.jsxs)("div",{className:"flex shrink-0 items-center border-l border-white/[0.05]",children:[(0,Ln.jsx)("button",{ref:d,type:"button",onClick:()=>{if(o){l(!1);return}let p=d.current?.getBoundingClientRect();p&&c({top:p.bottom+4,right:Math.max(4,window.innerWidth-p.right)}),l(!0)},className:$("flex items-center justify-center w-6 h-6 mx-1 rounded-md transition",o?"bg-white/10 text-white/80":"text-white/40 hover:bg-white/5 hover:text-white/70"),title:"Editor actions","aria-haspopup":"menu","aria-expanded":o,children:(0,Ln.jsx)(bs,{className:"w-4 h-4"})}),o&&u?(0,B1.createPortal)((0,Ln.jsxs)("div",{ref:f,role:"menu",style:{position:"fixed",top:u.top,right:u.right},className:"z-[1000] min-w-[190px] rounded-lg border border-white/10 bg-[#14141b] py-1 text-[11px] text-white/80 shadow-[0_18px_46px_-20px_rgba(0,0,0,0.8)]",children:[(0,Ln.jsx)(mp,{label:"Close All",onClick:()=>{n(),l(!1)}}),(0,Ln.jsx)(mp,{label:"Close Saved",onClick:()=>{r(),l(!1)}}),(0,Ln.jsx)(mp,{label:"Close Others",disabled:!e,onClick:()=>{e&&a(e),l(!1)}}),(0,Ln.jsx)("div",{className:"my-1 h-px bg-white/[0.06]"}),(0,Ln.jsxs)("button",{type:"button",role:"menuitemcheckbox","aria-checked":s,onClick:()=>i(!s),className:"flex w-full items-center gap-2 px-3 py-1.5 text-left hover:bg-white/[0.06]",children:[(0,Ln.jsx)("span",{className:"w-3.5 shrink-0 text-emerald-300",children:s?(0,Ln.jsx)(Dn,{className:"w-3.5 h-3.5"}):null}),(0,Ln.jsx)("span",{children:"Enable Preview Editors"})]})]}),document.body):null]})}function mp({label:t,onClick:e,disabled:n}){return(0,Ln.jsx)("button",{type:"button",role:"menuitem",disabled:n,onClick:e,className:"flex w-full items-center px-3 py-1.5 text-left hover:bg-white/[0.06] disabled:opacity-40 disabled:cursor-not-allowed",children:t})}var wi=j($e(),1);var dt=j(ie(),1);function MM(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function gp(t){if(!t)return null;try{return new Date(t).toLocaleString(void 0,{dateStyle:"medium",timeStyle:"short"})}catch{return t}}function xp({node:t,className:e,hideVersionDiff:n=!1}){let{tags:r,category:a,createdAt:s,updatedAt:i,metadata:o,sourceAgentId:l,version:u,readSource:c}=t,d=t.uri?qe(t.uri):void 0,h=hn().useAgents(),p=(0,wi.useMemo)(()=>Ms(h),[h]),g=(0,wi.useMemo)(()=>l?p.byId.get(l)??null:null,[p,l]),m=g?.name||g?.slug,x=co(g?.id,p);if(!yp(t))return null;let b=o&&typeof o.mimeType=="string"?o.mimeType:void 0,C=o&&typeof o.size=="number"?o.size:void 0,L=$l(t),P=u?.sync,w=fi(u?.changedAt),k=vh(u?.changedAt),_=vh(P?.syncedAt);return(0,dt.jsxs)("div",{className:$("flex flex-wrap items-center gap-1.5 px-2 py-2 text-[10px]",e),style:{background:"linear-gradient(180deg, rgba(255,255,255,0.03) 0%, rgba(255,255,255,0.01) 100%)",borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[(0,dt.jsxs)("span",{className:$("inline-flex items-center gap-1 rounded-full border px-2 py-1",L.highlightTone,"border-white/[0.07]",L.tone),children:[(0,dt.jsx)(L.icon,{className:$("w-3 h-3",L.iconTone)}),L.label]}),d?(0,dt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.03] px-2 py-1 text-white/60",children:[(0,dt.jsx)(Xa,{className:"w-3 h-3 text-white/35"}),(0,dt.jsx)("span",{className:"uppercase font-semibold tracking-wide",children:d})]}):null,t.os_uri?(0,dt.jsx)(TM,{value:t.os_uri}):null,m?(0,dt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.03] px-2 py-1 text-white/55",title:`Created by ${m}`,children:[(0,dt.jsx)(yl,{className:"w-3 h-3 text-white/35"}),(0,dt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wide",style:{color:x||"var(--icon-muted)",backgroundColor:x?`${x}20`:"rgba(255,255,255,0.04)"},children:[(0,dt.jsx)("span",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:x||"var(--icon-muted)"}}),m]})]}):null,a?(0,dt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.03] px-2 py-1 text-white/55",children:[(0,dt.jsx)(Tr,{className:"w-3 h-3 text-white/35"}),a]}):null,r&&r.length>0?(0,dt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.03] px-2 py-1 text-white/55",children:[(0,dt.jsx)(Gl,{className:"w-3 h-3 text-white/35"}),r.map(M=>(0,dt.jsx)("span",{className:"inline-flex rounded-full px-1.5 py-0.5 text-[9px] font-medium bg-white/[0.06] text-white/70",children:M},M))]}):null,b?(0,dt.jsx)("span",{className:"rounded-full border border-white/[0.06] bg-white/[0.02] px-2 py-1 text-white/40",children:b}):null,C?(0,dt.jsx)("span",{className:"rounded-full border border-white/[0.06] bg-white/[0.02] px-2 py-1 text-white/40",children:MM(C)}):null,s?(0,dt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.02] px-2 py-1 text-white/38",children:[(0,dt.jsx)(wa,{className:"w-3 h-3"}),gp(s)]}):null,i&&i!==s?(0,dt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.02] px-2 py-1 text-white/40",children:[(0,dt.jsx)(_t,{className:"w-2.5 h-2.5"}),gp(i)]}):null,u?.changedAt?(0,dt.jsxs)("span",{className:$("inline-flex items-center gap-1 rounded-full border px-2 py-1",w.pillClassName),children:[(0,dt.jsx)(wa,{className:$("w-3 h-3",w.iconClassName)}),"changed ",k?`${k} ago`:gp(u.changedAt)]}):null,!n&&u?.diff?(0,dt.jsxs)("span",{className:$("inline-flex items-center gap-1 rounded-full border px-2 py-1",w.pillClassName),children:[(0,dt.jsx)(or,{className:$("w-3 h-3",w.iconClassName)}),(0,dt.jsxs)("span",{className:"text-emerald-200/95",children:["+",u.diff.added]}),(0,dt.jsx)("span",{className:"text-white/25",children:"/"}),(0,dt.jsxs)("span",{className:"text-rose-200/95",children:["-",u.diff.removed]})]}):null,_?(0,dt.jsxs)("span",{className:"rounded-full border border-white/[0.06] bg-white/[0.02] px-2 py-1 text-white/38",children:["synced ",_," ago"]}):null]})}function TM({value:t}){let[e,n]=(0,wi.useState)(!1),r=(0,wi.useCallback)(()=>{navigator.clipboard.writeText(t).then(()=>{n(!0),setTimeout(()=>n(!1),1500)}).catch(()=>{})},[t]),a=t.length>60?"..."+t.slice(-57):t;return(0,dt.jsxs)("button",{type:"button",onClick:r,title:t,className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.03] px-2 py-1 text-white/45 hover:text-white/70 hover:bg-white/[0.06] transition-colors cursor-pointer",children:[e?(0,dt.jsx)(na,{className:"w-3 h-3 text-emerald-300/80"}):(0,dt.jsx)(zn,{className:"w-3 h-3 text-white/35"}),(0,dt.jsx)("span",{className:"font-mono truncate max-w-[280px]",children:a})]})}function yp(t){let{tags:e,category:n,createdAt:r,updatedAt:a,metadata:s,sourceAgentId:i,version:o}=t,l=t.uri?qe(t.uri):void 0;return!!i||!!e?.length||!!n||!!l||!!t.os_uri||!!r||!!a||!!o||!!(s&&Object.keys(s).length>0)}var xf=j($e(),1);var wp=[],z1=[];(()=>{let t="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,1n,9,16,o,,x,1i,3,,i,,7,a,2,t,3,1k,,,7,2,2,2,3,9,,a,2,q,,2,3,1k,,,5,4,2,2,3,3,,u,2,3,,b,3,1k,,,8,,3,,3,k,2,m,6,,3,1k,,,7,2,2,2,3,7,3,a,2,u,,1n,5,3,3,,4,9,,14,5,1j,,,7,,3,,4,7,2,b,2,t,3,1k,,,7,,3,,4,7,2,b,2,f,,c,4,1j,2,,7,,3,,4,9,,a,2,t,3,1y,,4,6,,,,8,i,2,1p,,,8,c,8,2q,,,a,b,7,21,2,r,,,,,,4,2,1d,k,,2,5,b,,10,9,,2u,b,,6,n,4,4,3,g,4,d,,,3,6,,f,,jj,3,qa,4,s,3,t,2,u,2,1s,w,9,,19,3,,,39,2,y,,3a,c,4,c,63,5,1l,a,,,,,2,o,2,,1c,1a,2,c,k,5,1b,h,12,9,c,3,u,d,1k,e,1c,k,48,3,,l,4,,6,,2,3,5i,1s,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,n,5,4,,2b,2,1e,i,q,i,d,,12,8,p,d,18,4,1b,e,10,,1v,e,c,,8,2,1a,,1f,,,3,2,2,5,2,,,15,5,5,2,6k,8,,2,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,1t,5,8t,2,25,6,1y,b,1d,4,3e,3,1h,f,15,,2,2,a,4,19,b,7,,1p,3,10,e,g,2,18,,c,3,1c,e,8,4,,2,2k,c,6,,2,,4d,c,l,4,1j,2,,7,2,2,2,3,9,,a,2,2,7,3,5,1v,9,,,2,,,4,,5,,,e,2,2a,i,n,,29,k,6j,7,2,9,r,2,2a,h,2y,d,2t,3,2,a,74,f,6t,6,,2,2,4,,,,2,3x,7,2,7,3,,s,a,14,7,,4,8,,9,b,1a,g,5i,8,5j,8,,8,2a,m,,e,3e,6,3,,,2,,7,,,1u,5,,2,,5,9n,4,9,2,,,1c,7,3,5,n,,44l,,6,f,8ug,i,1xc,5,1n,7,t4,,,1j,7,4,29,,b,2,f57,2,3mp,1a,2,n,f2,5,3,6,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,2s,,4g,7,af,,1p,4,e4,4,72,2,6r,,2,,7,2,5,,d6,7,31,7,240,5".split(",").map(e=>e?parseInt(e,36):1);for(let e=0,n=0;e<t.length;e++)(e%2?z1:wp).push(n=n+t[e])})();function DM(t){if(t<768)return!1;for(let e=0,n=wp.length;;){let r=e+n>>1;if(t<wp[r])n=r;else if(t>=z1[r])e=r+1;else return!0;if(e==n)return!1}}function U1(t){return t>=127462&&t<=127487}var G1=8205;function j1(t,e,n=!0,r=!0){return(n?V1:FM)(t,e,r)}function V1(t,e,n){if(e==t.length)return e;e&&q1(t.charCodeAt(e))&&$1(t.charCodeAt(e-1))&&e--;let r=bp(t,e);for(e+=W1(r);e<t.length;){let a=bp(t,e);if(r==G1||a==G1||n&&DM(a))e+=W1(a),r=a;else if(U1(a)){let s=0,i=e-2;for(;i>=0&&U1(bp(t,i));)s++,i-=2;if(s%2==0)break;e+=2}else break}return e}function FM(t,e,n){for(;e>1;){let r=V1(t,e-2,n);if(r<e)return r;e--}return 0}function bp(t,e){let n=t.charCodeAt(e);if(!$1(n)||e+1==t.length)return n;let r=t.charCodeAt(e+1);return q1(r)?(n-55296<<10)+(r-56320)+65536:n}function q1(t){return t>=56320&&t<57344}function $1(t){return t>=55296&&t<56320}function W1(t){return t<65536?1:2}var st=class t{lineAt(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,n,r){[e,n]=Po(this,e,n);let a=[];return this.decompose(0,e,a,2),r.length&&r.decompose(0,r.length,a,3),this.decompose(n,this.length,a,1),Io.from(a,this.length-(n-e)+r.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,n=this.length){[e,n]=Po(this,e,n);let r=[];return this.decompose(e,n,r,0),Io.from(r,n-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let n=this.scanIdentical(e,1),r=this.length-this.scanIdentical(e,-1),a=new Ci(this),s=new Ci(e);for(let i=n,o=n;;){if(a.next(i),s.next(i),i=0,a.lineBreak!=s.lineBreak||a.done!=s.done||a.value!=s.value)return!1;if(o+=a.value.length,a.done||o>=r)return!0}}iter(e=1){return new Ci(this,e)}iterRange(e,n=this.length){return new pd(this,e,n)}iterLines(e,n){let r;if(e==null)r=this.iter();else{n==null&&(n=this.lines+1);let a=this.line(e).from;r=this.iterRange(a,Math.max(a,n==this.lines+1?this.length:n<=1?0:this.line(n-1).to))}return new md(r)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?t.empty:e.length<=32?new Sr(e):Io.from(Sr.split(e,[]))}},Sr=class t extends st{constructor(e,n=EM(e)){super(),this.text=e,this.length=n}get lines(){return this.text.length}get children(){return null}lineInner(e,n,r,a){for(let s=0;;s++){let i=this.text[s],o=a+i.length;if((n?r:o)>=e)return new kp(a,o,r,i);a=o+1,r++}}decompose(e,n,r,a){let s=e<=0&&n>=this.length?this:new t(K1(this.text,e,n),Math.min(n,this.length)-Math.max(0,e));if(a&1){let i=r.pop(),o=hd(s.text,i.text.slice(),0,s.length);if(o.length<=32)r.push(new t(o,i.length+s.length));else{let l=o.length>>1;r.push(new t(o.slice(0,l)),new t(o.slice(l)))}}else r.push(s)}replace(e,n,r){if(!(r instanceof t))return super.replace(e,n,r);[e,n]=Po(this,e,n);let a=hd(this.text,hd(r.text,K1(this.text,0,e)),n),s=this.length+r.length-(n-e);return a.length<=32?new t(a,s):Io.from(t.split(a,[]),s)}sliceString(e,n=this.length,r=`
33
+ `){[e,n]=Po(this,e,n);let a="";for(let s=0,i=0;s<=n&&i<this.text.length;i++){let o=this.text[i],l=s+o.length;s>e&&i&&(a+=r),e<l&&n>s&&(a+=o.slice(Math.max(0,e-s),n-s)),s=l+1}return a}flatten(e){for(let n of this.text)e.push(n)}scanIdentical(){return 0}static split(e,n){let r=[],a=-1;for(let s of e)r.push(s),a+=s.length+1,r.length==32&&(n.push(new t(r,a)),r=[],a=-1);return a>-1&&n.push(new t(r,a)),n}},Io=class t extends st{constructor(e,n){super(),this.children=e,this.length=n,this.lines=0;for(let r of e)this.lines+=r.lines}lineInner(e,n,r,a){for(let s=0;;s++){let i=this.children[s],o=a+i.length,l=r+i.lines-1;if((n?l:o)>=e)return i.lineInner(e,n,r,a);a=o+1,r=l+1}}decompose(e,n,r,a){for(let s=0,i=0;i<=n&&s<this.children.length;s++){let o=this.children[s],l=i+o.length;if(e<=l&&n>=i){let u=a&((i<=e?1:0)|(l>=n?2:0));i>=e&&l<=n&&!u?r.push(o):o.decompose(e-i,n-i,r,u)}i=l+1}}replace(e,n,r){if([e,n]=Po(this,e,n),r.lines<this.lines)for(let a=0,s=0;a<this.children.length;a++){let i=this.children[a],o=s+i.length;if(e>=s&&n<=o){let l=i.replace(e-s,n-s,r),u=this.lines-i.lines+l.lines;if(l.lines<u>>4&&l.lines>u>>6){let c=this.children.slice();return c[a]=l,new t(c,this.length-(n-e)+r.length)}return super.replace(s,o,l)}s=o+1}return super.replace(e,n,r)}sliceString(e,n=this.length,r=`
34
+ `){[e,n]=Po(this,e,n);let a="";for(let s=0,i=0;s<this.children.length&&i<=n;s++){let o=this.children[s],l=i+o.length;i>e&&s&&(a+=r),e<l&&n>i&&(a+=o.sliceString(e-i,n-i,r)),i=l+1}return a}flatten(e){for(let n of this.children)n.flatten(e)}scanIdentical(e,n){if(!(e instanceof t))return 0;let r=0,[a,s,i,o]=n>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;a+=n,s+=n){if(a==i||s==o)return r;let l=this.children[a],u=e.children[s];if(l!=u)return r+l.scanIdentical(u,n);r+=l.length+1}}static from(e,n=e.reduce((r,a)=>r+a.length+1,-1)){let r=0;for(let h of e)r+=h.lines;if(r<32){let h=[];for(let p of e)p.flatten(h);return new Sr(h,n)}let a=Math.max(32,r>>5),s=a<<1,i=a>>1,o=[],l=0,u=-1,c=[];function d(h){let p;if(h.lines>s&&h instanceof t)for(let g of h.children)d(g);else h.lines>i&&(l>i||!l)?(f(),o.push(h)):h instanceof Sr&&l&&(p=c[c.length-1])instanceof Sr&&h.lines+p.lines<=32?(l+=h.lines,u+=h.length+1,c[c.length-1]=new Sr(p.text.concat(h.text),p.length+1+h.length)):(l+h.lines>a&&f(),l+=h.lines,u+=h.length+1,c.push(h))}function f(){l!=0&&(o.push(c.length==1?c[0]:t.from(c,u)),u=-1,l=c.length=0)}for(let h of e)d(h);return f(),o.length==1?o[0]:new t(o,n)}};st.empty=new Sr([""],0);function EM(t){let e=-1;for(let n of t)e+=n.length+1;return e}function hd(t,e,n=0,r=1e9){for(let a=0,s=0,i=!0;s<t.length&&a<=r;s++){let o=t[s],l=a+o.length;l>=n&&(l>r&&(o=o.slice(0,r-a)),a<n&&(o=o.slice(n-a)),i?(e[e.length-1]+=o,i=!1):e.push(o)),a=l+1}return e}function K1(t,e,n){return hd(t,[""],e,n)}var Ci=class{constructor(e,n=1){this.dir=n,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[e],this.offsets=[n>0?1:(e instanceof Sr?e.text.length:e.children.length)<<1]}nextInner(e,n){for(this.done=this.lineBreak=!1;;){let r=this.nodes.length-1,a=this.nodes[r],s=this.offsets[r],i=s>>1,o=a instanceof Sr?a.text.length:a.children.length;if(i==(n>0?o:0)){if(r==0)return this.done=!0,this.value="",this;n>0&&this.offsets[r-1]++,this.nodes.pop(),this.offsets.pop()}else if((s&1)==(n>0?0:1)){if(this.offsets[r]+=n,e==0)return this.lineBreak=!0,this.value=`
35
+ `,this;e--}else if(a instanceof Sr){let l=a.text[i+(n<0?-1:0)];if(this.offsets[r]+=n,l.length>Math.max(0,e))return this.value=e==0?l:n>0?l.slice(e):l.slice(0,l.length-e),this;e-=l.length}else{let l=a.children[i+(n<0?-1:0)];e>l.length?(e-=l.length,this.offsets[r]+=n):(n<0&&this.offsets[r]--,this.nodes.push(l),this.offsets.push(n>0?1:(l instanceof Sr?l.text.length:l.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}},pd=class{constructor(e,n,r){this.value="",this.done=!1,this.cursor=new Ci(e,n>r?-1:1),this.pos=n>r?e.length:0,this.from=Math.min(n,r),this.to=Math.max(n,r)}nextInner(e,n){if(n<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;e+=Math.max(0,n<0?this.pos-this.to:this.from-this.pos);let r=n<0?this.pos-this.from:this.to-this.pos;e>r&&(e=r),r-=e;let{value:a}=this.cursor.next(e);return this.pos+=(a.length+e)*n,this.value=a.length<=r?a:n<0?a.slice(a.length-r):a.slice(0,r),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}},md=class{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:n,lineBreak:r,value:a}=this.inner.next(e);return n&&this.afterBreak?(this.value="",this.afterBreak=!1):n?(this.done=!0,this.value=""):r?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=a,this.afterBreak=!1),this}get lineBreak(){return!1}};typeof Symbol<"u"&&(st.prototype[Symbol.iterator]=function(){return this.iter()},Ci.prototype[Symbol.iterator]=pd.prototype[Symbol.iterator]=md.prototype[Symbol.iterator]=function(){return this});var kp=class{constructor(e,n,r,a){this.from=e,this.to=n,this.number=r,this.text=a}get length(){return this.to-this.from}};function Po(t,e,n){return e=Math.max(0,Math.min(t.length,e)),[e,Math.max(e,Math.min(t.length,n))]}function Pn(t,e,n=!0,r=!0){return j1(t,e,n,r)}function OM(t){return t>=56320&&t<57344}function BM(t){return t>=55296&&t<56320}function Q1(t,e){let n=t.charCodeAt(e);if(!BM(n)||e+1==t.length)return n;let r=t.charCodeAt(e+1);return OM(r)?(n-55296<<10)+(r-56320)+65536:n}function ek(t){return t<65536?1:2}var Sp=/\r\n?|\n/,cr=(function(t){return t[t.Simple=0]="Simple",t[t.TrackDel=1]="TrackDel",t[t.TrackBefore=2]="TrackBefore",t[t.TrackAfter=3]="TrackAfter",t})(cr||(cr={})),rs=class t{constructor(e){this.sections=e}get length(){let e=0;for(let n=0;n<this.sections.length;n+=2)e+=this.sections[n];return e}get newLength(){let e=0;for(let n=0;n<this.sections.length;n+=2){let r=this.sections[n+1];e+=r<0?this.sections[n]:r}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let n=0,r=0,a=0;n<this.sections.length;){let s=this.sections[n++],i=this.sections[n++];i<0?(e(r,a,s),a+=s):a+=i,r+=s}}iterChangedRanges(e,n=!1){Cp(this,e,n)}get invertedDesc(){let e=[];for(let n=0;n<this.sections.length;){let r=this.sections[n++],a=this.sections[n++];a<0?e.push(r,a):e.push(a,r)}return new t(e)}composeDesc(e){return this.empty?e:e.empty?this:tk(this,e)}mapDesc(e,n=!1){return e.empty?this:Ip(this,e,n)}mapPos(e,n=-1,r=cr.Simple){let a=0,s=0;for(let i=0;i<this.sections.length;){let o=this.sections[i++],l=this.sections[i++],u=a+o;if(l<0){if(u>e)return s+(e-a);s+=o}else{if(r!=cr.Simple&&u>=e&&(r==cr.TrackDel&&a<e&&u>e||r==cr.TrackBefore&&a<e||r==cr.TrackAfter&&u>e))return null;if(u>e||u==e&&n<0&&!o)return e==a||n<0?s:s+l;s+=l}a=u}if(e>a)throw new RangeError(`Position ${e} is out of range for changeset of length ${a}`);return s}touchesRange(e,n=e){for(let r=0,a=0;r<this.sections.length&&a<=n;){let s=this.sections[r++],i=this.sections[r++],o=a+s;if(i>=0&&a<=n&&o>=e)return a<e&&o>n?"cover":!0;a=o}return!1}toString(){let e="";for(let n=0;n<this.sections.length;){let r=this.sections[n++],a=this.sections[n++];e+=(e?" ":"")+r+(a>=0?":"+a:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(n=>typeof n!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new t(e)}static create(e){return new t(e)}},Nn=class t extends rs{constructor(e,n){super(e),this.inserted=n}apply(e){if(this.length!=e.length)throw new RangeError("Applying change set to a document with the wrong length");return Cp(this,(n,r,a,s,i)=>e=e.replace(a,a+(r-n),i),!1),e}mapDesc(e,n=!1){return Ip(this,e,n,!0)}invert(e){let n=this.sections.slice(),r=[];for(let a=0,s=0;a<n.length;a+=2){let i=n[a],o=n[a+1];if(o>=0){n[a]=o,n[a+1]=i;let l=a>>1;for(;r.length<l;)r.push(st.empty);r.push(i?e.slice(s,s+i):st.empty)}s+=i}return new t(n,r)}compose(e){return this.empty?e:e.empty?this:tk(this,e,!0)}map(e,n=!1){return e.empty?this:Ip(this,e,n,!0)}iterChanges(e,n=!1){Cp(this,e,n)}get desc(){return rs.create(this.sections)}filter(e){let n=[],r=[],a=[],s=new Ii(this);e:for(let i=0,o=0;;){let l=i==e.length?1e9:e[i++];for(;o<l||o==l&&s.len==0;){if(s.done)break e;let c=Math.min(s.len,l-o);Vn(a,c,-1);let d=s.ins==-1?-1:s.off==0?s.ins:0;Vn(n,c,d),d>0&&Hs(r,n,s.text),s.forward(c),o+=c}let u=e[i++];for(;o<u;){if(s.done)break e;let c=Math.min(s.len,u-o);Vn(n,c,-1),Vn(a,c,s.ins==-1?-1:s.off==0?s.ins:0),s.forward(c),o+=c}}return{changes:new t(n,r),filtered:rs.create(a)}}toJSON(){let e=[];for(let n=0;n<this.sections.length;n+=2){let r=this.sections[n],a=this.sections[n+1];a<0?e.push(r):a==0?e.push([r]):e.push([r].concat(this.inserted[n>>1].toJSON()))}return e}static of(e,n,r){let a=[],s=[],i=0,o=null;function l(c=!1){if(!c&&!a.length)return;i<n&&Vn(a,n-i,-1);let d=new t(a,s);o=o?o.compose(d.map(o)):d,a=[],s=[],i=0}function u(c){if(Array.isArray(c))for(let d of c)u(d);else if(c instanceof t){if(c.length!=n)throw new RangeError(`Mismatched change set length (got ${c.length}, expected ${n})`);l(),o=o?o.compose(c.map(o)):c}else{let{from:d,to:f=d,insert:h}=c;if(d>f||d<0||f>n)throw new RangeError(`Invalid change range ${d} to ${f} (in doc of length ${n})`);let p=h?typeof h=="string"?st.of(h.split(r||Sp)):h:st.empty,g=p.length;if(d==f&&g==0)return;d<i&&l(),d>i&&Vn(a,d-i,-1),Vn(a,f-d,g),Hs(s,a,p),i=f}}return u(e),l(!o),o}static empty(e){return new t(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let n=[],r=[];for(let a=0;a<e.length;a++){let s=e[a];if(typeof s=="number")n.push(s,-1);else{if(!Array.isArray(s)||typeof s[0]!="number"||s.some((i,o)=>o&&typeof i!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(s.length==1)n.push(s[0],0);else{for(;r.length<a;)r.push(st.empty);r[a]=st.of(s.slice(1)),n.push(s[0],r[a].length)}}}return new t(n,r)}static createSet(e,n){return new t(e,n)}};function Vn(t,e,n,r=!1){if(e==0&&n<=0)return;let a=t.length-2;a>=0&&n<=0&&n==t[a+1]?t[a]+=e:a>=0&&e==0&&t[a]==0?t[a+1]+=n:r?(t[a]+=e,t[a+1]+=n):t.push(e,n)}function Hs(t,e,n){if(n.length==0)return;let r=e.length-2>>1;if(r<t.length)t[t.length-1]=t[t.length-1].append(n);else{for(;t.length<r;)t.push(st.empty);t.push(n)}}function Cp(t,e,n){let r=t.inserted;for(let a=0,s=0,i=0;i<t.sections.length;){let o=t.sections[i++],l=t.sections[i++];if(l<0)a+=o,s+=o;else{let u=a,c=s,d=st.empty;for(;u+=o,c+=l,l&&r&&(d=d.append(r[i-2>>1])),!(n||i==t.sections.length||t.sections[i+1]<0);)o=t.sections[i++],l=t.sections[i++];e(a,u,s,c,d),a=u,s=c}}}function Ip(t,e,n,r=!1){let a=[],s=r?[]:null,i=new Ii(t),o=new Ii(e);for(let l=-1;;){if(i.done&&o.len||o.done&&i.len)throw new Error("Mismatched change set lengths");if(i.ins==-1&&o.ins==-1){let u=Math.min(i.len,o.len);Vn(a,u,-1),i.forward(u),o.forward(u)}else if(o.ins>=0&&(i.ins<0||l==i.i||i.off==0&&(o.len<i.len||o.len==i.len&&!n))){let u=o.len;for(Vn(a,o.ins,-1);u;){let c=Math.min(i.len,u);i.ins>=0&&l<i.i&&i.len<=c&&(Vn(a,0,i.ins),s&&Hs(s,a,i.text),l=i.i),i.forward(c),u-=c}o.next()}else if(i.ins>=0){let u=0,c=i.len;for(;c;)if(o.ins==-1){let d=Math.min(c,o.len);u+=d,c-=d,o.forward(d)}else if(o.ins==0&&o.len<c)c-=o.len,o.next();else break;Vn(a,u,l<i.i?i.ins:0),s&&l<i.i&&Hs(s,a,i.text),l=i.i,i.forward(i.len-c)}else{if(i.done&&o.done)return s?Nn.createSet(a,s):rs.create(a);throw new Error("Mismatched change set lengths")}}}function tk(t,e,n=!1){let r=[],a=n?[]:null,s=new Ii(t),i=new Ii(e);for(let o=!1;;){if(s.done&&i.done)return a?Nn.createSet(r,a):rs.create(r);if(s.ins==0)Vn(r,s.len,0,o),s.next();else if(i.len==0&&!i.done)Vn(r,0,i.ins,o),a&&Hs(a,r,i.text),i.next();else{if(s.done||i.done)throw new Error("Mismatched change set lengths");{let l=Math.min(s.len2,i.len),u=r.length;if(s.ins==-1){let c=i.ins==-1?-1:i.off?0:i.ins;Vn(r,l,c,o),a&&c&&Hs(a,r,i.text)}else i.ins==-1?(Vn(r,s.off?0:s.len,l,o),a&&Hs(a,r,s.textBit(l))):(Vn(r,s.off?0:s.len,i.off?0:i.ins,o),a&&!i.off&&Hs(a,r,i.text));o=(s.ins>l||i.ins>=0&&i.len>l)&&(o||r.length>u),s.forward2(l),i.forward(l)}}}}var Ii=class{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,n=this.i-2>>1;return n>=e.length?st.empty:e[n]}textBit(e){let{inserted:n}=this.set,r=this.i-2>>1;return r>=n.length&&!e?st.empty:n[r].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}},vi=class t{constructor(e,n,r,a){this.from=e,this.to=n,this.flags=r,this.goalColumn=a}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get undirectional(){return(this.flags&64)>0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}map(e,n=-1){let r,a;return this.empty?r=a=e.mapPos(this.from,n):(r=e.mapPos(this.from,1),a=e.mapPos(this.to,-1)),r==this.from&&a==this.to?this:new t(r,a,this.flags,this.goalColumn)}extend(e,n=e,r=0){if(e<=this.anchor&&n>=this.anchor)return se.range(e,n,void 0,void 0,r);let a=Math.abs(e-this.anchor)>Math.abs(n-this.anchor)?e:n;return se.range(this.anchor,a,void 0,void 0,r)}eq(e,n=!1){return this.anchor==e.anchor&&this.head==e.head&&this.goalColumn==e.goalColumn&&(!n||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return se.range(e.anchor,e.head)}static create(e,n,r,a){return new t(e,n,r,a)}},se=class t{constructor(e,n){this.ranges=e,this.mainIndex=n}map(e,n=-1){return e.empty?this:t.create(this.ranges.map(r=>r.map(e,n)),this.mainIndex)}eq(e,n=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let r=0;r<this.ranges.length;r++)if(!this.ranges[r].eq(e.ranges[r],n))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new t([this.main],0)}addRange(e,n=!0){return t.create([e].concat(this.ranges),n?0:this.mainIndex+1)}replaceRange(e,n=this.mainIndex){let r=this.ranges.slice();return r[n]=e,t.create(r,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new t(e.ranges.map(n=>vi.fromJSON(n)),e.main)}static single(e,n=e){return new t([t.range(e,n)],0)}static create(e,n=0){if(e.length==0)throw new RangeError("A selection needs at least one range");for(let r=0,a=0;a<e.length;a++){let s=e[a];if(s.empty?s.from<=r:s.from<r)return t.normalized(e.slice(),n);r=s.to}return new t(e,n)}static cursor(e,n=0,r,a){return vi.create(e,e,(n==0?0:n<0?8:16)|(r==null?7:Math.min(6,r)),a)}static range(e,n,r,a,s){let i=a==null?7:Math.min(6,a);return!s&&e!=n&&(s=n<e?1:-1),s&&(i|=s<0?8:16),n<e?vi.create(n,e,i|32,r):vi.create(e,n,i,r)}static undirectionalRange(e,n){return vi.create(e,n,64,void 0)}static normalized(e,n=0){let r=e[n];e.sort((a,s)=>a.from-s.from),n=e.indexOf(r);for(let a=1;a<e.length;a++){let s=e[a],i=e[a-1];if(s.empty?s.from<=i.to:s.from<i.to){let o=i.from,l=Math.max(s.to,i.to);a<=n&&n--,e.splice(--a,2,s.anchor>s.head?t.range(l,o):t.range(o,l))}}return new t(e,n)}};function nk(t,e){for(let n of t.ranges)if(n.to>e)throw new RangeError("Selection points outside of document")}var Ep=0,Me=class t{constructor(e,n,r,a,s){this.combine=e,this.compareInput=n,this.compare=r,this.isStatic=a,this.id=Ep++,this.default=e([]),this.extensions=typeof s=="function"?s(this):s}get reader(){return this}static define(e={}){return new t(e.combine||(n=>n),e.compareInput||((n,r)=>n===r),e.compare||(e.combine?(n,r)=>n===r:Op),!!e.static,e.enables)}of(e){return new Lo([],this,0,e)}compute(e,n){if(this.isStatic)throw new Error("Can't compute a static facet");return new Lo(e,this,1,n)}computeN(e,n){if(this.isStatic)throw new Error("Can't compute a static facet");return new Lo(e,this,2,n)}from(e,n){return n||(n=r=>r),this.compute([e],r=>n(r.field(e)))}};function Op(t,e){return t==e||t.length==e.length&&t.every((n,r)=>n===e[r])}var Lo=class{constructor(e,n,r,a){this.dependencies=e,this.facet=n,this.type=r,this.value=a,this.id=Ep++}dynamicSlot(e){var n;let r=this.value,a=this.facet.compareInput,s=this.id,i=e[s]>>1,o=this.type==2,l=!1,u=!1,c=[];for(let d of this.dependencies)d=="doc"?l=!0:d=="selection"?u=!0:(((n=e[d.id])!==null&&n!==void 0?n:1)&1)==0&&c.push(e[d.id]);return{create(d){return d.values[i]=r(d),1},update(d,f){if(l&&f.docChanged||u&&(f.docChanged||f.selection)||Lp(d,c)){let h=r(d);if(o?!X1(h,d.values[i],a):!a(h,d.values[i]))return d.values[i]=h,1}return 0},reconfigure:(d,f)=>{let h,p=f.config.address[s];if(p!=null){let g=yd(f,p);if(this.dependencies.every(m=>m instanceof Me?f.facet(m)===d.facet(m):m instanceof vn?f.field(m,!1)==d.field(m,!1):!0)||(o?X1(h=r(d),g,a):a(h=r(d),g)))return d.values[i]=g,0}else h=r(d);return d.values[i]=h,1}}}get extension(){return this}};function X1(t,e,n){if(t.length!=e.length)return!1;for(let r=0;r<t.length;r++)if(!n(t[r],e[r]))return!1;return!0}function Lp(t,e){let n=!1;for(let r of e)uu(t,r)&1&&(n=!0);return n}function _M(t,e,n){let r=n.map(l=>t[l.id]),a=n.map(l=>l.type),s=r.filter(l=>!(l&1)),i=t[e.id]>>1;function o(l){let u=[];for(let c=0;c<r.length;c++){let d=yd(l,r[c]);if(a[c]==2)for(let f of d)u.push(f);else u.push(d)}return e.combine(u)}return{create(l){for(let u of r)uu(l,u);return l.values[i]=o(l),1},update(l,u){if(!Lp(l,s))return 0;let c=o(l);return e.compare(c,l.values[i])?0:(l.values[i]=c,1)},reconfigure(l,u){let c=Lp(l,r),d=u.config.facets[e.id],f=u.facet(e);if(d&&!c&&Op(n,d))return l.values[i]=f,0;let h=o(l);return e.compare(h,f)?(l.values[i]=f,0):(l.values[i]=h,1)}}}var cd=Me.define({static:!0}),vn=class t{constructor(e,n,r,a,s){this.id=e,this.createF=n,this.updateF=r,this.compareF=a,this.spec=s,this.provides=void 0}static define(e){let n=new t(Ep++,e.create,e.update,e.compare||((r,a)=>r===a),e);return e.provide&&(n.provides=e.provide(n)),n}create(e){let n=e.facet(cd).find(r=>r.field==this);return(n?.create||this.createF)(e)}slot(e){let n=e[this.id]>>1;return{create:r=>(r.values[n]=this.create(r),1),update:(r,a)=>{let s=r.values[n],i=this.updateF(s,a);return this.compareF(s,i)?0:(r.values[n]=i,1)},reconfigure:(r,a)=>{let s=r.facet(cd),i=a.facet(cd),o;return(o=s.find(l=>l.field==this))&&o!=i.find(l=>l.field==this)?(r.values[n]=o.create(r),1):a.config.address[this.id]!=null?(r.values[n]=a.field(this),0):(r.values[n]=this.create(r),1)}}}init(e){return[this,cd.of({field:this,create:e})]}get extension(){return this}},ki={lowest:4,low:3,default:2,high:1,highest:0};function lu(t){return e=>new gd(e,t)}var Ma={highest:lu(ki.highest),high:lu(ki.high),default:lu(ki.default),low:lu(ki.low),lowest:lu(ki.lowest)},gd=class{constructor(e,n){this.inner=e,this.prec=n}get extension(){return this}},_r=class t{of(e){return new cu(this,e)}reconfigure(e){return t.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}},cu=class{constructor(e,n){this.compartment=e,this.inner=n}get extension(){return this}},xd=class t{constructor(e,n,r,a,s,i){for(this.base=e,this.compartments=n,this.dynamicSlots=r,this.address=a,this.staticValues=s,this.facets=i,this.statusTemplate=[];this.statusTemplate.length<r.length;)this.statusTemplate.push(0)}staticFacet(e){let n=this.address[e.id];return n==null?e.default:this.staticValues[n>>1]}static resolve(e,n,r){let a=[],s=Object.create(null),i=new Map;for(let f of HM(e,n,i))f instanceof vn?a.push(f):(s[f.facet.id]||(s[f.facet.id]=[])).push(f);let o=Object.create(null),l=[],u=[];for(let f of a)o[f.id]=u.length<<1,u.push(h=>f.slot(h));let c=r?.config.facets;for(let f in s){let h=s[f],p=h[0].facet,g=c&&c[f]||[];if(h.every(m=>m.type==0))if(o[p.id]=l.length<<1|1,Op(g,h))l.push(r.facet(p));else{let m=p.combine(h.map(x=>x.value));l.push(r&&p.compare(m,r.facet(p))?r.facet(p):m)}else{for(let m of h)m.type==0?(o[m.id]=l.length<<1|1,l.push(m.value)):(o[m.id]=u.length<<1,u.push(x=>m.dynamicSlot(x)));o[p.id]=u.length<<1,u.push(m=>_M(m,p,h))}}let d=u.map(f=>f(o));return new t(e,i,d,o,l,s)}};function HM(t,e,n){let r=[[],[],[],[],[]],a=new Map;function s(i,o){let l=a.get(i);if(l!=null){if(l<=o)return;let u=r[l].indexOf(i);u>-1&&r[l].splice(u,1),i instanceof cu&&n.delete(i.compartment)}if(a.set(i,o),Array.isArray(i))for(let u of i)s(u,o);else if(i instanceof cu){if(n.has(i.compartment))throw new RangeError("Duplicate use of compartment in extensions");let u=e.get(i.compartment)||i.inner;n.set(i.compartment,u),s(u,o)}else if(i instanceof gd)s(i.inner,i.prec);else if(i instanceof vn)r[o].push(i),i.provides&&s(i.provides,o);else if(i instanceof Lo)r[o].push(i),i.facet.extensions&&s(i.facet.extensions,ki.default);else{let u=i.extension;if(!u)throw new Error(`Unrecognized extension value in extension set (${i}).`);if(u==i)throw new Error(`Unrecognized extension value in extension set (${i}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);s(u,o)}}return s(t,ki.default),r.reduce((i,o)=>i.concat(o))}function uu(t,e){if(e&1)return 2;let n=e>>1,r=t.status[n];if(r==4)throw new Error("Cyclic dependency between fields and/or facets");if(r&2)return r;t.status[n]=4;let a=t.computeSlot(t,t.config.dynamicSlots[n]);return t.status[n]=2|a}function yd(t,e){return e&1?t.config.staticValues[e>>1]:t.values[e>>1]}var rk=Me.define(),Ap=Me.define({combine:t=>t.some(e=>e),static:!0}),ak=Me.define({combine:t=>t.length?t[0]:void 0,static:!0}),sk=Me.define(),ik=Me.define(),ok=Me.define(),lk=Me.define({combine:t=>t.length?t[0]:!1}),Hr=class{constructor(e,n){this.type=e,this.value=n}static define(){return new Pp}},Pp=class{of(e){return new Hr(this,e)}},Np=class{constructor(e){this.map=e}of(e){return new pt(this,e)}},pt=class t{constructor(e,n){this.type=e,this.value=n}map(e){let n=this.type.map(this.value,e);return n===void 0?void 0:n==this.value?this:new t(this.type,n)}is(e){return this.type==e}static define(e={}){return new Np(e.map||(n=>n))}static mapEffects(e,n){if(!e.length)return e;let r=[];for(let a of e){let s=a.map(n);s&&r.push(s)}return r}};pt.reconfigure=pt.define();pt.appendConfig=pt.define();var An=class t{constructor(e,n,r,a,s,i){this.startState=e,this.changes=n,this.selection=r,this.effects=a,this.annotations=s,this.scrollIntoView=i,this._doc=null,this._state=null,r&&nk(r,n.newLength),s.some(o=>o.type==t.time)||(this.annotations=s.concat(t.time.of(Date.now())))}static create(e,n,r,a,s,i){return new t(e,n,r,a,s,i)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let n of this.annotations)if(n.type==e)return n.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(e){let n=this.annotation(t.userEvent);return!!(n&&(n==e||n.length>e.length&&n.slice(0,e.length)==e&&n[e.length]=="."))}};An.time=Hr.define();An.userEvent=Hr.define();An.addToHistory=Hr.define();An.remote=Hr.define();function UM(t,e){let n=[];for(let r=0,a=0;;){let s,i;if(r<t.length&&(a==e.length||e[a]>=t[r]))s=t[r++],i=t[r++];else if(a<e.length)s=e[a++],i=e[a++];else return n;!n.length||n[n.length-1]<s?n.push(s,i):n[n.length-1]<i&&(n[n.length-1]=i)}}function uk(t,e,n){var r;let a,s,i;return n?(a=e.changes,s=Nn.empty(e.changes.length),i=t.changes.compose(e.changes)):(a=e.changes.map(t.changes),s=t.changes.mapDesc(e.changes,!0),i=t.changes.compose(a)),{changes:i,selection:e.selection?e.selection.map(s):(r=t.selection)===null||r===void 0?void 0:r.map(a),effects:pt.mapEffects(t.effects,a).concat(pt.mapEffects(e.effects,s)),annotations:t.annotations.length?t.annotations.concat(e.annotations):e.annotations,scrollIntoView:t.scrollIntoView||e.scrollIntoView}}function Rp(t,e,n){let r=e.selection,a=Ao(e.annotations);return e.userEvent&&(a=a.concat(An.userEvent.of(e.userEvent))),{changes:e.changes instanceof Nn?e.changes:Nn.of(e.changes||[],n,t.facet(ak)),selection:r&&(r instanceof se?r:se.single(r.anchor,r.head)),effects:Ao(e.effects),annotations:a,scrollIntoView:!!e.scrollIntoView}}function ck(t,e,n){let r=Rp(t,e.length?e[0]:{},t.doc.length);e.length&&e[0].filter===!1&&(n=!1);for(let s=1;s<e.length;s++){e[s].filter===!1&&(n=!1);let i=!!e[s].sequential;r=uk(r,Rp(t,e[s],i?r.changes.newLength:t.doc.length),i)}let a=An.create(t,r.changes,r.selection,r.effects,r.annotations,r.scrollIntoView);return WM(n?GM(a):a)}function GM(t){let e=t.startState,n=!0;for(let a of e.facet(sk)){let s=a(t);if(s===!1){n=!1;break}Array.isArray(s)&&(n=n===!0?s:UM(n,s))}if(n!==!0){let a,s;if(n===!1)s=t.changes.invertedDesc,a=Nn.empty(e.doc.length);else{let i=t.changes.filter(n);a=i.changes,s=i.filtered.mapDesc(i.changes).invertedDesc}t=An.create(e,a,t.selection&&t.selection.map(s),pt.mapEffects(t.effects,s),t.annotations,t.scrollIntoView)}let r=e.facet(ik);for(let a=r.length-1;a>=0;a--){let s=r[a](t);s instanceof An?t=s:Array.isArray(s)&&s.length==1&&s[0]instanceof An?t=s[0]:t=ck(e,Ao(s),!1)}return t}function WM(t){let e=t.startState,n=e.facet(ok),r=t;for(let a=n.length-1;a>=0;a--){let s=n[a](t);s&&Object.keys(s).length&&(r=uk(r,Rp(e,s,t.changes.newLength),!0))}return r==t?t:An.create(e,t.changes,t.selection,r.effects,r.annotations,r.scrollIntoView)}var zM=[];function Ao(t){return t==null?zM:Array.isArray(t)?t:[t]}var sa=(function(t){return t[t.Word=0]="Word",t[t.Space=1]="Space",t[t.Other=2]="Other",t})(sa||(sa={})),jM=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/,Mp;try{Mp=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function VM(t){if(Mp)return Mp.test(t);for(let e=0;e<t.length;e++){let n=t[e];if(/\w/.test(n)||n>"\x80"&&(n.toUpperCase()!=n.toLowerCase()||jM.test(n)))return!0}return!1}function qM(t){return e=>{if(!/\S/.test(e))return sa.Space;if(VM(e))return sa.Word;for(let n=0;n<t.length;n++)if(e.indexOf(t[n])>-1)return sa.Word;return sa.Other}}var It=class t{constructor(e,n,r,a,s,i){this.config=e,this.doc=n,this.selection=r,this.values=a,this.status=e.statusTemplate.slice(),this.computeSlot=s,i&&(i._state=this);for(let o=0;o<this.config.dynamicSlots.length;o++)uu(this,o<<1);this.computeSlot=null}field(e,n=!0){let r=this.config.address[e.id];if(r==null){if(n)throw new RangeError("Field is not present in this state");return}return uu(this,r),yd(this,r)}update(...e){return ck(this,e,!0)}applyTransaction(e){let n=this.config,{base:r,compartments:a}=n;for(let o of e.effects)o.is(_r.reconfigure)?(n&&(a=new Map,n.compartments.forEach((l,u)=>a.set(u,l)),n=null),a.set(o.value.compartment,o.value.extension)):o.is(pt.reconfigure)?(n=null,r=o.value):o.is(pt.appendConfig)&&(n=null,r=Ao(r).concat(o.value));let s;n?s=e.startState.values.slice():(n=xd.resolve(r,a,this),s=new t(n,this.doc,this.selection,n.dynamicSlots.map(()=>null),(l,u)=>u.reconfigure(l,this),null).values);let i=e.startState.facet(Ap)?e.newSelection:e.newSelection.asSingle();new t(n,e.newDoc,i,s,(o,l)=>l.update(o,e),e)}replaceSelection(e){return typeof e=="string"&&(e=this.toText(e)),this.changeByRange(n=>({changes:{from:n.from,to:n.to,insert:e},range:se.cursor(n.from+e.length,-1)}))}changeByRange(e){let n=this.selection,r=e(n.ranges[0]),a=this.changes(r.changes),s=[r.range],i=Ao(r.effects);for(let o=1;o<n.ranges.length;o++){let l=e(n.ranges[o]),u=this.changes(l.changes),c=u.map(a);for(let f=0;f<o;f++)s[f]=s[f].map(c);let d=a.mapDesc(u,!0);s.push(l.range.map(d)),a=a.compose(c),i=pt.mapEffects(i,c).concat(pt.mapEffects(Ao(l.effects),d))}return{changes:a,selection:se.create(s,n.mainIndex),effects:i}}changes(e=[]){return e instanceof Nn?e:Nn.of(e,this.doc.length,this.facet(t.lineSeparator))}toText(e){return st.of(e.split(this.facet(t.lineSeparator)||Sp))}sliceDoc(e=0,n=this.doc.length){return this.doc.sliceString(e,n,this.lineBreak)}facet(e){let n=this.config.address[e.id];return n==null?e.default:(uu(this,n),yd(this,n))}toJSON(e){let n={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let r in e){let a=e[r];a instanceof vn&&this.config.address[a.id]!=null&&(n[r]=a.spec.toJSON(this.field(e[r]),this))}return n}static fromJSON(e,n={},r){if(!e||typeof e.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let a=[];if(r){for(let s in r)if(Object.prototype.hasOwnProperty.call(e,s)){let i=r[s],o=e[s];a.push(i.init(l=>i.spec.fromJSON(o,l)))}}return t.create({doc:e.doc,selection:se.fromJSON(e.selection),extensions:n.extensions?a.concat([n.extensions]):a})}static create(e={}){let n=xd.resolve(e.extensions||[],new Map),r=e.doc instanceof st?e.doc:st.of((e.doc||"").split(n.staticFacet(t.lineSeparator)||Sp)),a=e.selection?e.selection instanceof se?e.selection:se.single(e.selection.anchor,e.selection.head):se.single(0);return nk(a,r.length),n.staticFacet(Ap)||(a=a.asSingle()),new t(n,r,a,n.dynamicSlots.map(()=>null),(s,i)=>i.create(s),null)}get tabSize(){return this.facet(t.tabSize)}get lineBreak(){return this.facet(t.lineSeparator)||`
36
+ `}get readOnly(){return this.facet(lk)}phrase(e,...n){for(let r of this.facet(t.phrases))if(Object.prototype.hasOwnProperty.call(r,e)){e=r[e];break}return n.length&&(e=e.replace(/\$(\$|\d*)/g,(r,a)=>{if(a=="$")return"$";let s=+(a||1);return!s||s>n.length?r:n[s-1]})),e}languageDataAt(e,n,r=-1){let a=[];for(let s of this.facet(rk))for(let i of s(this,n,r))Object.prototype.hasOwnProperty.call(i,e)&&a.push(i[e]);return a}charCategorizer(e){let n=this.languageDataAt("wordChars",e);return qM(n.length?n[0]:"")}wordAt(e){let{text:n,from:r,length:a}=this.doc.lineAt(e),s=this.charCategorizer(e),i=e-r,o=e-r;for(;i>0;){let l=Pn(n,i,!1);if(s(n.slice(l,i))!=sa.Word)break;i=l}for(;o<a;){let l=Pn(n,o);if(s(n.slice(o,l))!=sa.Word)break;o=l}return i==o?null:se.range(i+r,o+r)}};It.allowMultipleSelections=Ap;It.tabSize=Me.define({combine:t=>t.length?t[0]:4});It.lineSeparator=ak;It.readOnly=lk;It.phrases=Me.define({compare(t,e){let n=Object.keys(t),r=Object.keys(e);return n.length==r.length&&n.every(a=>t[a]==e[a])}});It.languageData=rk;It.changeFilter=sk;It.transactionFilter=ik;It.transactionExtender=ok;_r.reconfigure=pt.define();function No(t,e,n={}){let r={};for(let a of t)for(let s of Object.keys(a)){let i=a[s],o=r[s];if(o===void 0)r[s]=i;else if(!(o===i||i===void 0))if(Object.hasOwnProperty.call(n,s))r[s]=n[s](o,i);else throw new Error("Config merge conflict for field "+s)}for(let a in e)r[a]===void 0&&(r[a]=e[a]);return r}var Ra=class{eq(e){return this==e}range(e,n=e){return du.create(e,n,this)}};Ra.prototype.startSide=Ra.prototype.endSide=0;Ra.prototype.point=!1;Ra.prototype.mapMode=cr.TrackDel;function Bp(t,e){return t==e||t.constructor==e.constructor&&t.eq(e)}var du=class t{constructor(e,n,r){this.from=e,this.to=n,this.value=r}static create(e,n,r){return new t(e,n,r)}};function Tp(t,e){return t.from-e.from||t.value.startSide-e.value.startSide}var Dp=class t{constructor(e,n,r,a){this.from=e,this.to=n,this.value=r,this.maxPoint=a}get length(){return Co(this.to)}findIndex(e,n,r,a=0){let s=r?this.to:this.from;for(let i=a,o=s.length;;){if(i==o)return i;let l=i+o>>1,u=s[l]-e||(r?this.value[l].endSide:this.value[l].startSide)-n;if(l==i)return u>=0?i:o;u>=0?o=l:i=l+1}}between(e,n,r,a){for(let s=this.findIndex(n,-1e9,!0),i=this.findIndex(r,1e9,!1,s);s<i;s++)if(a(this.from[s]+e,this.to[s]+e,this.value[s])===!1)return!1}map(e,n,r,a,s){let i=[],o=[],l=[],u=-1,c=-1;e:for(let d=0;d<this.value.length;d++){let f=this.value[d],h=this.from[d]+e,p=this.to[d]+e,g,m;if(h==p){let x=n.mapPos(h,f.startSide,f.mapMode);if(x==null||(g=m=x,f.startSide!=f.endSide&&(m=n.mapPos(h,f.endSide),m<g)))continue}else if(g=n.mapPos(h,f.startSide),m=n.mapPos(p,f.endSide),g>m||g==m&&f.startSide>0&&f.endSide<=0)continue;if(!((m-g||f.endSide-f.startSide)<0))if(u<0&&(u=g),f.point&&(c=Math.max(c,m-g)),(g-r||f.startSide-a)>=0)i.push(f),o.push(g-u),l.push(m-u),r=m,a=f.endSide;else{if(g==m)for(let x=i.length;x>0;x--){if((g-(l[x-1]+u)||f.startSide-i[x-1].endSide)>=0){i.splice(x,0,f),o.splice(x,0,g-u),l.splice(x,0,m-u);continue e}if((g-(o[x-1]+u)||f.endSide-i[x-1].startSide)>0)break}s(g,m,f)}}return{mapped:i.length?new t(o,l,i,c):null,pos:u}}},wt=class t{constructor(e,n,r,a){this.chunkPos=e,this.chunk=n,this.nextLayer=r,this.maxPoint=a}static create(e,n,r,a){return new t(e,n,r,a)}get length(){let e=this.chunk.length-1;return e<0?0:Math.max(this.chunkEnd(e),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let e=this.nextLayer.size;for(let n of this.chunk)e+=n.value.length;return e}chunkEnd(e){return this.chunkPos[e]+this.chunk[e].length}update(e){let{add:n=[],sort:r=!1,filterFrom:a=0,filterTo:s=this.length}=e,i=e.filter;if(n.length==0&&!i)return this;if(r&&(n=n.slice().sort(Tp)),this.isEmpty)return n.length?t.of(n):this;let o=new bd(this,null,-1).goto(0),l=0,u=[],c=new qn;for(;o.value||l<n.length;)if(l<n.length&&(o.from-n[l].from||o.startSide-n[l].value.startSide)>=0){let d=n[l++];c.addInner(d.from,d.to,d.value,!1)||u.push(d)}else o.rangeIndex==1&&o.chunkIndex<this.chunk.length&&(l==n.length||this.chunkEnd(o.chunkIndex)<n[l].from)&&(!i||a>this.chunkEnd(o.chunkIndex)||s<this.chunkPos[o.chunkIndex])&&c.addChunk(this.chunkPos[o.chunkIndex],this.chunk[o.chunkIndex])?o.nextChunk():((!i||a>o.to||s<o.from||i(o.from,o.to,o.value))&&(c.addInner(o.from,o.to,o.value,!1)||u.push(du.create(o.from,o.to,o.value))),o.next());return c.finishInner(this.nextLayer.isEmpty&&!u.length?t.empty:this.nextLayer.update({add:u,filter:i,filterFrom:a,filterTo:s}))}map(e){if(e.empty||this.isEmpty)return this;let n=[],r=[],a=-1,s,i=(l,u,c)=>{s||(s=new qn),s.addRange(l,u,c,!1)};for(let l=0;l<this.chunk.length;l++){let u=this.chunkPos[l],c=this.chunk[l],d=e.touchesRange(u,u+c.length);if(d===!1)a=Math.max(a,c.maxPoint),n.push(c),r.push(e.mapPos(u));else if(d===!0){let[f,h]=n.length?[Co(r)+Co(n).length,Co(Co(n).value).endSide]:[-1,-1],{mapped:p,pos:g}=c.map(u,e,f,h,i);p&&(a=Math.max(a,p.maxPoint),n.push(p),r.push(g))}}let o=this.nextLayer.map(e);return s&&(o=s.finishInner(o)),n.length==0?o:new t(r,n,o||t.empty,a)}between(e,n,r){if(!this.isEmpty){for(let a=0;a<this.chunk.length;a++){let s=this.chunkPos[a],i=this.chunk[a];if(n>=s&&e<=s+i.length&&i.between(s,e-s,n-s,r)===!1)return}this.nextLayer.between(e,n,r)}}iter(e=0){return fu.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,n=0){return fu.from(e).goto(n)}static compare(e,n,r,a,s=-1){let i=e.filter(d=>d.maxPoint>0||!d.isEmpty&&d.maxPoint>=s),o=n.filter(d=>d.maxPoint>0||!d.isEmpty&&d.maxPoint>=s),l=Y1(i,o,r),u=new Si(i,l,s),c=new Si(o,l,s);r.iterGaps((d,f,h)=>J1(u,d,c,f,h,a)),r.empty&&r.length==0&&J1(u,0,c,0,0,a)}static eq(e,n,r=0,a){a==null&&(a=999999999);let s=e.filter(c=>!c.isEmpty&&n.indexOf(c)<0),i=n.filter(c=>!c.isEmpty&&e.indexOf(c)<0);if(s.length!=i.length)return!1;if(!s.length)return!0;let o=Y1(s,i),l=new Si(s,o,0).goto(r),u=new Si(i,o,0).goto(r);for(;;){if(l.to!=u.to||!Fp(l.active,u.active)||l.point&&(!u.point||!Bp(l.point,u.point)))return!1;if(l.to>a)return!0;l.next(),u.next()}}static spans(e,n,r,a,s=-1){let i=new Si(e,null,s).goto(n),o=n,l=i.openStart;for(;;){let u=Math.min(i.to,r);if(i.point){let c=i.activeForPoint(i.to),d=i.pointFrom<n?c.length+1:i.point.startSide<0?c.length:Math.min(c.length,l);a.point(o,u,i.point,c,d,i.pointRank),l=Math.min(i.openEnd(u),c.length)}else u>o&&(a.span(o,u,i.active,l),l=i.openEnd(u));if(i.to>r)return l+(i.point&&i.to>r?1:0);o=i.to,i.next()}}static of(e,n=!1){let r=new qn;for(let a of e instanceof du?[e]:n?$M(e):e)r.add(a.from,a.to,a.value);return r.finish()}static join(e){if(!e.length)return t.empty;let n=Co(e);for(let r=e.length-2;r>=0;r--)for(let a=e[r];a!=t.empty;a=a.nextLayer)n=new t(a.chunkPos,a.chunk,n,Math.max(a.maxPoint,n.maxPoint));return n}};wt.empty=new wt([],[],null,-1);function Co(t){return t[t.length-1]}function $M(t){if(t.length>1)for(let e=t[0],n=1;n<t.length;n++){let r=t[n];if(Tp(e,r)>0)return t.slice().sort(Tp);e=r}return t}wt.empty.nextLayer=wt.empty;var qn=class t{finishChunk(e){this.chunks.push(new Dp(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,e&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(e,n,r){this.addRange(e,n,r,!0)}addRange(e,n,r,a){this.addInner(e,n,r,a)||(this.nextLayer||(this.nextLayer=new t)).addRange(e,n,r,a)}addInner(e,n,r,a){let s=e-this.lastTo||r.startSide-this.last.endSide;if(a&&s<=0&&(e-this.lastFrom||r.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return s<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=e),this.from.push(e-this.chunkStart),this.to.push(n-this.chunkStart),this.last=r,this.lastFrom=e,this.lastTo=n,this.value.push(r),r.point&&(this.maxPoint=Math.max(this.maxPoint,n-e)),!0)}addChunk(e,n){if((e-this.lastTo||n.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,n.maxPoint),this.chunks.push(n),this.chunkPos.push(e);let r=n.value.length-1;return this.last=n.value[r],this.lastFrom=n.from[r]+e,this.lastTo=n.to[r]+e,!0}finish(){return this.finishInner(wt.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let n=wt.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,n}};function Y1(t,e,n){let r=new Map;for(let s of t)for(let i=0;i<s.chunk.length;i++)s.chunk[i].maxPoint<=0&&r.set(s.chunk[i],s.chunkPos[i]);let a=new Set;for(let s of e)for(let i=0;i<s.chunk.length;i++){let o=r.get(s.chunk[i]);o!=null&&(n?n.mapPos(o):o)==s.chunkPos[i]&&!n?.touchesRange(o,o+s.chunk[i].length)&&a.add(s.chunk[i])}return a}var bd=class{constructor(e,n,r,a=0){this.layer=e,this.skip=n,this.minPoint=r,this.rank=a}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(e,n=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(e,n,!1),this}gotoInner(e,n,r){for(;this.chunkIndex<this.layer.chunk.length;){let a=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(a)||this.layer.chunkEnd(this.chunkIndex)<e||a.maxPoint<this.minPoint))break;this.chunkIndex++,r=!1}if(this.chunkIndex<this.layer.chunk.length){let a=this.layer.chunk[this.chunkIndex].findIndex(e-this.layer.chunkPos[this.chunkIndex],n,!0);(!r||this.rangeIndex<a)&&this.setRangeIndex(a)}this.next()}forward(e,n){(this.to-e||this.endSide-n)<0&&this.gotoInner(e,n,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let e=this.layer.chunkPos[this.chunkIndex],n=this.layer.chunk[this.chunkIndex],r=e+n.from[this.rangeIndex];if(this.from=r,this.to=e+n.to[this.rangeIndex],this.value=n.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=e}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(e){return this.from-e.from||this.startSide-e.startSide||this.rank-e.rank||this.to-e.to||this.endSide-e.endSide}},fu=class t{constructor(e){this.heap=e}static from(e,n=null,r=-1){let a=[];for(let s=0;s<e.length;s++)for(let i=e[s];!i.isEmpty;i=i.nextLayer)i.maxPoint>=r&&a.push(new bd(i,n,r,s));return a.length==1?a[0]:new t(a)}get startSide(){return this.value?this.value.startSide:0}goto(e,n=-1e9){for(let r of this.heap)r.goto(e,n);for(let r=this.heap.length>>1;r>=0;r--)vp(this.heap,r);return this.next(),this}forward(e,n){for(let r of this.heap)r.forward(e,n);for(let r=this.heap.length>>1;r>=0;r--)vp(this.heap,r);(this.to-e||this.value.endSide-n)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let e=this.heap[0];this.from=e.from,this.to=e.to,this.value=e.value,this.rank=e.rank,e.value&&e.next(),vp(this.heap,0)}}};function vp(t,e){for(let n=t[e];;){let r=(e<<1)+1;if(r>=t.length)break;let a=t[r];if(r+1<t.length&&a.compare(t[r+1])>=0&&(a=t[r+1],r++),n.compare(a)<0)break;t[r]=n,t[e]=a,e=r}}var Si=class{constructor(e,n,r){this.minPoint=r,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=fu.from(e,n,r)}goto(e,n=-1e9){return this.cursor.goto(e,n),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=e,this.endSide=n,this.openStart=-1,this.next(),this}forward(e,n){for(;this.minActive>-1&&(this.activeTo[this.minActive]-e||this.active[this.minActive].endSide-n)<0;)this.removeActive(this.minActive);this.cursor.forward(e,n)}removeActive(e){dd(this.active,e),dd(this.activeTo,e),dd(this.activeRank,e),this.minActive=Z1(this.active,this.activeTo)}addActive(e){let n=0,{value:r,to:a,rank:s}=this.cursor;for(;n<this.activeRank.length&&(s-this.activeRank[n]||a-this.activeTo[n])>0;)n++;fd(this.active,n,r),fd(this.activeTo,n,a),fd(this.activeRank,n,s),e&&fd(e,n,this.cursor.from),this.minActive=Z1(this.active,this.activeTo)}next(){let e=this.to,n=this.point;this.point=null;let r=this.openStart<0?[]:null;for(;;){let a=this.minActive;if(a>-1&&(this.activeTo[a]-this.cursor.from||this.active[a].endSide-this.cursor.startSide)<0){if(this.activeTo[a]>e){this.to=this.activeTo[a],this.endSide=this.active[a].endSide;break}this.removeActive(a),r&&dd(r,a)}else if(this.cursor.value)if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let s=this.cursor.value;if(!s.point)this.addActive(r),this.cursor.next();else if(n&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=s,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=s.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(r){this.openStart=0;for(let a=r.length-1;a>=0&&r[a]<e;a--)this.openStart++}}activeForPoint(e){if(!this.active.length)return this.active;let n=[];for(let r=this.active.length-1;r>=0&&!(this.activeRank[r]<this.pointRank);r--)(this.activeTo[r]>e||this.activeTo[r]==e&&this.active[r].endSide>=this.point.endSide)&&n.push(this.active[r]);return n.reverse()}openEnd(e){let n=0;for(let r=this.activeTo.length-1;r>=0&&this.activeTo[r]>e;r--)n++;return n}};function J1(t,e,n,r,a,s){t.goto(e),n.goto(r);let i=r+a,o=r,l=r-e,u=!!s.boundChange;for(let c=!1;;){let d=t.to+l-n.to,f=d||t.endSide-n.endSide,h=f<0?t.to+l:n.to,p=Math.min(h,i);if(t.point||n.point?(t.point&&n.point&&Bp(t.point,n.point)&&Fp(t.activeForPoint(t.to),n.activeForPoint(n.to))||s.comparePoint(o,p,t.point,n.point),c=!1):(c&&(s.boundChange(o),c=!1),p>o&&!Fp(t.active,n.active)&&s.compareRange(o,p,t.active,n.active),u&&p<i&&(d||t.openEnd(h)!=n.openEnd(h))&&(c=!0)),h>i)break;o=h,f<=0&&t.next(),f>=0&&n.next()}}function Fp(t,e){if(t.length!=e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!=e[n]&&!Bp(t[n],e[n]))return!1;return!0}function dd(t,e){for(let n=e,r=t.length-1;n<r;n++)t[n]=t[n+1];t.pop()}function fd(t,e,n){for(let r=t.length-1;r>=e;r--)t[r+1]=t[r];t[e]=n}function Z1(t,e){let n=-1,r=1e9;for(let a=0;a<e.length;a++)(e[a]-r||t[a].endSide-t[n].endSide)<0&&(n=a,r=e[a]);return n}function Li(t,e,n=t.length){let r=0;for(let a=0;a<n&&a<t.length;)t.charCodeAt(a)==9?(r+=e-r%e,a++):(r++,a=Pn(t,a));return r}function dk(t,e,n,r){for(let a=0,s=0;;){if(s>=e)return a;if(a==t.length)break;s+=t.charCodeAt(a)==9?n-s%n:1,a=Pn(t,a)}return r===!0?-1:t.length}var fk=typeof Symbol>"u"?"__\u037C":Symbol.for("\u037C"),_p=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),hk=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{},dr=class{constructor(e,n){this.rules=[];let{finish:r}=n||{};function a(i){return/^@/.test(i)?[i]:i.split(/,\s*/)}function s(i,o,l,u){let c=[],d=/^@(\w+)\b/.exec(i[0]),f=d&&d[1]=="keyframes";if(d&&o==null)return l.push(i[0]+";");for(let h in o){let p=o[h];if(/&/.test(h))s(h.split(/,\s*/).map(g=>i.map(m=>g.replace(/&/,m))).reduce((g,m)=>g.concat(m)),p,l);else if(p&&typeof p=="object"){if(!d)throw new RangeError("The value of a property ("+h+") should be a primitive value.");s(a(h),p,c,f)}else p!=null&&c.push(h.replace(/_.*/,"").replace(/[A-Z]/g,g=>"-"+g.toLowerCase())+": "+p+";")}(c.length||f)&&l.push((r&&!d&&!u?i.map(r):i).join(", ")+" {"+c.join(" ")+"}")}for(let i in e)s(a(i),e[i],this.rules)}getRules(){return this.rules.join(`
37
+ `)}static newName(){let e=hk[fk]||1;return hk[fk]=e+1,"\u037C"+e.toString(36)}static mount(e,n,r){let a=e[_p],s=r&&r.nonce;a?s&&a.setNonce(s):a=new Hp(e,s),a.mount(Array.isArray(n)?n:[n],e)}},pk=new Map,Hp=class{constructor(e,n){let r=e.ownerDocument||e,a=r.defaultView;if(!e.head&&e.adoptedStyleSheets&&a.CSSStyleSheet){let s=pk.get(r);if(s)return e[_p]=s;this.sheet=new a.CSSStyleSheet,pk.set(r,this)}else this.styleTag=r.createElement("style"),n&&this.styleTag.setAttribute("nonce",n);this.modules=[],e[_p]=this}mount(e,n){let r=this.sheet,a=0,s=0,i=!1;for(let o=0;o<e.length;o++){let l=e[o],u=this.modules.indexOf(l);if(u<s&&u>-1&&(this.modules.splice(u,1),i=!0,s--,u=-1),u==-1){if(this.modules.splice(s++,0,l),i=!0,r)for(let c=0;c<l.rules.length;c++)r.insertRule(l.rules[c],a++)}else{for(;s<u;)a+=this.modules[s++].rules.length;a+=l.rules.length,s++}}if(r)n.adoptedStyleSheets.indexOf(this.sheet)<0&&(n.adoptedStyleSheets=[this.sheet,...n.adoptedStyleSheets]);else{if(i){let l="";for(let u=0;u<this.modules.length;u++)l+=this.modules[u].getRules()+`
38
+ `;this.styleTag.textContent=l}let o=n.head||n;this.styleTag.parentNode!=o&&o.insertBefore(this.styleTag,o.firstChild)}}setNonce(e){this.styleTag&&this.styleTag.getAttribute("nonce")!=e&&this.styleTag.setAttribute("nonce",e)}};var as={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},Ro={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},KM=typeof navigator<"u"&&/Mac/.test(navigator.platform),XM=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(mn=0;mn<10;mn++)as[48+mn]=as[96+mn]=String(mn);var mn;for(mn=1;mn<=24;mn++)as[mn+111]="F"+mn;var mn;for(mn=65;mn<=90;mn++)as[mn]=String.fromCharCode(mn+32),Ro[mn]=String.fromCharCode(mn);var mn;for(wd in as)Ro.hasOwnProperty(wd)||(Ro[wd]=as[wd]);var wd;function mk(t){var e=KM&&t.metaKey&&t.shiftKey&&!t.ctrlKey&&!t.altKey||XM&&t.shiftKey&&t.key&&t.key.length==1||t.key=="Unidentified",n=!e&&t.key||(t.shiftKey?Ro:as)[t.keyCode]||t.key||"Unidentified";return n=="Esc"&&(n="Escape"),n=="Del"&&(n="Delete"),n=="Left"&&(n="ArrowLeft"),n=="Up"&&(n="ArrowUp"),n=="Right"&&(n="ArrowRight"),n=="Down"&&(n="ArrowDown"),n}var er=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},qp=typeof document<"u"?document:{documentElement:{style:{}}},$p=/Edge\/(\d+)/.exec(er.userAgent),$k=/MSIE \d/.test(er.userAgent),Kp=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(er.userAgent),Vd=!!($k||Kp||$p),gk=!Vd&&/gecko\/(\d+)/i.test(er.userAgent),Up=!Vd&&/Chrome\/(\d+)/.exec(er.userAgent),xk="webkitFontSmoothing"in qp.documentElement.style,Xp=!Vd&&/Apple Computer/.test(er.vendor),yk=Xp&&(/Mobile\/\w+/.test(er.userAgent)||er.maxTouchPoints>2),ke={mac:yk||/Mac/.test(er.platform),windows:/Win/.test(er.platform),linux:/Linux|X11/.test(er.platform),ie:Vd,ie_version:$k?qp.documentMode||6:Kp?+Kp[1]:$p?+$p[1]:0,gecko:gk,gecko_version:gk?+(/Firefox\/(\d+)/.exec(er.userAgent)||[0,0])[1]:0,chrome:!!Up,chrome_version:Up?+Up[1]:0,ios:yk,android:/Android\b/.test(er.userAgent),webkit:xk,webkit_version:xk?+(/\bAppleWebKit\/(\d+)/.exec(er.userAgent)||[0,0])[1]:0,safari:Xp,safari_version:Xp?+(/\bVersion\/(\d+(\.\d+)?)/.exec(er.userAgent)||[0,0])[1]:0,tabSize:qp.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};function Om(t,e){for(let n in t)n=="class"&&e.class?e.class+=" "+t.class:n=="style"&&e.style?e.style+=";"+t.style:e[n]=t[n];return e}var Md=Object.create(null);function Bm(t,e,n){if(t==e)return!0;t||(t=Md),e||(e=Md);let r=Object.keys(t),a=Object.keys(e);if(r.length-(n&&r.indexOf(n)>-1?1:0)!=a.length-(n&&a.indexOf(n)>-1?1:0))return!1;for(let s of r)if(s!=n&&(a.indexOf(s)==-1||t[s]!==e[s]))return!1;return!0}function YM(t,e){for(let n=t.attributes.length-1;n>=0;n--){let r=t.attributes[n].name;e[r]==null&&t.removeAttribute(r)}for(let n in e){let r=e[n];n=="style"?t.style.cssText=r:t.getAttribute(n)!=r&&t.setAttribute(n,r)}}function bk(t,e,n){let r=!1;if(e)for(let a in e)n&&a in n||(r=!0,a=="style"?t.style.cssText="":t.removeAttribute(a));if(n)for(let a in n)e&&e[a]==n[a]||(r=!0,a=="style"?t.style.cssText=n[a]:t.setAttribute(a,n[a]));return r}function JM(t){let e=Object.create(null);for(let n=0;n<t.attributes.length;n++){let r=t.attributes[n];e[r.name]=r.value}return e}var Ir=class{eq(e){return!1}updateDOM(e,n,r){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(e){return!0}coordsAt(e,n,r){return null}get isHidden(){return!1}get editable(){return!1}destroy(e){}},On=(function(t){return t[t.Text=0]="Text",t[t.WidgetBefore=1]="WidgetBefore",t[t.WidgetAfter=2]="WidgetAfter",t[t.WidgetRange=3]="WidgetRange",t})(On||(On={})),Ke=class extends Ra{constructor(e,n,r,a){super(),this.startSide=e,this.endSide=n,this.widget=r,this.spec=a}get heightRelevant(){return!1}static mark(e){return new Iu(e)}static widget(e){let n=Math.max(-1e4,Math.min(1e4,e.side||0)),r=!!e.block;return n+=r&&!e.inlineOrder?n>0?3e8:-4e8:n>0?1e8:-1e8,new Ri(e,n,n,r,e.widget||null,!1)}static replace(e){let n=!!e.block,r,a;if(e.isBlockGap)r=-5e8,a=4e8;else{let{start:s,end:i}=Kk(e,n);r=(s?n?-3e8:-1:5e8)-1,a=(i?n?2e8:1:-6e8)+1}return new Ri(e,r,a,n,e.widget||null,!0)}static line(e){return new Lu(e)}static set(e,n=!1){return wt.of(e,n)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}};Ke.none=wt.empty;var Iu=class t extends Ke{constructor(e){let{start:n,end:r}=Kk(e);super(n?-1:5e8,r?1:-6e8,null,e),this.tagName=e.tagName||"span",this.attrs=e.class&&e.attributes?Om(e.attributes,{class:e.class}):e.class?{class:e.class}:e.attributes||Md}eq(e){return this==e||e instanceof t&&this.tagName==e.tagName&&Bm(this.attrs,e.attrs)}range(e,n=e){if(e>=n)throw new RangeError("Mark decorations may not be empty");return super.range(e,n)}};Iu.prototype.point=!1;var Lu=class t extends Ke{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof t&&this.spec.class==e.spec.class&&Bm(this.spec.attributes,e.spec.attributes)}range(e,n=e){if(n!=e)throw new RangeError("Line decoration ranges must be zero-length");return super.range(e,n)}};Lu.prototype.mapMode=cr.TrackBefore;Lu.prototype.point=!0;var Ri=class t extends Ke{constructor(e,n,r,a,s,i){super(n,r,s,e),this.block=a,this.isReplace=i,this.mapMode=a?n<=0?cr.TrackBefore:cr.TrackAfter:cr.TrackDel}get type(){return this.startSide!=this.endSide?On.WidgetRange:this.startSide<=0?On.WidgetBefore:On.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(e){return e instanceof t&&ZM(this.widget,e.widget)&&this.block==e.block&&this.startSide==e.startSide&&this.endSide==e.endSide}range(e,n=e){if(this.isReplace&&(e>n||e==n&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&n!=e)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(e,n)}};Ri.prototype.point=!0;function Kk(t,e=!1){let{inclusiveStart:n,inclusiveEnd:r}=t;return n==null&&(n=t.inclusive),r==null&&(r=t.inclusive),{start:n??e,end:r??e}}function ZM(t,e){return t==e||!!(t&&e&&t.compare(e))}function Eo(t,e,n,r=0){let a=n.length-1;a>=0&&n[a]+r>=t?n[a]=Math.max(n[a],e):n.push(t,e)}var Td=class t extends Ra{constructor(e,n,r){super(),this.tagName=e,this.attributes=n,this.rank=r}eq(e){return e==this||e instanceof t&&this.tagName==e.tagName&&Bm(this.attributes,e.attributes)}static create(e){return new t(e.tagName,e.attributes||Md,e.rank==null?50:Math.max(0,Math.min(e.rank,100)))}static set(e,n=!1){return wt.of(e,n)}};Td.prototype.startSide=Td.prototype.endSide=-1;function Au(t){let e;return t.nodeType==11?e=t.getSelection?t:t.ownerDocument:e=t,e.getSelection()}function Yp(t,e){return e?t==e||t.contains(e.nodeType!=1?e.parentNode:e):!1}function mu(t,e){if(!e.anchorNode)return!1;try{return Yp(t,e.anchorNode)}catch{return!1}}function gu(t){return t.nodeType==3?Nu(t,0,t.nodeValue.length).getClientRects():t.nodeType==1?t.getClientRects():[]}function xu(t,e,n,r){return n?wk(t,e,n,r,-1)||wk(t,e,n,r,1):!1}function Ws(t){for(var e=0;;e++)if(t=t.previousSibling,!t)return e}function Dd(t){return t.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(t.nodeName)}function wk(t,e,n,r,a){for(;;){if(t==n&&e==r)return!0;if(e==(a<0?0:os(t))){if(t.nodeName=="DIV")return!1;let s=t.parentNode;if(!s||s.nodeType!=1)return!1;e=Ws(t)+(a<0?0:1),t=s}else if(t.nodeType==1){if(t=t.childNodes[e+(a<0?-1:0)],t.nodeType==1&&t.contentEditable=="false")return!1;e=a<0?os(t):0}else return!1}}function os(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function Pu(t,e){let{left:n,right:r}=t;if(n==r)return t;let a=e?n:r;return{left:a,right:a,top:t.top,bottom:t.bottom}}function QM(t){let e=t.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:t.innerWidth,top:0,bottom:t.innerHeight}}function Xk(t,e){let n=e.width/t.offsetWidth,r=e.height/t.offsetHeight;return(n>.995&&n<1.005||!isFinite(n)||Math.abs(e.width-t.offsetWidth)<1)&&(n=1),(r>.995&&r<1.005||!isFinite(r)||Math.abs(e.height-t.offsetHeight)<1)&&(r=1),{scaleX:n,scaleY:r}}function eT(t,e,n,r,a,s,i,o){let l=t.ownerDocument,u=l.defaultView||window;for(let c=t,d=!1;c&&!d;)if(c.nodeType==1){let f,h=c==l.body,p=1,g=1;if(h)f=QM(u);else{if(/^(fixed|sticky)$/.test(getComputedStyle(c).position)&&(d=!0),c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.assignedSlot||c.parentNode;continue}let y=c.getBoundingClientRect();({scaleX:p,scaleY:g}=Xk(c,y)),f={left:y.left,right:y.left+c.clientWidth*p,top:y.top,bottom:y.top+c.clientHeight*g}}let m=0,x=0;if(a=="nearest")e.top<f.top+i?(x=e.top-(f.top+i),n>0&&e.bottom>f.bottom+x&&(x=e.bottom-f.bottom+i)):e.bottom>f.bottom-i&&(x=e.bottom-f.bottom+i,n<0&&e.top-x<f.top&&(x=e.top-(f.top+i)));else{let y=e.bottom-e.top,b=f.bottom-f.top;x=(a=="center"&&y<=b?e.top+y/2-b/2:a=="start"||a=="center"&&n<0?e.top-i:e.bottom-b+i)-f.top}if(r=="nearest"?e.left<f.left+s?(m=e.left-(f.left+s),n>0&&e.right>f.right+m&&(m=e.right-f.right+s)):e.right>f.right-s&&(m=e.right-f.right+s,n<0&&e.left<f.left+m&&(m=e.left-(f.left+s))):m=(r=="center"?e.left+(e.right-e.left)/2-(f.right-f.left)/2:r=="start"==o?e.left-s:e.right-(f.right-f.left)+s)-f.left,m||x)if(h)u.scrollBy(m,x);else{let y=0,b=0;if(x){let C=c.scrollTop;c.scrollTop+=x/g,b=(c.scrollTop-C)*g}if(m){let C=c.scrollLeft;c.scrollLeft+=m/p,y=(c.scrollLeft-C)*p}e={left:e.left-y,top:e.top-b,right:e.right-y,bottom:e.bottom-b},y&&Math.abs(y-m)<1&&(r="nearest"),b&&Math.abs(b-x)<1&&(a="nearest")}if(h)break;(e.top<f.top||e.bottom>f.bottom||e.left<f.left||e.right>f.right)&&(e={left:Math.max(e.left,f.left),right:Math.min(e.right,f.right),top:Math.max(e.top,f.top),bottom:Math.min(e.bottom,f.bottom)}),c=c.assignedSlot||c.parentNode}else if(c.nodeType==11)c=c.host;else break}function Yk(t,e=!0){let n=t.ownerDocument,r=null,a=null;for(let s=t.parentNode;s&&!(s==n.body||(!e||r)&&a);)if(s.nodeType==1)!a&&s.scrollHeight>s.clientHeight&&(a=s),e&&!r&&s.scrollWidth>s.clientWidth&&(r=s),s=s.assignedSlot||s.parentNode;else if(s.nodeType==11)s=s.host;else break;return{x:r,y:a}}var Jp=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(e){return this.anchorNode==e.anchorNode&&this.anchorOffset==e.anchorOffset&&this.focusNode==e.focusNode&&this.focusOffset==e.focusOffset}setRange(e){let{anchorNode:n,focusNode:r}=e;this.set(n,Math.min(e.anchorOffset,n?os(n):0),r,Math.min(e.focusOffset,r?os(r):0))}set(e,n,r,a){this.anchorNode=e,this.anchorOffset=n,this.focusNode=r,this.focusOffset=a}};function Jk(t){let e=[];for(let n=t;n;n=n.nodeType==11?n.host:n.parentNode)n.nodeType==1&&e.push({node:n,left:n.scrollLeft,top:n.scrollTop});return e}function Zk(t,e=!0){for(let{node:n,left:r,top:a}of t)e&&n.scrollTop!=a&&(n.scrollTop=a),n.scrollLeft!=r&&(n.scrollLeft=r)}var Ai=null;ke.safari&&ke.safari_version>=26&&(Ai=!1);function Qk(t){if(t.setActive)return t.setActive();if(Ai)return t.focus(Ai);let e=Jk(t);t.focus(Ai==null?{get preventScroll(){return Ai={preventScroll:!0},!0}}:void 0),Ai||(Ai=!1,Zk(e))}var vk;function Nu(t,e,n=e){let r=vk||(vk=document.createRange());return r.setEnd(t,n),r.setStart(t,e),r}function Oo(t,e,n,r){let a={key:e,code:e,keyCode:n,which:n,cancelable:!0};r&&({altKey:a.altKey,ctrlKey:a.ctrlKey,shiftKey:a.shiftKey,metaKey:a.metaKey}=r);let s=new KeyboardEvent("keydown",a);s.synthetic=!0,t.dispatchEvent(s);let i=new KeyboardEvent("keyup",a);return i.synthetic=!0,t.dispatchEvent(i),s.defaultPrevented||i.defaultPrevented}function tT(t){for(;t;){if(t&&(t.nodeType==9||t.nodeType==11&&t.host))return t;t=t.assignedSlot||t.parentNode}return null}function nT(t,e){let n=e.focusNode,r=e.focusOffset;if(!n||e.anchorNode!=n||e.anchorOffset!=r)return!1;for(r=Math.min(r,os(n));;)if(r){if(n.nodeType!=1)return!1;let a=n.childNodes[r-1];a.contentEditable=="false"?r--:(n=a,r=os(n))}else{if(n==t)return!0;r=Ws(n),n=n.parentNode}}function eS(t){return t instanceof Window?t.pageYOffset>Math.max(0,t.document.documentElement.scrollHeight-t.innerHeight-4):t.scrollTop>Math.max(1,t.scrollHeight-t.clientHeight-4)}function tS(t,e){for(let n=t,r=e;;){if(n.nodeType==3&&r>0)return{node:n,offset:r};if(n.nodeType==1&&r>0){if(n.contentEditable=="false")return null;n=n.childNodes[r-1],r=os(n)}else if(n.parentNode&&!Dd(n))r=Ws(n),n=n.parentNode;else return null}}function nS(t,e){for(let n=t,r=e;;){if(n.nodeType==3&&r<n.nodeValue.length)return{node:n,offset:r};if(n.nodeType==1&&r<n.childNodes.length){if(n.contentEditable=="false")return null;n=n.childNodes[r],r=0}else if(n.parentNode&&!Dd(n))r=Ws(n)+1,n=n.parentNode;else return null}}var Da=class t{constructor(e,n,r=!0){this.node=e,this.offset=n,this.precise=r}static before(e,n){return new t(e.parentNode,Ws(e),n)}static after(e,n){return new t(e.parentNode,Ws(e)+1,n)}},Vt=(function(t){return t[t.LTR=0]="LTR",t[t.RTL=1]="RTL",t})(Vt||(Vt={})),Mi=Vt.LTR,_m=Vt.RTL;function rS(t){let e=[];for(let n=0;n<t.length;n++)e.push(1<<+t[n]);return e}var rT=rS("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),aT=rS("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),Zp=Object.create(null),Ta=[];for(let t of["()","[]","{}"]){let e=t.charCodeAt(0),n=t.charCodeAt(1);Zp[e]=n,Zp[n]=-e}function aS(t){return t<=247?rT[t]:1424<=t&&t<=1524?2:1536<=t&&t<=1785?aT[t-1536]:1774<=t&&t<=2220?4:8192<=t&&t<=8204?256:64336<=t&&t<=65023?4:1}var sT=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/,Wr=class{get dir(){return this.level%2?_m:Mi}constructor(e,n,r){this.from=e,this.to=n,this.level=r}side(e,n){return this.dir==n==e?this.to:this.from}forward(e,n){return e==(this.dir==n)}static find(e,n,r,a){let s=-1;for(let i=0;i<e.length;i++){let o=e[i];if(o.from<=n&&o.to>=n){if(o.level==r)return i;(s<0||(a!=0?a<0?o.from<n:o.to>n:e[s].level>o.level))&&(s=i)}}if(s<0)throw new RangeError("Index out of range");return s}};function sS(t,e){if(t.length!=e.length)return!1;for(let n=0;n<t.length;n++){let r=t[n],a=e[n];if(r.from!=a.from||r.to!=a.to||r.direction!=a.direction||!sS(r.inner,a.inner))return!1}return!0}var Ut=[];function iT(t,e,n,r,a){for(let s=0;s<=r.length;s++){let i=s?r[s-1].to:e,o=s<r.length?r[s].from:n,l=s?256:a;for(let u=i,c=l,d=l;u<o;u++){let f=aS(t.charCodeAt(u));f==512?f=c:f==8&&d==4&&(f=16),Ut[u]=f==4?2:f,f&7&&(d=f),c=f}for(let u=i,c=l,d=l;u<o;u++){let f=Ut[u];if(f==128)u<o-1&&c==Ut[u+1]&&c&24?f=Ut[u]=c:Ut[u]=256;else if(f==64){let h=u+1;for(;h<o&&Ut[h]==64;)h++;let p=u&&c==8||h<n&&Ut[h]==8?d==1?1:8:256;for(let g=u;g<h;g++)Ut[g]=p;u=h-1}else f==8&&d==1&&(Ut[u]=1);c=f,f&7&&(d=f)}}}function oT(t,e,n,r,a){let s=a==1?2:1;for(let i=0,o=0,l=0;i<=r.length;i++){let u=i?r[i-1].to:e,c=i<r.length?r[i].from:n;for(let d=u,f,h,p;d<c;d++)if(h=Zp[f=t.charCodeAt(d)])if(h<0){for(let g=o-3;g>=0;g-=3)if(Ta[g+1]==-h){let m=Ta[g+2],x=m&2?a:m&4?m&1?s:a:0;x&&(Ut[d]=Ut[Ta[g]]=x),o=g;break}}else{if(Ta.length==189)break;Ta[o++]=d,Ta[o++]=f,Ta[o++]=l}else if((p=Ut[d])==2||p==1){let g=p==a;l=g?0:1;for(let m=o-3;m>=0;m-=3){let x=Ta[m+2];if(x&2)break;if(g)Ta[m+2]|=2;else{if(x&4)break;Ta[m+2]|=4}}}}}function lT(t,e,n,r){for(let a=0,s=r;a<=n.length;a++){let i=a?n[a-1].to:t,o=a<n.length?n[a].from:e;for(let l=i;l<o;){let u=Ut[l];if(u==256){let c=l+1;for(;;)if(c==o){if(a==n.length)break;c=n[a++].to,o=a<n.length?n[a].from:e}else if(Ut[c]==256)c++;else break;let d=s==1,f=(c<e?Ut[c]:r)==1,h=d==f?d?1:2:r;for(let p=c,g=a,m=g?n[g-1].to:t;p>l;)p==m&&(p=n[--g].from,m=g?n[g-1].to:t),Ut[--p]=h;l=c}else s=u,l++}}}function Qp(t,e,n,r,a,s,i){let o=r%2?2:1;if(r%2==a%2)for(let l=e,u=0;l<n;){let c=!0,d=!1;if(u==s.length||l<s[u].from){let g=Ut[l];g!=o&&(c=!1,d=g==16)}let f=!c&&o==1?[]:null,h=c?r:r+1,p=l;e:for(;;)if(u<s.length&&p==s[u].from){if(d)break e;let g=s[u];if(!c)for(let m=g.to,x=u+1;;){if(m==n)break e;if(x<s.length&&s[x].from==m)m=s[x++].to;else{if(Ut[m]==o)break e;break}}if(u++,f)f.push(g);else{g.from>l&&i.push(new Wr(l,g.from,h));let m=g.direction==Mi!=!(h%2);em(t,m?r+1:r,a,g.inner,g.from,g.to,i),l=g.to}p=g.to}else{if(p==n||(c?Ut[p]!=o:Ut[p]==o))break;p++}f?Qp(t,l,p,r+1,a,f,i):l<p&&i.push(new Wr(l,p,h)),l=p}else for(let l=n,u=s.length;l>e;){let c=!0,d=!1;if(!u||l>s[u-1].to){let g=Ut[l-1];g!=o&&(c=!1,d=g==16)}let f=!c&&o==1?[]:null,h=c?r:r+1,p=l;e:for(;;)if(u&&p==s[u-1].to){if(d)break e;let g=s[--u];if(!c)for(let m=g.from,x=u;;){if(m==e)break e;if(x&&s[x-1].to==m)m=s[--x].from;else{if(Ut[m-1]==o)break e;break}}if(f)f.push(g);else{g.to<l&&i.push(new Wr(g.to,l,h));let m=g.direction==Mi!=!(h%2);em(t,m?r+1:r,a,g.inner,g.from,g.to,i),l=g.from}p=g.from}else{if(p==e||(c?Ut[p-1]!=o:Ut[p-1]==o))break;p--}f?Qp(t,p,l,r+1,a,f,i):p<l&&i.push(new Wr(p,l,h)),l=p}}function em(t,e,n,r,a,s,i){let o=e%2?2:1;iT(t,a,s,r,o),oT(t,a,s,r,o),lT(a,s,r,o),Qp(t,a,s,e,n,r,i)}function uT(t,e,n){if(!t)return[new Wr(0,0,e==_m?1:0)];if(e==Mi&&!n.length&&!sT.test(t))return iS(t.length);if(n.length)for(;t.length>Ut.length;)Ut[Ut.length]=256;let r=[],a=e==Mi?0:1;return em(t,a,a,n,0,t.length,r),r}function iS(t){return[new Wr(0,t,0)]}var oS="";function cT(t,e,n,r,a){var s;if(!t.length)return null;let i=r.head-t.from,o;if(r.head==t.from&&r.assoc<0){if(!a)return null;i=e[o=0].side(!1,n)}else if(r.head==t.to&&r.assoc>0){if(a)return null;i=e[o=e.length-1].side(!0,n)}else o=Wr.find(e,i,(s=r.bidiLevel)!==null&&s!==void 0?s:-1,r.assoc);let l=e[o],u=l.side(a,n);if(i==u){let f=o+=a?1:-1;if(f<0||f>=e.length)return null;l=e[o=f],i=l.side(!a,n),u=l.side(a,n)}let c=Pn(t.text,i,l.forward(a,n));(c<l.from||c>l.to)&&(c=u),oS=t.text.slice(Math.min(i,c),Math.max(i,c));let d=o==(a?e.length-1:0)?null:e[o+(a?1:-1)];if(c==u){if(!d)return a?se.cursor(t.to,1):se.cursor(t.from,-1);if(d.level+(a?0:1)<l.level)return se.cursor(d.side(!a,n)+t.from,d.forward(a,n)?1:-1,d.level)}return se.cursor(c+t.from,l.forward(a,n)?-1:1,l.level)}function dT(t,e,n){for(let r=e;r<n;r++){let a=aS(t.charCodeAt(r));if(a==1)return Mi;if(a==2||a==4)return _m}return Mi}var lS=Me.define(),uS=Me.define(),cS=Me.define(),dS=Me.define(),tm=Me.define(),fS=Me.define(),hS=Me.define(),Hm=Me.define(),Um=Me.define(),pS=Me.define({combine:t=>t.some(e=>e)}),mS=Me.define({combine:t=>t.some(e=>e)}),gS=Me.define(),yu=class t{constructor(e,n,r,a,s,i=!1){this.range=e,this.y=n,this.x=r,this.yMargin=a,this.xMargin=s,this.isSnapshot=i}map(e){return e.empty?this:new t(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(e){return this.range.to<=e.doc.length?this:new t(se.cursor(e.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}},vd=pt.define({map:(t,e)=>t.map(e)}),xS=pt.define();function oa(t,e,n){let r=t.facet(dS);r.length?r[0](e):window.onerror&&window.onerror(String(e),n,void 0,void 0,e)||(n?console.error(n+":",e):console.error(e))}var ss=Me.define({combine:t=>t.length?t[0]:!0}),fT=0,To=Me.define({combine(t){return t.filter((e,n)=>{for(let r=0;r<n;r++)if(t[r].plugin==e.plugin)return!1;return!0})}}),hr=class t{constructor(e,n,r,a,s){this.id=e,this.create=n,this.domEventHandlers=r,this.domEventObservers=a,this.baseExtensions=s(this),this.extension=this.baseExtensions.concat(To.of({plugin:this,arg:void 0}))}of(e){return this.baseExtensions.concat(To.of({plugin:this,arg:e}))}static define(e,n){let{eventHandlers:r,eventObservers:a,provide:s,decorations:i}=n||{};return new t(fT++,e,r,a,o=>{let l=[];return i&&l.push(qd.of(u=>{let c=u.plugin(o);return c?i(c):Ke.none})),s&&l.push(s(o)),l})}static fromClass(e,n){return t.define((r,a)=>new e(r,a),n)}},bu=class{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(e){if(this.value){if(this.mustUpdate){let n=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(n)}catch(r){if(oa(n.state,r,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(e,this.spec.arg)}catch(n){oa(e.state,n,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(e){var n;if(!((n=this.value)===null||n===void 0)&&n.destroy)try{this.value.destroy()}catch(r){oa(e.state,r,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}},yS=Me.define(),Gm=Me.define(),qd=Me.define(),bS=Me.define(),Wm=Me.define(),Ru=Me.define(),wS=Me.define();function kk(t,e){let n=t.state.facet(wS);if(!n.length)return n;let r=n.map(s=>s instanceof Function?s(t):s),a=[];return wt.spans(r,e.from,e.to,{point(){},span(s,i,o,l){let u=s-e.from,c=i-e.from,d=a;for(let f=o.length-1;f>=0;f--,l--){let h=o[f].spec.bidiIsolate,p;if(h==null&&(h=dT(e.text,u,c)),l>0&&d.length&&(p=d[d.length-1]).to==u&&p.direction==h)p.to=c,d=p.inner;else{let g={from:u,to:c,direction:h,inner:[]};d.push(g),d=g.inner}}}}),a}var vS=Me.define();function kS(t){let e=0,n=0,r=0,a=0;for(let s of t.state.facet(vS)){let i=s(t);i&&(i.left!=null&&(e=Math.max(e,i.left)),i.right!=null&&(n=Math.max(n,i.right)),i.top!=null&&(r=Math.max(r,i.top)),i.bottom!=null&&(a=Math.max(a,i.bottom)))}return{left:e,right:n,top:r,bottom:a}}var hu=Me.define(),la=class t{constructor(e,n,r,a){this.fromA=e,this.toA=n,this.fromB=r,this.toB=a}join(e){return new t(Math.min(this.fromA,e.fromA),Math.max(this.toA,e.toA),Math.min(this.fromB,e.fromB),Math.max(this.toB,e.toB))}addToSet(e){let n=e.length,r=this;for(;n>0;n--){let a=e[n-1];if(!(a.fromA>r.toA)){if(a.toA<r.fromA)break;r=r.join(a),e.splice(n-1,1)}}return e.splice(n,0,r),e}static extendWithRanges(e,n){if(n.length==0)return e;let r=[];for(let a=0,s=0,i=0;;){let o=a<e.length?e[a].fromB:1e9,l=s<n.length?n[s]:1e9,u=Math.min(o,l);if(u==1e9)break;let c=u+i,d=u,f=c;for(;;)if(s<n.length&&n[s]<=d){let h=n[s+1];s+=2,d=Math.max(d,h);for(let p=a;p<e.length&&e[p].fromB<=d;p++)i=e[p].toA-e[p].toB;f=Math.max(f,h+i)}else if(a<e.length&&e[a].fromB<=d){let h=e[a++];d=Math.max(d,h.toB),f=Math.max(f,h.toA),i=h.toA-h.toB}else break;r.push(new t(c,f,u,d))}return r}},Fd=class t{constructor(e,n,r){this.view=e,this.state=n,this.transactions=r,this.flags=0,this.startState=e.state,this.changes=Nn.empty(this.startState.doc.length);for(let s of r)this.changes=this.changes.compose(s.changes);let a=[];this.changes.iterChangedRanges((s,i,o,l)=>a.push(new la(s,i,o,l))),this.changedRanges=a}static create(e,n,r){return new t(e,n,r)}get viewportChanged(){return(this.flags&4)>0}get viewportMoved(){return(this.flags&8)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&18)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(e=>e.selection)}get empty(){return this.flags==0&&this.transactions.length==0}},hT=[],Yt=class{constructor(e,n,r=0){this.dom=e,this.length=n,this.flags=r,this.parent=null,e.cmTile=this}get breakAfter(){return this.flags&1}get children(){return hT}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(e){if(this.flags|=2,this.flags&4){this.flags&=-5;let n=this.domAttrs;n&&YM(this.dom,n)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:"")+(this.breakAfter?"#":"")}destroy(){this.parent=null}setDOM(e){this.dom=e,e.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e,n=this.posAtStart){let r=n;for(let a of this.children){if(a==e)return r;r+=a.length+a.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(e){return this.posBefore(e)+e.length}covers(e){return!0}coordsIn(e,n,r){return null}domPosFor(e,n){let r=Ws(this.dom),a=this.length?e>0:n>0;return new Da(this.parent.dom,r+(a?1:0),e==0||e==this.length)}markDirty(e){this.flags&=-3,e&&(this.flags|=4),this.parent&&this.parent.flags&2&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let e=this;e;e=e.parent)if(e instanceof _o)return e;return null}static get(e){return e.cmTile}},Bo=class extends Yt{constructor(e){super(e,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(e){this.children.push(e),e.parent=this}sync(e){if(this.flags&2)return;super.sync(e);let n=this.dom,r=null,a,s=e?.node==n?e:null,i=0;for(let o of this.children){if(o.sync(e),i+=o.length+o.breakAfter,a=r?r.nextSibling:n.firstChild,s&&a!=o.dom&&(s.written=!0),o.dom.parentNode==n)for(;a&&a!=o.dom;)a=Sk(a);else n.insertBefore(o.dom,a);r=o.dom}for(a=r?r.nextSibling:n.firstChild,s&&a&&(s.written=!0);a;)a=Sk(a);this.length=i}};function Sk(t){let e=t.nextSibling;return t.parentNode.removeChild(t),e}var _o=class extends Bo{constructor(e,n){super(n),this.view=e}owns(e){for(;e;e=e.parent)if(e==this)return!0;return!1}isBlock(){return!0}nearest(e){for(;;){if(!e)return null;let n=Yt.get(e);if(n&&this.owns(n))return n;e=e.parentNode}}blockTiles(e){for(let n=[],r=this,a=0,s=0;;)if(a==r.children.length){if(!n.length)return;r=r.parent,r.breakAfter&&s++,a=n.pop()}else{let i=r.children[a++];if(i instanceof is)n.push(a),r=i,a=0;else{let o=s+i.length,l=e(i,s);if(l!==void 0)return l;s=o+i.breakAfter}}}resolveBlock(e,n){let r,a=-1,s,i=-1;if(this.blockTiles((o,l)=>{let u=l+o.length;if(e>=l&&e<=u){if(o.isWidget()&&n>=-1&&n<=1){if(o.flags&32)return!0;o.flags&16&&(r=void 0)}(l<e||e==u&&(n<-1?o.length:o.covers(1)))&&(!r||!o.isWidget()&&r.isWidget())&&(r=o,a=e-l),(u>e||e==l&&(n>1?o.length:o.covers(-1)))&&(!s||!o.isWidget()&&s.isWidget())&&(s=o,i=e-l)}}),!r&&!s)throw new Error("No tile at position "+e);return r&&n<0||!s?{tile:r,offset:a}:{tile:s,offset:i}}},is=class t extends Bo{constructor(e,n){super(e),this.wrapper=n}isBlock(){return!0}covers(e){return this.children.length?e<0?this.children[0].covers(-1):this.lastChild.covers(1):!1}get domAttrs(){return this.wrapper.attributes}static of(e,n){let r=new t(n||document.createElement(e.tagName),e);return n||(r.flags|=4),r}},Ho=class t extends Bo{constructor(e,n){super(e),this.attrs=n}isLine(){return!0}static start(e,n,r){let a=new t(n||document.createElement("div"),e);return(!n||!r)&&(a.flags|=4),a}get domAttrs(){return this.attrs}resolveInline(e,n,r){let a=null,s=-1,i=null,o=-1;function l(c,d){for(let f=0,h=0;f<c.children.length&&h<=d;f++){let p=c.children[f],g=h+p.length;g>=d&&(p.isComposite()?l(p,d-h):(!i||i.isHidden&&(n>0&&!(i.flags&32)||r&&mT(i,p)))&&(g>d||p.flags&32&&n<=1)?(i=p,o=d-h):(h<d||p.flags&16&&!p.isHidden&&n>=-1)&&(a=p,s=d-h)),h=g}}l(this,e);let u=(n<0?a:i)||a||i;return u?{tile:u,offset:u==a?s:o}:null}coordsIn(e,n,r){let a=this.resolveInline(e,n,!0);return a?a.tile.coordsIn(Math.max(0,a.offset),n,r):pT(this)}domIn(e,n){let r=this.resolveInline(e,n);if(r){let{tile:a,offset:s}=r;if(this.dom.contains(a.dom))return a.isText()?new Da(a.dom,Math.min(a.dom.nodeValue.length,s)):a.domPosFor(s,a.flags&16?1:a.flags&32?-1:n);let i=r.tile.parent,o=!1;for(let l of i.children){if(o)return new Da(l.dom,0);l==r.tile&&(o=!0)}}return new Da(this.dom,0)}};function pT(t){let e=t.dom.lastChild;if(!e)return t.dom.getBoundingClientRect();let n=gu(e);return n[n.length-1]||null}function mT(t,e){let n=t.coordsIn(0,1),r=e.coordsIn(0,1);return n&&r&&r.top<n.bottom}var fr=class t extends Bo{constructor(e,n){super(e),this.mark=n}get domAttrs(){return this.mark.attrs}static of(e,n){let r=new t(n||document.createElement(e.tagName),e);return n||(r.flags|=4),r}},Pi=class t extends Yt{constructor(e,n){super(e,n.length),this.text=n}sync(e){this.flags&2||(super.sync(e),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text))}isText(){return!0}toString(){return JSON.stringify(this.text)}coordsIn(e,n,r){let a=this.dom.nodeValue.length;e>a&&(e=a);let s=e,i=e,o=0;e==0&&n<0||e==a&&n>=0?ke.chrome||ke.gecko||(e?(s--,o=1):i<a&&(i++,o=-1)):n<0?s--:i<a&&i++;let l=Nu(this.dom,s,i).getClientRects();if(!l.length)return null;let u=l[(o?o<0:n>=0)?0:l.length-1];return ke.safari&&!o&&u.width==0&&(u=Array.prototype.find.call(l,c=>c.width)||u),r==null?u:Pu(u,(o?o>0:n<0)==r)}static of(e,n){let r=new t(n||document.createTextNode(e),e);return n||(r.flags|=2),r}},Ti=class t extends Yt{constructor(e,n,r,a){super(e,n,a),this.widget=r}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(e){return this.flags&48?!1:(this.flags&(e<0?64:128))>0}coordsIn(e,n){return this.coordsInWidget(e,n,!1)}coordsInWidget(e,n,r){let a=this.widget.coordsAt(this.dom,e,n);if(a)return a;if(r)return Pu(this.dom.getBoundingClientRect(),this.length?e==0:n<=0);{let s=this.dom.getClientRects(),i=null;if(!s.length)return null;let o=this.flags&16?!0:this.flags&32?!1:e>0;for(let l=o?s.length-1:0;i=s[l],!(e>0?l==0:l==s.length-1||i.top<i.bottom);l+=o?-1:1);return Pu(i,!o)}}get overrideDOMText(){if(!this.length)return st.empty;let{root:e}=this;if(!e)return st.empty;let n=this.posAtStart;return e.view.state.doc.slice(n,n+this.length)}destroy(){super.destroy(),this.widget.destroy(this.dom)}static of(e,n,r,a,s){return s||(s=e.toDOM(n),e.editable||(s.contentEditable="false")),new t(s,r,e,a)}},Uo=class extends Yt{constructor(e){let n=document.createElement("img");n.className="cm-widgetBuffer",n.setAttribute("aria-hidden","true"),super(n,0,e)}get isHidden(){return!0}get overrideDOMText(){return st.empty}coordsIn(e,n,r){let a=this.dom.getBoundingClientRect();return r==null?a:Pu(a,n>0==r)}},nm=class{constructor(e){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=e}advance(e,n,r){let{tile:a,index:s,beforeBreak:i,parents:o}=this;for(;e||n>0;)if(a.isComposite())if(i){if(!e)break;r&&r.break(),e--,i=!1}else if(s==a.children.length){if(!e&&!o.length)break;r&&r.leave(a),i=!!a.breakAfter,{tile:a,index:s}=o.pop(),s++}else{let l=a.children[s],u=l.breakAfter;(n>0?l.length<=e:l.length<e)&&(!r||r.skip(l,0,l.length)!==!1||!l.isComposite)?(i=!!u,s++,e-=l.length):(o.push({tile:a,index:s}),a=l,s=0,r&&l.isComposite()&&r.enter(l))}else{let l=a.length;if(s<l&&e){let u=Math.min(e,l-s);r&&r.skip(a,s,s+u),e-=u,s+=u}if(s==l)i=!!a.breakAfter,{tile:a,index:s}=o.pop(),s++;else if(!e)break}return this.tile=a,this.index=s,this.beforeBreak=i,this}get root(){return this.parents.length?this.parents[0].tile:this.tile}},rm=class{constructor(e,n,r,a){this.from=e,this.to=n,this.wrapper=r,this.rank=a}},am=class{constructor(e,n,r){this.cache=e,this.root=n,this.blockWrappers=r,this.curLine=null,this.lastBlock=null,this.afterWidget=null,this.pos=0,this.wrappers=[],this.wrapperPos=0}addText(e,n,r,a){var s;this.flushBuffer();let i=this.ensureMarks(n,r),o=i.lastChild;if(o&&o.isText()&&!(o.flags&8)&&o.length+e.length<512){this.cache.reused.set(o,2);let l=i.children[i.children.length-1]=new Pi(o.dom,o.text+e);l.parent=i}else i.append(a||Pi.of(e,(s=this.cache.find(Pi))===null||s===void 0?void 0:s.dom));this.pos+=e.length,this.afterWidget=null}addComposition(e,n){let r=this.curLine;r.dom!=n.line.dom&&(r.setDOM(this.cache.reused.has(n.line)?Gp(n.line.dom):n.line.dom),this.cache.reused.set(n.line,2));let a=r;for(let o=n.marks.length-1;o>=0;o--){let l=n.marks[o],u=a.lastChild;if(u instanceof fr&&u.mark.eq(l.mark))u.dom!=l.dom&&u.setDOM(Gp(l.dom)),a=u;else{let{dom:c}=l;this.cache.reused.get(l)&&Yt.get(l.dom)&&(c=Gp(l.dom));let d=fr.of(l.mark,c);a.append(d),a=d}this.cache.reused.set(l,2)}let s=Yt.get(e.text);s&&this.cache.reused.set(s,2);let i=new Pi(e.text,e.text.nodeValue);i.flags|=8,this.pos=e.range.toB,a.append(i)}addInlineWidget(e,n,r){let a=this.afterWidget&&e.flags&48&&(this.afterWidget.flags&48)==(e.flags&48);a||this.flushBuffer();let s=this.ensureMarks(n,r);!a&&!(e.flags&16)&&s.append(this.getBuffer(1)),s.append(e),this.pos+=e.length,this.afterWidget=e}addMark(e,n,r){this.flushBuffer(),this.ensureMarks(n,r).append(e),this.pos+=e.length,this.afterWidget=null}addBlockWidget(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}continueWidget(e){let n=this.afterWidget||this.lastBlock;n.length+=e,this.pos+=e}addLineStart(e,n){var r;e||(e=SS);let a=Ho.start(e,n||((r=this.cache.find(Ho))===null||r===void 0?void 0:r.dom),!!n);this.getBlockPos().append(this.lastBlock=this.curLine=a)}addLine(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(e){this.blockPosCovered()||this.addLineStart(e)}ensureLine(e){this.curLine||this.addLineStart(e)}ensureMarks(e,n){var r;let a=this.curLine;for(let s=e.length-1;s>=0;s--){let i=e[s],o;if(n>0&&(o=a.lastChild)&&o instanceof fr&&o.mark.eq(i))a=o,n--;else{let l=fr.of(i,(r=this.cache.find(fr,u=>u.mark.eq(i)))===null||r===void 0?void 0:r.dom);a.append(l),a=l,n=0}}return a}endLine(){if(this.curLine){this.flushBuffer();let e=this.curLine.lastChild;(!e||!Ck(this.curLine,!1)||e.dom.nodeName!="BR"&&e.isWidget()&&!(ke.ios&&Ck(this.curLine,!0)))&&this.curLine.append(this.cache.findWidget(Wp,0,32)||new Ti(Wp.toDOM(),0,Wp,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let e=this.wrappers.length-1;e>=0;e--)this.wrappers[e].to<this.pos&&this.wrappers.splice(e,1);for(let e=this.blockWrappers;e.value&&e.from<=this.pos;e.next())if(e.to>=this.pos){let n=e.rank*102+e.value.rank,r=new rm(e.from,e.to,e.value,n),a=this.wrappers.length;for(;a>0&&(this.wrappers[a-1].rank-r.rank||this.wrappers[a-1].to-r.to)<0;)a--;this.wrappers.splice(a,0,r)}this.wrapperPos=this.pos}getBlockPos(){var e;this.updateBlockWrappers();let n=this.root;for(let r of this.wrappers){let a=n.lastChild;if(r.from<this.pos&&a instanceof is&&a.wrapper.eq(r.wrapper))n=a;else{let s=is.of(r.wrapper,(e=this.cache.find(is,i=>i.wrapper.eq(r.wrapper)))===null||e===void 0?void 0:e.dom);n.append(s),n=s}}return n}blockPosCovered(){let e=this.lastBlock;return e!=null&&!e.breakAfter&&(!e.isWidget()||(e.flags&160)>0)}getBuffer(e){let n=2|(e<0?16:32),r=this.cache.find(Uo,void 0,1);return r&&(r.flags=n),r||new Uo(n)}flushBuffer(){this.afterWidget&&!(this.afterWidget.flags&32)&&(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}},sm=class{constructor(e){this.skipCount=0,this.text="",this.textOff=0,this.cursor=e.iter()}skip(e){this.textOff+e<=this.text.length?this.textOff+=e:(this.skipCount+=e-(this.text.length-this.textOff),this.text="",this.textOff=0)}next(e){if(this.textOff==this.text.length){let{value:a,lineBreak:s,done:i}=this.cursor.next(this.skipCount);if(this.skipCount=0,i)throw new Error("Ran out of text content when drawing inline views");this.text=a;let o=this.textOff=Math.min(e,a.length);return s?null:a.slice(0,o)}let n=Math.min(this.text.length,this.textOff+e),r=this.text.slice(this.textOff,n);return this.textOff=n,r}},Ed=[Ti,Ho,Pi,fr,Uo,is,_o];for(let t=0;t<Ed.length;t++)Ed[t].bucket=t;var im=class{constructor(e){this.view=e,this.buckets=Ed.map(()=>[]),this.index=Ed.map(()=>0),this.reused=new Map}add(e){let n=e.constructor.bucket,r=this.buckets[n];r.length<6?r.push(e):r[this.index[n]=(this.index[n]+1)%6]=e}find(e,n,r=2){let a=e.bucket,s=this.buckets[a],i=this.index[a];for(let o=0;o<s.length;o++){let l=(o+i)%s.length,u=s[l];if((!n||n(u))&&!this.reused.has(u))return s.splice(l,1),l<i&&this.index[a]--,this.reused.set(u,r),u}return null}findWidget(e,n,r){let a=this.buckets[0];if(a.length)for(let s=0,i=0;;s++){if(s==a.length){if(i)return null;i=1,s=0}let o=a[s];if(!this.reused.has(o)&&(i==0?o.widget.compare(e):o.widget.constructor==e.constructor&&e.updateDOM(o.dom,this.view,o.widget)))return a.splice(s,1),s<this.index[0]&&this.index[0]--,o.widget==e&&o.length==n&&(o.flags&497)==r?(this.reused.set(o,1),o):(this.reused.set(o,2),new Ti(o.dom,n,e,o.flags&-498|r))}}reuse(e){return this.reused.set(e,1),e}maybeReuse(e,n=2){if(!this.reused.has(e))return this.reused.set(e,n),e.dom}clear(){for(let e=0;e<this.buckets.length;e++)this.buckets[e].length=this.index[e]=0}},om=class{constructor(e,n,r,a,s){this.view=e,this.decorations=a,this.disallowBlockEffectsFor=s,this.openWidget=!1,this.openMarks=0,this.cache=new im(e),this.text=new sm(e.state.doc),this.builder=new am(this.cache,new _o(e,e.contentDOM),wt.iter(r)),this.cache.reused.set(n,2),this.old=new nm(n),this.reuseWalker={skip:(i,o,l)=>{if(this.cache.add(i),i.isComposite())return!1},enter:i=>this.cache.add(i),leave:()=>{},break:()=>{}}}run(e,n){let r=n&&this.getCompositionContext(n.text);for(let a=0,s=0,i=0;;){let o=i<e.length?e[i++]:null,l=o?o.fromA:this.old.root.length;if(l>a){let u=l-a;this.preserve(u,!i,!o),a=l,s+=u}if(!o)break;n&&o.fromA<=n.range.fromA&&o.toA>=n.range.toA?(this.forward(o.fromA,n.range.fromA,n.range.fromA<n.range.toA?1:-1),this.emit(s,n.range.fromB),this.builder.flushBuffer(),this.cache.clear(),this.builder.addComposition(n,r),this.text.skip(n.range.toB-n.range.fromB),this.forward(n.range.fromA,o.toA),this.emit(n.range.toB,o.toB)):(this.forward(o.fromA,o.toA),this.emit(s,o.toB)),s=o.toB,a=o.toA}return this.builder.curLine&&this.builder.endLine(),this.builder.root}preserve(e,n,r){let a=yT(this.old),s=this.openMarks;this.old.advance(e,r?1:-1,{skip:(i,o,l)=>{if(i.isWidget())if(this.openWidget)this.builder.continueWidget(l-o);else{let u=l>0||o<i.length?Ti.of(i.widget,this.view,l-o,i.flags&496,this.cache.maybeReuse(i)):this.cache.reuse(i);u.flags&256?(u.flags&=-2,this.builder.addBlockWidget(u)):(this.builder.ensureLine(null),this.builder.addInlineWidget(u,a,s),s=a.length)}else if(i.isText())this.builder.ensureLine(null),!o&&l==i.length&&!this.cache.reused.has(i)?this.builder.addText(i.text,a,s,this.cache.reuse(i)):(this.cache.add(i),this.builder.addText(i.text.slice(o,l),a,s)),s=a.length;else if(i.isLine())i.flags&=-2,this.cache.reused.set(i,1),this.builder.addLine(i);else if(i instanceof Uo)this.cache.add(i);else if(i instanceof fr)this.builder.ensureLine(null),this.builder.addMark(i,a,s),this.cache.reused.set(i,1),s=a.length;else return!1;this.openWidget=!1},enter:i=>{i.isLine()?this.builder.addLineStart(i.attrs,this.cache.maybeReuse(i)):(this.cache.add(i),i instanceof fr&&a.unshift(i.mark)),this.openWidget=!1},leave:i=>{i.isLine()?a.length&&(a.length=s=0):i instanceof fr&&(a.shift(),s=Math.min(s,a.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(e)}emit(e,n){let r=null,a=this.builder,s=-1,i=wt.spans(this.decorations,e,n,{point:(o,l,u,c,d,f)=>{if(u instanceof Ri){if(this.disallowBlockEffectsFor[f]){if(u.block)throw new RangeError("Block decorations may not be specified via plugins");if(l>this.view.state.doc.lineAt(o).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}if(s=c.length,d>c.length)a.continueWidget(l-o);else{let h=u.widget||(u.block?zs.block:zs.inline),p=gT(u),g=this.cache.findWidget(h,l-o,p)||Ti.of(h,this.view,l-o,p);u.block?(u.startSide>0&&a.addLineStartIfNotCovered(r),a.addBlockWidget(g)):(a.ensureLine(r),a.addInlineWidget(g,c,d))}r=null}else r=xT(r,u);l>o&&this.text.skip(l-o)},span:(o,l,u,c)=>{for(let d=o;d<l;){let f=this.text.next(Math.min(512,l-d));f==null?(a.addLineStartIfNotCovered(r),a.addBreak(),d++):(a.ensureLine(r),a.addText(f,u,d==o?c:u.length),d+=f.length),r=null}s=u.length}});s>-1&&(this.openWidget=i>s),this.openWidget||a.addLineStartIfNotCovered(r),this.openMarks=i}forward(e,n,r=1){n-e<=10?this.old.advance(n-e,r,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(n-e-10,-1),this.old.advance(5,r,this.reuseWalker))}getCompositionContext(e){let n=[],r=null;for(let a=e.parentNode;;a=a.parentNode){let s=Yt.get(a);if(a==this.view.contentDOM)break;s instanceof fr?n.push(s):s?.isLine()?r=s:s instanceof is||(a.nodeName=="DIV"&&!r?r=new Ho(a,SS):r||n.push(fr.of(new Iu({tagName:a.nodeName.toLowerCase(),attributes:JM(a)}),a)))}return r?{line:r,marks:n}:null}};function Ck(t,e){let n=r=>{for(let a of r.children)if((e?a.isText():a.length)||n(a))return!0;return!1};return n(t)}function gT(t){let e=t.isReplace?(t.startSide<0?64:0)|(t.endSide>0?128:0):t.startSide>0?32:16;return t.block&&(e|=256),e}var SS={class:"cm-line"};function xT(t,e){let n=e.spec.attributes,r=e.spec.class;return!n&&!r||(t||(t={class:"cm-line"}),n&&Om(n,t),r&&(t.class+=" "+r)),t}function yT(t){let e=[];for(let n=t.parents.length;n>1;n--){let r=n==t.parents.length?t.tile:t.parents[n].tile;r instanceof fr&&e.push(r.mark)}return e}function Gp(t){let e=Yt.get(t);return e&&e.setDOM(t.cloneNode()),t}var zs=class extends Ir{constructor(e){super(),this.tag=e}eq(e){return e.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(e){return e.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}};zs.inline=new zs("span");zs.block=new zs("div");var Wp=new class extends Ir{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}},Od=class{constructor(e){this.view=e,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=Ke.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new _o(e,e.contentDOM),this.updateInner([new la(0,0,0,e.state.doc.length)],null)}update(e){var n;let r=e.changedRanges;this.minWidth>0&&r.length&&(r.every(({fromA:c,toA:d})=>d<this.minWidthFrom||c>this.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(e);let a=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((n=this.domChanged)===null||n===void 0)&&n.newSel?a=this.domChanged.newSel.head:!LT(e.changes,this.hasComposition)&&!e.selectionSet&&(a=e.state.selection.main.head));let s=a>-1?wT(this.view,e.changes,a):null;if(this.domChanged=null,this.hasComposition){let{from:c,to:d}=this.hasComposition;r=new la(c,d,e.changes.mapPos(c,-1),e.changes.mapPos(d,1)).addToSet(r.slice())}this.hasComposition=s?{from:s.range.fromB,to:s.range.toB}:null,(ke.ie||ke.chrome)&&!s&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let i=this.decorations,o=this.blockWrappers;this.updateDeco();let l=ST(i,this.decorations,e.changes);l.length&&(r=la.extendWithRanges(r,l));let u=CT(o,this.blockWrappers,e.changes);return u.length&&(r=la.extendWithRanges(r,u)),s&&!r.some(c=>c.fromA<=s.range.fromA&&c.toA>=s.range.toA)&&(r=s.range.addToSet(r.slice())),this.tile.flags&2&&r.length==0?!1:(this.updateInner(r,s),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,n){this.view.viewState.mustMeasureContent=!0;let{observer:r}=this.view;r.ignore(()=>{if(n||e.length){let i=this.tile,o=new om(this.view,i,this.blockWrappers,this.decorations,this.dynamicDecorationMap);n&&Yt.get(n.text)&&o.cache.reused.set(Yt.get(n.text),2),this.tile=o.run(e,n),lm(i,o.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let s=ke.chrome||ke.ios?{node:r.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(s),s&&(s.written||r.selectionRange.focusNode!=s.node||!this.tile.dom.contains(s.node))&&(this.forceSelection=!0),this.tile.dom.style.height=""});let a=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let s of this.tile.children)s.isWidget()&&s.widget instanceof wu&&a.push(s.dom);r.updateGaps(a)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let n of e.transactions)for(let r of n.effects)r.is(xS)&&(this.editContextFormatting=r.value)}updateSelection(e=!1,n=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let{dom:r}=this.tile,a=this.view.root.activeElement,s=a==r,i=!s&&!(this.view.state.facet(ss)||r.tabIndex>-1)&&mu(r,this.view.observer.selectionRange)&&!(a&&r.contains(a));if(!(s||n||i))return;let o=this.forceSelection;this.forceSelection=!1;let l=this.view.state.selection.main,u,c;if(l.empty?c=u=this.inlineDOMNearPos(l.anchor,l.assoc||1):(c=this.inlineDOMNearPos(l.head,l.head==l.from?1:-1),u=this.inlineDOMNearPos(l.anchor,l.anchor==l.from?1:-1)),ke.gecko&&l.empty&&!this.hasComposition&&bT(u)){let f=document.createTextNode("");this.view.observer.ignore(()=>u.node.insertBefore(f,u.node.childNodes[u.offset]||null)),u=c=new Da(f,0),o=!0}let d=this.view.observer.selectionRange;(o||!d.focusNode||(!xu(u.node,u.offset,d.anchorNode,d.anchorOffset)||!xu(c.node,c.offset,d.focusNode,d.focusOffset))&&!this.suppressWidgetCursorChange(d,l))&&(this.view.observer.ignore(()=>{ke.android&&ke.chrome&&r.contains(d.focusNode)&&IT(d.focusNode,r)&&(r.blur(),r.focus({preventScroll:!0}));let f=Au(this.view.root);if(f)if(l.empty){if(ke.gecko){let h=vT(u.node,u.offset);if(h&&h!=3){let p=(h==1?tS:nS)(u.node,u.offset);p&&(u=new Da(p.node,p.offset))}}f.collapse(u.node,u.offset),l.bidiLevel!=null&&f.caretBidiLevel!==void 0&&(f.caretBidiLevel=l.bidiLevel)}else if(f.extend){f.collapse(u.node,u.offset);try{f.extend(c.node,c.offset)}catch{}}else{let h=document.createRange();l.anchor>l.head&&([u,c]=[c,u]),h.setEnd(c.node,c.offset),h.setStart(u.node,u.offset),f.removeAllRanges(),f.addRange(h)}i&&this.view.root.activeElement==r&&(r.blur(),a&&a.focus())}),this.view.observer.setSelectionRange(u,c)),this.impreciseAnchor=u.precise?null:new Da(d.anchorNode,d.anchorOffset),this.impreciseHead=c.precise?null:new Da(d.focusNode,d.focusOffset)}suppressWidgetCursorChange(e,n){return this.hasComposition&&n.empty&&xu(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)&&this.posFromDOM(e.focusNode,e.focusOffset)==n.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,n=e.state.selection.main,r=Au(e.root),{anchorNode:a,anchorOffset:s}=e.observer.selectionRange;if(!r||!n.empty||!n.assoc||!r.modify)return;let i=this.lineAt(n.head,n.assoc);if(!i)return;let o=i.posAtStart;if(n.head==o||n.head==o+i.length)return;let l=this.coordsAt(n.head,-1),u=this.coordsAt(n.head,1);if(!l||!u||l.bottom>u.top)return;let c=this.domAtPos(n.head+n.assoc,n.assoc);r.collapse(c.node,c.offset),r.modify("move",n.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let d=e.observer.selectionRange;e.docView.posFromDOM(d.anchorNode,d.anchorOffset)!=n.from&&r.collapse(a,s)}posFromDOM(e,n){let r=this.tile.nearest(e);if(!r)return this.tile.dom.compareDocumentPosition(e)&2?0:this.view.state.doc.length;let a=r.posAtStart;if(r.isComposite()){let s;if(e==r.dom)s=r.dom.childNodes[n];else{let i=os(e)==0?0:n==0?-1:1;for(;;){let o=e.parentNode;if(o==r.dom)break;i==0&&o.firstChild!=o.lastChild&&(e==o.firstChild?i=-1:i=1),e=o}i<0?s=e:s=e.nextSibling}if(s==r.dom.firstChild)return a;for(;s&&!Yt.get(s);)s=s.nextSibling;if(!s)return a+r.length;for(let i=0,o=a;;i++){let l=r.children[i];if(l.dom==s)return o;o+=l.length+l.breakAfter}}else return r.isText()?e==r.dom?a+n:a+(n?r.length:0):a}domAtPos(e,n){let{tile:r,offset:a}=this.tile.resolveBlock(e,n);return r.isWidget()?r.domPosFor(a,n):r.domIn(a,n)}inlineDOMNearPos(e,n){let r,a=-1,s=!1,i,o=-1,l=!1;return this.tile.blockTiles((u,c)=>{if(u.isWidget()){if(u.flags&32&&c>=e)return!0;u.flags&16&&(s=!0)}else{let d=c+u.length;if(c<=e&&(r=u,a=e-c,s=d<e),d>=e&&!i&&(i=u,o=e-c,l=c>e),c>e&&i)return!0}}),!r&&!i?this.domAtPos(e,n):(s&&i?r=null:l&&r&&(i=null),r&&n<0||!i?r.domIn(a,n):i.domIn(o,n))}coordsAt(e,n,r){let{tile:a,offset:s}=this.tile.resolveBlock(e,n);return a.isWidget()?a.widget instanceof wu?null:a.coordsInWidget(s,n,!0):a.coordsIn(s,n,r)}lineAt(e,n){let{tile:r}=this.tile.resolveBlock(e,n);return r.isLine()?r:null}coordsForChar(e){let{tile:n,offset:r}=this.tile.resolveBlock(e,1);if(!n.isLine())return null;function a(s,i){if(s.isComposite())for(let o of s.children){if(o.length>=i){let l=a(o,i);if(l)return l}if(i-=o.length,i<0)break}else if(s.isText()&&i<s.length){let o=Pn(s.text,i);if(o==i)return null;let l=Nu(s.dom,i,o).getClientRects();for(let u=0;u<l.length;u++){let c=l[u];if(u==l.length-1||c.top<c.bottom&&c.left<c.right)return c}}return null}return a(n,r)}measureVisibleLineHeights(e){let n=[],{from:r,to:a}=e,s=this.view.contentDOM.clientWidth,i=s>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,o=-1,l=this.view.textDirection==Vt.LTR,u=0,c=(d,f,h)=>{for(let p=0;p<d.children.length&&!(f>a);p++){let g=d.children[p],m=f+g.length,x=g.dom.getBoundingClientRect(),{height:y}=x;if(h&&!p&&(u+=x.top-h.top),g instanceof is)m>r&&c(g,f,x);else if(f>=r&&(u>0&&n.push(-u),n.push(y+u),u=0,i)){let b=g.dom.lastChild,C=b?gu(b):[];if(C.length){let L=C[C.length-1],P=l?L.right-x.left:x.right-L.left;P>o&&(o=P,this.minWidth=s,this.minWidthFrom=f,this.minWidthTo=m)}}h&&p==d.children.length-1&&(u+=h.bottom-x.bottom),f=m+g.breakAfter}};return c(this.tile,0,null),n}textDirectionAt(e){let{tile:n}=this.tile.resolveBlock(e,1);return getComputedStyle(n.dom).direction=="rtl"?Vt.RTL:Vt.LTR}measureTextSize(){let e=this.tile.blockTiles(i=>{if(i.isLine()&&i.children.length&&i.length<=20){let o=0,l;for(let u of i.children){if(!u.isText()||/[^ -~]/.test(u.text))return;let c=gu(u.dom);if(c.length!=1)return;o+=c[0].width,l=c[0].height}if(o)return{lineHeight:i.dom.getBoundingClientRect().height,charWidth:o/i.length,textHeight:l}}});if(e)return e;let n=document.createElement("div"),r,a,s;return n.className="cm-line",n.style.width="99999px",n.style.position="absolute",n.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.tile.dom.appendChild(n);let i=gu(n.firstChild)[0];r=n.getBoundingClientRect().height,a=i&&i.width?i.width/27:7,s=i&&i.height?i.height:r,n.remove()}),{lineHeight:r,charWidth:a,textHeight:s}}computeBlockGapDeco(){let e=[],n=this.view.viewState;for(let r=0,a=0;;a++){let s=a==n.viewports.length?null:n.viewports[a],i=s?s.from-1:this.view.state.doc.length;if(i>r){let o=(n.lineBlockAt(i).bottom-n.lineBlockAt(r).top)/this.view.scaleY;e.push(Ke.replace({widget:new wu(o),block:!0,inclusive:!0,isBlockGap:!0}).range(r,i))}if(!s)break;r=s.to+1}return Ke.set(e)}updateDeco(){let e=1,n=this.view.state.facet(qd).map(s=>(this.dynamicDecorationMap[e++]=typeof s=="function")?s(this.view):s),r=!1,a=this.view.state.facet(Wm).map((s,i)=>{let o=typeof s=="function";return o&&(r=!0),o?s(this.view):s});for(a.length&&(this.dynamicDecorationMap[e++]=r,n.push(wt.join(a))),this.decorations=[this.editContextFormatting,...n,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];e<this.decorations.length;)this.dynamicDecorationMap[e++]=!1;this.blockWrappers=this.view.state.facet(bS).map(s=>typeof s=="function"?s(this.view):s)}scrollIntoView(e){if(e.isSnapshot){let u=this.view.viewState.lineBlockAt(e.range.head);this.view.scrollDOM.scrollTop=u.top-e.yMargin,this.view.scrollDOM.scrollLeft=e.xMargin;return}for(let u of this.view.state.facet(gS))try{if(u(this.view,e.range,e))return!0}catch(c){oa(this.view.state,c,"scroll handler")}let{range:n}=e,r=this.coordsAt(n.head,n.assoc||(n.head>n.anchor?-1:1)),a;if(!r)return;!n.empty&&(a=this.coordsAt(n.anchor,n.anchor>n.head?-1:1))&&(r={left:Math.min(r.left,a.left),top:Math.min(r.top,a.top),right:Math.max(r.right,a.right),bottom:Math.max(r.bottom,a.bottom)});let s=kS(this.view),i={left:r.left-s.left,top:r.top-s.top,right:r.right+s.right,bottom:r.bottom+s.bottom},{offsetWidth:o,offsetHeight:l}=this.view.scrollDOM;if(eT(this.view.scrollDOM,i,n.head<n.anchor?-1:1,e.x,e.y,Math.max(Math.min(e.xMargin,o),-o),Math.max(Math.min(e.yMargin,l),-l),this.view.textDirection==Vt.LTR),window.visualViewport&&window.innerHeight-window.visualViewport.height>1&&(r.top>window.visualViewport.offsetTop+window.visualViewport.height||r.bottom<window.visualViewport.offsetTop)){let u=this.view.docView.lineAt(n.head,1);if(u){let c=Jk(u.dom);u.dom.scrollIntoView({block:"nearest"}),Zk(c,!1)}}}lineHasWidget(e){let n=r=>r.isWidget()||r.children.some(n);return n(this.tile.resolveBlock(e,1).tile)}destroy(){lm(this.tile)}};function lm(t,e){let n=e?.get(t);if(n!=1){n==null&&t.destroy();for(let r of t.children)lm(r,e)}}function bT(t){return t.node.nodeType==1&&t.node.firstChild&&(t.offset==0||t.node.childNodes[t.offset-1].contentEditable=="false")&&(t.offset==t.node.childNodes.length||t.node.childNodes[t.offset].contentEditable=="false")}function CS(t,e){let n=t.observer.selectionRange;if(!n.focusNode)return null;let r=tS(n.focusNode,n.focusOffset),a=nS(n.focusNode,n.focusOffset),s=r||a;if(a&&r&&a.node!=r.node){let o=Yt.get(a.node);if(!o||o.isText()&&o.text!=a.node.nodeValue)s=a;else if(t.docView.lastCompositionAfterCursor){let l=Yt.get(r.node);!l||l.isText()&&l.text!=r.node.nodeValue||(s=a)}}if(t.docView.lastCompositionAfterCursor=s!=r,!s)return null;let i=e-s.offset;return{from:i,to:i+s.node.nodeValue.length,node:s.node}}function wT(t,e,n){let r=CS(t,n);if(!r)return null;let{node:a,from:s,to:i}=r,o=a.nodeValue;if(/[\n\r]/.test(o)||t.state.doc.sliceString(r.from,r.to)!=o)return null;let l=e.invertedDesc;return{range:new la(l.mapPos(s),l.mapPos(i),s,i),text:a}}function vT(t,e){return t.nodeType!=1?0:(e&&t.childNodes[e-1].contentEditable=="false"?1:0)|(e<t.childNodes.length&&t.childNodes[e].contentEditable=="false"?2:0)}var kT=class{constructor(){this.changes=[]}compareRange(e,n){Eo(e,n,this.changes)}comparePoint(e,n){Eo(e,n,this.changes)}boundChange(e){Eo(e,e,this.changes)}};function ST(t,e,n){let r=new kT;return wt.compare(t,e,n,r),r.changes}var um=class{constructor(){this.changes=[]}compareRange(e,n){Eo(e,n,this.changes)}comparePoint(){}boundChange(e){Eo(e,e,this.changes)}};function CT(t,e,n){let r=new um;return wt.compare(t,e,n,r),r.changes}function IT(t,e){for(let n=t;n&&n!=e;n=n.assignedSlot||n.parentNode)if(n.nodeType==1&&n.contentEditable=="false")return!0;return!1}function LT(t,e){let n=!1;return e&&t.iterChangedRanges((r,a)=>{r<e.to&&a>e.from&&(n=!0)}),n}var wu=class extends Ir{constructor(e){super(),this.height=e}toDOM(){let e=document.createElement("div");return e.className="cm-gap",this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}};function AT(t,e,n=1){let r=t.charCategorizer(e),a=t.doc.lineAt(e),s=e-a.from;if(a.length==0)return se.cursor(e);s==0?n=1:s==a.length&&(n=-1);let i=s,o=s;n<0?i=Pn(a.text,s,!1):o=Pn(a.text,s);let l=r(a.text.slice(i,o));for(;i>0;){let u=Pn(a.text,i,!1);if(r(a.text.slice(u,i))!=l)break;i=u}for(;o<a.length;){let u=Pn(a.text,o);if(r(a.text.slice(o,u))!=l)break;o=u}return se.undirectionalRange(i+a.from,o+a.from)}function PT(t,e,n,r,a){let s=Math.round((r-e.left)*t.defaultCharacterWidth);if(t.lineWrapping&&n.height>t.defaultLineHeight*1.5){let o=t.viewState.heightOracle.textHeight,l=Math.floor((a-n.top-(t.defaultLineHeight-o)*.5)/o);s+=l*t.viewState.heightOracle.lineLength}let i=t.state.sliceDoc(n.from,n.to);return n.from+dk(i,s,t.state.tabSize)}function cm(t,e,n){let r=t.lineBlockAt(e);if(Array.isArray(r.type)){let a;for(let s of r.type){if(s.from>e)break;if(!(s.to<e)){if(s.from<e&&s.to>e)return s;(!a||s.type==On.Text&&(a.type!=s.type||(n<0?s.from<e:s.to>e)))&&(a=s)}}return a||r}return r}function NT(t,e,n,r){let a=cm(t,e.head,e.assoc||-1),s=!r||a.type!=On.Text||!(t.lineWrapping||a.widgetLineBreaks)?null:t.coordsAtPos(e.assoc<0&&e.head>a.from?e.head-1:e.head);if(s){let i=t.dom.getBoundingClientRect(),o=t.textDirectionAt(a.from),l=t.posAtCoords({x:n==(o==Vt.LTR)?i.right-1:i.left+1,y:(s.top+s.bottom)/2});if(l!=null)return se.cursor(l,n?-1:1)}return se.cursor(n?a.to:a.from,n?-1:1)}function Ik(t,e,n,r){let a=t.state.doc.lineAt(e.head),s=t.bidiSpans(a),i=t.textDirectionAt(a.from);for(let o=e,l=null;;){let u=cT(a,s,i,o,n),c=oS;if(!u){if(a.number==(n?t.state.doc.lines:1))return o;c=`
39
+ `,a=t.state.doc.line(a.number+(n?1:-1)),s=t.bidiSpans(a),u=n?se.cursor(a.from,-1):se.cursor(a.to,1)}if(l){if(!l(c))return o}else{if(!r)return u;l=r(c)}o=u}}function RT(t,e,n){let r=t.state.charCategorizer(e),a=r(n);return s=>{let i=r(s);return a==sa.Space&&(a=i),a==i}}function MT(t,e,n,r){let a=e.head,s=n?1:-1;if(a==(n?t.state.doc.length:0))return se.cursor(a,e.assoc);let i=e.goalColumn,o,l=t.contentDOM.getBoundingClientRect(),u=t.coordsAtPos(a,e.assoc||((e.empty?n:e.head==e.from)?1:-1)),c=t.documentTop;if(u)i==null&&(i=u.left-l.left),o=s<0?u.top:u.bottom;else{let p=t.viewState.lineBlockAt(a);i==null&&(i=Math.min(l.right-l.left,t.defaultCharacterWidth*(a-p.from))),o=(s<0?p.top:p.bottom)+c}let d=l.left+i,f=t.viewState.heightOracle.textHeight>>1,h=r??f;for(let p=0;;p+=f){let g=o+(h+p)*s,m=dm(t,{x:d,y:g},!1,s);if(n?g>l.bottom:g<l.top)return se.cursor(m.pos,m.assoc);let x=t.coordsAtPos(m.pos,m.assoc),y=x?(x.top+x.bottom)/2:0;if(!x||(n?y>o:y<o))return se.cursor(m.pos,m.assoc,void 0,i)}}function vu(t,e,n){for(;;){let r=0;for(let a of t)a.between(e-1,e+1,(s,i,o)=>{if(e>s&&e<i){let l=r||n||(e-s<i-e?-1:1);e=l<0?s:i,r=l}});if(!r)return e}}function IS(t,e){let n=null;for(let r=0;r<e.ranges.length;r++){let a=e.ranges[r],s=null;if(a.empty){let i=vu(t,a.from,0);i!=a.from&&(s=se.cursor(i,-1))}else{let i=vu(t,a.from,-1),o=vu(t,a.to,1);(i!=a.from||o!=a.to)&&(a.undirectional?s=se.undirectionalRange(a.from,a.to):s=se.range(a.from==a.anchor?i:o,a.from==a.head?i:o))}s&&(n||(n=e.ranges.slice()),n[r]=s)}return n?se.create(n,e.mainIndex):e}function zp(t,e,n){let r=vu(t.state.facet(Ru).map(a=>a(t)),n.from,e.head>n.from?-1:1);return r==n.from?n:se.cursor(r,r<n.from?1:-1)}var Gr=class{constructor(e,n){this.pos=e,this.assoc=n}};function dm(t,e,n,r){let a=t.contentDOM.getBoundingClientRect(),s=a.top+t.viewState.paddingTop,{x:i,y:o}=e,l=o-s,u;for(;;){if(l<0)return new Gr(0,1);if(l>t.viewState.docHeight)return new Gr(t.state.doc.length,-1);if(u=t.elementAtHeight(l),r==null)break;if(u.type==On.Text){if(r<0?u.to<t.viewport.from:u.from>t.viewport.to)break;let f=t.docView.coordsAt(r<0?u.from:u.to,r>0?-1:1);if(f&&(r<0?f.top<=l+s:f.bottom>=l+s))break}let d=t.viewState.heightOracle.textHeight/2;l=r>0?u.bottom+d:u.top-d}if(t.viewport.from>=u.to||t.viewport.to<=u.from){if(n)return null;if(u.type==On.Text){let d=PT(t,a,u,i,o);return new Gr(d,d==u.from?1:-1)}}if(u.type!=On.Text)return l<(u.top+u.bottom)/2?new Gr(u.from,1):new Gr(u.to,-1);let c=t.docView.lineAt(u.from,2);return(!c||c.length!=u.length)&&(c=t.docView.lineAt(u.from,-2)),new fm(t,i,o,t.textDirectionAt(u.from)).scanTile(c,u.from)}var fm=class{constructor(e,n,r,a){this.view=e,this.x=n,this.y=r,this.baseDir=a,this.line=null,this.spans=null}bidiSpansAt(e){return(!this.line||this.line.from>e||this.line.to<e)&&(this.line=this.view.state.doc.lineAt(e),this.spans=this.view.bidiSpans(this.line)),this}baseDirAt(e,n){let{line:r,spans:a}=this.bidiSpansAt(e);return a[Wr.find(a,e-r.from,-1,n)].level==this.baseDir}dirAt(e,n){let{line:r,spans:a}=this.bidiSpansAt(e);return a[Wr.find(a,e-r.from,-1,n)].dir}bidiIn(e,n){let{spans:r,line:a}=this.bidiSpansAt(e);return r.length>1||r.length&&(r[0].level!=this.baseDir||r[0].to+a.from<n)}scan(e,n,r=!1){let a=0,s=e.length-1,i=new Set,o=this.bidiIn(e[0],e[s]),l,u,c=-1,d=1e9,f;e:for(;a<s;){let p=s-a,g=a+s>>1;t:if(i.has(g)){for(let y=1;y<p;y++){let b=g+y;if(b>=s&&(b-=p),!i.has(b)){g=b;break t}}break e}i.add(g);let m=n(g),x=0;if(m)for(let y=0;y<m.length;y++){let b=m[y];if(!(b.width==0&&m.length>1))if(b.bottom<this.y)(!l||l.bottom<b.bottom)&&(l=b),x=1;else if(b.top>this.y)(!u||u.top>b.top)&&(u=b),x=-1;else{let C=b.left>this.x?this.x-b.left:b.right<this.x?this.x-b.right:0,L=Math.abs(C);L<d&&(c=g,d=L,f=b),C&&(x=C<0==(this.baseDir==Vt.LTR)?-1:1)}}x==-1&&(!o||this.baseDirAt(e[g],1))?s=g:x==1&&(!o||this.baseDirAt(e[g+1],-1))&&(a=g+1)}if(!f){if(!u&&!l)return{i:0,after:!1};let p=l&&(!u||this.y-l.bottom<u.top-this.y)?l:u;return this.y=(p.top+p.bottom)/2,this.scan(e,n,!0)}if(d&&!r){let{top:p,bottom:g}=f;if(l&&l.bottom>(p+p+g)/3)return this.y=l.bottom-1,this.scan(e,n,!0);if(u&&u.top<(p+g+g)/3)return this.y=u.top+1,this.scan(e,n,!0)}let h=(o?this.dirAt(e[c],1):this.baseDir)==Vt.LTR;return{i:c,after:this.x>(f.left+f.right)/2==h}}scanText(e,n){let r=[];for(let s=0;s<e.length;s=Pn(e.text,s))r.push(n+s);r.push(n+e.length);let a=this.scan(r,s=>{let i=r[s]-n,o=r[s+1]-n;return Nu(e.dom,i,o).getClientRects()});return a.after?new Gr(r[a.i+1],-1):new Gr(r[a.i],1)}scanTile(e,n){if(!e.length)return new Gr(n,1);if(e.children.length==1){let o=e.children[0];if(o.isText())return this.scanText(o,n);if(o.isComposite())return this.scanTile(o,n)}let r=[n];for(let o=0,l=n;o<e.children.length;o++)r.push(l+=e.children[o].length);let a=this.scan(r,o=>{let l=e.children[o];return l.flags&48?null:(l.dom.nodeType==1?l.dom:Nu(l.dom,0,l.length)).getClientRects()}),s=e.children[a.i],i=r[a.i];return s.isText()?this.scanText(s,i):s.isComposite()?this.scanTile(s,i):a.after?new Gr(r[a.i+1],-1):new Gr(i,1)}},Mo="\uFFFF",hm=class{constructor(e,n){this.points=e,this.view=n,this.text="",this.lineSeparator=n.state.facet(It.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=Mo}readRange(e,n){if(!e)return this;let r=e.parentNode;for(let a=e;;){this.findPointBefore(r,a);let s=this.text.length;this.readNode(a);let i=Yt.get(a),o=a.nextSibling;if(o==n){i?.breakAfter&&!o&&r!=this.view.contentDOM&&this.lineBreak();break}let l=Yt.get(o);(i&&l?i.breakAfter:(i?i.breakAfter:Dd(a))||Dd(o)&&(a.nodeName!="BR"||i?.isWidget())&&this.text.length>s)&&!DT(o,n)&&this.lineBreak(),a=o}return this.findPointBefore(r,n),this}readTextNode(e){let n=e.nodeValue;for(let r of this.points)r.node==e&&(r.pos=this.text.length+Math.min(r.offset,n.length));for(let r=0,a=this.lineSeparator?null:/\r\n?|\n/g;;){let s=-1,i=1,o;if(this.lineSeparator?(s=n.indexOf(this.lineSeparator,r),i=this.lineSeparator.length):(o=a.exec(n))&&(s=o.index,i=o[0].length),this.append(n.slice(r,s<0?n.length:s)),s<0)break;if(this.lineBreak(),i>1)for(let l of this.points)l.node==e&&l.pos>this.text.length&&(l.pos-=i-1);r=s+i}}readNode(e){let n=Yt.get(e),r=n&&n.overrideDOMText;if(r!=null){this.findPointInside(e,r.length);for(let a=r.iter();!a.next().done;)a.lineBreak?this.lineBreak():this.append(a.value)}else e.nodeType==3?this.readTextNode(e):e.nodeName=="BR"?e.nextSibling&&this.lineBreak():e.nodeType==1&&this.readRange(e.firstChild,null)}findPointBefore(e,n){for(let r of this.points)r.node==e&&e.childNodes[r.offset]==n&&(r.pos=this.text.length)}findPointInside(e,n){for(let r of this.points)(e.nodeType==3?r.node==e:e.contains(r.node))&&(r.pos=this.text.length+(TT(e,r.node,r.offset)?n:0))}};function TT(t,e,n){for(;;){if(!e||n<os(e))return!1;if(e==t)return!0;n=Ws(e)+1,e=e.parentNode}}function DT(t,e){let n;for(;!(t==e||!t);t=t.nextSibling){let r=Yt.get(t);if(!r?.isWidget())return!1;r&&(n||(n=[])).push(r)}if(n)for(let r of n){let a=r.overrideDOMText;if(a?.length)return!1}return!0}var Bd=class{constructor(e,n){this.node=e,this.offset=n,this.pos=-1}},pm=class{constructor(e,n,r,a){this.typeOver=a,this.bounds=null,this.text="",this.domChanged=n>-1;let{impreciseHead:s,impreciseAnchor:i}=e.docView,o=e.state.selection;if(e.state.readOnly&&n>-1)this.newSel=null;else if(n>-1&&(this.bounds=LS(e.docView.tile,n,r,0))){let l=s||i?[]:ET(e),u=new hm(l,e);u.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=u.text,this.newSel=OT(l,this.bounds.from)}else{let l=e.observer.selectionRange,u=s&&s.node==l.focusNode&&s.offset==l.focusOffset||!Yp(e.contentDOM,l.focusNode)?o.main.head:e.docView.posFromDOM(l.focusNode,l.focusOffset),c=i&&i.node==l.anchorNode&&i.offset==l.anchorOffset||!Yp(e.contentDOM,l.anchorNode)?o.main.anchor:e.docView.posFromDOM(l.anchorNode,l.anchorOffset),d=e.viewport;if((ke.ios||ke.chrome)&&u!=c&&Math.min(u,c)<=o.main.from&&Math.max(u,c)>=o.main.to&&(d.from>0||d.to<e.state.doc.length)){let f=Math.min(u,c),h=Math.max(u,c),p=d.from-f,g=d.to-h;(p==0||p==1||f==0)&&(g==0||g==-1||h==e.state.doc.length)&&(u=0,c=e.state.doc.length)}if(e.inputState.composing>-1&&o.ranges.length>1)this.newSel=o.replaceRange(se.range(c,u));else if(e.lineWrapping&&c==u&&!(o.main.empty&&o.main.head==u)&&e.inputState.lastTouchTime>Date.now()-100){let f=e.coordsAtPos(u,-1),h=0;f&&(h=e.inputState.lastTouchY<=f.bottom?-1:1),this.newSel=se.create([se.cursor(u,h)])}else this.newSel=se.single(c,u)}}};function LS(t,e,n,r){if(t.isComposite()){let a=-1,s=-1,i=-1,o=-1;for(let l=0,u=r,c=r;l<t.children.length;l++){let d=t.children[l],f=u+d.length;if(u<e&&f>n)return LS(d,e,n,u);if(f>=e&&a==-1&&(a=l,s=u),u>n&&d.dom.parentNode==t.dom){i=l,o=c;break}c=f,u=f+d.breakAfter}return{from:s,to:o<0?r+t.length:o,startDOM:(a?t.children[a-1].dom.nextSibling:null)||t.dom.firstChild,endDOM:i<t.children.length&&i>=0?t.children[i].dom:null}}else return t.isText()?{from:r,to:r+t.length,startDOM:t.dom,endDOM:t.dom.nextSibling}:null}function AS(t,e){let n,{newSel:r}=e,{state:a}=t,s=a.selection.main,i=t.inputState.lastKeyTime>Date.now()-100?t.inputState.lastKeyCode:-1;if(e.bounds){let{from:o,to:l}=e.bounds,u=s.from,c=null;(i===8||ke.android&&e.text.length<l-o)&&(u=s.to,c="end");let d=a.doc.sliceString(o,l,Mo),f,h;!s.empty&&s.from>=o&&s.to<=l&&(e.typeOver||d!=e.text)&&d.slice(0,s.from-o)==e.text.slice(0,s.from-o)&&d.slice(s.to-o)==e.text.slice(f=e.text.length-(d.length-(s.to-o)))?n={from:s.from,to:s.to,insert:st.of(e.text.slice(s.from-o,f).split(Mo))}:(h=PS(d,e.text,u-o,c))&&(ke.chrome&&i==13&&h.toB==h.from+2&&e.text.slice(h.from,h.toB)==Mo+Mo&&h.toB--,n={from:o+h.from,to:o+h.toA,insert:st.of(e.text.slice(h.from,h.toB).split(Mo))})}else r&&(!t.hasFocus&&a.facet(ss)||_d(r,s))&&(r=null);if(!n&&!r)return!1;if((ke.mac||ke.android)&&n&&n.from==n.to&&n.from==s.head-1&&/^\. ?$/.test(n.insert.toString())&&t.contentDOM.getAttribute("autocorrect")=="off"?(r&&n.insert.length==2&&(r=se.single(r.main.anchor-1,r.main.head-1)),n={from:n.from,to:n.to,insert:st.of([n.insert.toString().replace("."," ")])}):a.doc.lineAt(s.from).to<s.to&&t.docView.lineHasWidget(s.to)&&t.inputState.insertingTextAt>Date.now()-50?n={from:s.from,to:s.to,insert:a.toText(t.inputState.insertingText)}:ke.chrome&&n&&n.from==n.to&&n.from==s.head&&n.insert.toString()==`
40
+ `&&t.lineWrapping&&(r&&(r=se.single(r.main.anchor-1,r.main.head-1)),n={from:s.from,to:s.to,insert:st.of([" "])}),n)return zm(t,n,r,i);if(r&&!_d(r,s)){let o=!1,l="select";return t.inputState.lastSelectionTime>Date.now()-50&&(t.inputState.lastSelectionOrigin=="select"&&(o=!0),l=t.inputState.lastSelectionOrigin,l=="select.pointer"&&(r=IS(a.facet(Ru).map(u=>u(t)),r))),t.dispatch({selection:r,scrollIntoView:o,userEvent:l}),!0}else return!1}function zm(t,e,n,r=-1){if(ke.ios&&t.inputState.flushIOSKey(e))return!0;let a=t.state.selection.main;if(ke.android&&(e.to==a.to&&(e.from==a.from||e.from==a.from-1&&t.state.sliceDoc(e.from,a.from)==" ")&&e.insert.length==1&&e.insert.lines==2&&Oo(t.contentDOM,"Enter",13)||(e.from==a.from-1&&e.to==a.to&&e.insert.length==0||r==8&&e.insert.length<e.to-e.from&&e.to>a.head)&&Oo(t.contentDOM,"Backspace",8)||e.from==a.from&&e.to==a.to+1&&e.insert.length==0&&Oo(t.contentDOM,"Delete",46)))return!0;let s=e.insert.toString();t.inputState.composing>=0&&t.inputState.composing++;let i,o=()=>i||(i=FT(t,e,n));return t.state.facet(fS).some(l=>l(t,e.from,e.to,s,o))||t.dispatch(o()),!0}function FT(t,e,n){let r,a=t.state,s=a.selection.main,i=-1;if(e.from==e.to&&e.from<s.from||e.from>s.to){let l=e.from<s.from?-1:1,u=l<0?s.from:s.to,c=vu(a.facet(Ru).map(d=>d(t)),u,l);e.from==c&&(i=c)}if(i>-1)r={changes:e,selection:se.cursor(e.from+e.insert.length,-1)};else if(e.from>=s.from&&e.to<=s.to&&e.to-e.from>=(s.to-s.from)/3&&(!n||n.main.empty&&n.main.from==e.from+e.insert.length)&&t.inputState.composing<0){let l=s.from<e.from?a.sliceDoc(s.from,e.from):"",u=s.to>e.to?a.sliceDoc(e.to,s.to):"";r=a.replaceSelection(t.state.toText(l+e.insert.sliceString(0,void 0,t.state.lineBreak)+u))}else{let l=a.changes(e),u=n&&n.main.to<=l.newLength?n.main:void 0;if(a.selection.ranges.length>1&&(t.inputState.composing>=0||t.inputState.compositionPendingChange)&&e.to<=s.to+10&&e.to>=s.to-10){let c=t.state.sliceDoc(e.from,e.to),d,f=n&&CS(t,n.main.head);if(f){let p=e.insert.length-(e.to-e.from);d={from:f.from,to:f.to-p}}else d=t.state.doc.lineAt(s.head);let h=s.to-e.to;r=a.changeByRange(p=>{if(p.from==s.from&&p.to==s.to)return{changes:l,range:u||p.map(l)};let g=p.to-h,m=g-c.length;if(t.state.sliceDoc(m,g)!=c||g>=d.from&&m<=d.to)return{range:p};let x=a.changes({from:m,to:g,insert:e.insert}),y=p.to-s.to;return{changes:x,range:u?se.range(Math.max(0,u.anchor+y),Math.max(0,u.head+y)):p.map(x)}})}else r={changes:l,selection:u&&a.selection.replaceRange(u)}}let o="input.type";return(t.composing||t.inputState.compositionPendingChange&&t.inputState.compositionEndedAt>Date.now()-50)&&(t.inputState.compositionPendingChange=!1,o+=".compose",t.inputState.compositionFirstChange&&(o+=".start",t.inputState.compositionFirstChange=!1)),a.update(r,{userEvent:o,scrollIntoView:!0})}function PS(t,e,n,r){let a=Math.min(t.length,e.length),s=0;for(;s<a&&t.charCodeAt(s)==e.charCodeAt(s);)s++;if(s==a&&t.length==e.length)return null;let i=t.length,o=e.length;for(;i>0&&o>0&&t.charCodeAt(i-1)==e.charCodeAt(o-1);)i--,o--;if(r=="end"){let l=Math.max(0,s-Math.min(i,o));n-=i+l-s}if(i<s&&t.length<e.length){let l=n<=s&&n>=i?s-n:0;s-=l,o=s+(o-i),i=s}else if(o<s){let l=n<=s&&n>=o?s-n:0;s-=l,i=s+(i-o),o=s}return{from:s,toA:i,toB:o}}function ET(t){let e=[];if(t.root.activeElement!=t.contentDOM)return e;let{anchorNode:n,anchorOffset:r,focusNode:a,focusOffset:s}=t.observer.selectionRange;return n&&(e.push(new Bd(n,r)),(a!=n||s!=r)&&e.push(new Bd(a,s))),e}function OT(t,e){if(t.length==0)return null;let n=t[0].pos,r=t.length==2?t[1].pos:n;return n<0||r<0?null:n==r?se.create([se.cursor(r+e,-1)]):se.single(n+e,r+e)}function _d(t,e){return e.head==t.main.head&&e.anchor==t.main.anchor}var mm=class{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.touchActive=!1,this.lastTouchTime=0,this.lastTouchX=0,this.lastTouchY=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.lastWheelEvent=0,this.pendingIOSKey=void 0,this.lastIOSMomentumScroll=0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,ke.safari&&e.contentDOM.addEventListener("input",()=>null),ke.gecko&&JT(e.contentDOM.ownerDocument)}handleEvent(e){!jT(this.view,e)||this.ignoreDuringComposition(e)||e.type=="keydown"&&this.keydown(e)||(this.view.updateState!=0?Promise.resolve().then(()=>this.runHandlers(e.type,e)):this.runHandlers(e.type,e))}runHandlers(e,n){let r=this.handlers[e];if(r){for(let a of r.observers)a(this.view,n);for(let a of r.handlers){if(n.defaultPrevented)break;if(a(this.view,n)){n.preventDefault();break}}}}ensureHandlers(e){let n=_T(e),r=this.handlers,a=this.view.contentDOM;for(let s in n)if(s!="scroll"){let i=!n[s].handlers.length,o=r[s];o&&i!=!o.handlers.length&&(a.removeEventListener(s,this.handleEvent),o=null),o||a.addEventListener(s,this.handleEvent,{passive:i})}for(let s in r)s!="scroll"&&!n[s]&&a.removeEventListener(s,this.handleEvent);this.handlers=n}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),e.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&e.keyCode!=27&&RS.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),ke.android&&ke.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;if(ke.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&(NS.some(n=>n.keyCode==e.keyCode)&&!e.ctrlKey||HT.indexOf(e.key)>-1&&e.ctrlKey)){let n={ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey,shiftKey:e.shiftKey};n.shiftKey&&ke.ios&&!/^(off|none)$/.test(this.view.contentDOM.autocapitalize)&&BT(this.view.win)&&(n.shiftKey=!1);let r=this.pendingIOSKey={key:e.key,keyCode:e.keyCode,mods:n};return setTimeout(()=>{this.pendingIOSKey==r&&this.flushIOSKey()},50),!0}return e.keyCode!=229&&this.view.observer.forceFlush(),!1}flushIOSKey(e){let n=this.pendingIOSKey;return!n||this.view.observer.pendingRecords().length||n.key=="Enter"&&e&&e.from<e.to&&/^\S+$/.test(e.insert.toString())?!1:(this.pendingIOSKey=void 0,Oo(this.view.contentDOM,n.key,n.keyCode,n.mods))}ignoreDuringComposition(e){return!/^key/.test(e.type)||e.synthetic?!1:this.composing>0?!0:ke.safari&&!ke.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.view.observer.update(e),this.mouseSelection&&this.mouseSelection.update(e),this.draggedContent&&e.docChanged&&(this.draggedContent=this.draggedContent.map(e.changes)),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}};function BT(t){return t.visualViewport?t.visualViewport.height*t.visualViewport.scale/t.document.documentElement.clientHeight<.85:!1}function Lk(t,e){return(n,r)=>{try{return e.call(t,r,n)}catch(a){oa(n.state,a)}}}function _T(t){let e=Object.create(null);function n(r){return e[r]||(e[r]={observers:[],handlers:[]})}for(let r of t){let a=r.spec,s=a&&a.plugin.domEventHandlers,i=a&&a.plugin.domEventObservers;if(s)for(let o in s){let l=s[o];l&&n(o).handlers.push(Lk(r.value,l))}if(i)for(let o in i){let l=i[o];l&&n(o).observers.push(Lk(r.value,l))}}for(let r in ua)n(r).handlers.push(ua[r]);for(let r in tr)n(r).observers.push(tr[r]);return e}var NS=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],HT="dthko",RS=[16,17,18,20,91,92,224,225],kd=6;function Sd(t){return Math.max(0,t)*.7+8}function UT(t,e){return Math.max(Math.abs(t.clientX-e.clientX),Math.abs(t.clientY-e.clientY))}var gm=class{constructor(e,n,r,a){this.view=e,this.startEvent=n,this.style=r,this.mustSelect=a,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=n,this.scrollParents=Yk(e.contentDOM),this.atoms=e.state.facet(Ru).map(i=>i(e));let s=e.contentDOM.ownerDocument;s.addEventListener("mousemove",this.move=this.move.bind(this)),s.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=n.shiftKey,this.multiple=e.state.facet(It.allowMultipleSelections)&&GT(e,n),this.dragging=zT(e,n)&&DS(n)==1?null:!1}start(e){this.dragging===!1&&this.select(e)}move(e){if(e.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&UT(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let n=0,r=0,a=0,s=0,i=this.view.win.innerWidth,o=this.view.win.innerHeight;this.scrollParents.x&&({left:a,right:i}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:s,bottom:o}=this.scrollParents.y.getBoundingClientRect());let l=kS(this.view);e.clientX-l.left<=a+kd?n=-Sd(a-e.clientX):e.clientX+l.right>=i-kd&&(n=Sd(e.clientX-i)),e.clientY-l.top<=s+kd?r=-Sd(s-e.clientY):e.clientY+l.bottom>=o-kd&&(r=Sd(e.clientY-o)),this.setScrollSpeed(n,r)}up(e){this.dragging==null&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(e,n){this.scrollSpeed={x:e,y:n},e||n?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:e,y:n}=this.scrollSpeed;e&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=e,e=0),n&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=n,n=0),(e||n)&&this.view.win.scrollBy(e,n),this.dragging===!1&&this.select(this.lastEvent)}select(e){let{view:n}=this,r=IS(this.atoms,this.style.get(e,this.extend,this.multiple));(this.mustSelect||!r.eq(n.state.selection,this.dragging===!1))&&this.view.dispatch({selection:r,userEvent:"select.pointer"}),this.mustSelect=!1}update(e){e.transactions.some(n=>n.isUserEvent("input.type"))?this.destroy():this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}};function GT(t,e){let n=t.state.facet(lS);return n.length?n[0](e):ke.mac?e.metaKey:e.ctrlKey}function WT(t,e){let n=t.state.facet(uS);return n.length?n[0](e):ke.mac?!e.altKey:!e.ctrlKey}function zT(t,e){let{main:n}=t.state.selection;if(n.empty)return!1;let r=Au(t.root);if(!r||r.rangeCount==0)return!0;let a=r.getRangeAt(0).getClientRects();for(let s=0;s<a.length;s++){let i=a[s];if(i.left<=e.clientX&&i.right>=e.clientX&&i.top<=e.clientY&&i.bottom>=e.clientY)return!0}return!1}function jT(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let n=e.target,r;n!=t.contentDOM;n=n.parentNode)if(!n||n.nodeType==11||(r=Yt.get(n))&&r.isWidget()&&!r.isHidden&&r.widget.ignoreEvent(e))return!1;return!0}var ua=Object.create(null),tr=Object.create(null),MS=ke.ie&&ke.ie_version<15||ke.ios&&ke.webkit_version<604;function VT(t){let e=t.dom.parentNode;if(!e)return;let n=e.appendChild(document.createElement("textarea"));n.style.cssText="position: fixed; left: -10000px; top: 10px",n.focus(),setTimeout(()=>{t.focus(),n.remove(),TS(t,n.value)},50)}function $d(t,e,n){for(let r of t.facet(e))n=r(n,t);return n}function TS(t,e){e=$d(t.state,Hm,e);let{state:n}=t,r,a=1,s=n.toText(e),i=s.lines==n.selection.ranges.length;if(xm!=null&&n.selection.ranges.every(l=>l.empty)&&xm==s.toString()){let l=-1;r=n.changeByRange(u=>{let c=n.doc.lineAt(u.from);if(c.from==l)return{range:u};l=c.from;let d=n.toText((i?s.line(a++).text:e)+n.lineBreak);return{changes:{from:c.from,insert:d},range:se.cursor(u.from+d.length,-1)}})}else i?r=n.changeByRange(l=>{let u=s.line(a++);return{changes:{from:l.from,to:l.to,insert:u.text},range:se.cursor(l.from+u.length,-1)}}):r=n.replaceSelection(s);t.dispatch(r,{userEvent:"input.paste",scrollIntoView:!0})}tr.scroll=t=>{let e=t.inputState;e.lastScrollTop=t.scrollDOM.scrollTop,e.lastScrollLeft=t.scrollDOM.scrollLeft,ke.ios&&!e.touchActive&&(e.lastIOSMomentumScroll=Date.now())};tr.wheel=tr.mousewheel=t=>{t.inputState.lastWheelEvent=Date.now()};ua.keydown=(t,e)=>(t.inputState.setSelectionOrigin("select"),e.keyCode==27&&t.inputState.tabFocusMode!=0&&(t.inputState.tabFocusMode=Date.now()+2e3),!1);tr.touchstart=(t,e)=>{let n=t.inputState,r=e.targetTouches[0];n.touchActive=!0,n.lastTouchTime=Date.now(),r&&(n.lastTouchX=r.clientX,n.lastTouchY=r.clientY),n.setSelectionOrigin("select.pointer")};tr.touchmove=t=>{t.inputState.setSelectionOrigin("select.pointer")};tr.touchend=(t,e)=>{t.inputState.touchActive=!1};ua.mousedown=(t,e)=>{if(t.observer.flush(),t.inputState.lastTouchTime>Date.now()-2e3)return!1;let n=null;for(let r of t.state.facet(cS))if(n=r(t,e),n)break;if(!n&&e.button==0&&(n=$T(t,e)),n){let r=!t.hasFocus;t.inputState.startMouseSelection(new gm(t,e,n,r)),r&&t.observer.ignore(()=>{Qk(t.contentDOM);let s=t.root.activeElement;s&&!s.contains(t.contentDOM)&&s.blur()});let a=t.inputState.mouseSelection;if(a)return a.start(e),a.dragging===!1}else t.inputState.setSelectionOrigin("select.pointer");return!1};function Ak(t,e,n,r){if(r==1)return se.cursor(e,n);if(r==2)return AT(t.state,e,n);{let a=t.docView.lineAt(e,n),s=t.state.doc.lineAt(a?a.posAtEnd:e),i=a?a.posAtStart:s.from,o=a?a.posAtEnd:s.to;return o<t.state.doc.length&&o==s.to&&o++,se.undirectionalRange(i,o)}}var qT=ke.ie&&ke.ie_version<=11,Pk=null,Nk=0,Rk=0;function DS(t){if(!qT)return t.detail;let e=Pk,n=Rk;return Pk=t,Rk=Date.now(),Nk=!e||n>Date.now()-400&&Math.abs(e.clientX-t.clientX)<2&&Math.abs(e.clientY-t.clientY)<2?(Nk+1)%3:1}function $T(t,e){let n=t.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),r=DS(e),a=t.state.selection;return{update(s){s.docChanged&&(n.pos=s.changes.mapPos(n.pos),a=a.map(s.changes))},get(s,i,o){let l=t.posAndSideAtCoords({x:s.clientX,y:s.clientY},!1),u,c=Ak(t,l.pos,l.assoc,r);if(n.pos!=l.pos&&!i){let d=Ak(t,n.pos,n.assoc,r),f=Math.min(d.from,c.from),h=Math.max(d.to,c.to);c=f<c.from?se.range(f,h,c.assoc):se.range(h,f,c.assoc)}return i?a.replaceRange(a.main.extend(c.from,c.to,c.assoc)):o&&r==1&&a.ranges.length>1&&(u=KT(a,l.pos))?u:o?a.addRange(c):se.create([c])}}}function KT(t,e){for(let n=0;n<t.ranges.length;n++){let{from:r,to:a}=t.ranges[n];if(r<=e&&a>=e)return se.create(t.ranges.slice(0,n).concat(t.ranges.slice(n+1)),t.mainIndex==n?0:t.mainIndex-(t.mainIndex>n?1:0))}return null}ua.dragstart=(t,e)=>{let{selection:{main:n}}=t.state;if(e.target.draggable){let a=t.docView.tile.nearest(e.target);if(a&&a.isWidget()){let s=a.posAtStart,i=s+a.length;(s>=n.to||i<=n.from)&&(n=se.undirectionalRange(s,i))}}let{inputState:r}=t;return r.mouseSelection&&(r.mouseSelection.dragging=!0),r.draggedContent=n,e.dataTransfer&&(e.dataTransfer.setData("Text",$d(t.state,Um,t.state.sliceDoc(n.from,n.to))),e.dataTransfer.effectAllowed="copyMove"),!1};ua.dragend=t=>(t.inputState.draggedContent=null,!1);function Mk(t,e,n,r){if(n=$d(t.state,Hm,n),!n)return;let a=t.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:s}=t.inputState,i=r&&s&&WT(t,e)?{from:s.from,to:s.to}:null,o={from:a,insert:n},l=t.state.changes(i?[i,o]:o);t.focus(),t.dispatch({changes:l,selection:{anchor:l.mapPos(a,-1),head:l.mapPos(a,1)},userEvent:i?"move.drop":"input.drop"}),t.inputState.draggedContent=null}ua.drop=(t,e)=>{if(!e.dataTransfer)return!1;if(t.state.readOnly)return!0;let n=e.dataTransfer.files;if(n&&n.length){let r=Array(n.length),a=0,s=()=>{++a==n.length&&Mk(t,e,r.filter(i=>i!=null).join(t.state.lineBreak),!1)};for(let i=0;i<n.length;i++){let o=new FileReader;o.onerror=s,o.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(o.result)||(r[i]=o.result),s()},o.readAsText(n[i])}return!0}else{let r=e.dataTransfer.getData("Text");if(r)return Mk(t,e,r,!0),!0}return!1};ua.paste=(t,e)=>{if(t.state.readOnly)return!0;t.observer.flush();let n=MS?null:e.clipboardData;return n?(TS(t,n.getData("text/plain")||n.getData("text/uri-list")),!0):(VT(t),!1)};function XT(t,e){let n=t.dom.parentNode;if(!n)return;let r=n.appendChild(document.createElement("textarea"));r.style.cssText="position: fixed; left: -10000px; top: 10px",r.value=e,r.focus(),r.selectionEnd=e.length,r.selectionStart=0,setTimeout(()=>{r.remove(),t.focus()},50)}function YT(t){let e=[],n=[],r=!1;for(let a of t.selection.ranges)a.empty||(e.push(t.sliceDoc(a.from,a.to)),n.push(a));if(!e.length){let a=-1;for(let{from:s}of t.selection.ranges){let i=t.doc.lineAt(s);i.number>a&&(e.push(i.text),n.push({from:i.from,to:Math.min(t.doc.length,i.to+1)})),a=i.number}r=!0}return{text:$d(t,Um,e.join(t.lineBreak)),ranges:n,linewise:r}}var xm=null;ua.copy=ua.cut=(t,e)=>{if(!mu(t.contentDOM,t.observer.selectionRange))return!1;let{text:n,ranges:r,linewise:a}=YT(t.state);if(!n&&!a)return!1;xm=a?n:null,e.type=="cut"&&!t.state.readOnly&&t.dispatch({changes:r,scrollIntoView:!0,userEvent:"delete.cut"});let s=MS?null:e.clipboardData;return s?(s.clearData(),s.setData("text/plain",n),!0):(XT(t,n),!1)};var FS=Hr.define();function ES(t,e){let n=[];for(let r of t.facet(hS)){let a=r(t,e);a&&n.push(a)}return n.length?t.update({effects:n,annotations:FS.of(!0)}):null}function OS(t){setTimeout(()=>{let e=t.hasFocus;if(e!=t.inputState.notifiedFocused){let n=ES(t.state,e);n?t.dispatch(n):t.update([])}},10)}tr.focus=t=>{t.inputState.lastFocusTime=Date.now(),!t.scrollDOM.scrollTop&&(t.inputState.lastScrollTop||t.inputState.lastScrollLeft)&&(t.scrollDOM.scrollTop=t.inputState.lastScrollTop,t.scrollDOM.scrollLeft=t.inputState.lastScrollLeft),OS(t)};tr.blur=t=>{t.observer.clearSelectionRange(),OS(t)};tr.compositionstart=tr.compositionupdate=t=>{if(!t.observer.editContext&&(t.inputState.compositionFirstChange==null&&(t.inputState.compositionFirstChange=!0),t.inputState.composing<0)){let{main:e}=t.state.selection;!e.empty&&t.lineBlockAt(e.from).from!=t.lineBlockAt(e.to).from&&t.dispatch({changes:t.state.selection.ranges.filter(n=>!n.empty).map(n=>({from:n.from,to:n.to})),userEvent:"input"}),t.inputState.composing=0}};tr.compositionend=t=>{t.observer.editContext||(t.inputState.composing=-1,t.inputState.compositionEndedAt=Date.now(),t.inputState.compositionPendingKey=!0,t.inputState.compositionPendingChange=t.observer.pendingRecords().length>0,t.inputState.compositionFirstChange=null,ke.chrome&&ke.android?t.observer.flushSoon():t.inputState.compositionPendingChange?Promise.resolve().then(()=>t.observer.flush()):setTimeout(()=>{t.inputState.composing<0&&t.docView.hasComposition&&t.update([])},50))};tr.contextmenu=t=>{t.inputState.lastContextMenu=Date.now()};ua.beforeinput=(t,e)=>{var n,r;if((e.inputType=="insertText"||e.inputType=="insertCompositionText")&&(t.inputState.insertingText=e.data,t.inputState.insertingTextAt=Date.now()),e.inputType=="insertReplacementText"&&t.observer.editContext){let s=(n=e.dataTransfer)===null||n===void 0?void 0:n.getData("text/plain"),i=e.getTargetRanges();if(s&&i.length){let o=i[0],l=t.posAtDOM(o.startContainer,o.startOffset),u=t.posAtDOM(o.endContainer,o.endOffset);return zm(t,{from:l,to:u,insert:t.state.toText(s)},null),!0}}let a;if(ke.chrome&&ke.android&&(a=NS.find(s=>s.inputType==e.inputType))&&(t.observer.delayAndroidKey(a.key,a.keyCode),a.key=="Backspace"||a.key=="Delete")){let s=((r=window.visualViewport)===null||r===void 0?void 0:r.height)||0;setTimeout(()=>{var i;(((i=window.visualViewport)===null||i===void 0?void 0:i.height)||0)>s+10&&t.hasFocus&&(t.contentDOM.blur(),t.focus())},100)}return ke.ios&&e.inputType=="deleteContentForward"&&t.observer.flushSoon(),ke.safari&&e.inputType=="insertText"&&t.inputState.composing>=0&&setTimeout(()=>tr.compositionend(t,e),20),!1};var Tk=new Set;function JT(t){Tk.has(t)||(Tk.add(t),t.addEventListener("copy",()=>{}),t.addEventListener("cut",()=>{}))}var Dk=["pre-wrap","normal","pre-line","break-spaces"],Go=!1;function Fk(){Go=!1}var ym=class{constructor(e){this.lineWrapping=e,this.doc=st.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(e,n){let r=this.doc.lineAt(n).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(r+=Math.max(0,Math.ceil((n-e-r*this.lineLength*.5)/this.lineLength))),this.lineHeight*r}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return Dk.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let n=!1;for(let r=0;r<e.length;r++){let a=e[r];a<0?r++:this.heightSamples[Math.floor(a*10)]||(n=!0,this.heightSamples[Math.floor(a*10)]=!0)}return n}refresh(e,n,r,a,s,i){let o=Dk.indexOf(e)>-1,l=Math.abs(n-this.lineHeight)>.3||this.lineWrapping!=o;if(this.lineWrapping=o,this.lineHeight=n,this.charWidth=r,this.textHeight=a,this.lineLength=s,l){this.heightSamples={};for(let u=0;u<i.length;u++){let c=i[u];c<0?u++:this.heightSamples[Math.floor(c*10)]=!0}}return l}},bm=class{constructor(e,n){this.from=e,this.heights=n,this.index=0}get more(){return this.index<this.heights.length}},ia=class t{constructor(e,n,r,a,s){this.from=e,this.length=n,this.top=r,this.height=a,this._content=s}get type(){return typeof this._content=="number"?On.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof Ri?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(e){let n=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(e._content)?e._content:[e]);return new t(this.from,this.length+e.length,this.top,this.height+e.height,n)}},jt=(function(t){return t[t.ByPos=0]="ByPos",t[t.ByHeight=1]="ByHeight",t[t.ByPosNoHeight=2]="ByPosNoHeight",t})(jt||(jt={})),Pd=.001,Cr=class t{constructor(e,n,r=2){this.length=e,this.height=n,this.flags=r}get outdated(){return(this.flags&2)>0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>Pd&&(Go=!0),this.height=e)}replace(e,n,r){return t.of(r)}decomposeLeft(e,n){n.push(this)}decomposeRight(e,n){n.push(this)}applyChanges(e,n,r,a){let s=this,i=r.doc;for(let o=a.length-1;o>=0;o--){let{fromA:l,toA:u,fromB:c,toB:d}=a[o],f=s.lineAt(l,jt.ByPosNoHeight,r.setDoc(n),0,0),h=f.to>=u?f:s.lineAt(u,jt.ByPosNoHeight,r,0,0);for(d+=h.to-u,u=h.to;o>0&&f.from<=a[o-1].toA;)l=a[o-1].fromA,c=a[o-1].fromB,o--,l<f.from&&(f=s.lineAt(l,jt.ByPosNoHeight,r,0,0));c+=f.from-l,l=f.from;let p=vm.build(r.setDoc(i),e,c,d);s=Hd(s,s.replace(l,u,p))}return s.updateHeight(r,0)}static empty(){return new Ur(0,0,0)}static of(e){if(e.length==1)return e[0];let n=0,r=e.length,a=0,s=0;for(;;)if(n==r)if(a>s*2){let o=e[n-1];o.break?e.splice(--n,1,o.left,null,o.right):e.splice(--n,1,o.left,o.right),r+=1+o.break,a-=o.size}else if(s>a*2){let o=e[r];o.break?e.splice(r,1,o.left,null,o.right):e.splice(r,1,o.left,o.right),r+=2+o.break,s-=o.size}else break;else if(a<s){let o=e[n++];o&&(a+=o.size)}else{let o=e[--r];o&&(s+=o.size)}let i=!1;return e[n-1]==null?(i=!0,n--):e[n]==null&&(i=!0,r++),new wm(t.of(e.slice(0,n)),i,t.of(e.slice(r)))}};function Hd(t,e){return t==e?t:(t.constructor!=e.constructor&&(Go=!0),e)}Cr.prototype.size=1;var ZT=Ke.replace({}),Ud=class extends Cr{constructor(e,n,r){super(e,n),this.deco=r,this.spaceAbove=0}mainBlock(e,n){return new ia(n,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(e,n,r,a){return this.spaceAbove&&e<r+this.spaceAbove?new ia(a,0,r,this.spaceAbove,ZT):this.mainBlock(r,a)}lineAt(e,n,r,a,s){let i=this.mainBlock(a,s);return this.spaceAbove?this.blockAt(0,r,a,s).join(i):i}forEachLine(e,n,r,a,s,i){e<=s+this.length&&n>=s&&i(this.lineAt(0,jt.ByPos,r,a,s))}setMeasuredHeight(e){let n=e.heights[e.index++];n<0?(this.spaceAbove=-n,n=e.heights[e.index++]):this.spaceAbove=0,this.setHeight(n)}updateHeight(e,n=0,r=!1,a){return a&&a.from<=n&&a.more&&this.setMeasuredHeight(a),this.outdated=!1,this}toString(){return`block(${this.length})`}},Ur=class t extends Ud{constructor(e,n,r){super(e,n,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=r}mainBlock(e,n){return new ia(n,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(e,n,r){let a=r[0];return r.length==1&&(a instanceof t||a instanceof Gs&&a.flags&4)&&Math.abs(this.length-a.length)<10?(a instanceof Gs?a=new t(a.length,this.height,this.spaceAbove):a.height=this.height,this.outdated||(a.outdated=!1),a):Cr.of(r)}updateHeight(e,n=0,r=!1,a){return a&&a.from<=n&&a.more?this.setMeasuredHeight(a):(r||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}},Gs=class t extends Cr{constructor(e){super(e,0)}heightMetrics(e,n){let r=e.doc.lineAt(n).number,a=e.doc.lineAt(n+this.length).number,s=a-r+1,i,o=0;if(e.lineWrapping){let l=Math.min(this.height,e.lineHeight*s);i=l/s,this.length>s+1&&(o=(this.height-l)/(this.length-s-1))}else i=this.height/s;return{firstLine:r,lastLine:a,perLine:i,perChar:o}}blockAt(e,n,r,a){let{firstLine:s,lastLine:i,perLine:o,perChar:l}=this.heightMetrics(n,a);if(n.lineWrapping){let u=a+(e<n.lineHeight?0:Math.round(Math.max(0,Math.min(1,(e-r)/this.height))*this.length)),c=n.doc.lineAt(u),d=o+c.length*l,f=Math.max(r,e-d/2);return new ia(c.from,c.length,f,d,0)}else{let u=Math.max(0,Math.min(i-s,Math.floor((e-r)/o))),{from:c,length:d}=n.doc.line(s+u);return new ia(c,d,r+o*u,o,0)}}lineAt(e,n,r,a,s){if(n==jt.ByHeight)return this.blockAt(e,r,a,s);if(n==jt.ByPosNoHeight){let{from:h,to:p}=r.doc.lineAt(e);return new ia(h,p-h,0,0,0)}let{firstLine:i,perLine:o,perChar:l}=this.heightMetrics(r,s),u=r.doc.lineAt(e),c=o+u.length*l,d=u.number-i,f=a+o*d+l*(u.from-s-d);return new ia(u.from,u.length,Math.max(a,Math.min(f,a+this.height-c)),c,0)}forEachLine(e,n,r,a,s,i){e=Math.max(e,s),n=Math.min(n,s+this.length);let{firstLine:o,perLine:l,perChar:u}=this.heightMetrics(r,s);for(let c=e,d=a;c<=n;){let f=r.doc.lineAt(c);if(c==e){let p=f.number-o;d+=l*p+u*(e-s-p)}let h=l+u*f.length;i(new ia(f.from,f.length,d,h,0)),d+=h,c=f.to+1}}replace(e,n,r){let a=this.length-n;if(a>0){let s=r[r.length-1];s instanceof t?r[r.length-1]=new t(s.length+a):r.push(null,new t(a-1))}if(e>0){let s=r[0];s instanceof t?r[0]=new t(e+s.length):r.unshift(new t(e-1),null)}return Cr.of(r)}decomposeLeft(e,n){n.push(new t(e-1),null)}decomposeRight(e,n){n.push(null,new t(this.length-e-1))}updateHeight(e,n=0,r=!1,a){let s=n+this.length;if(a&&a.from<=n+this.length&&a.more){let i=[],o=Math.max(n,a.from),l=-1;for(a.from>n&&i.push(new t(a.from-n-1).updateHeight(e,n));o<=s&&a.more;){let c=e.doc.lineAt(o).length;i.length&&i.push(null);let d=a.heights[a.index++],f=0;d<0&&(f=-d,d=a.heights[a.index++]),l==-1?l=d:Math.abs(d-l)>=Pd&&(l=-2);let h=new Ur(c,d,f);h.outdated=!1,i.push(h),o+=c+1}o<=s&&i.push(null,new t(s-o).updateHeight(e,o));let u=Cr.of(i);return(l<0||Math.abs(u.height-this.height)>=Pd||Math.abs(l-this.heightMetrics(e,n).perLine)>=Pd)&&(Go=!0),Hd(this,u)}else(r||this.outdated)&&(this.setHeight(e.heightForGap(n,n+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}},wm=class extends Cr{constructor(e,n,r){super(e.length+(n?1:0)+r.length,e.height+r.height,(n?1:0)|(e.outdated||r.outdated?2:0)),this.left=e,this.right=r,this.size=e.size+r.size}get break(){return this.flags&1}blockAt(e,n,r,a){let s=r+this.left.height;return e<s?this.left.blockAt(e,n,r,a):this.right.blockAt(e,n,s,a+this.left.length+this.break)}lineAt(e,n,r,a,s){let i=a+this.left.height,o=s+this.left.length+this.break,l=n==jt.ByHeight?e<i:e<o,u=l?this.left.lineAt(e,n,r,a,s):this.right.lineAt(e,n,r,i,o);if(this.break||(l?u.to<o:u.from>o))return u;let c=n==jt.ByPosNoHeight?jt.ByPosNoHeight:jt.ByPos;return l?u.join(this.right.lineAt(o,c,r,i,o)):this.left.lineAt(o,c,r,a,s).join(u)}forEachLine(e,n,r,a,s,i){let o=a+this.left.height,l=s+this.left.length+this.break;if(this.break)e<l&&this.left.forEachLine(e,n,r,a,s,i),n>=l&&this.right.forEachLine(e,n,r,o,l,i);else{let u=this.lineAt(l,jt.ByPos,r,a,s);e<u.from&&this.left.forEachLine(e,Math.min(n,u.from-1),r,a,s,i),u.to>=e&&u.from<=n&&i(u),n>u.to&&this.right.forEachLine(Math.max(e,u.to+1),n,r,o,l,i)}}replace(e,n,r){let a=this.left.length+this.break;if(n<a)return this.balanced(this.left.replace(e,n,r),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-a,n-a,r));let s=[];e>0&&this.decomposeLeft(e,s);let i=s.length;for(let o of r)s.push(o);if(e>0&&Ek(s,i-1),n<this.length){let o=s.length;this.decomposeRight(n,s),Ek(s,o)}return Cr.of(s)}decomposeLeft(e,n){let r=this.left.length;if(e<=r)return this.left.decomposeLeft(e,n);n.push(this.left),this.break&&(r++,e>=r&&n.push(null)),e>r&&this.right.decomposeLeft(e-r,n)}decomposeRight(e,n){let r=this.left.length,a=r+this.break;if(e>=a)return this.right.decomposeRight(e-a,n);e<r&&this.left.decomposeRight(e,n),this.break&&e<a&&n.push(null),n.push(this.right)}balanced(e,n){return e.size>2*n.size||n.size>2*e.size?Cr.of(this.break?[e,null,n]:[e,n]):(this.left=Hd(this.left,e),this.right=Hd(this.right,n),this.setHeight(e.height+n.height),this.outdated=e.outdated||n.outdated,this.size=e.size+n.size,this.length=e.length+this.break+n.length,this)}updateHeight(e,n=0,r=!1,a){let{left:s,right:i}=this,o=n+s.length+this.break,l=null;return a&&a.from<=n+s.length&&a.more?l=s=s.updateHeight(e,n,r,a):s.updateHeight(e,n,r),a&&a.from<=o+i.length&&a.more?l=i=i.updateHeight(e,o,r,a):i.updateHeight(e,o,r),l?this.balanced(s,i):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}};function Ek(t,e){let n,r;t[e]==null&&(n=t[e-1])instanceof Gs&&(r=t[e+1])instanceof Gs&&t.splice(e-1,3,new Gs(n.length+1+r.length))}var QT=5,vm=class t{constructor(e,n){this.pos=e,this.oracle=n,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=e}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(e,n){if(this.lineStart>-1){let r=Math.min(n,this.lineEnd),a=this.nodes[this.nodes.length-1];a instanceof Ur?a.length+=r-this.pos:(r>this.pos||!this.isCovered)&&this.nodes.push(new Ur(r-this.pos,-1,0)),this.writtenTo=r,n>r&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=n}point(e,n,r){if(e<n||r.heightRelevant){let a=r.widget?r.widget.estimatedHeight:0,s=r.widget?r.widget.lineBreaks:0;a<0&&(a=this.oracle.lineHeight);let i=n-e;r.block?this.addBlock(new Ud(i,a,r)):(i||s||a>=QT)&&this.addLineDeco(a,s,i)}else n>e&&this.span(e,n);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:e,to:n}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=n,this.writtenTo<e&&((this.writtenTo<e-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,e-1)),this.nodes.push(null)),this.pos>e&&this.nodes.push(new Ur(this.pos-e,-1,0)),this.writtenTo=this.pos}blankContent(e,n){let r=new Gs(n-e);return this.oracle.doc.lineAt(e).to==n&&(r.flags|=4),r}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof Ur)return e;let n=new Ur(0,-1,0);return this.nodes.push(n),n}addBlock(e){this.enterLine();let n=e.deco;n&&n.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,n&&n.endSide>0&&(this.covering=e)}addLineDeco(e,n,r){let a=this.ensureLine();a.length+=r,a.collapsed+=r,a.widgetHeight=Math.max(a.widgetHeight,e),a.breaks+=n,this.writtenTo=this.pos=this.pos+r}finish(e){let n=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(n instanceof Ur)&&!this.isCovered?this.nodes.push(new Ur(0,-1,0)):(this.writtenTo<this.pos||n==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let r=e;for(let a of this.nodes)a instanceof Ur&&a.updateHeight(this.oracle,r),r+=a?a.length:1;return this.nodes}static build(e,n,r,a){let s=new t(r,e);return wt.spans(n,r,a,s,0),s.finish(r)}};function eD(t,e,n){let r=new km;return wt.compare(t,e,n,r,0),r.changes}var km=class{constructor(){this.changes=[]}compareRange(){}comparePoint(e,n,r,a){(e<n||r&&r.heightRelevant||a&&a.heightRelevant)&&Eo(e,n,this.changes,5)}};function tD(t,e){let n=t.getBoundingClientRect(),r=t.ownerDocument,a=r.defaultView||window,s=Math.max(0,n.left),i=Math.min(a.innerWidth,n.right),o=Math.max(0,n.top),l=Math.min(a.innerHeight,n.bottom);for(let u=t.parentNode;u&&u!=r.body;)if(u.nodeType==1){let c=u,d=window.getComputedStyle(c);if((c.scrollHeight>c.clientHeight||c.scrollWidth>c.clientWidth)&&d.overflow!="visible"){let f=c.getBoundingClientRect();s=Math.max(s,f.left),i=Math.min(i,f.right),o=Math.max(o,f.top),l=Math.min(u==t.parentNode?a.innerHeight:l,f.bottom)}u=d.position=="absolute"||d.position=="fixed"?c.offsetParent:c.parentNode}else if(u.nodeType==11)u=u.host;else break;return{left:s-n.left,right:Math.max(s,i)-n.left,top:o-(n.top+e),bottom:Math.max(o,l)-(n.top+e)}}function nD(t){let e=t.getBoundingClientRect(),n=t.ownerDocument.defaultView||window;return e.left<n.innerWidth&&e.right>0&&e.top<n.innerHeight&&e.bottom>0}function rD(t,e){let n=t.getBoundingClientRect();return{left:0,right:n.right-n.left,top:e,bottom:n.bottom-(n.top+e)}}var ku=class{constructor(e,n,r,a){this.from=e,this.to=n,this.size=r,this.displaySize=a}static same(e,n){if(e.length!=n.length)return!1;for(let r=0;r<e.length;r++){let a=e[r],s=n[r];if(a.from!=s.from||a.to!=s.to||a.size!=s.size)return!1}return!0}draw(e,n){return Ke.replace({widget:new Sm(this.displaySize*(n?e.scaleY:e.scaleX),n)}).range(this.from,this.to)}},Sm=class extends Ir{constructor(e,n){super(),this.size=e,this.vertical=n}eq(e){return e.size==this.size&&e.vertical==this.vertical}toDOM(){let e=document.createElement("div");return this.vertical?e.style.height=this.size+"px":(e.style.width=this.size+"px",e.style.height="2px",e.style.display="inline-block"),e}get estimatedHeight(){return this.vertical?this.size:-1}},Gd=class{constructor(e,n){this.view=e,this.state=n,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scaleX=1,this.scaleY=1,this.scrollOffset=0,this.scrolledToBottom=!1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=Ok,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=Vt.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let r=n.facet(Gm).some(a=>typeof a!="function"&&a.class=="cm-lineWrapping");this.heightOracle=new ym(r),this.stateDeco=Bk(n),this.heightMap=Cr.empty().applyChanges(this.stateDeco,st.empty,this.heightOracle.setDoc(n.doc),[new la(0,0,0,n.doc.length)]);for(let a=0;a<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());a++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=Ke.set(this.lineGaps.map(a=>a.draw(this,!1))),this.scrollParent=e.scrollDOM,this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:n}=this.state.selection;for(let r=0;r<=1;r++){let a=r?n.head:n.anchor;if(!e.some(({from:s,to:i})=>a>=s&&a<=i)){let{from:s,to:i}=this.lineBlockAt(a);e.push(new Do(s,i))}}return this.viewports=e.sort((r,a)=>r.from-a.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?Ok:new Cm(this.heightOracle,this.heightMap,this.viewports),e.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,e=>{this.viewportLines.push(pu(e,this.scaler))})}update(e,n=null){this.state=e.state;let r=this.stateDeco;this.stateDeco=Bk(this.state);let a=e.changedRanges,s=la.extendWithRanges(a,eD(r,this.stateDeco,e?e.changes:Nn.empty(this.state.doc.length))),i=this.heightMap.height,o=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollOffset);Fk(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),s),(this.heightMap.height!=i||Go)&&(e.flags|=2),o?(this.scrollAnchorPos=e.changes.mapPos(o.from,-1),this.scrollAnchorHeight=o.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=i);let l=s.length?this.mapViewport(this.viewport,e.changes):this.viewport;(n&&(n.range.head<l.from||n.range.head>l.to)||!this.viewportIsAppropriate(l))&&(l=this.getViewport(0,n));let u=l.from!=this.viewport.from||l.to!=this.viewport.to;this.viewport=l,e.flags|=this.updateForViewport(),(u||!e.changes.empty||e.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(e.changes),n&&(this.scrollTarget=n),!this.mustEnforceCursorAssoc&&(e.selectionSet||e.focusChanged)&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(mS)&&(this.mustEnforceCursorAssoc=!0)}measure(){let{view:e}=this,n=e.contentDOM,r=window.getComputedStyle(n),a=this.heightOracle,s=r.whiteSpace;this.defaultTextDirection=r.direction=="rtl"?Vt.RTL:Vt.LTR;let i=this.heightOracle.mustRefreshForWrapping(s)||this.mustMeasureContent==="refresh",o=n.getBoundingClientRect(),l=i||this.mustMeasureContent||this.contentDOMHeight!=o.height;this.contentDOMHeight=o.height,this.mustMeasureContent=!1;let u=0,c=0;if(o.width&&o.height){let{scaleX:L,scaleY:P}=Xk(n,o);(L>.005&&Math.abs(this.scaleX-L)>.005||P>.005&&Math.abs(this.scaleY-P)>.005)&&(this.scaleX=L,this.scaleY=P,u|=16,i=l=!0)}let d=(parseInt(r.paddingTop)||0)*this.scaleY,f=(parseInt(r.paddingBottom)||0)*this.scaleY;(this.paddingTop!=d||this.paddingBottom!=f)&&(this.paddingTop=d,this.paddingBottom=f,u|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(a.lineWrapping&&(l=!0),this.editorWidth=e.scrollDOM.clientWidth,u|=16);let h=Yk(this.view.contentDOM,!1).y;h!=this.scrollParent&&(this.scrollParent=h,this.scrollAnchorHeight=-1,this.scrollOffset=0);let p=this.getScrollOffset();this.scrollOffset!=p&&(this.scrollAnchorHeight=-1,this.scrollOffset=p),this.scrolledToBottom=eS(this.scrollParent||e.win);let g=(this.printing?rD:tD)(n,this.paddingTop),m=g.top-this.pixelViewport.top,x=g.bottom-this.pixelViewport.bottom;this.pixelViewport=g;let y=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(y!=this.inView&&(this.inView=y,y&&(l=!0)),!this.inView&&!this.scrollTarget&&!nD(e.dom))return 0;let b=o.width;if((this.contentDOMWidth!=b||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=o.width,this.editorHeight=e.scrollDOM.clientHeight,u|=16),l){let L=e.docView.measureVisibleLineHeights(this.viewport);if(a.mustRefreshForHeights(L)&&(i=!0),i||a.lineWrapping&&Math.abs(b-this.contentDOMWidth)>a.charWidth){let{lineHeight:P,charWidth:w,textHeight:k}=e.docView.measureTextSize();i=P>0&&a.refresh(s,P,w,k,Math.max(5,b/w),L),i&&(e.docView.minWidth=0,u|=16)}m>0&&x>0?c=Math.max(m,x):m<0&&x<0&&(c=Math.min(m,x)),Fk();for(let P of this.viewports){let w=P.from==this.viewport.from?L:e.docView.measureVisibleLineHeights(P);this.heightMap=(i?Cr.empty().applyChanges(this.stateDeco,st.empty,this.heightOracle,[new la(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(a,0,i,new bm(P.from,w))}Go&&(u|=2)}let C=!this.viewportIsAppropriate(this.viewport,c)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return C&&(u&2&&(u|=this.updateScaler()),this.viewport=this.getViewport(c,this.scrollTarget),u|=this.updateForViewport()),(u&2||C)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(i?[]:this.lineGaps,e)),u|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),u}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,n){let r=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),a=this.heightMap,s=this.heightOracle,{visibleTop:i,visibleBottom:o}=this,l=new Do(a.lineAt(i-r*1e3,jt.ByHeight,s,0,0).from,a.lineAt(o+(1-r)*1e3,jt.ByHeight,s,0,0).to);if(n){let{head:u}=n.range;if(u<l.from||u>l.to){let c=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),d=a.lineAt(u,jt.ByPos,s,0,0),f;n.y=="center"?f=(d.top+d.bottom)/2-c/2:n.y=="start"||n.y=="nearest"&&u<l.from?f=d.top:f=d.bottom-c,l=new Do(a.lineAt(f-1e3/2,jt.ByHeight,s,0,0).from,a.lineAt(f+c+1e3/2,jt.ByHeight,s,0,0).to)}}return l}mapViewport(e,n){let r=n.mapPos(e.from,-1),a=n.mapPos(e.to,1);return new Do(this.heightMap.lineAt(r,jt.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(a,jt.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:n},r=0){if(!this.inView)return!0;let{top:a}=this.heightMap.lineAt(e,jt.ByPos,this.heightOracle,0,0),{bottom:s}=this.heightMap.lineAt(n,jt.ByPos,this.heightOracle,0,0),{visibleTop:i,visibleBottom:o}=this;return(e==0||a<=i-Math.max(10,Math.min(-r,250)))&&(n==this.state.doc.length||s>=o+Math.max(10,Math.min(r,250)))&&a>i-2*1e3&&s<o+2*1e3}mapLineGaps(e,n){if(!e.length||n.empty)return e;let r=[];for(let a of e)n.touchesRange(a.from,a.to)||r.push(new ku(n.mapPos(a.from),n.mapPos(a.to),a.size,a.displaySize));return r}ensureLineGaps(e,n){let r=this.heightOracle.lineWrapping,a=r?1e4:2e3,s=a>>1,i=a<<1;if(this.defaultTextDirection!=Vt.LTR&&!r)return[];let o=[],l=(c,d,f,h)=>{if(d-c<s)return;let p=this.state.selection.main,g=[p.from];p.empty||g.push(p.to);for(let x of g)if(x>c&&x<d){l(c,x-10,f,h),l(x+10,d,f,h);return}let m=sD(e,x=>x.from>=f.from&&x.to<=f.to&&Math.abs(x.from-c)<s&&Math.abs(x.to-d)<s&&!g.some(y=>x.from<y&&x.to>y));if(!m){if(d<f.to&&n&&r&&n.visibleRanges.some(b=>b.from<=d&&b.to>=d)){let b=n.moveToLineBoundary(se.cursor(d),!1,!0).head;b>c&&(d=b)}let x=this.gapSize(f,c,d,h),y=r||x<2e6?x:2e6;m=new ku(c,d,x,y)}o.push(m)},u=c=>{if(c.length<i||c.type!=On.Text)return;let d=aD(c.from,c.to,this.stateDeco);if(d.total<i)return;let f=this.scrollTarget?this.scrollTarget.range.head:null,h,p;if(r){let g=a/this.heightOracle.lineLength*this.heightOracle.lineHeight,m,x;if(f!=null){let y=Id(d,f),b=((this.visibleBottom-this.visibleTop)/2+g)/c.height;m=y-b,x=y+b}else m=(this.visibleTop-c.top-g)/c.height,x=(this.visibleBottom-c.top+g)/c.height;h=Cd(d,m),p=Cd(d,x)}else{let g=d.total*this.heightOracle.charWidth,m=a*this.heightOracle.charWidth,x=0;if(g>2e6)for(let P of e)P.from>=c.from&&P.from<c.to&&P.size!=P.displaySize&&P.from*this.heightOracle.charWidth+x<this.pixelViewport.left&&(x=P.size-P.displaySize);let y=this.pixelViewport.left+x,b=this.pixelViewport.right+x,C,L;if(f!=null){let P=Id(d,f),w=((b-y)/2+m)/g;C=P-w,L=P+w}else C=(y-m)/g,L=(b+m)/g;h=Cd(d,C),p=Cd(d,L)}h>c.from&&l(c.from,h,c,d),p<c.to&&l(p,c.to,c,d)};for(let c of this.viewportLines)Array.isArray(c.type)?c.type.forEach(u):u(c);return o}gapSize(e,n,r,a){let s=Id(a,r)-Id(a,n);return this.heightOracle.lineWrapping?e.height*s:a.total*this.heightOracle.charWidth*s}updateLineGaps(e){ku.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=Ke.set(e.map(n=>n.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(e){let n=this.stateDeco;this.lineGaps.length&&(n=n.concat(this.lineGapDeco));let r=[];wt.spans(n,this.viewport.from,this.viewport.to,{span(s,i){r.push({from:s,to:i})},point(){}},20);let a=0;if(r.length!=this.visibleRanges.length)a=12;else for(let s=0;s<r.length&&!(a&8);s++){let i=this.visibleRanges[s],o=r[s];(i.from!=o.from||i.to!=o.to)&&(a|=4,e&&e.mapPos(i.from,-1)==o.from&&e.mapPos(i.to,1)==o.to||(a|=8))}return this.visibleRanges=r,a}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(n=>n.from<=e&&n.to>=e)||pu(this.heightMap.lineAt(e,jt.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return e>=this.viewportLines[0].top&&e<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(n=>n.top<=e&&n.bottom>=e)||pu(this.heightMap.lineAt(this.scaler.fromDOM(e),jt.ByHeight,this.heightOracle,0,0),this.scaler)}getScrollOffset(){return this.scrollParent==this.view.scrollDOM?this.scrollParent.scrollTop*this.scaleY:(this.scrollParent?this.scrollParent.getBoundingClientRect().top:0)-this.view.contentDOM.getBoundingClientRect().top}scrollAnchorAt(e){let n=this.lineBlockAtHeight(e+8);return n.from>=this.viewport.from||this.viewportLines[0].top-e>200?n:this.viewportLines[0]}elementAtHeight(e){return pu(this.heightMap.blockAt(this.scaler.fromDOM(e),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}},Do=class{constructor(e,n){this.from=e,this.to=n}};function aD(t,e,n){let r=[],a=t,s=0;return wt.spans(n,t,e,{span(){},point(i,o){i>a&&(r.push({from:a,to:i}),s+=i-a),a=o}},20),a<e&&(r.push({from:a,to:e}),s+=e-a),{total:s,ranges:r}}function Cd({total:t,ranges:e},n){if(n<=0)return e[0].from;if(n>=1)return e[e.length-1].to;let r=Math.floor(t*n);for(let a=0;;a++){let{from:s,to:i}=e[a],o=i-s;if(r<=o)return s+r;r-=o}}function Id(t,e){let n=0;for(let{from:r,to:a}of t.ranges){if(e<=a){n+=e-r;break}n+=a-r}return n/t.total}function sD(t,e){for(let n of t)if(e(n))return n}var Ok={toDOM(t){return t},fromDOM(t){return t},scale:1,eq(t){return t==this}};function Bk(t){let e=t.facet(qd).filter(r=>typeof r!="function"),n=t.facet(Wm).filter(r=>typeof r!="function");return n.length&&e.push(wt.join(n)),e}var Cm=class t{constructor(e,n,r){let a=0,s=0,i=0;this.viewports=r.map(({from:o,to:l})=>{let u=n.lineAt(o,jt.ByPos,e,0,0).top,c=n.lineAt(l,jt.ByPos,e,0,0).bottom;return a+=c-u,{from:o,to:l,top:u,bottom:c,domTop:0,domBottom:0}}),this.scale=(7e6-a)/(n.height-a);for(let o of this.viewports)o.domTop=i+(o.top-s)*this.scale,i=o.domBottom=o.domTop+(o.bottom-o.top),s=o.bottom}toDOM(e){for(let n=0,r=0,a=0;;n++){let s=n<this.viewports.length?this.viewports[n]:null;if(!s||e<s.top)return a+(e-r)*this.scale;if(e<=s.bottom)return s.domTop+(e-s.top);r=s.bottom,a=s.domBottom}}fromDOM(e){for(let n=0,r=0,a=0;;n++){let s=n<this.viewports.length?this.viewports[n]:null;if(!s||e<s.domTop)return r+(e-a)/this.scale;if(e<=s.domBottom)return s.top+(e-s.domTop);r=s.bottom,a=s.domBottom}}eq(e){return e instanceof t?this.scale==e.scale&&this.viewports.length==e.viewports.length&&this.viewports.every((n,r)=>n.from==e.viewports[r].from&&n.to==e.viewports[r].to):!1}};function pu(t,e){if(e.scale==1)return t;let n=e.toDOM(t.top),r=e.toDOM(t.bottom);return new ia(t.from,t.length,n,r-n,Array.isArray(t._content)?t._content.map(a=>pu(a,e)):t._content)}var Ld=Me.define({combine:t=>t.join(" ")}),Im=Me.define({combine:t=>t.indexOf(!0)>-1}),Lm=dr.newName(),BS=dr.newName(),_S=dr.newName(),HS={"&light":"."+BS,"&dark":"."+_S};function Am(t,e,n){return new dr(e,{finish(r){return/&/.test(r)?r.replace(/&\w*/,a=>{if(a=="&")return t;if(!n||!n[a])throw new RangeError(`Unsupported selector: ${a}`);return n[a]}):t+" "+r}})}var iD=Am("."+Lm,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{userSelect:"none",position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-selectionHandle":{backgroundColor:"currentColor",width:"1.5px"},".cm-selectionHandle-start::before, .cm-selectionHandle-end::before":{content:'""',backgroundColor:"inherit",borderRadius:"50%",width:"8px",height:"8px",position:"absolute",left:"-3.25px"},".cm-selectionHandle-start::before":{top:"-8px"},".cm-selectionHandle-end::before":{bottom:"-8px"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},".cm-panels-top":{top:"0"},".cm-panels-bottom":{bottom:"0"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{background:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 0) no-repeat",backgroundSize:".4em",backgroundPosition:"calc(min(50%, 0px)) center"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},HS),oD={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},jp=ke.ie&&ke.ie_version<=11,Pm=class{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new Jp,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(n=>{for(let r of n)this.queue.push(r);(ke.ie&&ke.ie_version<=11||ke.ios&&e.composing)&&n.some(r=>r.type=="childList"&&r.removedNodes.length||r.type=="characterData"&&r.oldValue.length>r.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&ke.android&&e.constructor.EDIT_CONTEXT!==!1&&!(ke.chrome&&ke.chrome_version<126)&&(this.editContext=new Nm(e),e.state.facet(ss)&&(e.contentDOM.editContext=this.editContext.editContext)),jp&&(this.onCharData=n=>{this.queue.push({target:n.target,type:"characterData",oldValue:n.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var n;((n=this.view.docView)===null||n===void 0?void 0:n.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(e.scrollDOM)),this.addWindowListeners(this.win=e.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(n=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),n.length>0&&n[n.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(n=>{n.length>0&&n[n.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(e){this.view.inputState.runHandlers("scroll",e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(e){(e.type=="change"||!e.type)&&!e.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((n,r)=>n!=e[r]))){this.gapIntersection.disconnect();for(let n of e)this.gapIntersection.observe(n);this.gaps=e}}onSelectionChange(e){let n=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:r}=this,a=this.selectionRange;if(r.state.facet(ss)?r.root.activeElement!=this.dom:!mu(this.dom,a))return;let s=a.anchorNode&&r.docView.tile.nearest(a.anchorNode);if(s&&s.isWidget()&&s.widget.ignoreEvent(e)){n||(this.selectionChanged=!1);return}(ke.ie&&ke.ie_version<=11||ke.android&&ke.chrome)&&!r.state.selection.main.empty&&a.focusNode&&xu(a.focusNode,a.focusOffset,a.anchorNode,a.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,n=Au(e.root);if(!n)return!1;let r=ke.safari&&e.root.nodeType==11&&e.root.activeElement==this.dom&&lD(this.view,n)||n;if(!r||this.selectionRange.eq(r))return!1;let a=mu(this.dom,r);return a&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&nT(this.dom,r)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(r),a&&(this.selectionChanged=!0),!0)}setSelectionRange(e,n){this.selectionRange.set(e.node,e.offset,n.node,n.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let e=0,n=null;for(let r=this.dom;r;)if(r.nodeType==1)!n&&e<this.scrollTargets.length&&this.scrollTargets[e]==r?e++:n||(n=this.scrollTargets.slice(0,e)),n&&n.push(r),r=r.assignedSlot||r.parentNode;else if(r.nodeType==11)r=r.host;else break;if(e<this.scrollTargets.length&&!n&&(n=this.scrollTargets.slice(0,e)),n){for(let r of this.scrollTargets)r.removeEventListener("scroll",this.onScroll);for(let r of this.scrollTargets=n)r.addEventListener("scroll",this.onScroll)}}ignore(e){if(!this.active)return e();try{return this.stop(),e()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,oD),jp&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),jp&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,n){var r;if(!this.delayedAndroidKey){let a=()=>{let s=this.delayedAndroidKey;s&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=s.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&s.force&&Oo(this.dom,s.key,s.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(a)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:n,force:this.lastChange<Date.now()-50||!!(!((r=this.delayedAndroidKey)===null||r===void 0)&&r.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let n=-1,r=-1,a=!1;for(let s of e){let i=this.readMutation(s);i&&(i.typeOver&&(a=!0),n==-1?{from:n,to:r}=i:(n=Math.min(i.from,n),r=Math.max(i.to,r)))}return{from:n,to:r,typeOver:a}}readChange(){let{from:e,to:n,typeOver:r}=this.processRecords(),a=this.selectionChanged&&mu(this.dom,this.selectionRange);if(e<0&&!a)return null;e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let s=new pm(this.view,e,n,r);return this.view.docView.domChanged={newSel:s.newSel?s.newSel.main:null},s}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let n=this.readChange();if(!n)return this.view.requestMeasure(),!1;let r=this.view.state,a=AS(this.view,n);return this.view.state==r&&(n.domChanged||n.newSel&&!_d(this.view.state.selection,n.newSel.main))&&this.view.update([]),a}readMutation(e){let n=this.view.docView.tile.nearest(e.target);if(!n||n.isWidget())return null;if(n.markDirty(e.type=="attributes"),e.type=="childList"){let r=_k(n,e.previousSibling||e.target.previousSibling,-1),a=_k(n,e.nextSibling||e.target.nextSibling,1);return{from:r?n.posAfter(r):n.posAtStart,to:a?n.posBefore(a):n.posAtEnd,typeOver:!1}}else return e.type=="characterData"?{from:n.posAtStart,to:n.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}:null}setWindow(e){e!=this.win&&(this.removeWindowListeners(this.win),this.win=e,this.addWindowListeners(this.win))}addWindowListeners(e){e.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):e.addEventListener("beforeprint",this.onPrint),e.addEventListener("scroll",this.onScroll),e.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(e){e.removeEventListener("scroll",this.onScroll),e.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}update(e){this.editContext&&(this.editContext.update(e),e.startState.facet(ss)!=e.state.facet(ss)&&(e.view.contentDOM.editContext=e.state.facet(ss)?this.editContext.editContext:null))}destroy(){var e,n,r;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(n=this.gapIntersection)===null||n===void 0||n.disconnect(),(r=this.resizeScroll)===null||r===void 0||r.disconnect();for(let a of this.scrollTargets)a.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}};function _k(t,e,n){for(;e;){let r=Yt.get(e);if(r&&r.parent==t)return r;let a=e.parentNode;e=a!=t.dom?a:n>0?e.nextSibling:e.previousSibling}return null}function Hk(t,e){let n=e.startContainer,r=e.startOffset,a=e.endContainer,s=e.endOffset,i=t.docView.domAtPos(t.state.selection.main.anchor,1);return xu(i.node,i.offset,a,s)&&([n,r,a,s]=[a,s,n,r]),{anchorNode:n,anchorOffset:r,focusNode:a,focusOffset:s}}function lD(t,e){if(e.getComposedRanges){let a=e.getComposedRanges(t.root)[0];if(a)return Hk(t,a)}let n=null;function r(a){a.preventDefault(),a.stopImmediatePropagation(),n=a.getTargetRanges()[0]}return t.contentDOM.addEventListener("beforeinput",r,!0),t.dom.ownerDocument.execCommand("indent"),t.contentDOM.removeEventListener("beforeinput",r,!0),n?Hk(t,n):null}var Nm=class{constructor(e){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(e.state);let n=this.editContext=new window.EditContext({text:e.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,e.state.selection.main.anchor))),selectionEnd:this.toContextPos(e.state.selection.main.head)});this.handlers.textupdate=r=>{let a=e.state.selection.main,{anchor:s,head:i}=a,o=this.toEditorPos(r.updateRangeStart),l=this.toEditorPos(r.updateRangeEnd);e.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:r.updateRangeStart,editorBase:o,drifted:!1});let u=l-o>r.text.length;o==this.from&&s<this.from?o=s:l==this.to&&s>this.to&&(l=s);let c=PS(e.state.sliceDoc(o,l),r.text,(u?a.from:a.to)-o,u?"end":null);if(!c){let f=se.single(this.toEditorPos(r.selectionStart),this.toEditorPos(r.selectionEnd));_d(f,a)||e.dispatch({selection:f,userEvent:"select"});return}let d={from:c.from+o,to:c.toA+o,insert:st.of(r.text.slice(c.from,c.toB).split(`
41
+ `))};if((ke.mac||ke.android)&&d.from==i-1&&/^\. ?$/.test(r.text)&&e.contentDOM.getAttribute("autocorrect")=="off"&&(d={from:o,to:l,insert:st.of([r.text.replace("."," ")])}),this.pendingContextChange=d,!e.state.readOnly){let f=this.to-this.from+(d.to-d.from+d.insert.length);zm(e,d,se.single(this.toEditorPos(r.selectionStart,f),this.toEditorPos(r.selectionEnd,f)))}this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state)),d.from<d.to&&!d.insert.length&&e.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(n.text.slice(Math.max(0,r.updateRangeStart-1),Math.min(n.text.length,r.updateRangeStart+1)))&&this.handlers.compositionend(r)},this.handlers.characterboundsupdate=r=>{let a=[],s=null;for(let i=this.toEditorPos(r.rangeStart),o=this.toEditorPos(r.rangeEnd);i<o;i++){let l=e.coordsForChar(i);s=l&&new DOMRect(l.left,l.top,l.right-l.left,l.bottom-l.top)||s||new DOMRect,a.push(s)}n.updateCharacterBounds(r.rangeStart,a)},this.handlers.textformatupdate=r=>{let a=[];for(let s of r.getTextFormats()){let i=s.underlineStyle,o=s.underlineThickness;if(!/none/i.test(i)&&!/none/i.test(o)){let l=this.toEditorPos(s.rangeStart),u=this.toEditorPos(s.rangeEnd);if(l<u){let c=`text-decoration: underline ${/^[a-z]/.test(i)?i+" ":i=="Dashed"?"dashed ":i=="Squiggle"?"wavy ":""}${/thin/i.test(o)?1:2}px`;a.push(Ke.mark({attributes:{style:c}}).range(l,u))}}}e.dispatch({effects:xS.of(Ke.set(a))})},this.handlers.compositionstart=()=>{e.inputState.composing<0&&(e.inputState.composing=0,e.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(e.inputState.composing=-1,e.inputState.compositionFirstChange=null,this.composing){let{drifted:r}=this.composing;this.composing=null,r&&this.reset(e.state)}};for(let r in this.handlers)n.addEventListener(r,this.handlers[r]);this.measureReq={read:r=>{let a=Au(r.root);a&&a.rangeCount&&this.editContext.updateSelectionBounds(a.getRangeAt(0).getBoundingClientRect())}}}applyEdits(e){let n=0,r=!1,a=this.pendingContextChange;return e.changes.iterChanges((s,i,o,l,u)=>{if(r)return;let c=u.length-(i-s);if(a&&i>=a.to)if(a.from==s&&a.to==i&&a.insert.eq(u)){a=this.pendingContextChange=null,n+=c,this.to+=c;return}else a=null,this.revertPending(e.state);if(s+=n,i+=n,i<=this.from)this.from+=c,this.to+=c;else if(s<this.to){if(s<this.from||i>this.to||this.to-this.from+u.length>3e4){r=!0;return}this.editContext.updateText(this.toContextPos(s),this.toContextPos(i),u.toString()),this.to+=c}n+=c}),a&&!r&&this.revertPending(e.state),!r}update(e){let n=this.pendingContextChange,r=e.startState.selection.main;this.composing&&(this.composing.drifted||!e.changes.touchesRange(r.from,r.to)&&e.transactions.some(a=>!a.isUserEvent("input.type")&&a.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=e.changes.mapPos(this.composing.editorBase)):!this.applyEdits(e)||!this.rangeIsValid(e.state)?(this.pendingContextChange=null,this.reset(e.state)):(e.docChanged||e.selectionSet||n)&&this.setSelection(e.state),(e.geometryChanged||e.docChanged||e.selectionSet)&&e.view.requestMeasure(this.measureReq)}resetRange(e){let{head:n}=e.selection.main;this.from=Math.max(0,n-1e4),this.to=Math.min(e.doc.length,n+1e4)}reset(e){this.resetRange(e),this.editContext.updateText(0,this.editContext.text.length,e.doc.sliceString(this.from,this.to)),this.setSelection(e)}revertPending(e){let n=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(n.from),this.toContextPos(n.from+n.insert.length),e.doc.sliceString(n.from,n.to))}setSelection(e){let{main:n}=e.selection,r=this.toContextPos(Math.max(this.from,Math.min(this.to,n.anchor))),a=this.toContextPos(n.head);(this.editContext.selectionStart!=r||this.editContext.selectionEnd!=a)&&this.editContext.updateSelection(r,a)}rangeIsValid(e){let{head:n}=e.selection.main;return!(this.from>0&&n-this.from<500||this.to<e.doc.length&&this.to-n<500||this.to-this.from>1e4*3)}toEditorPos(e,n=this.to-this.from){e=Math.min(e,n);let r=this.composing;return r&&r.drifted?r.editorBase+(e-r.contextBase):e+this.from}toContextPos(e){let n=this.composing;return n&&n.drifted?n.contextBase+(e-n.editorBase):e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}},Pe=class t{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(e={}){var n;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.clearAnnouncement=-1,this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),e.parent&&e.parent.appendChild(this.dom);let{dispatch:r}=e;this.dispatchTransactions=e.dispatchTransactions||r&&(a=>a.forEach(s=>r(s,this)))||(a=>this.update(a)),this.dispatch=this.dispatch.bind(this),this._root=e.root||tT(e.parent)||document,this.viewState=new Gd(this,e.state||It.create(e)),e.scrollTo&&e.scrollTo.is(vd)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(To).map(a=>new bu(a));for(let a of this.plugins)a.update(this);this.observer=new Pm(this),this.inputState=new mm(this),this.inputState.ensureHandlers(this.plugins),this.docView=new Od(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((n=document.fonts)===null||n===void 0)&&n.ready&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent="refresh",this.requestMeasure()})}dispatch(...e){let n=e.length==1&&e[0]instanceof An?e:e.length==1&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(n,this)}update(e){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let n=!1,r=!1,a,s=this.state;for(let f of e){if(f.startState!=s)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");s=f.state}if(this.destroyed){this.viewState.state=s;return}let i=this.hasFocus,o=0,l=null;e.some(f=>f.annotation(FS))?(this.inputState.notifiedFocused=i,o=1):i!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=i,l=ES(s,i),l||(o=1));let u=this.observer.delayedAndroidKey,c=null;if(u?(this.observer.clearDelayedAndroidKey(),c=this.observer.readChange(),(c&&!this.state.doc.eq(s.doc)||!this.state.selection.eq(s.selection))&&(c=null)):this.observer.clear(),s.facet(It.phrases)!=this.state.facet(It.phrases))return this.setState(s);a=Fd.create(this,s,e),a.flags|=o;let d=this.viewState.scrollTarget;try{this.updateState=2;for(let f of e){if(d&&(d=d.map(f.changes)),f.scrollIntoView){let{main:h}=f.state.selection,{x:p,y:g}=this.state.facet(t.cursorScrollMargin);d=new yu(h.empty?h:se.cursor(h.head,h.head>h.anchor?-1:1),"nearest","nearest",g,p)}for(let h of f.effects)h.is(vd)&&(d=h.value.clip(this.state))}this.viewState.update(a,d),this.bidiCache=Wd.update(this.bidiCache,a.changes),a.empty||(this.updatePlugins(a),this.inputState.update(a)),n=this.docView.update(a),this.state.facet(hu)!=this.styleModules&&this.mountStyles(),r=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(n,e.some(f=>f.isUserEvent("select.pointer")))}finally{this.updateState=0}if(a.startState.facet(Ld)!=a.state.facet(Ld)&&(this.viewState.mustMeasureContent=!0),(n||r||d||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),n&&this.docViewUpdate(),!a.empty)for(let f of this.state.facet(tm))try{f(a)}catch(h){oa(this.state,h,"update listener")}(l||c)&&Promise.resolve().then(()=>{l&&this.state==l.startState&&this.dispatch(l),c&&!AS(this,c)&&u.force&&Oo(this.contentDOM,u.key,u.keyCode)})}setState(e){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=e;return}this.updateState=2;let n=this.hasFocus;try{for(let r of this.plugins)r.destroy(this);this.viewState=new Gd(this,e),this.plugins=e.facet(To).map(r=>new bu(r)),this.pluginMap.clear();for(let r of this.plugins)r.update(this);this.docView.destroy(),this.docView=new Od(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}n&&this.focus(),this.requestMeasure()}updatePlugins(e){let n=e.startState.facet(To),r=e.state.facet(To);if(n!=r){let a=[];for(let s of r){let i=n.indexOf(s);if(i<0)a.push(new bu(s));else{let o=this.plugins[i];o.mustUpdate=e,a.push(o)}}for(let s of this.plugins)s.mustUpdate!=e&&s.destroy(this);this.plugins=a,this.pluginMap.clear()}else for(let a of this.plugins)a.mustUpdate=e;for(let a=0;a<this.plugins.length;a++)this.plugins[a].update(this);n!=r&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let e of this.plugins){let n=e.value;if(n&&n.docViewUpdate)try{n.docViewUpdate(this)}catch(r){oa(this.state,r,"doc view update listener")}}}measure(e=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,e&&this.observer.forceFlush();let n=null,r=this.viewState.scrollParent,a=this.viewState.getScrollOffset(),{scrollAnchorPos:s,scrollAnchorHeight:i,scaleY:o}=this.viewState;Math.abs(a-this.viewState.scrollOffset)>1&&(i=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(i<0){if(eS(r||this.win))s=-1,i=this.viewState.heightMap.height/this.viewState.scaleY;else{let p=this.viewState.scrollAnchorAt(a);s=p.from,i=p.top}o=this.viewState.scaleY}this.updateState=1;let u=this.viewState.measure();if(!u&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(l>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let c=[];u&4||([this.measureRequests,c]=[c,this.measureRequests]);let d=c.map(p=>{try{return p.read(this)}catch(g){return oa(this.state,g),Uk}}),f=Fd.create(this,this.state,[]),h=!1;f.flags|=u,n?n.flags|=u:n=f,this.updateState=2,f.empty||(this.updatePlugins(f),this.inputState.update(f),this.updateAttrs(),h=this.docView.update(f),h&&this.docViewUpdate());for(let p=0;p<c.length;p++)if(d[p]!=Uk)try{let g=c[p];g.write&&g.write(d[p],this)}catch(g){oa(this.state,g)}if(h&&this.docView.updateSelection(!0),!f.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,i=-1;continue}else{let g=(s<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(s).top)/this.viewState.scaleY-i/o;if((g>1||g<-1)&&!(ke.ios&&this.inputState.lastIOSMomentumScroll>Date.now()-100)&&(r==this.scrollDOM||this.hasFocus||Math.max(this.inputState.lastWheelEvent,this.inputState.lastTouchTime)>Date.now()-100)){a=a+g,r?s<0?r.scrollTop=r.scrollHeight:r.scrollTop+=g:this.win.scrollBy(0,g),i=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(n&&!n.empty)for(let l of this.state.facet(tm))l(n)}get themeClasses(){return Lm+" "+(this.state.facet(Im)?_S:BS)+" "+this.state.facet(Ld)}updateAttrs(){let e=Gk(this,yS,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),n={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(ss)?"true":"false",class:"cm-content",style:`${ke.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(n["aria-readonly"]="true"),Gk(this,Gm,n);let r=this.observer.ignore(()=>{let a=bk(this.contentDOM,this.contentAttrs,n),s=bk(this.dom,this.editorAttrs,e);return a||s});return this.editorAttrs=e,this.contentAttrs=n,r}showAnnouncements(e){let n=!0;for(let r of e)for(let a of r.effects)if(a.is(t.announce)){n&&(this.announceDOM.textContent="",this.win.clearTimeout(this.clearAnnouncement),this.clearAnnouncement=this.win.setTimeout(()=>{this.announceDOM.textContent="\xA0"},200),n=!1);let s=this.announceDOM.appendChild(document.createElement("div"));s.textContent=a.value}}mountStyles(){this.styleModules=this.state.facet(hu);let e=this.state.facet(t.cspNonce);dr.mount(this.root,this.styleModules.concat(iD).reverse(),e?{nonce:e}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),e){if(this.measureRequests.indexOf(e)>-1)return;if(e.key!=null){for(let n=0;n<this.measureRequests.length;n++)if(this.measureRequests[n].key===e.key){this.measureRequests[n]=e;return}}this.measureRequests.push(e)}}plugin(e){let n=this.pluginMap.get(e);return(n===void 0||n&&n.plugin!=e)&&this.pluginMap.set(e,n=this.plugins.find(r=>r.plugin==e)||null),n&&n.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,n,r){return zp(this,e,Ik(this,e,n,r))}moveByGroup(e,n){return zp(this,e,Ik(this,e,n,r=>RT(this,e.head,r)))}visualLineSide(e,n){return n?se.cursor(e.to,1):se.cursor(e.from,-1)}moveToLineBoundary(e,n,r=!0){return NT(this,e,n,r)}moveVertically(e,n,r){return zp(this,e,MT(this,e,n,r))}domAtPos(e,n=1){return this.docView.domAtPos(e,n)}posAtDOM(e,n=0){return this.docView.posFromDOM(e,n)}posAtCoords(e,n=!0){this.readMeasured();let r=dm(this,e,n);return r&&r.pos}posAndSideAtCoords(e,n=!0){return this.readMeasured(),dm(this,e,n)}coordsAtPos(e,n=1){this.readMeasured();let r=this.state.doc.lineAt(e),a=this.bidiSpans(r),s=a[Wr.find(a,e-r.from,-1,n)];return r.length&&(e==r.from&&n<0||e==r.to&&n>0)&&s.dir!=this.textDirectionAt(r.from)&&(e==r.to?(e=r.from+s.from,n=1):(e=r.from+s.to,n=-1)),this.docView.coordsAt(e,n,s.dir==Vt.RTL)}coordsForChar(e){return this.readMeasured(),this.docView.coordsForChar(e)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet(pS)||e<this.viewport.from||e>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>uD)return iS(e.length);let n=this.textDirectionAt(e.from),r;for(let s of this.bidiCache)if(s.from==e.from&&s.dir==n&&(s.fresh||sS(s.isolates,r=kk(this,e))))return s.order;r||(r=kk(this,e));let a=uT(e.text,n,r);return this.bidiCache.push(new Wd(e.from,e.to,n,r,!0,a)),a}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||ke.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Qk(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((e.nodeType==9?e:e.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.win.clearTimeout(this.clearAnnouncement),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,n={}){var r,a,s,i;return vd.of(new yu(typeof e=="number"?se.cursor(e):e,(r=n.y)!==null&&r!==void 0?r:"nearest",(a=n.x)!==null&&a!==void 0?a:"nearest",(s=n.yMargin)!==null&&s!==void 0?s:5,(i=n.xMargin)!==null&&i!==void 0?i:5))}scrollSnapshot(){let{scrollTop:e,scrollLeft:n}=this.scrollDOM,r=this.viewState.scrollAnchorAt(e);return vd.of(new yu(se.cursor(r.from),"start","start",r.top-e,n,!0))}setTabFocusMode(e){e==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof e=="boolean"?this.inputState.tabFocusMode=e?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+e)}static domEventHandlers(e){return hr.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return hr.define(()=>({}),{eventObservers:e})}static theme(e,n){let r=dr.newName(),a=[Ld.of(r),hu.of(Am(`.${r}`,e))];return n&&n.dark&&a.push(Im.of(!0)),a}static baseTheme(e){return Ma.lowest(hu.of(Am("."+Lm,e,HS)))}static findFromDOM(e){var n;let r=e.querySelector(".cm-content"),a=r&&Yt.get(r)||Yt.get(e);return((n=a?.root)===null||n===void 0?void 0:n.view)||null}};Pe.styleModule=hu;Pe.inputHandler=fS;Pe.clipboardInputFilter=Hm;Pe.clipboardOutputFilter=Um;Pe.scrollHandler=gS;Pe.focusChangeEffect=hS;Pe.perLineTextDirection=pS;Pe.exceptionSink=dS;Pe.updateListener=tm;Pe.editable=ss;Pe.mouseSelectionStyle=cS;Pe.dragMovesSelection=uS;Pe.clickAddsSelectionRange=lS;Pe.decorations=qd;Pe.blockWrappers=bS;Pe.outerDecorations=Wm;Pe.atomicRanges=Ru;Pe.bidiIsolatedRanges=wS;Pe.cursorScrollMargin=Me.define({combine:t=>{let e=5,n=5;for(let r of t)typeof r=="number"?e=n=r:{x:e,y:n}=r;return{x:e,y:n}}});Pe.scrollMargins=vS;Pe.darkTheme=Im;Pe.cspNonce=Me.define({combine:t=>t.length?t[0]:""});Pe.contentAttributes=Gm;Pe.editorAttributes=yS;Pe.lineWrapping=Pe.contentAttributes.of({class:"cm-lineWrapping"});Pe.announce=pt.define();var uD=4096,Uk={},Wd=class t{constructor(e,n,r,a,s,i){this.from=e,this.to=n,this.dir=r,this.isolates=a,this.fresh=s,this.order=i}static update(e,n){if(n.empty&&!e.some(s=>s.fresh))return e;let r=[],a=e.length?e[e.length-1].dir:Vt.LTR;for(let s=Math.max(0,e.length-10);s<e.length;s++){let i=e[s];i.dir==a&&!n.touchesRange(i.from,i.to)&&r.push(new t(n.mapPos(i.from,1),n.mapPos(i.to,-1),i.dir,i.isolates,!1,i.order))}return r}};function Gk(t,e,n){for(let r=t.state.facet(e),a=r.length-1;a>=0;a--){let s=r[a],i=typeof s=="function"?s(t):s;i&&Om(i,n)}return n}var cD=ke.mac?"mac":ke.windows?"win":ke.linux?"linux":"key";function dD(t,e){let n=t.split(/-(?!$)/),r=n[n.length-1];r=="Space"&&(r=" ");let a,s,i,o;for(let l=0;l<n.length-1;++l){let u=n[l];if(/^(cmd|meta|m)$/i.test(u))o=!0;else if(/^a(lt)?$/i.test(u))a=!0;else if(/^(c|ctrl|control)$/i.test(u))s=!0;else if(/^s(hift)?$/i.test(u))i=!0;else if(/^mod$/i.test(u))e=="mac"?o=!0:s=!0;else throw new Error("Unrecognized modifier name: "+u)}return a&&(r="Alt-"+r),s&&(r="Ctrl-"+r),o&&(r="Meta-"+r),i&&(r="Shift-"+r),r}function Ad(t,e,n){return e.altKey&&(t="Alt-"+t),e.ctrlKey&&(t="Ctrl-"+t),e.metaKey&&(t="Meta-"+t),n!==!1&&e.shiftKey&&(t="Shift-"+t),t}var fD=Ma.default(Pe.domEventHandlers({keydown(t,e){return gD(hD(e.state),t,e,"editor")}})),jm=Me.define({enables:fD}),Wk=new WeakMap;function hD(t){let e=t.facet(jm),n=Wk.get(e);return n||Wk.set(e,n=mD(e.reduce((r,a)=>r.concat(a),[]))),n}var Us=null,pD=4e3;function mD(t,e=cD){let n=Object.create(null),r=Object.create(null),a=(i,o)=>{let l=r[i];if(l==null)r[i]=o;else if(l!=o)throw new Error("Key binding "+i+" is used both as a regular binding and as a multi-stroke prefix")},s=(i,o,l,u,c)=>{var d,f;let h=n[i]||(n[i]=Object.create(null)),p=o.split(/ (?!$)/).map(x=>dD(x,e));for(let x=1;x<p.length;x++){let y=p.slice(0,x).join(" ");a(y,!0),h[y]||(h[y]={preventDefault:!0,stopPropagation:!1,run:[b=>{let C=Us={view:b,prefix:y,scope:i};return setTimeout(()=>{Us==C&&(Us=null)},pD),!0}]})}let g=p.join(" ");a(g,!1);let m=h[g]||(h[g]={preventDefault:!1,stopPropagation:!1,run:((f=(d=h._any)===null||d===void 0?void 0:d.run)===null||f===void 0?void 0:f.slice())||[]});l&&m.run.push(l),u&&(m.preventDefault=!0),c&&(m.stopPropagation=!0)};for(let i of t){let o=i.scope?i.scope.split(" "):["editor"];if(i.any)for(let u of o){let c=n[u]||(n[u]=Object.create(null));c._any||(c._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:d}=i;for(let f in c)c[f].run.push(h=>d(h,Rm))}let l=i[e]||i.key;if(l)for(let u of o)s(u,l,i.run,i.preventDefault,i.stopPropagation),i.shift&&s(u,"Shift-"+l,i.shift,i.preventDefault,i.stopPropagation)}return n}var Rm=null;function gD(t,e,n,r){Rm=e;let a=mk(e),s=Q1(a,0),i=ek(s)==a.length&&a!=" ",o="",l=!1,u=!1,c=!1;Us&&Us.view==n&&Us.scope==r&&(o=Us.prefix+" ",RS.indexOf(e.keyCode)<0&&(u=!0,Us=null));let d=new Set,f=m=>{if(m){for(let x of m.run)if(!d.has(x)&&(d.add(x),x(n)))return m.stopPropagation&&(c=!0),!0;m.preventDefault&&(m.stopPropagation&&(c=!0),u=!0)}return!1},h=t[r],p,g;return h&&(f(h[o+Ad(a,e,!i)])?l=!0:i&&(e.altKey||e.metaKey||e.ctrlKey)&&!(ke.windows&&e.ctrlKey&&e.altKey)&&!(ke.mac&&e.altKey&&!(e.ctrlKey||e.metaKey))&&(p=as[e.keyCode])&&p!=a?(f(h[o+Ad(p,e,!0)])||e.shiftKey&&(g=Ro[e.keyCode])!=a&&g!=p&&f(h[o+Ad(g,e,!1)]))&&(l=!0):i&&e.shiftKey&&f(h[o+Ad(a,e,!0)])&&(l=!0),!l&&f(h._any)&&(l=!0)),u&&(l=!0),l&&c&&e.stopPropagation(),Rm=null,l}var Ni=class t{constructor(e,n,r,a,s){this.className=e,this.left=n,this.top=r,this.width=a,this.height=s}draw(){let e=document.createElement("div");return e.className=this.className,this.adjust(e),e}update(e,n){return n.className!=this.className?!1:(this.adjust(e),!0)}adjust(e){e.style.left=this.left+"px",e.style.top=this.top+"px",this.width!=null&&(e.style.width=this.width+"px"),e.style.height=this.height+"px"}eq(e){return this.left==e.left&&this.top==e.top&&this.width==e.width&&this.height==e.height&&this.className==e.className}static forRange(e,n,r){if(r.empty){let a=e.coordsAtPos(r.head,r.assoc||1);if(!a)return[];let s=US(e);return[new t(n,a.left-s.left,a.top-s.top,null,a.bottom-a.top)]}else return xD(e,n,r)}};function US(t){let e=t.scrollDOM.getBoundingClientRect();return{left:(t.textDirection==Vt.LTR?e.left:e.right-t.scrollDOM.clientWidth*t.scaleX)-t.scrollDOM.scrollLeft*t.scaleX,top:e.top-t.scrollDOM.scrollTop*t.scaleY}}function zk(t,e,n,r){let a=t.coordsAtPos(e,n*2);if(!a)return r;let s=t.dom.getBoundingClientRect(),i=(a.top+a.bottom)/2,o=t.posAtCoords({x:s.left+1,y:i}),l=t.posAtCoords({x:s.right-1,y:i});return o==null||l==null?r:{from:Math.max(r.from,Math.min(o,l)),to:Math.min(r.to,Math.max(o,l))}}function xD(t,e,n){if(n.to<=t.viewport.from||n.from>=t.viewport.to)return[];let r=Math.max(n.from,t.viewport.from),a=Math.min(n.to,t.viewport.to),s=t.textDirection==Vt.LTR,i=t.contentDOM,o=i.getBoundingClientRect(),l=US(t),u=i.querySelector(".cm-line"),c=u&&window.getComputedStyle(u),d=o.left+(c?parseInt(c.paddingLeft)+Math.min(0,parseInt(c.textIndent)):0),f=o.right-(c?parseInt(c.paddingRight):0),h=cm(t,r,1),p=cm(t,a,-1),g=h.type==On.Text?h:null,m=p.type==On.Text?p:null;if(g&&(t.lineWrapping||h.widgetLineBreaks)&&(g=zk(t,r,1,g)),m&&(t.lineWrapping||p.widgetLineBreaks)&&(m=zk(t,a,-1,m)),g&&m&&g.from==m.from&&g.to==m.to)return y(b(n.from,n.to,g));{let L=g?b(n.from,null,g):C(h,!1),P=m?b(null,n.to,m):C(p,!0),w=[];return(g||h).to<(m||p).from-(g&&m?1:0)||h.widgetLineBreaks>1&&L.bottom+t.defaultLineHeight/2<P.top?w.push(x(d,L.bottom,f,P.top)):L.bottom<P.top&&t.elementAtHeight((L.bottom+P.top)/2).type==On.Text&&(L.bottom=P.top=(L.bottom+P.top)/2),y(L).concat(w).concat(y(P))}function x(L,P,w,k){return new Ni(e,L-l.left,P-l.top,Math.max(0,w-L),k-P)}function y({top:L,bottom:P,horizontal:w}){let k=[];for(let _=0;_<w.length;_+=2)k.push(x(w[_],L,w[_+1],P));return k}function b(L,P,w){let k=1e9,_=-1e9,M=[];function R(T,V,Y,N,A){let B=t.coordsAtPos(T,T==w.to?-2:2),K=t.coordsAtPos(Y,Y==w.from?2:-2);!B||!K||(k=Math.min(B.top,K.top,k),_=Math.max(B.bottom,K.bottom,_),A==Vt.LTR?M.push(s&&V?d:B.left,s&&N?f:K.right):M.push(!s&&N?d:K.left,!s&&V?f:B.right))}let U=L??w.from,v=P??w.to;for(let T of t.visibleRanges)if(T.to>U&&T.from<v)for(let V=Math.max(T.from,U),Y=Math.min(T.to,v);;){let N=t.state.doc.lineAt(V);for(let A of t.bidiSpans(N)){let B=A.from+N.from,K=A.to+N.from;if(B>=Y)break;K>V&&R(Math.max(B,V),L==null&&B<=U,Math.min(K,Y),P==null&&K>=v,A.dir)}if(V=N.to+1,V>=Y)break}return M.length==0&&R(U,L==null,v,P==null,t.textDirection),{top:k,bottom:_,horizontal:M}}function C(L,P){let w=o.top+(P?L.top:L.bottom);return{top:w,bottom:w,horizontal:[]}}}function yD(t,e){return t.constructor==e.constructor&&t.eq(e)}var Mm=class{constructor(e,n){this.view=e,this.layer=n,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=e.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),n.above&&this.dom.classList.add("cm-layer-above"),n.class&&this.dom.classList.add(n.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(e.state),e.requestMeasure(this.measureReq),n.mount&&n.mount(this.dom,e)}update(e){e.startState.facet(Nd)!=e.state.facet(Nd)&&this.setOrder(e.state),(this.layer.update(e,this.dom)||e.geometryChanged)&&(this.scale(),e.view.requestMeasure(this.measureReq))}docViewUpdate(e){this.layer.updateOnDocViewUpdate!==!1&&e.requestMeasure(this.measureReq)}setOrder(e){let n=0,r=e.facet(Nd);for(;n<r.length&&r[n]!=this.layer;)n++;this.dom.style.zIndex=String((this.layer.above?150:-1)-n)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:e,scaleY:n}=this.view;(e!=this.scaleX||n!=this.scaleY)&&(this.scaleX=e,this.scaleY=n,this.dom.style.transform=`scale(${1/e}, ${1/n})`)}draw(e){if(e.length!=this.drawn.length||e.some((n,r)=>!yD(n,this.drawn[r]))){let n=this.dom.firstChild,r=0;for(let a of e)a.update&&n&&a.constructor&&this.drawn[r].constructor&&a.update(n,this.drawn[r])?(n=n.nextSibling,r++):this.dom.insertBefore(a.draw(),n);for(;n;){let a=n.nextSibling;n.remove(),n=a}this.drawn=e,ke.webkit&&(this.dom.style.display=this.dom.firstChild?"":"none")}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}},Nd=Me.define();function GS(t){return[hr.define(e=>new Mm(e,t)),Nd.of(t)]}var Wo=Me.define({combine(t){return No(t,{cursorBlinkRate:1200,drawRangeCursor:!0,iosSelectionHandles:!0},{cursorBlinkRate:(e,n)=>Math.min(e,n),drawRangeCursor:(e,n)=>e||n})}});function WS(t={}){return[Wo.of(t),bD,wD,kD,mS.of(!0)]}function zS(t){return t.startState.facet(Wo)!=t.state.facet(Wo)}var bD=GS({above:!0,markers(t){let{state:e}=t,n=e.facet(Wo),r=[];for(let a of e.selection.ranges){let s=a==e.selection.main;if(a.empty||n.drawRangeCursor&&!(s&&ke.ios&&n.iosSelectionHandles)){let i=s?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",o=a.empty?a:se.cursor(a.head,a.assoc);for(let l of Ni.forRange(t,i,o))r.push(l)}}return r},update(t,e){t.transactions.some(r=>r.selection)&&(e.style.animationName=e.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let n=zS(t);return n&&jk(t.state,e),t.docChanged||t.selectionSet||n},mount(t,e){jk(e.state,t)},class:"cm-cursorLayer"});function jk(t,e){e.style.animationDuration=t.facet(Wo).cursorBlinkRate+"ms"}var wD=GS({above:!1,markers(t){let e=[],{main:n,ranges:r}=t.state.selection;for(let a of r)if(!a.empty)for(let s of Ni.forRange(t,"cm-selectionBackground",a))e.push(s);if(ke.ios&&!n.empty&&t.state.facet(Wo).iosSelectionHandles){for(let a of Ni.forRange(t,"cm-selectionHandle cm-selectionHandle-start",se.cursor(n.from,1)))e.push(a);for(let a of Ni.forRange(t,"cm-selectionHandle cm-selectionHandle-end",se.cursor(n.to,1)))e.push(a)}return e},update(t,e){return t.docChanged||t.selectionSet||t.viewportChanged||zS(t)},class:"cm-selectionLayer"}),vD=ke.gecko&&ke.gecko_version==153?"#ffffff01":"transparent",kD=Ma.highest(Pe.theme({".cm-line":{"& ::selection, &::selection":{backgroundColor:`${vD} !important`},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}}));var Kj=/x/.unicode!=null?"gu":"g";function jS(){return CD}var SD=Ke.line({class:"cm-activeLine"}),CD=hr.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.docChanged||t.selectionSet)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=-1,n=[];for(let r of t.state.selection.ranges){let a=t.lineBlockAt(r.head);a.from>e&&(n.push(SD.range(a.from)),e=a.from)}return Ke.set(n)}},{decorations:t=>t.decorations}),Tm=class extends Ir{constructor(e){super(),this.content=e}toDOM(e){let n=document.createElement("span");return n.className="cm-placeholder",n.style.pointerEvents="none",n.appendChild(typeof this.content=="string"?document.createTextNode(this.content):typeof this.content=="function"?this.content(e):this.content.cloneNode(!0)),n.setAttribute("aria-hidden","true"),n}coordsAt(e){let n=e.firstChild?gu(e.firstChild):[];if(!n.length)return null;let r=window.getComputedStyle(e.parentNode),a=Pu(n[0],r.direction!="rtl"),s=parseInt(r.lineHeight);return a.bottom-a.top>s*1.5?{left:a.left,right:a.right,top:a.top,bottom:a.top+s}:a}ignoreEvent(){return!1}};function VS(t){let e=hr.fromClass(class{constructor(n){this.view=n,this.placeholder=t?Ke.set([Ke.widget({widget:new Tm(t),side:1}).range(0)]):Ke.none}get decorations(){return this.view.state.doc.length?Ke.none:this.placeholder}},{decorations:n=>n.decorations});return typeof t=="string"?[e,Pe.contentAttributes.of({"aria-placeholder":t})]:e}var Bn=class extends Ra{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}};Bn.prototype.elementClass="";Bn.prototype.toDOM=void 0;Bn.prototype.mapMode=cr.TrackBefore;Bn.prototype.startSide=Bn.prototype.endSide=-1;Bn.prototype.point=!0;var Rd=Me.define(),ID=Me.define(),LD={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>wt.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"},Su=Me.define();function zo(t){return[qS(),Su.of({...LD,...t})]}var Dm=Me.define({combine:t=>t.some(e=>e)});function qS(t){let e=[AD];return t&&t.fixed===!1&&e.push(Dm.of(!0)),e}var AD=hr.fromClass(class{constructor(t){this.view=t,this.domAfter=null,this.prevViewport=t.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters cm-gutters-before",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=t.state.facet(Su).map(e=>new zd(t,e)),this.fixed=!t.state.facet(Dm);for(let e of this.gutters)e.config.side=="after"?this.getDOMAfter().appendChild(e.dom):this.dom.appendChild(e.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),t.scrollDOM.insertBefore(this.dom,t.contentDOM)}getDOMAfter(){return this.domAfter||(this.domAfter=document.createElement("div"),this.domAfter.className="cm-gutters cm-gutters-after",this.domAfter.setAttribute("aria-hidden","true"),this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.domAfter.style.position=this.fixed?"sticky":"",this.view.scrollDOM.appendChild(this.domAfter)),this.domAfter}update(t){if(this.updateGutters(t)){let e=this.prevViewport,n=t.view.viewport,r=Math.min(e.to,n.to)-Math.max(e.from,n.from);this.syncGutters(r<(n.to-n.from)*.8)}if(t.geometryChanged){let e=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=e,this.domAfter&&(this.domAfter.style.minHeight=e)}this.view.state.facet(Dm)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=t.view.viewport}syncGutters(t){let e=this.dom.nextSibling;t&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let n=wt.iter(this.view.state.facet(Rd),this.view.viewport.from),r=[],a=this.gutters.map(s=>new Em(s,this.view.viewport,-this.view.documentPadding.top));for(let s of this.view.viewportLineBlocks)if(r.length&&(r=[]),Array.isArray(s.type)){let i=!0;for(let o of s.type)if(o.type==On.Text&&i){Fm(n,r,o.from);for(let l of a)l.line(this.view,o,r);i=!1}else if(o.widget)for(let l of a)l.widget(this.view,o)}else if(s.type==On.Text){Fm(n,r,s.from);for(let i of a)i.line(this.view,s,r)}else if(s.widget)for(let i of a)i.widget(this.view,s);for(let s of a)s.finish();t&&(this.view.scrollDOM.insertBefore(this.dom,e),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(t){let e=t.startState.facet(Su),n=t.state.facet(Su),r=t.docChanged||t.heightChanged||t.viewportChanged||!wt.eq(t.startState.facet(Rd),t.state.facet(Rd),t.view.viewport.from,t.view.viewport.to);if(e==n)for(let a of this.gutters)a.update(t)&&(r=!0);else{r=!0;let a=[];for(let s of n){let i=e.indexOf(s);i<0?a.push(new zd(this.view,s)):(this.gutters[i].update(t),a.push(this.gutters[i]))}for(let s of this.gutters)s.dom.remove(),a.indexOf(s)<0&&s.destroy();for(let s of a)s.config.side=="after"?this.getDOMAfter().appendChild(s.dom):this.dom.appendChild(s.dom);this.gutters=a}return r}destroy(){for(let t of this.gutters)t.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:t=>Pe.scrollMargins.of(e=>{let n=e.plugin(t);if(!n||n.gutters.length==0||!n.fixed)return null;let r=n.dom.offsetWidth*e.scaleX,a=n.domAfter?n.domAfter.offsetWidth*e.scaleX:0;return e.textDirection==Vt.LTR?{left:r,right:a}:{right:r,left:a}})});function Vk(t){return Array.isArray(t)?t:[t]}function Fm(t,e,n){for(;t.value&&t.from<=n;)t.from==n&&e.push(t.value),t.next()}var Em=class{constructor(e,n,r){this.gutter=e,this.height=r,this.i=0,this.cursor=wt.iter(e.markers,n.from)}addElement(e,n,r){let{gutter:a}=this,s=(n.top-this.height)/e.scaleY,i=n.height/e.scaleY;if(this.i==a.elements.length){let o=new jd(e,i,s,r);a.elements.push(o),a.dom.appendChild(o.dom)}else a.elements[this.i].update(e,i,s,r);this.height=n.bottom,this.i++}line(e,n,r){let a=[];Fm(this.cursor,a,n.from),r.length&&(a=a.concat(r));let s=this.gutter.config.lineMarker(e,n,a);s&&a.unshift(s);let i=this.gutter;a.length==0&&!i.config.renderEmptyElements||this.addElement(e,n,a)}widget(e,n){let r=this.gutter.config.widgetMarker(e,n.widget,n),a=r?[r]:null;for(let s of e.state.facet(ID)){let i=s(e,n.widget,n);i&&(a||(a=[])).push(i)}a&&this.addElement(e,n,a)}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let n=e.elements.pop();e.dom.removeChild(n.dom),n.destroy()}}},zd=class{constructor(e,n){this.view=e,this.config=n,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let r in n.domEventHandlers)this.dom.addEventListener(r,a=>{let s=a.target,i;if(s!=this.dom&&this.dom.contains(s)){for(;s.parentNode!=this.dom;)s=s.parentNode;let l=s.getBoundingClientRect();i=(l.top+l.bottom)/2}else i=a.clientY;let o=e.lineBlockAtHeight(i-e.documentTop);n.domEventHandlers[r](e,o,a)&&a.preventDefault()});this.markers=Vk(n.markers(e)),n.initialSpacer&&(this.spacer=new jd(e,0,0,[n.initialSpacer(e)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(e){let n=this.markers;if(this.markers=Vk(this.config.markers(e.view)),this.spacer&&this.config.updateSpacer){let a=this.config.updateSpacer(this.spacer.markers[0],e);a!=this.spacer.markers[0]&&this.spacer.update(e.view,0,0,[a])}let r=e.view.viewport;return!wt.eq(this.markers,n,r.from,r.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(e):!1)}destroy(){for(let e of this.elements)e.destroy()}},jd=class{constructor(e,n,r,a){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(e,n,r,a)}update(e,n,r,a){this.height!=n&&(this.height=n,this.dom.style.height=n+"px"),this.above!=r&&(this.dom.style.marginTop=(this.above=r)?r+"px":""),PD(this.markers,a)||this.setMarkers(e,a)}setMarkers(e,n){let r="cm-gutterElement",a=this.dom.firstChild;for(let s=0,i=0;;){let o=i,l=s<n.length?n[s++]:null,u=!1;if(l){let c=l.elementClass;c&&(r+=" "+c);for(let d=i;d<this.markers.length;d++)if(this.markers[d].compare(l)){o=d,u=!0;break}}else o=this.markers.length;for(;i<o;){let c=this.markers[i++];if(c.toDOM){c.destroy(a);let d=a.nextSibling;a.remove(),a=d}}if(!l)break;l.toDOM&&(u?a=a.nextSibling:this.dom.insertBefore(l.toDOM(e),a)),u&&i++}this.dom.className=r,this.markers=n}destroy(){this.setMarkers(null,[])}};function PD(t,e){if(t.length!=e.length)return!1;for(let n=0;n<t.length;n++)if(!t[n].compare(e[n]))return!1;return!0}var ND=Me.define(),RD=Me.define(),Fo=Me.define({combine(t){return No(t,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(e,n){let r=Object.assign({},e);for(let a in n){let s=r[a],i=n[a];r[a]=s?(o,l,u)=>s(o,l,u)||i(o,l,u):i}return r}})}}),Cu=class extends Bn{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}};function Vp(t,e){return t.state.facet(Fo).formatNumber(e,t.state)}var MD=Su.compute([Fo],t=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(ND)},lineMarker(e,n,r){return r.some(a=>a.toDOM)?null:new Cu(Vp(e,e.state.doc.lineAt(n.from).number))},widgetMarker:(e,n,r)=>{for(let a of e.state.facet(RD)){let s=a(e,n,r);if(s)return s}return null},lineMarkerChange:e=>e.startState.facet(Fo)!=e.state.facet(Fo),initialSpacer(e){return new Cu(Vp(e,qk(e.state.doc.lines)))},updateSpacer(e,n){let r=Vp(n.view,qk(n.view.state.doc.lines));return r==e.number?e:new Cu(r)},domEventHandlers:t.facet(Fo).domEventHandlers,side:"before"}));function Kd(t={}){return[Fo.of(t),qS(),MD]}function qk(t){let e=9;for(;e<t;)e=e*10+9;return e}var TD=new class extends Bn{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},DD=Rd.compute(["selection"],t=>{let e=[],n=-1;for(let r of t.selection.ranges){let a=t.doc.lineAt(r.head).from;a>n&&(n=a,e.push(TD.range(a)))}return wt.of(e)});function $S(){return DD}var FD=0,Mu=class{constructor(e,n){this.from=e,this.to=n}},rt=class{constructor(e={}){this.id=FD++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=e.combine||null}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof e!="function"&&(e=Lr.match(e)),n=>{let r=e(n);return r===void 0?null:[this,r]}}};rt.closedBy=new rt({deserialize:t=>t.split(" ")});rt.openedBy=new rt({deserialize:t=>t.split(" ")});rt.group=new rt({deserialize:t=>t.split(" ")});rt.isolate=new rt({deserialize:t=>{if(t&&t!="rtl"&&t!="ltr"&&t!="auto")throw new RangeError("Invalid value for isolate: "+t);return t||"auto"}});rt.contextHash=new rt({perNode:!0});rt.lookAhead=new rt({perNode:!0});rt.mounted=new rt({perNode:!0});var Di=class{constructor(e,n,r,a=!1){this.tree=e,this.overlay=n,this.parser=r,this.bracketed=a}static get(e){return e&&e.props&&e.props[rt.mounted.id]}},ED=Object.create(null),Lr=class t{constructor(e,n,r,a=0){this.name=e,this.props=n,this.id=r,this.flags=a}static define(e){let n=e.props&&e.props.length?Object.create(null):ED,r=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),a=new t(e.name||"",n,e.id,r);if(e.props){for(let s of e.props)if(Array.isArray(s)||(s=s(a)),s){if(s[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");n[s[0].id]=s[1]}}return a}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e=="string"){if(this.name==e)return!0;let n=this.prop(rt.group);return n?n.indexOf(e)>-1:!1}return this.id==e}static match(e){let n=Object.create(null);for(let r in e)for(let a of r.split(" "))n[a]=e[r];return r=>{for(let a=r.prop(rt.group),s=-1;s<(a?a.length:0);s++){let i=n[s<0?r.name:a[s]];if(i)return i}}}};Lr.none=new Lr("",Object.create(null),0,8);var Xd=new WeakMap,KS=new WeakMap,an;(function(t){t[t.ExcludeBuffers=1]="ExcludeBuffers",t[t.IncludeAnonymous=2]="IncludeAnonymous",t[t.IgnoreMounts=4]="IgnoreMounts",t[t.IgnoreOverlays=8]="IgnoreOverlays",t[t.EnterBracketed=16]="EnterBracketed"})(an||(an={}));var _n=class t{constructor(e,n,r,a,s){if(this.type=e,this.children=n,this.positions=r,this.length=a,this.props=null,s&&s.length){this.props=Object.create(null);for(let[i,o]of s)this.props[typeof i=="number"?i:i.id]=o}}toString(){let e=Di.get(this);if(e&&!e.overlay)return e.tree.toString();let n="";for(let r of this.children){let a=r.toString();a&&(n&&(n+=","),n+=a)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(n.length?"("+n+")":""):n}cursor(e=0){return new Fu(this.topNode,e)}cursorAt(e,n=0,r=0){let a=Xd.get(this)||this.topNode,s=new Fu(a);return s.moveTo(e,n),Xd.set(this,s._tree),s}get topNode(){return new Fa(this,0,0,null)}resolve(e,n=0){let r=Tu(Xd.get(this)||this.topNode,e,n,!1);return Xd.set(this,r),r}resolveInner(e,n=0){let r=Tu(KS.get(this)||this.topNode,e,n,!0);return KS.set(this,r),r}resolveStack(e,n=0){return OD(this,e,n)}iterate(e){let{enter:n,leave:r,from:a=0,to:s=this.length}=e,i=e.mode||0,o=(i&an.IncludeAnonymous)>0;for(let l=this.cursor(i|an.IncludeAnonymous);;){let u=!1;if(l.from<=s&&l.to>=a&&(!o&&l.type.isAnonymous||n(l)!==!1)){if(l.firstChild())continue;u=!0}for(;u&&r&&(o||!l.type.isAnonymous)&&r(l),!l.nextSibling();){if(!l.parent())return;u=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let n in this.props)e.push([+n,this.props[n]]);return e}balance(e={}){return this.children.length<=8?this:Jm(Lr.none,this.children,this.positions,0,this.children.length,0,this.length,(n,r,a)=>new t(this.type,n,r,a,this.propValues),e.makeTree||((n,r,a)=>new t(Lr.none,n,r,a)))}static build(e){return BD(e)}};_n.empty=new _n(Lr.none,[],[],0);var Vm=class t{constructor(e,n){this.buffer=e,this.index=n}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new t(this.buffer,this.index)}},js=class t{constructor(e,n,r){this.buffer=e,this.length=n,this.set=r}get type(){return Lr.none}toString(){let e=[];for(let n=0;n<this.buffer.length;)e.push(this.childString(n)),n=this.buffer[n+3];return e.join(",")}childString(e){let n=this.buffer[e],r=this.buffer[e+3],a=this.set.types[n],s=a.name;if(/\W/.test(s)&&!a.isError&&(s=JSON.stringify(s)),e+=4,r==e)return s;let i=[];for(;e<r;)i.push(this.childString(e)),e=this.buffer[e+3];return s+"("+i.join(",")+")"}findChild(e,n,r,a,s){let{buffer:i}=this,o=-1;for(let l=e;l!=n&&!(JS(s,a,i[l+1],i[l+2])&&(o=l,r>0));l=i[l+3]);return o}slice(e,n,r){let a=this.buffer,s=new Uint16Array(n-e),i=0;for(let o=e,l=0;o<n;){s[l++]=a[o++],s[l++]=a[o++]-r;let u=s[l++]=a[o++]-r;s[l++]=a[o++]-e,i=Math.max(i,u)}return new t(s,i,this.set)}};function JS(t,e,n,r){switch(t){case-2:return n<e;case-1:return r>=e&&n<e;case 0:return n<e&&r>e;case 1:return n<=e&&r>e;case 2:return r>e;case 4:return!0}}function Tu(t,e,n,r){for(var a;t.from==t.to||(n<1?t.from>=e:t.from>e)||(n>-1?t.to<=e:t.to<e);){let i=!r&&t instanceof Fa&&t.index<0?null:t.parent;if(!i)return t;t=i}let s=r?0:an.IgnoreOverlays;if(r)for(let i=t,o=i.parent;o;i=o,o=i.parent)i instanceof Fa&&i.index<0&&((a=o.enter(e,n,s))===null||a===void 0?void 0:a.from)!=i.from&&(t=o);for(;;){let i=t.enter(e,n,s);if(!i)return t;t=i}}var Jd=class{cursor(e=0){return new Fu(this,e)}getChild(e,n=null,r=null){let a=XS(this,e,n,r);return a.length?a[0]:null}getChildren(e,n=null,r=null){return XS(this,e,n,r)}resolve(e,n=0){return Tu(this,e,n,!1)}resolveInner(e,n=0){return Tu(this,e,n,!0)}matchContext(e){return qm(this.parent,e)}enterUnfinishedNodesBefore(e){let n=this.childBefore(e),r=this;for(;n;){let a=n.lastChild;if(!a||a.to!=n.to)break;a.type.isError&&a.from==a.to?(r=n,n=a.prevSibling):n=a}return r}get node(){return this}get next(){return this.parent}},Fa=class t extends Jd{constructor(e,n,r,a){super(),this._tree=e,this.from=n,this.index=r,this._parent=a}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(e,n,r,a,s=0){for(let i=this;;){for(let{children:o,positions:l}=i._tree,u=n>0?o.length:-1;e!=u;e+=n){let c=o[e],d=l[e]+i.from,f;if(!(!(s&an.EnterBracketed&&c instanceof _n&&(f=Di.get(c))&&!f.overlay&&f.bracketed&&r>=d&&r<=d+c.length)&&!JS(a,r,d,d+c.length))){if(c instanceof js){if(s&an.ExcludeBuffers)continue;let h=c.findChild(0,c.buffer.length,n,r-d,a);if(h>-1)return new Du(new $m(i,c,e,d),null,h)}else if(s&an.IncludeAnonymous||!c.type.isAnonymous||Ym(c)){let h;if(!(s&an.IgnoreMounts)&&(h=Di.get(c))&&!h.overlay)return new t(h.tree,d,e,i);let p=new t(c,d,e,i);return s&an.IncludeAnonymous||!p.type.isAnonymous?p:p.nextChild(n<0?c.children.length-1:0,n,r,a,s)}}}if(s&an.IncludeAnonymous||!i.type.isAnonymous||(i.index>=0?e=i.index+n:e=n<0?-1:i._parent._tree.children.length,i=i._parent,!i))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}prop(e){return this._tree.prop(e)}enter(e,n,r=0){let a;if(!(r&an.IgnoreOverlays)&&(a=Di.get(this._tree))&&a.overlay){let s=e-this.from,i=r&an.EnterBracketed&&a.bracketed;for(let{from:o,to:l}of a.overlay)if((n>0||i?o<=s:o<s)&&(n<0||i?l>=s:l>s))return new t(a.tree,a.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,n,r)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}};function XS(t,e,n,r){let a=t.cursor(),s=[];if(!a.firstChild())return s;if(n!=null){for(let i=!1;!i;)if(i=a.type.is(n),!a.nextSibling())return s}for(;;){if(r!=null&&a.type.is(r))return s;if(a.type.is(e)&&s.push(a.node),!a.nextSibling())return r==null?s:[]}}function qm(t,e,n=e.length-1){for(let r=t;n>=0;r=r.parent){if(!r)return!1;if(!r.type.isAnonymous){if(e[n]&&e[n]!=r.name)return!1;n--}}return!0}var $m=class{constructor(e,n,r,a){this.parent=e,this.buffer=n,this.index=r,this.start=a}},Du=class t extends Jd{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,n,r){super(),this.context=e,this._parent=n,this.index=r,this.type=e.buffer.set.types[e.buffer.buffer[r]]}child(e,n,r){let{buffer:a}=this.context,s=a.findChild(this.index+4,a.buffer[this.index+3],e,n-this.context.start,r);return s<0?null:new t(this.context,this,s)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}prop(e){return this.type.prop(e)}enter(e,n,r=0){if(r&an.ExcludeBuffers)return null;let{buffer:a}=this.context,s=a.findChild(this.index+4,a.buffer[this.index+3],n>0?1:-1,e-this.context.start,n);return s<0?null:new t(this.context,this,s)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,n=e.buffer[this.index+3];return n<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new t(this.context,this._parent,n):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,n=this._parent?this._parent.index+4:0;return this.index==n?this.externalSibling(-1):new t(this.context,this._parent,e.findChild(n,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],n=[],{buffer:r}=this.context,a=this.index+4,s=r.buffer[this.index+3];if(s>a){let i=r.buffer[this.index+1];e.push(r.slice(a,s,i)),n.push(0)}return new _n(this.type,e,n,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}};function ZS(t){if(!t.length)return null;let e=0,n=t[0];for(let s=1;s<t.length;s++){let i=t[s];(i.from>n.from||i.to<n.to)&&(n=i,e=s)}let r=n instanceof Fa&&n.index<0?null:n.parent,a=t.slice();return r?a[e]=r:a.splice(e,1),new Km(a,n)}var Km=class{constructor(e,n){this.heads=e,this.node=n}get next(){return ZS(this.heads)}};function OD(t,e,n){let r=t.resolveInner(e,n),a=null;for(let s=r instanceof Fa?r:r.context.parent;s;s=s.parent)if(s.index<0){let i=s.parent;(a||(a=[r])).push(i.resolve(e,n)),s=i}else{let i=Di.get(s.tree);if(i&&i.overlay&&i.overlay[0].from<=e&&i.overlay[i.overlay.length-1].to>=e){let o=new Fa(i.tree,i.overlay[0].from+s.from,-1,s);(a||(a=[r])).push(Tu(o,e,n,!1))}}return a?ZS(a):r}var Fu=class{get name(){return this.type.name}constructor(e,n=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=n&~an.EnterBracketed,e instanceof Fa)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let r=e._parent;r;r=r._parent)this.stack.unshift(r.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,n){this.index=e;let{start:r,buffer:a}=this.buffer;return this.type=n||a.set.types[a.buffer[e]],this.from=r+a.buffer[e+1],this.to=r+a.buffer[e+2],!0}yield(e){return e?e instanceof Fa?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,n,r){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,n,r,this.mode));let{buffer:a}=this.buffer,s=a.findChild(this.index+4,a.buffer[this.index+3],e,n-this.buffer.start,r);return s<0?!1:(this.stack.push(this.index),this.yieldBuf(s))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,n,r=this.mode){return this.buffer?r&an.ExcludeBuffers?!1:this.enterChild(1,e,n):this.yield(this._tree.enter(e,n,r))}parent(){if(!this.buffer)return this.yieldNode(this.mode&an.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&an.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:n}=this.buffer,r=this.stack.length-1;if(e<0){let a=r<0?0:this.stack[r]+4;if(this.index!=a)return this.yieldBuf(n.findChild(a,this.index,-1,0,4))}else{let a=n.buffer[this.index+3];if(a<(r<0?n.buffer.length:n.buffer[this.stack[r]+3]))return this.yieldBuf(a)}return r<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let n,r,{buffer:a}=this;if(a){if(e>0){if(this.index<a.buffer.buffer.length)return!1}else for(let s=0;s<this.index;s++)if(a.buffer.buffer[s+3]<this.index)return!1;({index:n,parent:r}=a)}else({index:n,_parent:r}=this._tree);for(;r;{index:n,_parent:r}=r)if(n>-1)for(let s=n+e,i=e<0?-1:r._tree.children.length;s!=i;s+=e){let o=r._tree.children[s];if(this.mode&an.IncludeAnonymous||o instanceof js||!o.type.isAnonymous||Ym(o))return!1}return!0}move(e,n){if(n&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,n=0){for(;(this.from==this.to||(n<1?this.from>=e:this.from>e)||(n>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,n););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,n=null,r=0;if(e&&e.context==this.buffer)e:for(let a=this.index,s=this.stack.length;s>=0;){for(let i=e;i;i=i._parent)if(i.index==a){if(a==this.index)return i;n=i,r=s+1;break e}a=this.stack[--s]}for(let a=r;a<this.stack.length;a++)n=new Du(this.buffer,n,this.stack[a]);return this.bufferNode=new Du(this.buffer,n,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,n){for(let r=0;;){let a=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){r++;continue}this.type.isAnonymous||(a=!0)}for(;;){if(a&&n&&n(this),a=this.type.isAnonymous,!r)return;if(this.nextSibling())break;this.parent(),r--,a=!0}}}matchContext(e){if(!this.buffer)return qm(this.node.parent,e);let{buffer:n}=this.buffer,{types:r}=n.set;for(let a=e.length-1,s=this.stack.length-1;a>=0;s--){if(s<0)return qm(this._tree,e,a);let i=r[n.buffer[this.stack[s]]];if(!i.isAnonymous){if(e[a]&&e[a]!=i.name)return!1;a--}}return!0}};function Ym(t){return t.children.some(e=>e instanceof js||!e.type.isAnonymous||Ym(e))}function BD(t){var e;let{buffer:n,nodeSet:r,maxBufferLength:a=1024,reused:s=[],minRepeatType:i=r.types.length}=t,o=Array.isArray(n)?new Vm(n,n.length):n,l=r.types,u=0,c=0;function d(L,P,w,k,_,M){let{id:R,start:U,end:v,size:T}=o,V=c,Y=u;if(T<0)if(o.next(),T==-1){let te=s[R];w.push(te),k.push(U-L);return}else if(T==-3){u=R;return}else if(T==-4){c=R;return}else throw new RangeError(`Unrecognized record size: ${T}`);let N=l[R],A,B,K=U-L;if(v-U<=a&&(B=m(o.pos-P,_))){let te=new Uint16Array(B.size-B.skip),ne=o.pos-B.size,pe=te.length;for(;o.pos>ne;)pe=x(B.start,te,pe);A=new js(te,v-B.start,r),K=B.start-L}else{let te=o.pos-T;o.next();let ne=[],pe=[],Se=R>=i?R:-1,le=0,re=v;for(;o.pos>te;)Se>=0&&o.id==Se&&o.size>=0?(o.end<=re-a&&(p(ne,pe,U,le,o.end,re,Se,V,Y),le=ne.length,re=o.end),o.next()):M>2500?f(U,te,ne,pe):d(U,te,ne,pe,Se,M+1);if(Se>=0&&le>0&&le<ne.length&&p(ne,pe,U,le,U,re,Se,V,Y),ne.reverse(),pe.reverse(),Se>-1&&le>0){let he=h(N,Y);A=Jm(N,ne,pe,0,ne.length,0,v-U,he,he)}else A=g(N,ne,pe,v-U,V-v,Y)}w.push(A),k.push(K)}function f(L,P,w,k){let _=[],M=0,R=-1;for(;o.pos>P;){let{id:U,start:v,end:T,size:V}=o;if(V>4)o.next();else{if(R>-1&&v<R)break;R<0&&(R=T-a),_.push(U,v,T),M++,o.next()}}if(M){let U=new Uint16Array(M*4),v=_[_.length-2];for(let T=_.length-3,V=0;T>=0;T-=3)U[V++]=_[T],U[V++]=_[T+1]-v,U[V++]=_[T+2]-v,U[V++]=V;w.push(new js(U,_[2]-v,r)),k.push(v-L)}}function h(L,P){return(w,k,_)=>{let M=0,R=w.length-1,U,v;if(R>=0&&(U=w[R])instanceof _n){if(!R&&U.type==L&&U.length==_)return U;(v=U.prop(rt.lookAhead))&&(M=k[R]+U.length+v)}return g(L,w,k,_,M,P)}}function p(L,P,w,k,_,M,R,U,v){let T=[],V=[];for(;L.length>k;)T.push(L.pop()),V.push(P.pop()+w-_);L.push(g(r.types[R],T,V,M-_,U-M,v)),P.push(_-w)}function g(L,P,w,k,_,M,R){if(M){let U=[rt.contextHash,M];R=R?[U].concat(R):[U]}if(_>25){let U=[rt.lookAhead,_];R=R?[U].concat(R):[U]}return new _n(L,P,w,k,R)}function m(L,P){let w=o.fork(),k=0,_=0,M=0,R=w.end-a,U={size:0,start:0,skip:0};e:for(let v=w.pos-L;w.pos>v;){let T=w.size;if(w.id==P&&T>=0){U.size=k,U.start=_,U.skip=M,M+=4,k+=4,w.next();continue}let V=w.pos-T;if(T<0||V<v||w.start<R)break;let Y=w.id>=i?4:0,N=w.start;for(w.next();w.pos>V;){if(w.size<0)if(w.size==-3||w.size==-4)Y+=4;else break e;else w.id>=i&&(Y+=4);w.next()}_=N,k+=T,M+=Y}return(P<0||k==L)&&(U.size=k,U.start=_,U.skip=M),U.size>4?U:void 0}function x(L,P,w){let{id:k,start:_,end:M,size:R}=o;if(o.next(),R>=0&&k<i){let U=w;if(R>4){let v=o.pos-(R-4);for(;o.pos>v;)w=x(L,P,w)}P[--w]=U,P[--w]=M-L,P[--w]=_-L,P[--w]=k}else R==-3?u=k:R==-4&&(c=k);return w}let y=[],b=[];for(;o.pos>0;)d(t.start||0,t.bufferStart||0,y,b,-1,0);let C=(e=t.length)!==null&&e!==void 0?e:y.length?b[0]+y[0].length:0;return new _n(l[t.topID],y.reverse(),b.reverse(),C)}var YS=new WeakMap;function Yd(t,e){if(!t.isAnonymous||e instanceof js||e.type!=t)return 1;let n=YS.get(e);if(n==null){n=1;for(let r of e.children){if(r.type!=t||!(r instanceof _n)){n=1;break}n+=Yd(t,r)}YS.set(e,n)}return n}function Jm(t,e,n,r,a,s,i,o,l){let u=0;for(let p=r;p<a;p++)u+=Yd(t,e[p]);let c=Math.ceil(u*1.5/8),d=[],f=[];function h(p,g,m,x,y){for(let b=m;b<x;){let C=b,L=g[b],P=Yd(t,p[b]);for(b++;b<x;b++){let w=Yd(t,p[b]);if(P+w>=c)break;P+=w}if(b==C+1){if(P>c){let w=p[C];h(w.children,w.positions,0,w.children.length,g[C]+y);continue}d.push(p[C])}else{let w=g[b-1]+p[b-1].length-L;d.push(Jm(t,p,g,C,b,L,w,null,l))}f.push(L+y-s)}}return h(e,n,r,a,0),(o||l)(d,f,i)}var Fi=class t{constructor(e,n,r,a,s=!1,i=!1){this.from=e,this.to=n,this.tree=r,this.offset=a,this.open=(s?1:0)|(i?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(e,n=[],r=!1){let a=[new t(0,e.length,e,0,!1,r)];for(let s of n)s.to>e.length&&a.push(s);return a}static applyChanges(e,n,r=128){if(!n.length)return e;let a=[],s=1,i=e.length?e[0]:null;for(let o=0,l=0,u=0;;o++){let c=o<n.length?n[o]:null,d=c?c.fromA:1e9;if(d-l>=r)for(;i&&i.from<d;){let f=i;if(l>=f.from||d<=f.to||u){let h=Math.max(f.from,l)-u,p=Math.min(f.to,d)-u;f=h>=p?null:new t(h,p,f.tree,f.offset+u,o>0,!!c)}if(f&&a.push(f),i.to>d)break;i=s<e.length?e[s++]:null}if(!c)break;l=c.toA,u=c.toA-c.toB}return a}},Zd=class{startParse(e,n,r){return typeof e=="string"&&(e=new Xm(e)),r=r?r.length?r.map(a=>new Mu(a.from,a.to)):[new Mu(0,0)]:[new Mu(0,e.length)],this.createParse(e,n||[],r)}parse(e,n,r){let a=this.startParse(e,n,r);for(;;){let s=a.advance();if(s)return s}}},Xm=class{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,n){return this.string.slice(e,n)}};var t6=new rt({perNode:!0});var _D=0,ca=class t{constructor(e,n,r,a){this.name=e,this.set=n,this.base=r,this.modified=a,this.id=_D++}toString(){let{name:e}=this;for(let n of this.modified)n.name&&(e=`${n.name}(${e})`);return e}static define(e,n){let r=typeof e=="string"?e:"?";if(e instanceof t&&(n=e),n?.base)throw new Error("Can not derive from a modified tag");let a=new t(r,[],null,[]);if(a.set.push(a),n)for(let s of n.set)a.set.push(s);return a}static defineModifier(e){let n=new nf(e);return r=>r.modified.indexOf(n)>-1?r:nf.get(r.base||r,r.modified.concat(n).sort((a,s)=>a.id-s.id))}},HD=0,nf=class t{constructor(e){this.name=e,this.instances=[],this.id=HD++}static get(e,n){if(!n.length)return e;let r=n[0].instances.find(o=>o.base==e&&UD(n,o.modified));if(r)return r;let a=[],s=new ca(e.name,a,e,n);for(let o of n)o.instances.push(s);let i=GD(n);for(let o of e.set)if(!o.modified.length)for(let l of i)a.push(t.get(o,l));return s}};function UD(t,e){return t.length==e.length&&t.every((n,r)=>n==e[r])}function GD(t){let e=[[]];for(let n=0;n<t.length;n++)for(let r=0,a=e.length;r<a;r++)e.push(e[r].concat(t[n]));return e.sort((n,r)=>r.length-n.length)}function tC(t){let e=Object.create(null);for(let n in t){let r=t[n];Array.isArray(r)||(r=[r]);for(let a of n.split(" "))if(a){let s=[],i=2,o=a;for(let d=0;;){if(o=="..."&&d>0&&d+3==a.length){i=1;break}let f=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(o);if(!f)throw new RangeError("Invalid path: "+a);if(s.push(f[0]=="*"?"":f[0][0]=='"'?JSON.parse(f[0]):f[0]),d+=f[0].length,d==a.length)break;let h=a[d++];if(d==a.length&&h=="!"){i=0;break}if(h!="/")throw new RangeError("Invalid path: "+a);o=a.slice(d)}let l=s.length-1,u=s[l];if(!u)throw new RangeError("Invalid path: "+a);let c=new Oi(r,i,l>0?s.slice(0,l):null);e[u]=c.sort(e[u])}}return nC.add(e)}var nC=new rt({combine(t,e){let n,r,a;for(;t||e;){if(!t||e&&t.depth<=e.depth?(a=e,e=e.next):(a=t,t=t.next),n&&n.mode==a.mode&&!a.context&&!n.context)continue;let s=new Oi(a.tags,a.mode,a.context);n?n.next=s:r=s,n=s}return r}}),Oi=class{constructor(e,n,r,a){this.tags=e,this.mode=n,this.context=r,this.next=a}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}};Oi.empty=new Oi([],2,null);function tg(t,e){let n=Object.create(null);for(let s of t)if(!Array.isArray(s.tag))n[s.tag.id]=s.class;else for(let i of s.tag)n[i.id]=s.class;let{scope:r,all:a=null}=e||{};return{style:s=>{let i=a;for(let o of s)for(let l of o.set){let u=n[l.id];if(u){i=i?i+" "+u:u;break}}return i},scope:r}}function WD(t,e){let n=null;for(let r of t){let a=r.style(e);a&&(n=n?n+" "+a:a)}return n}function ng(t,e,n,r=0,a=t.length){let s=new Qm(r,Array.isArray(e)?e:[e],n);s.highlightRange(t.cursor(),r,a,"",s.highlighters),s.flush(a)}var Qm=class{constructor(e,n,r){this.at=e,this.highlighters=n,this.span=r,this.class=""}startSpan(e,n){n!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=n)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,n,r,a,s){let{type:i,from:o,to:l}=e;if(o>=r||l<=n)return;i.isTop&&(s=this.highlighters.filter(h=>!h.scope||h.scope(i)));let u=a,c=zD(e)||Oi.empty,d=WD(s,c.tags);if(d&&(u&&(u+=" "),u+=d,c.mode==1&&(a+=(a?" ":"")+d)),this.startSpan(Math.max(n,o),u),c.opaque)return;let f=e.tree&&e.tree.prop(rt.mounted);if(f&&f.overlay){let h=e.node.enter(f.overlay[0].from+o,1),p=this.highlighters.filter(m=>!m.scope||m.scope(f.tree.type)),g=e.firstChild();for(let m=0,x=o;;m++){let y=m<f.overlay.length?f.overlay[m]:null,b=y?y.from+o:l,C=Math.max(n,x),L=Math.min(r,b);if(C<L&&g)for(;e.from<L&&(this.highlightRange(e,C,L,a,s),this.startSpan(Math.min(L,e.to),u),!(e.to>=b||!e.nextSibling())););if(!y||b>r)break;x=y.to+o,x>n&&(this.highlightRange(h.cursor(),Math.max(n,y.from+o),Math.min(r,x),"",p),this.startSpan(Math.min(r,x),u))}g&&e.parent()}else if(e.firstChild()){f&&(a="");do if(!(e.to<=n)){if(e.from>=r)break;this.highlightRange(e,n,r,a,s),this.startSpan(Math.min(r,e.to),u)}while(e.nextSibling());e.parent()}}};function zD(t){let e=t.type.prop(nC);for(;e&&e.context&&!t.matchContext(e.context);)e=e.next;return e||null}var ye=ca.define,Qd=ye(),Vs=ye(),QS=ye(Vs),eC=ye(Vs),qs=ye(),ef=ye(qs),Zm=ye(qs),Ba=ye(),Ei=ye(Ba),Ea=ye(),Oa=ye(),eg=ye(),Eu=ye(eg),tf=ye(),ve={comment:Qd,lineComment:ye(Qd),blockComment:ye(Qd),docComment:ye(Qd),name:Vs,variableName:ye(Vs),typeName:QS,tagName:ye(QS),propertyName:eC,attributeName:ye(eC),className:ye(Vs),labelName:ye(Vs),namespace:ye(Vs),macroName:ye(Vs),literal:qs,string:ef,docString:ye(ef),character:ye(ef),attributeValue:ye(ef),number:Zm,integer:ye(Zm),float:ye(Zm),bool:ye(qs),regexp:ye(qs),escape:ye(qs),color:ye(qs),url:ye(qs),keyword:Ea,self:ye(Ea),null:ye(Ea),atom:ye(Ea),unit:ye(Ea),modifier:ye(Ea),operatorKeyword:ye(Ea),controlKeyword:ye(Ea),definitionKeyword:ye(Ea),moduleKeyword:ye(Ea),operator:Oa,derefOperator:ye(Oa),arithmeticOperator:ye(Oa),logicOperator:ye(Oa),bitwiseOperator:ye(Oa),compareOperator:ye(Oa),updateOperator:ye(Oa),definitionOperator:ye(Oa),typeOperator:ye(Oa),controlOperator:ye(Oa),punctuation:eg,separator:ye(eg),bracket:Eu,angleBracket:ye(Eu),squareBracket:ye(Eu),paren:ye(Eu),brace:ye(Eu),content:Ba,heading:Ei,heading1:ye(Ei),heading2:ye(Ei),heading3:ye(Ei),heading4:ye(Ei),heading5:ye(Ei),heading6:ye(Ei),contentSeparator:ye(Ba),list:ye(Ba),quote:ye(Ba),emphasis:ye(Ba),strong:ye(Ba),link:ye(Ba),monospace:ye(Ba),strikethrough:ye(Ba),inserted:ye(),deleted:ye(),changed:ye(),invalid:ye(),meta:tf,documentMeta:ye(tf),annotation:ye(tf),processingInstruction:ye(tf),definition:ca.defineModifier("definition"),constant:ca.defineModifier("constant"),function:ca.defineModifier("function"),standard:ca.defineModifier("standard"),local:ca.defineModifier("local"),special:ca.defineModifier("special")};for(let t in ve){let e=ve[t];e instanceof ca&&(e.name=t)}var a6=tg([{tag:ve.link,class:"tok-link"},{tag:ve.heading,class:"tok-heading"},{tag:ve.emphasis,class:"tok-emphasis"},{tag:ve.strong,class:"tok-strong"},{tag:ve.keyword,class:"tok-keyword"},{tag:ve.atom,class:"tok-atom"},{tag:ve.bool,class:"tok-bool"},{tag:ve.url,class:"tok-url"},{tag:ve.labelName,class:"tok-labelName"},{tag:ve.inserted,class:"tok-inserted"},{tag:ve.deleted,class:"tok-deleted"},{tag:ve.literal,class:"tok-literal"},{tag:ve.string,class:"tok-string"},{tag:ve.number,class:"tok-number"},{tag:[ve.regexp,ve.escape,ve.special(ve.string)],class:"tok-string2"},{tag:ve.variableName,class:"tok-variableName"},{tag:ve.local(ve.variableName),class:"tok-variableName tok-local"},{tag:ve.definition(ve.variableName),class:"tok-variableName tok-definition"},{tag:ve.special(ve.variableName),class:"tok-variableName2"},{tag:ve.definition(ve.propertyName),class:"tok-propertyName tok-definition"},{tag:ve.typeName,class:"tok-typeName"},{tag:ve.namespace,class:"tok-namespace"},{tag:ve.className,class:"tok-className"},{tag:ve.macroName,class:"tok-macroName"},{tag:ve.propertyName,class:"tok-propertyName"},{tag:ve.operator,class:"tok-operator"},{tag:ve.comment,class:"tok-comment"},{tag:ve.meta,class:"tok-meta"},{tag:ve.invalid,class:"tok-invalid"},{tag:ve.punctuation,class:"tok-punctuation"}]);var rg,Bu=new rt;var jD=new rt,zr=class{constructor(e,n,r=[],a=""){this.data=e,this.name=a,It.prototype.hasOwnProperty("tree")||Object.defineProperty(It.prototype,"tree",{get(){return ls(this)}}),this.parser=n,this.extension=[$s.of(this),It.languageData.of((s,i,o)=>{let l=rC(s,i,o),u=l.type.prop(Bu);if(!u)return[];let c=s.facet(u),d=l.type.prop(jD);if(d){let f=l.resolve(i-l.from,o);for(let h of d)if(h.test(f,s)){let p=s.facet(h.facet);return h.type=="replace"?p:p.concat(c)}}return c})].concat(r)}isActiveAt(e,n,r=-1){return rC(e,n,r).type.prop(Bu)==this.data}findRegions(e){let n=e.facet($s);if(n?.data==this.data)return[{from:0,to:e.doc.length}];if(!n||!n.allowsNesting)return[];let r=[],a=(s,i)=>{if(s.prop(Bu)==this.data){r.push({from:i,to:i+s.length});return}let o=s.prop(rt.mounted);if(o){if(o.tree.prop(Bu)==this.data){if(o.overlay)for(let l of o.overlay)r.push({from:l.from+i,to:l.to+i});else r.push({from:i,to:i+s.length});return}else if(o.overlay){let l=r.length;if(a(o.tree,o.overlay[0].from+i),r.length>l)return}}for(let l=0;l<s.children.length;l++){let u=s.children[l];u instanceof _n&&a(u,s.positions[l]+i)}};return a(ls(e),0),r}get allowsNesting(){return!0}};zr.setState=pt.define();function rC(t,e,n){let r=t.facet($s),a=ls(t).topNode;if(!r||r.allowsNesting)for(let s=a;s;s=s.enter(e,n,an.ExcludeBuffers|an.EnterBracketed))s.type.isTop&&(a=s);return a}function ls(t){let e=t.field(zr.state,!1);return e?e.tree:_n.empty}var ig=class{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,n){let r=this.cursorPos-this.string.length;return e<r||n>=this.cursorPos?this.doc.sliceString(e,n):this.string.slice(e-r,n-r)}},Ou=null,og=class t{constructor(e,n,r=[],a,s,i,o,l){this.parser=e,this.state=n,this.fragments=r,this.tree=a,this.treeLen=s,this.viewport=i,this.skipped=o,this.scheduleOn=l,this.parse=null,this.tempSkipped=[]}static create(e,n,r){return new t(e,n,[],_n.empty,0,r,[],null)}startParse(){return this.parser.startParse(new ig(this.state.doc),this.fragments)}work(e,n){return n!=null&&n>=this.state.doc.length&&(n=void 0),this.tree!=_n.empty&&this.isDone(n??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var r;if(typeof e=="number"){let a=Date.now()+e;e=()=>Date.now()>a}for(this.parse||(this.parse=this.startParse()),n!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>n)&&n<this.state.doc.length&&this.parse.stopAt(n);;){let a=this.parse.advance();if(a)if(this.fragments=this.withoutTempSkipped(Fi.addTree(a,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(r=this.parse.stoppedAt)!==null&&r!==void 0?r:this.state.doc.length,this.tree=a,this.parse=null,this.treeLen<(n??this.state.doc.length))this.parse=this.startParse();else return!0;if(e())return!1}})}takeTree(){let e,n;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(n=this.parse.advance()););}),this.treeLen=e,this.tree=n,this.fragments=this.withoutTempSkipped(Fi.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let n=Ou;Ou=this;try{return e()}finally{Ou=n}}withoutTempSkipped(e){for(let n;n=this.tempSkipped.pop();)e=aC(e,n.from,n.to);return e}changes(e,n){let{fragments:r,tree:a,treeLen:s,viewport:i,skipped:o}=this;if(this.takeTree(),!e.empty){let l=[];if(e.iterChangedRanges((u,c,d,f)=>l.push({fromA:u,toA:c,fromB:d,toB:f})),r=Fi.applyChanges(r,l),a=_n.empty,s=0,i={from:e.mapPos(i.from,-1),to:e.mapPos(i.to,1)},this.skipped.length){o=[];for(let u of this.skipped){let c=e.mapPos(u.from,1),d=e.mapPos(u.to,-1);c<d&&o.push({from:c,to:d})}}}return new t(this.parser,n,r,a,s,i,o,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let n=this.skipped.length;for(let r=0;r<this.skipped.length;r++){let{from:a,to:s}=this.skipped[r];a<e.to&&s>e.from&&(this.fragments=aC(this.fragments,a,s),this.skipped.splice(r--,1))}return this.skipped.length>=n?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,n){this.skipped.push({from:e,to:n})}static getSkippingParser(e){return new class extends Zd{createParse(n,r,a){let s=a[0].from,i=a[a.length-1].to;return{parsedPos:s,advance(){let l=Ou;if(l){for(let u of a)l.tempSkipped.push(u);e&&(l.scheduleOn=l.scheduleOn?Promise.all([l.scheduleOn,e]):e)}return this.parsedPos=i,new _n(Lr.none,[],[],i-s)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let n=this.fragments;return this.treeLen>=e&&n.length&&n[0].from==0&&n[0].to>=e}static get(){return Ou}};function aC(t,e,n){return Fi.applyChanges(t,[{fromA:e,toA:n,fromB:e,toB:n}])}var _u=class t{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let n=this.context.changes(e.changes,e.state),r=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),n.viewport.to);return n.work(20,r)||n.takeTree(),new t(n)}static init(e){let n=Math.min(3e3,e.doc.length),r=og.create(e.facet($s).parser,e,{from:0,to:n});return r.work(20,n)||r.takeTree(),new t(r)}};zr.state=vn.define({create:_u.init,update(t,e){for(let n of e.effects)if(n.is(zr.setState))return n.value;return e.startState.facet($s)!=e.state.facet($s)?_u.init(e.state):t.apply(e)}});var lC=t=>{let e=setTimeout(()=>t(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(lC=t=>{let e=-1,n=setTimeout(()=>{e=requestIdleCallback(t,{timeout:400})},100);return()=>e<0?clearTimeout(n):cancelIdleCallback(e)});var ag=typeof navigator<"u"&&(!((rg=navigator.scheduling)===null||rg===void 0)&&rg.isInputPending)?()=>navigator.scheduling.isInputPending():null,VD=hr.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let n=this.view.state.field(zr.state).context;(n.updateViewport(e.view.viewport)||this.view.viewport.to>n.treeLen)&&this.scheduleWork(),(e.docChanged||e.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(n)}scheduleWork(){if(this.working)return;let{state:e}=this.view,n=e.field(zr.state);(n.tree!=n.context.tree||!n.context.isDone(e.doc.length))&&(this.working=lC(this.work))}work(e){this.working=null;let n=Date.now();if(this.chunkEnd<n&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=n+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:r,viewport:{to:a}}=this.view,s=r.field(zr.state);if(s.tree==s.context.tree&&s.context.isDone(a+1e5))return;let i=Date.now()+Math.min(this.chunkBudget,100,e&&!ag?Math.max(25,e.timeRemaining()-5):1e9),o=s.context.treeLen<a&&r.doc.length>a+1e3,l=s.context.work(()=>ag&&ag()||Date.now()>i,a+(o?0:1e5));this.chunkBudget-=Date.now()-n,(l||this.chunkBudget<=0)&&(s.context.takeTree(),this.view.dispatch({effects:zr.setState.of(new _u(s.context))})),this.chunkBudget>0&&!(l&&!o)&&this.scheduleWork(),this.checkAsyncSchedule(s.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(n=>oa(this.view.state,n)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),$s=Me.define({combine(t){return t.length?t[0]:null},enables:t=>[zr.state,VD,Pe.contentAttributes.compute([t],e=>{let n=e.facet(t);return n&&n.name?{"data-language":n.name}:{}})]});var qD=Me.define(),rf=Me.define({combine:t=>{if(!t.length)return" ";let e=t[0];if(!e||/\S/.test(e)||Array.from(e).some(n=>n!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(t[0]));return e}});function Hu(t){let e=t.facet(rf);return e.charCodeAt(0)==9?t.tabSize*e.length:e.length}function Uu(t,e){let n="",r=t.tabSize,a=t.facet(rf)[0];if(a==" "){for(;e>=r;)n+=" ",e-=r;a=" "}for(let s=0;s<e;s++)n+=a;return n}function fg(t,e){t instanceof It&&(t=new Bi(t));for(let r of t.state.facet(qD)){let a=r(t,e);if(a!==void 0)return a}let n=ls(t.state);return n.length>=e?KD(t,n,e):null}var Bi=class{constructor(e,n={}){this.state=e,this.options=n,this.unit=Hu(e)}lineAt(e,n=1){let r=this.state.doc.lineAt(e),{simulateBreak:a,simulateDoubleBreak:s}=this.options;return a!=null&&a>=r.from&&a<=r.to?s&&a==e?{text:"",from:e}:(n<0?a<e:a<=e)?{text:r.text.slice(a-r.from),from:a}:{text:r.text.slice(0,a-r.from),from:r.from}:r}textAfterPos(e,n=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:r,from:a}=this.lineAt(e,n);return r.slice(e-a,Math.min(r.length,e+100-a))}column(e,n=1){let{text:r,from:a}=this.lineAt(e,n),s=this.countColumn(r,e-a),i=this.options.overrideIndentation?this.options.overrideIndentation(a):-1;return i>-1&&(s+=i-this.countColumn(r,r.search(/\S|$/))),s}countColumn(e,n=e.length){return Li(e,this.state.tabSize,n)}lineIndent(e,n=1){let{text:r,from:a}=this.lineAt(e,n),s=this.options.overrideIndentation;if(s){let i=s(a);if(i>-1)return i}return this.countColumn(r,r.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}},$D=new rt;function KD(t,e,n){let r=e.resolveStack(n),a=e.resolveInner(n,-1).resolve(n,0).enterUnfinishedNodesBefore(n);if(a!=r.node){let s=[];for(let i=a;i&&!(i.from<r.node.from||i.to>r.node.to||i.from==r.node.from&&i.type==r.node.type);i=i.parent)s.push(i);for(let i=s.length-1;i>=0;i--)r={node:s[i],next:r}}return uC(r,t,n)}function uC(t,e,n){for(let r=t;r;r=r.next){let a=YD(r.node);if(a)return a(lg.create(e,n,r))}return 0}function XD(t){return t.pos==t.options.simulateBreak&&t.options.simulateDoubleBreak}function YD(t){let e=t.type.prop($D);if(e)return e;let n=t.firstChild,r;if(n&&(r=n.type.prop(rt.closedBy))){let a=t.lastChild,s=a&&r.indexOf(a.name)>-1;return i=>eF(i,!0,1,void 0,s&&!XD(i)?a.from:void 0)}return t.parent==null?JD:null}function JD(){return 0}var lg=class t extends Bi{constructor(e,n,r){super(e.state,e.options),this.base=e,this.pos=n,this.context=r}get node(){return this.context.node}static create(e,n,r){return new t(e,n,r)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let n=this.state.doc.lineAt(e.from);for(;;){let r=e.resolve(n.from);for(;r.parent&&r.parent.from==r.from;)r=r.parent;if(ZD(r,e))break;n=this.state.doc.lineAt(r.from)}return this.lineIndent(n.from)}continue(){return uC(this.context.next,this.base,this.pos)}};function ZD(t,e){for(let n=e;n;n=n.parent)if(t==n)return!0;return!1}function QD(t){let e=t.node,n=e.childAfter(e.from),r=e.lastChild;if(!n)return null;let a=t.options.simulateBreak,s=t.state.doc.lineAt(n.from),i=a==null||a<=s.from?s.to:Math.min(s.to,a);for(let o=n.to;;){let l=e.childAfter(o);if(!l||l==r)return null;if(!l.type.isSkipped){if(l.from>=i)return null;let u=/^ */.exec(s.text.slice(n.to-s.from))[0].length;return{from:n.from,to:n.to+u}}o=l.to}}function eF(t,e,n,r,a){let s=t.textAfter,i=s.match(/^\s*/)[0].length,o=r&&s.slice(i,i+r.length)==r||a==t.pos+i,l=e?QD(t):null;return l?o?t.column(l.from):t.column(l.to):t.baseIndent+(o?0:t.unit*n)}var ug=class t{constructor(e,n){this.specs=e;let r;function a(o){let l=dr.newName();return(r||(r=Object.create(null)))["."+l]=o,l}let s=typeof n.all=="string"?n.all:n.all?a(n.all):void 0,i=n.scope;this.scope=i instanceof zr?o=>o.prop(Bu)==i.data:i?o=>o==i:void 0,this.style=tg(e.map(o=>({tag:o.tag,class:o.class||a(Object.assign({},o,{tag:null}))})),{all:s}).style,this.module=r?new dr(r):null,this.themeType=n.themeType}static define(e,n){return new t(e,n||{})}},tF=Me.define(),nF=Me.define({combine(t){return t.length?[t[0]]:null}});function rF(t){let e=t.facet(tF);return e.length?e:t.facet(nF)}function cC(t,e,n){let r=rF(t),a=null;if(r){for(let s of r)if(!s.scope||n&&s.scope(n)){let i=s.style(e);i&&(a=a?a+" "+i:i)}}return a}var h6=ug.define([{tag:ve.meta,color:"#404740"},{tag:ve.link,textDecoration:"underline"},{tag:ve.heading,textDecoration:"underline",fontWeight:"bold"},{tag:ve.emphasis,fontStyle:"italic"},{tag:ve.strong,fontWeight:"bold"},{tag:ve.strikethrough,textDecoration:"line-through"},{tag:ve.keyword,color:"#708"},{tag:[ve.atom,ve.bool,ve.url,ve.contentSeparator,ve.labelName],color:"#219"},{tag:[ve.literal,ve.inserted],color:"#164"},{tag:[ve.string,ve.deleted],color:"#a11"},{tag:[ve.regexp,ve.escape,ve.special(ve.string)],color:"#e40"},{tag:ve.definition(ve.variableName),color:"#00f"},{tag:ve.local(ve.variableName),color:"#30a"},{tag:[ve.typeName,ve.namespace],color:"#085"},{tag:ve.className,color:"#167"},{tag:[ve.special(ve.variableName),ve.macroName],color:"#256"},{tag:ve.definition(ve.propertyName),color:"#00c"},{tag:ve.comment,color:"#940"},{tag:ve.invalid,color:"#f00"}]);var aF=1e4,sF="()[]{}";var iF=new rt;function cg(t,e,n){let r=t.prop(e<0?rt.openedBy:rt.closedBy);if(r)return r;if(t.name.length==1){let a=n.indexOf(t.name);if(a>-1&&a%2==(e<0?1:0))return[n[a+e]]}return null}function dg(t){let e=t.type.prop(iF);return e?e(t.node):t}function _i(t,e,n,r={}){let a=r.maxScanDistance||aF,s=r.brackets||sF,i=ls(t),o=i.resolveInner(e,n);for(let l=o;l;l=l.parent){let u=cg(l.type,n,s);if(u&&l.from<l.to){let c=dg(l);if(c&&(n>0?e>=c.from&&e<c.to:e>c.from&&e<=c.to))return oF(t,e,n,l,c,u,s)}}return lF(t,e,n,i,o.type,a,s)}function oF(t,e,n,r,a,s,i){let o=r.parent,l={from:a.from,to:a.to},u=0,c=o?.cursor();if(c&&(n<0?c.childBefore(r.from):c.childAfter(r.to)))do if(n<0?c.to<=r.from:c.from>=r.to){if(u==0&&s.indexOf(c.type.name)>-1&&c.from<c.to){let d=dg(c);return{start:l,end:d?{from:d.from,to:d.to}:void 0,matched:!0}}else if(cg(c.type,n,i))u++;else if(cg(c.type,-n,i)){if(u==0){let d=dg(c);return{start:l,end:d&&d.from<d.to?{from:d.from,to:d.to}:void 0,matched:!1}}u--}}while(n<0?c.prevSibling():c.nextSibling());return{start:l,matched:!1}}function lF(t,e,n,r,a,s,i){if(n<0?!e:e==t.doc.length)return null;let o=n<0?t.sliceDoc(e-1,e):t.sliceDoc(e,e+1),l=i.indexOf(o);if(l<0||l%2==0!=n>0)return null;let u={from:n<0?e-1:e,to:n>0?e+1:e},c=t.doc.iterRange(e,n>0?t.doc.length:0),d=0;for(let f=0;!c.next().done&&f<=s;){let h=c.value;n<0&&(f+=h.length);let p=e+f*n;for(let g=n>0?0:h.length-1,m=n>0?h.length:-1;g!=m;g+=n){let x=i.indexOf(h[g]);if(!(x<0||r.resolveInner(p+g,1).type!=a))if(x%2==0==n>0)d++;else{if(d==1)return{start:u,end:{from:p+g,to:p+g+1},matched:x>>1==l>>1};d--}}n>0&&(f+=h.length)}return c.done?{start:u,matched:!1}:null}var uF=Object.create(null),sC=[Lr.none];var iC=[],oC=Object.create(null),cF=Object.create(null);for(let[t,e]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])cF[t]=dF(uF,e);function sg(t,e){iC.indexOf(t)>-1||(iC.push(t),console.warn(e))}function dF(t,e){let n=[];for(let o of e.split(" ")){let l=[];for(let u of o.split(".")){let c=t[u]||ve[u];c?typeof c=="function"?l.length?l=l.map(c):sg(u,`Modifier ${u} used at start of tag`):l.length?sg(u,`Tag ${u} used as modifier`):l=Array.isArray(c)?c:[c]:sg(u,`Unknown highlighting tag ${u}`)}for(let u of l)n.push(u)}if(!n.length)return 0;let r=e.replace(/ /g,"_"),a=r+" "+n.map(o=>o.id),s=oC[a];if(s)return s.id;let i=oC[a]=Lr.define({id:sC.length,name:r,props:[tC({[r]:n})]});return sC.push(i),i.id}var p6={rtl:Ke.mark({class:"cm-iso",inclusive:!0,attributes:{dir:"rtl"},bidiIsolate:Vt.RTL}),ltr:Ke.mark({class:"cm-iso",inclusive:!0,attributes:{dir:"ltr"},bidiIsolate:Vt.LTR}),auto:Ke.mark({class:"cm-iso",inclusive:!0,attributes:{dir:"auto"},bidiIsolate:null})};var gn=class t{constructor(e,n,r,a){this.fromA=e,this.toA=n,this.fromB=r,this.toB=a}offset(e,n=e){return new t(this.fromA+e,this.toA+e,this.fromB+n,this.toB+n)}};function Ui(t,e,n,r,a,s){if(t==r)return[];let i=kg(t,e,n,r,a,s),o=Sg(t,e+i,n,r,a+i,s);e+=i,n-=o,a+=i,s-=o;let l=n-e,u=s-a;if(!l||!u)return[new gn(e,n,a,s)];if(l>u){let d=t.slice(e,n).indexOf(r.slice(a,s));if(d>-1)return[new gn(e,e+d,a,a),new gn(e+d+u,n,s,s)]}else if(u>l){let d=r.slice(a,s).indexOf(t.slice(e,n));if(d>-1)return[new gn(e,e,a,a+d),new gn(n,n,a+d+l,s)]}if(l==1||u==1)return[new gn(e,n,a,s)];let c=MC(t,e,n,r,a,s);if(c){let[d,f,h]=c;return Ui(t,e,d,r,a,f).concat(Ui(t,d+h,n,r,f+h,s))}return fF(t,e,n,r,a,s)}var Gu=1e9,Wu=0,vg=!1;function fF(t,e,n,r,a,s){let i=n-e,o=s-a;if(Gu<1e9&&Math.min(i,o)>Gu*16||Wu>0&&Date.now()>Wu)return Math.min(i,o)>Gu*64?[new gn(e,n,a,s)]:dC(t,e,n,r,a,s);let l=Math.ceil((i+o)/2);hg.reset(l),pg.reset(l);let u=(h,p)=>t.charCodeAt(e+h)==r.charCodeAt(a+p),c=(h,p)=>t.charCodeAt(n-h-1)==r.charCodeAt(s-p-1),d=(i-o)%2!=0?pg:null,f=d?null:hg;for(let h=0;h<l;h++){if(h>Gu||Wu>0&&!(h&63)&&Date.now()>Wu)return dC(t,e,n,r,a,s);let p=hg.advance(h,i,o,l,d,!1,u)||pg.advance(h,i,o,l,f,!0,c);if(p)return hF(t,e,n,e+p[0],r,a,s,a+p[1])}return[new gn(e,n,a,s)]}var uf=class{constructor(){this.vec=[]}reset(e){this.len=e<<1;for(let n=0;n<this.len;n++)this.vec[n]=-1;this.vec[e+1]=0,this.start=this.end=0}advance(e,n,r,a,s,i,o){for(let l=-e+this.start;l<=e-this.end;l+=2){let u=a+l,c=l==-e||l!=e&&this.vec[u-1]<this.vec[u+1]?this.vec[u+1]:this.vec[u-1]+1,d=c-l;for(;c<n&&d<r&&o(c,d);)c++,d++;if(this.vec[u]=c,c>n)this.end+=2;else if(d>r)this.start+=2;else if(s){let f=a+(n-r)-l;if(f>=0&&f<this.len&&s.vec[f]!=-1)if(i){let h=s.vec[f];if(h>=n-c)return[h,a+h-f]}else{let h=n-s.vec[f];if(c>=h)return[c,d]}}}return null}},hg=new uf,pg=new uf;function hF(t,e,n,r,a,s,i,o){let l=!1;return!Vo(t,r)&&++r==n&&(l=!0),!Vo(a,o)&&++o==i&&(l=!0),l?[new gn(e,n,s,i)]:Ui(t,e,r,a,s,o).concat(Ui(t,r,n,a,o,i))}function RC(t,e){let n=1,r=Math.min(t,e);for(;n<r;)n=n<<1;return n}function kg(t,e,n,r,a,s){if(e==n||e==s||t.charCodeAt(e)!=r.charCodeAt(a))return 0;let i=RC(n-e,s-a);for(let o=e,l=a;;){let u=o+i,c=l+i;if(u>n||c>s||t.slice(o,u)!=r.slice(l,c)){if(i==1)return o-e-(Vo(t,o)?0:1);i=i>>1}else{if(u==n||c==s)return u-e;o=u,l=c}}}function Sg(t,e,n,r,a,s){if(e==n||a==s||t.charCodeAt(n-1)!=r.charCodeAt(s-1))return 0;let i=RC(n-e,s-a);for(let o=n,l=s;;){let u=o-i,c=l-i;if(u<e||c<a||t.slice(u,o)!=r.slice(c,l)){if(i==1)return n-o-(Vo(t,o)?0:1);i=i>>1}else{if(u==e||c==a)return n-u;o=u,l=c}}}function mg(t,e,n,r,a,s,i,o){let l=r.slice(a,s),u=null;for(;;){if(u||i<o)return u;for(let c=e+i;;){Vo(t,c)||c++;let d=c+i;if(Vo(t,d)||(d+=d==c+1?1:-1),d>=n)break;let f=t.slice(c,d),h=-1;for(;(h=l.indexOf(f,h+1))!=-1;){let p=kg(t,d,n,r,a+h+f.length,s),g=Sg(t,e,c,r,a,a+h),m=f.length+p+g;(!u||u[2]<m)&&(u=[c-g,a+h-g,m])}c=d}if(o<0)return u;i=i>>1}}function MC(t,e,n,r,a,s){let i=n-e,o=s-a;if(i<o){let l=MC(r,a,s,t,e,n);return l&&[l[1],l[0],l[2]]}return i<4||o*2<i?null:mg(t,e,n,r,a,s,Math.floor(i/4),-1)}function dC(t,e,n,r,a,s){vg=!0;let i=n-e,o=s-a,l;if(i<o){let f=mg(r,a,s,t,e,n,Math.floor(i/6),50);l=f&&[f[1],f[0],f[2]]}else l=mg(t,e,n,r,a,s,Math.floor(o/6),50);if(!l)return[new gn(e,n,a,s)];let[u,c,d]=l;return Ui(t,e,u,r,a,c).concat(Ui(t,u+d,n,r,c+d,s))}function TC(t,e){for(let n=1;n<t.length;n++){let r=t[n-1],a=t[n];r.toA>a.fromA-e&&r.toB>a.fromB-e&&(t[n-1]=new gn(r.fromA,a.toA,r.fromB,a.toB),t.splice(n--,1))}}function pF(t,e,n){for(;;){TC(n,1);let r=!1;for(let a=0;a<n.length;a++){let s=n[a],i,o;(i=kg(t,s.fromA,s.toA,e,s.fromB,s.toB))&&(s=n[a]=new gn(s.fromA+i,s.toA,s.fromB+i,s.toB)),(o=Sg(t,s.fromA,s.toA,e,s.fromB,s.toB))&&(s=n[a]=new gn(s.fromA,s.toA-o,s.fromB,s.toB-o));let l=s.toA-s.fromA,u=s.toB-s.fromB;if(l&&u)continue;let c=s.fromA-(a?n[a-1].toA:0),d=(a<n.length-1?n[a+1].fromA:t.length)-s.toA;if(!c||!d)continue;let f=l?t.slice(s.fromA,s.toA):e.slice(s.fromB,s.toB);c<=f.length&&t.slice(s.fromA-c,s.fromA)==f.slice(f.length-c)?(n[a]=new gn(s.fromA-c,s.toA-c,s.fromB-c,s.toB-c),r=!0):d<=f.length&&t.slice(s.toA,s.toA+d)==f.slice(0,d)&&(n[a]=new gn(s.fromA+d,s.toA+d,s.fromB+d,s.toB+d),r=!0)}if(!r)break}return n}function mF(t,e,n){for(let r=0,a=0;a<t.length;a++){let s=t[a],i=s.toA-s.fromA,o=s.toB-s.fromB;if(i&&o||i>3||o>3){let l=a==t.length-1?e.length:t[a+1].fromA,u=s.fromA-r,c=l-s.toA,d=hC(e,s.fromA,u),f=fC(e,s.toA,c),h=s.fromA-d,p=f-s.toA;if((!i||!o)&&h&&p){let g=Math.max(i,o),[m,x,y]=i?[e,s.fromA,s.toA]:[n,s.fromB,s.toB];g>h&&e.slice(d,s.fromA)==m.slice(y-h,y)?(s=t[a]=new gn(d,d+i,s.fromB-h,s.toB-h),d=s.fromA,f=fC(e,s.toA,l-s.toA)):g>p&&e.slice(s.toA,f)==m.slice(x,x+p)&&(s=t[a]=new gn(f-i,f,s.fromB+p,s.toB+p),f=s.toA,d=hC(e,s.fromA,s.fromA-r)),h=s.fromA-d,p=f-s.toA}if(h||p)s=t[a]=new gn(s.fromA-h,s.toA+p,s.fromB-h,s.toB+p);else if(i){if(!o){let g=mC(e,s.fromA,s.toA),m,x=g<0?-1:pC(e,s.toA,s.fromA);g>-1&&(m=g-s.fromA)<=c&&e.slice(s.fromA,g)==e.slice(s.toA,s.toA+m)?s=t[a]=s.offset(m):x>-1&&(m=s.toA-x)<=u&&e.slice(s.fromA-m,s.fromA)==e.slice(x,s.toA)&&(s=t[a]=s.offset(-m))}}else{let g=mC(n,s.fromB,s.toB),m,x=g<0?-1:pC(n,s.toB,s.fromB);g>-1&&(m=g-s.fromB)<=c&&n.slice(s.fromB,g)==n.slice(s.toB,s.toB+m)?s=t[a]=s.offset(m):x>-1&&(m=s.toB-x)<=u&&n.slice(s.fromB-m,s.fromB)==n.slice(x,s.toB)&&(s=t[a]=s.offset(-m))}}r=s.toA}return TC(t,3),t}var Hi;try{Hi=new RegExp("[\\p{Alphabetic}\\p{Number}]","u")}catch{}function DC(t){return t>48&&t<58||t>64&&t<91||t>96&&t<123}function FC(t,e){if(e==t.length)return 0;let n=t.charCodeAt(e);return n<192?DC(n)?1:0:Hi?!BC(n)||e==t.length-1?Hi.test(String.fromCharCode(n))?1:0:Hi.test(t.slice(e,e+2))?2:0:0}function EC(t,e){if(!e)return 0;let n=t.charCodeAt(e-1);return n<192?DC(n)?1:0:Hi?!_C(n)||e==1?Hi.test(String.fromCharCode(n))?1:0:Hi.test(t.slice(e-2,e))?2:0:0}var OC=8;function fC(t,e,n){if(e==t.length||!EC(t,e))return e;for(let r=e,a=e+n,s=0;s<OC;s++){let i=FC(t,r);if(!i||r+i>a)return r;r+=i}return e}function hC(t,e,n){if(!e||!FC(t,e))return e;for(let r=e,a=e-n,s=0;s<OC;s++){let i=EC(t,r);if(!i||r-i<a)return r;r-=i}return e}function pC(t,e,n){for(;e!=n;e--)if(t.charCodeAt(e-1)==10)return e;return-1}function mC(t,e,n){for(;e!=n;e++)if(t.charCodeAt(e)==10)return e;return-1}var BC=t=>t>=55296&&t<=56319,_C=t=>t>=56320&&t<=57343;function Vo(t,e){return!e||e==t.length||!BC(t.charCodeAt(e-1))||!_C(t.charCodeAt(e))}function gF(t,e,n){var r;let a=n?.override;return a?a(t,e):(Gu=((r=n?.scanLimit)!==null&&r!==void 0?r:1e9)>>1,Wu=n?.timeout?Date.now()+n.timeout:0,vg=!1,pF(t,e,Ui(t,0,t.length,e,0,e.length)))}function HC(){return!vg}function UC(t,e,n){return mF(gF(t,e,n),t,e)}var pr=Me.define({combine:t=>t[0]}),gg=pt.define(),GC=Me.define(),nr=vn.define({create(t){return null},update(t,e){for(let n of e.effects)n.is(gg)&&(t=n.value);for(let n of e.state.facet(GC))t=n(t,e);return t}});var us=class t{constructor(e,n,r,a,s,i=!0){this.changes=e,this.fromA=n,this.toA=r,this.fromB=a,this.toB=s,this.precise=i}offset(e,n){return e||n?new t(this.changes,this.fromA+e,this.toA+e,this.fromB+n,this.toB+n,this.precise):this}get endA(){return Math.max(this.fromA,this.toA-1)}get endB(){return Math.max(this.fromB,this.toB-1)}static build(e,n,r){let a=UC(e.toString(),n.toString(),r);return WC(a,e,n,0,0,HC())}static updateA(e,n,r,a,s){return wC(bC(e,a,!0,r.length),e,n,r,s)}static updateB(e,n,r,a,s){return wC(bC(e,a,!1,n.length),e,n,r,s)}};function gC(t,e,n,r){let a=n.lineAt(t),s=r.lineAt(e);return a.to==t&&s.to==e&&t<n.length&&e<r.length?[t+1,e+1]:[a.from,s.from]}function xC(t,e,n,r){let a=n.lineAt(t),s=r.lineAt(e);return a.from==t&&s.from==e?[t,e]:[a.to+1,s.to+1]}function WC(t,e,n,r,a,s){let i=[];for(let o=0;o<t.length;o++){let l=t[o],[u,c]=gC(l.fromA+r,l.fromB+a,e,n),[d,f]=xC(l.toA+r,l.toB+a,e,n),h=[l.offset(-u+r,-c+a)];for(;o<t.length-1;){let p=t[o+1],[g,m]=gC(p.fromA+r,p.fromB+a,e,n);if(g>d+1&&m>f+1)break;h.push(p.offset(-u+r,-c+a)),[d,f]=xC(p.toA+r,p.toB+a,e,n),o++}i.push(new us(h,u,Math.max(u,d),c,Math.max(c,f),s))}return i}var af=1e3;function yC(t,e,n,r){let a=0,s=t.length;for(;;){if(a==s){let c=0,d=0;a&&({toA:c,toB:d}=t[a-1]);let f=e-(n?c:d);return[c+f,d+f]}let i=a+s>>1,o=t[i],[l,u]=n?[o.fromA,o.toA]:[o.fromB,o.toB];if(l>e)s=i;else if(u<=e)a=i+1;else return r?[o.fromA,o.fromB]:[o.toA,o.toB]}}function bC(t,e,n,r){let a=[];return e.iterChangedRanges((s,i,o,l)=>{let u=0,c=n?e.length:r,d=0,f=n?r:e.length;s>af&&([u,d]=yC(t,s-af,n,!0)),i<e.length-af&&([c,f]=yC(t,i+af,n,!1));let h=l-o-(i-s),p,[g,m]=n?[h,0]:[0,h];a.length&&(p=a[a.length-1]).toA>=u?a[a.length-1]={fromA:p.fromA,fromB:p.fromB,toA:c,toB:f,diffA:p.diffA+g,diffB:p.diffB+m}:a.push({fromA:u,toA:c,fromB:d,toB:f,diffA:g,diffB:m})}),a}function wC(t,e,n,r,a){if(!t.length)return e;let s=[];for(let i=0,o=0,l=0,u=0;;i++){let c=i==t.length?null:t[i],d=c?c.fromA+o:n.length,f=c?c.fromB+l:r.length;for(;u<e.length;){let m=e[u];if(c&&(m.toA+o>d||m.toB+l>f))break;s.push(m.offset(o,l)),u++}if(!c)break;let h=c.toA+o+c.diffA,p=c.toB+l+c.diffB,g=UC(n.sliceString(d,h),r.sliceString(f,p),a);for(let m of WC(g,n,r,d,f,HC()))s.push(m);for(o+=c.diffA,l+=c.diffB;u<e.length;){let m=e[u];if(m.fromA+o>h&&m.fromB+l>p)break;u++}}return s}var zC={scanLimit:500},hf=hr.fromClass(class{constructor(t){({deco:this.deco,gutter:this.gutter}=SC(t))}update(t){(t.docChanged||t.viewportChanged||xF(t.startState,t.state)||yF(t.startState,t.state))&&({deco:this.deco,gutter:this.gutter}=SC(t.view))}},{decorations:t=>t.deco}),sf=Ma.low(zo({class:"cm-changeGutter",markers:t=>{var e;return((e=t.plugin(hf))===null||e===void 0?void 0:e.gutter)||wt.empty}}));function xF(t,e){return t.field(nr,!1)!=e.field(nr,!1)}function yF(t,e){return t.facet(pr)!=e.facet(pr)}var vC=Ke.line({class:"cm-changedLine"}),jC=Ke.mark({class:"cm-changedText"}),bF=Ke.mark({tagName:"ins",class:"cm-insertedLine"}),wF=Ke.mark({tagName:"del",class:"cm-deletedLine"}),kC=new class extends Bn{constructor(){super(...arguments),this.elementClass="cm-changedLineGutter"}};function vF(t,e,n,r,a,s){let i=n?t.fromA:t.fromB,o=n?t.toA:t.toB,l=0;if(i!=o){a.add(i,i,vC),a.add(i,o,n?wF:bF),s&&s.add(i,i,kC);for(let u=e.iterRange(i,o-1),c=i;!u.next().done;){if(u.lineBreak){c++,a.add(c,c,vC),s&&s.add(c,c,kC);continue}let d=c+u.value.length;if(r)for(;l<t.changes.length;){let f=t.changes[l],h=i+(n?f.fromA:f.fromB),p=i+(n?f.toA:f.toB),g=Math.max(c,h),m=Math.min(d,p);if(g<m&&a.add(g,m,jC),p<d)l++;else break}c=d}}}function SC(t){let e=t.state.field(nr),{side:n,highlightChanges:r,markGutter:a,overrideChunk:s}=t.state.facet(pr),i=n=="a",o=new qn,l=a?new qn:null,{from:u,to:c}=t.viewport;for(let d of e){if((i?d.fromA:d.fromB)>=c)break;(i?d.toA:d.toB)>u&&(!s||!s(t.state,d,o,l))&&vF(d,t.state.doc,i,r,o,l)}return{deco:o.finish(),gutter:l&&l.finish()}}var jo=class extends Ir{constructor(e){super(),this.height=e}eq(e){return this.height==e.height}toDOM(){let e=document.createElement("div");return e.className="cm-mergeSpacer",e.style.height=this.height+"px",e}updateDOM(e){return e.style.height=this.height+"px",!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}},cf=pt.define({map:(t,e)=>t.map(e)}),zu=vn.define({create:()=>Ke.none,update:(t,e)=>{for(let n of e.effects)if(n.is(cf))return n.value;return t.map(e.changes)},provide:t=>Pe.decorations.from(t)}),of=.01;function CC(t,e){if(t.size!=e.size)return!1;let n=t.iter(),r=e.iter();for(;n.value;){if(n.from!=r.from||Math.abs(n.value.spec.widget.height-r.value.spec.widget.height)>1)return!1;n.next(),r.next()}return!0}function kF(t,e,n){let r=new qn,a=new qn,s=t.state.field(zu).iter(),i=e.state.field(zu).iter(),o=0,l=0,u=0,c=0,d=t.viewport,f=e.viewport;for(let m=0;;m++){let x=m<n.length?n[m]:null,y=x?x.fromA:t.state.doc.length,b=x?x.fromB:e.state.doc.length;if(o<y){let C=t.lineBlockAt(o).top+u,L=e.lineBlockAt(l).top+c,P=C-L;P<-of?(u-=P,r.add(o,o,Ke.widget({widget:new jo(-P),block:!0,side:-1}))):P>of&&(c+=P,a.add(l,l,Ke.widget({widget:new jo(P),block:!0,side:-1})))}if(y>o+1e3&&o<d.from&&y>d.from&&l<f.from&&b>f.from){let C=Math.min(d.from-o,f.from-l);o+=C,l+=C,m--}else if(x)o=x.toA,l=x.toB;else break;for(;s.value&&s.from<o;)u-=s.value.spec.widget.height,s.next();for(;i.value&&i.from<l;)c-=i.value.spec.widget.height,i.next()}for(;s.value;)u-=s.value.spec.widget.height,s.next();for(;i.value;)c-=i.value.spec.widget.height,i.next();let h=t.contentHeight+u-(e.contentHeight+c);h<of?r.add(t.state.doc.length,t.state.doc.length,Ke.widget({widget:new jo(-h),block:!0,side:1})):h>of&&a.add(e.state.doc.length,e.state.doc.length,Ke.widget({widget:new jo(h),block:!0,side:1}));let p=r.finish(),g=a.finish();CC(p,t.state.field(zu))||t.dispatch({effects:cf.of(p)}),CC(g,e.state.field(zu))||e.dispatch({effects:cf.of(g)})}var xg=pt.define({map:(t,e)=>e.mapPos(t)});var yg=class extends Ir{constructor(e){super(),this.lines=e}eq(e){return this.lines==e.lines}toDOM(e){let n=document.createElement("div");return n.className="cm-collapsedLines",n.textContent=e.state.phrase("$ unchanged lines",this.lines),n.addEventListener("click",r=>{let a=e.posAtDOM(r.target);e.dispatch({effects:xg.of(a)});let{side:s,sibling:i}=e.state.facet(pr);i&&i().dispatch({effects:xg.of(SF(a,e.state.field(nr),s=="a"))})}),n}ignoreEvent(e){return e instanceof MouseEvent}get estimatedHeight(){return 27}get type(){return"collapsed-unchanged-code"}};function SF(t,e,n){let r=0,a=0;for(let s=0;;s++){let i=s<e.length?e[s]:null;if(!i||(n?i.fromA:i.fromB)>=t)return a+(t-r);[r,a]=n?[i.toA,i.toB]:[i.toB,i.toA]}}var CF=vn.define({create(t){return Ke.none},update(t,e){t=t.map(e.changes);for(let n of e.effects)n.is(xg)&&(t=t.update({filter:r=>r!=n.value}));if(t.size&&e.state.field(nr)!=e.startState.field(nr,!1)){let n=e.state.facet(pr).side=="a",r=[];for(let a of e.state.field(nr))t.between(n?a.fromA:a.fromB,n?a.toA:a.toB,s=>{r.push(s)});r.length&&(t=t.update({filter:a=>r.indexOf(a)<0}))}return t},provide:t=>Pe.decorations.from(t)});function bg({margin:t=3,minSize:e=4}){return CF.init(n=>IF(n,t,e))}function IF(t,e,n){let r=new qn,a=t.facet(pr).side=="a",s=t.field(nr),i=1;for(let o=0;;o++){let l=o<s.length?s[o]:null,u=o?i+e:1,c=l?t.doc.lineAt(a?l.fromA:l.fromB).number-1-e:t.doc.lines,d=c-u+1;if(d>=n&&r.add(t.doc.line(u).from,t.doc.line(c).to,Ke.replace({widget:new yg(d),block:!0})),!l)break;i=t.doc.lineAt(Math.min(t.doc.length,a?l.toA:l.toB)).number}return r.finish()}var LF=Pe.styleModule.of(new dr({".cm-mergeView":{overflowY:"auto"},".cm-mergeViewEditors":{display:"flex",alignItems:"stretch"},".cm-mergeViewEditor":{flexGrow:1,flexBasis:0,overflow:"hidden"},".cm-merge-revert":{width:"1.6em",flexGrow:0,flexShrink:0,position:"relative"},".cm-merge-revert button":{position:"absolute",display:"block",width:"100%",boxSizing:"border-box",textAlign:"center",background:"none",border:"none",font:"inherit",cursor:"pointer"}})),VC=Pe.baseTheme({".cm-mergeView & .cm-scroller, .cm-mergeView &":{height:"auto !important",overflowY:"visible !important"},"&.cm-merge-a .cm-changedLine, .cm-deletedChunk":{backgroundColor:"rgba(160, 128, 100, .08)"},"&.cm-merge-b .cm-changedLine, .cm-inlineChangedLine":{backgroundColor:"rgba(100, 160, 128, .08)"},"&light.cm-merge-a .cm-changedText, &light .cm-deletedChunk .cm-deletedText":{background:"linear-gradient(#ee443366, #ee443366) bottom/100% 2px no-repeat"},"&dark.cm-merge-a .cm-changedText, &dark .cm-deletedChunk .cm-deletedText":{background:"linear-gradient(#ffaa9966, #ffaa9966) bottom/100% 2px no-repeat"},"&light.cm-merge-b .cm-changedText":{background:"linear-gradient(#22bb22aa, #22bb22aa) bottom/100% 2px no-repeat"},"&dark.cm-merge-b .cm-changedText":{background:"linear-gradient(#88ff88aa, #88ff88aa) bottom/100% 2px no-repeat"},"&.cm-merge-b .cm-deletedText":{background:"#ff000033"},".cm-insertedLine, .cm-deletedLine, .cm-deletedLine del":{textDecoration:"none"},".cm-deletedChunk":{paddingLeft:"6px","& .cm-chunkButtons":{position:"absolute",insetInlineEnd:"5px"},"& button":{border:"none",cursor:"pointer",color:"white",margin:"0 2px",borderRadius:"3px","&[name=accept]":{background:"#2a2"},"&[name=reject]":{background:"#d43"}}},".cm-collapsedLines":{padding:"5px 5px 5px 10px",cursor:"pointer","&:before":{content:'"\u299A"',marginInlineEnd:"7px"},"&:after":{content:'"\u299A"',marginInlineStart:"7px"}},"&light .cm-collapsedLines":{color:"#444",background:"linear-gradient(to bottom, transparent 0, #f3f3f3 30%, #f3f3f3 70%, transparent 100%)"},"&dark .cm-collapsedLines":{color:"#ddd",background:"linear-gradient(to bottom, transparent 0, #222 30%, #222 70%, transparent 100%)"},".cm-changeGutter":{width:"3px",paddingLeft:"1px"},"&light.cm-merge-a .cm-changedLineGutter, &light .cm-deletedLineGutter":{background:"#e43"},"&dark.cm-merge-a .cm-changedLineGutter, &dark .cm-deletedLineGutter":{background:"#fa9"},"&light.cm-merge-b .cm-changedLineGutter":{background:"#2b2"},"&dark.cm-merge-b .cm-changedLineGutter":{background:"#8f8"},".cm-inlineChangedLineGutter":{background:"#75d"}}),IC=new _r,lf=new _r,df=class{constructor(e){this.revertDOM=null,this.revertToA=!1,this.revertToLeft=!1,this.measuring=-1,this.diffConf=e.diffConfig||zC;let n=[Ma.low(hf),VC,LF,zu,Pe.updateListener.of(d=>{this.measuring<0&&(d.heightChanged||d.viewportChanged)&&!d.transactions.some(f=>f.effects.some(h=>h.is(cf)))&&this.measure()})],r=[pr.of({side:"a",sibling:()=>this.b,highlightChanges:e.highlightChanges!==!1,markGutter:e.gutter!==!1})];e.gutter!==!1&&r.push(sf);let a=It.create({doc:e.a.doc,selection:e.a.selection,extensions:[e.a.extensions||[],Pe.editorAttributes.of({class:"cm-merge-a"}),lf.of(r),n]}),s=[pr.of({side:"b",sibling:()=>this.a,highlightChanges:e.highlightChanges!==!1,markGutter:e.gutter!==!1})];e.gutter!==!1&&s.push(sf);let i=It.create({doc:e.b.doc,selection:e.b.selection,extensions:[e.b.extensions||[],Pe.editorAttributes.of({class:"cm-merge-b"}),lf.of(s),n]});this.chunks=us.build(a.doc,i.doc,this.diffConf);let o=[nr.init(()=>this.chunks),IC.of(e.collapseUnchanged?bg(e.collapseUnchanged):[])];a=a.update({effects:pt.appendConfig.of(o)}).state,i=i.update({effects:pt.appendConfig.of(o)}).state,this.dom=document.createElement("div"),this.dom.className="cm-mergeView",this.editorDOM=this.dom.appendChild(document.createElement("div")),this.editorDOM.className="cm-mergeViewEditors";let l=e.orientation||"a-b",u=document.createElement("div");u.className="cm-mergeViewEditor";let c=document.createElement("div");c.className="cm-mergeViewEditor",this.editorDOM.appendChild(l=="a-b"?u:c),this.editorDOM.appendChild(l=="a-b"?c:u),this.a=new Pe({state:a,parent:u,root:e.root,dispatchTransactions:d=>this.dispatch(d,this.a)}),this.b=new Pe({state:i,parent:c,root:e.root,dispatchTransactions:d=>this.dispatch(d,this.b)}),this.setupRevertControls(!!e.revertControls,e.revertControls=="b-to-a",e.renderRevertControl),e.parent&&e.parent.appendChild(this.dom),this.scheduleMeasure()}dispatch(e,n){if(e.some(r=>r.docChanged)){let r=e[e.length-1],a=e.reduce((i,o)=>i.compose(o.changes),Nn.empty(e[0].startState.doc.length));this.chunks=n==this.a?us.updateA(this.chunks,r.newDoc,this.b.state.doc,a,this.diffConf):us.updateB(this.chunks,this.a.state.doc,r.newDoc,a,this.diffConf),n.update([...e,r.state.update({effects:gg.of(this.chunks)})]);let s=n==this.a?this.b:this.a;s.update([s.state.update({effects:gg.of(this.chunks)})]),this.scheduleMeasure()}else n.update(e)}reconfigure(e){if("diffConfig"in e&&(this.diffConf=e.diffConfig),"orientation"in e){let s=e.orientation!="b-a";if(s!=(this.editorDOM.firstChild==this.a.dom.parentNode)){let i=this.a.dom.parentNode,o=this.b.dom.parentNode;i.remove(),o.remove(),this.editorDOM.insertBefore(s?i:o,this.editorDOM.firstChild),this.editorDOM.appendChild(s?o:i),this.revertToLeft=!this.revertToLeft,this.revertDOM&&(this.revertDOM.textContent="")}}if("revertControls"in e||"renderRevertControl"in e){let s=!!this.revertDOM,i=this.revertToA,o=this.renderRevert;"revertControls"in e&&(s=!!e.revertControls,i=e.revertControls=="b-to-a"),"renderRevertControl"in e&&(o=e.renderRevertControl),this.setupRevertControls(s,i,o)}let n="highlightChanges"in e,r="gutter"in e,a="collapseUnchanged"in e;if(n||r||a){let s=[],i=[];if(n||r){let o=this.a.state.facet(pr),l=r?e.gutter!==!1:o.markGutter,u=n?e.highlightChanges!==!1:o.highlightChanges;s.push(lf.reconfigure([pr.of({side:"a",sibling:()=>this.b,highlightChanges:u,markGutter:l}),l?sf:[]])),i.push(lf.reconfigure([pr.of({side:"b",sibling:()=>this.a,highlightChanges:u,markGutter:l}),l?sf:[]]))}if(a){let o=IC.reconfigure(e.collapseUnchanged?bg(e.collapseUnchanged):[]);s.push(o),i.push(o)}this.a.dispatch({effects:s}),this.b.dispatch({effects:i})}this.scheduleMeasure()}setupRevertControls(e,n,r){this.revertToA=n,this.revertToLeft=this.revertToA==(this.editorDOM.firstChild==this.a.dom.parentNode),this.renderRevert=r,!e&&this.revertDOM?(this.revertDOM.remove(),this.revertDOM=null):e&&!this.revertDOM?(this.revertDOM=this.editorDOM.insertBefore(document.createElement("div"),this.editorDOM.firstChild.nextSibling),this.revertDOM.addEventListener("mousedown",a=>this.revertClicked(a)),this.revertDOM.className="cm-merge-revert"):this.revertDOM&&(this.revertDOM.textContent="")}scheduleMeasure(){if(this.measuring<0){let e=this.dom.ownerDocument.defaultView||window;this.measuring=e.requestAnimationFrame(()=>{this.measuring=-1,this.measure()})}}measure(){kF(this.a,this.b,this.chunks),this.revertDOM&&this.updateRevertButtons()}updateRevertButtons(){let e=this.revertDOM,n=e.firstChild,r=this.a.viewport,a=this.b.viewport;for(let s=0;s<this.chunks.length;s++){let i=this.chunks[s];if(i.fromA>r.to||i.fromB>a.to)break;if(i.fromA<r.from||i.fromB<a.from)continue;let o=this.a.lineBlockAt(i.fromA).top+"px";for(;n&&+n.dataset.chunk<s;)n=LC(n);n&&n.dataset.chunk==String(s)?(n.style.top!=o&&(n.style.top=o),n=n.nextSibling):e.insertBefore(this.renderRevertButton(o,s),n)}for(;n;)n=LC(n)}renderRevertButton(e,n){let r;if(this.renderRevert)r=this.renderRevert();else{r=document.createElement("button");let a=this.a.state.phrase("Revert this chunk");r.setAttribute("aria-label",a),r.setAttribute("title",a),r.textContent=this.revertToLeft?"\u21DC":"\u21DD"}return r.style.top=e,r.setAttribute("data-chunk",String(n)),r}revertClicked(e){let n=e.target,r;for(;n&&n.parentNode!=this.revertDOM;)n=n.parentNode;if(n&&(r=this.chunks[n.dataset.chunk])){let[a,s,i,o,l,u]=this.revertToA?[this.b,this.a,r.fromB,r.toB,r.fromA,r.toA]:[this.a,this.b,r.fromA,r.toA,r.fromB,r.toB],c=a.state.sliceDoc(i,Math.max(i,o-1));i!=o&&u<=s.state.doc.length&&(c+=a.state.lineBreak),s.dispatch({changes:{from:l,to:Math.min(s.state.doc.length,u),insert:c},userEvent:"revert"}),e.preventDefault()}}destroy(){this.a.destroy(),this.b.destroy(),this.measuring>-1&&(this.dom.ownerDocument.defaultView||window).cancelAnimationFrame(this.measuring),this.dom.remove()}};function LC(t){let e=t.nextSibling;return t.remove(),e}var AF=new class extends Bn{constructor(){super(...arguments),this.elementClass="cm-deletedLineGutter"}},PF=Ma.low(zo({class:"cm-changeGutter",markers:t=>{var e;return((e=t.plugin(hf))===null||e===void 0?void 0:e.gutter)||wt.empty},widgetMarker:(t,e)=>e instanceof ff?AF:null}));function qC(t){var e;let n=typeof t.original=="string"?st.of(t.original.split(/\r?\n/)):t.original,r=t.diffConfig||zC;return[Ma.low(hf),TF,VC,Pe.editorAttributes.of({class:"cm-merge-b"}),GC.of((a,s)=>{let i=s.effects.find(o=>o.is(Cg));return i&&(a=us.updateA(a,i.value.doc,s.startState.doc,i.value.changes,r)),s.docChanged&&(a=us.updateB(a,s.state.field(qo),s.newDoc,s.changes,r)),a}),pr.of({highlightChanges:t.highlightChanges!==!1,markGutter:t.gutter!==!1,syntaxHighlightDeletions:t.syntaxHighlightDeletions!==!1,syntaxHighlightDeletionsMaxLength:3e3,mergeControls:(e=t.mergeControls)!==null&&e!==void 0?e:!0,overrideChunk:t.allowInlineDiffs?EF:void 0,side:"b"}),qo.init(()=>n),t.gutter!==!1?PF:[],t.collapseUnchanged?bg(t.collapseUnchanged):[],nr.init(a=>us.build(n,a.doc,r))]}var Cg=pt.define();var qo=vn.define({create:()=>st.empty,update(t,e){for(let n of e.effects)n.is(Cg)&&(t=n.value.doc);return t}});var AC=new WeakMap,ff=class extends Ir{constructor(e){super(),this.buildDOM=e,this.dom=null}eq(e){return this.dom==e.dom}toDOM(e){return this.dom||(this.dom=this.buildDOM(e))}};function NF(t,e,n){let r=AC.get(e.changes);if(r)return r;let a=i=>{let{highlightChanges:o,syntaxHighlightDeletions:l,syntaxHighlightDeletionsMaxLength:u,mergeControls:c}=t.facet(pr),d=document.createElement("div");if(d.className="cm-deletedChunk",c){let C=d.appendChild(document.createElement("div"));C.className="cm-chunkButtons";let L=w=>{w.preventDefault(),RF(i,i.posAtDOM(d))},P=w=>{w.preventDefault(),MF(i,i.posAtDOM(d))};if(typeof c=="function")C.appendChild(c("accept",L)),C.appendChild(c("reject",P));else{let w=C.appendChild(document.createElement("button"));w.name="accept",w.textContent=t.phrase("Accept"),w.onmousedown=L;let k=C.appendChild(document.createElement("button"));k.name="reject",k.textContent=t.phrase("Reject"),k.onmousedown=P}}if(n||e.fromA>=e.toA)return d;let f=i.state.field(qo).sliceString(e.fromA,e.endA),h=l&&t.facet($s),p=y(),g=e.changes,m=0,x=!1;function y(){let C=d.appendChild(document.createElement("div"));return C.className="cm-deletedLine",C.appendChild(document.createElement("del"))}function b(C,L,P){for(let w=C;w<L;){if(f.charAt(w)==`
42
+ `){p.firstChild||p.appendChild(document.createElement("br")),p=y(),w++;continue}let k=L,_=P+(x?" cm-deletedText":""),M=!1,R=f.indexOf(`
43
+ `,w);if(R>-1&&R<L&&(k=R),o&&m<g.length){let U=Math.max(0,x?g[m].toA:g[m].fromA);U<=k&&(k=U,x&&m++,M=!0)}if(k>w){let U=document.createTextNode(f.slice(w,k));if(_){let v=p.appendChild(document.createElement("span"));v.className=_,v.appendChild(U)}else p.appendChild(U);w=k}M&&(x=!x)}}if(h&&e.toA-e.fromA<=u){let C=h.parser.parse(f),L=0;ng(C,{style:P=>cC(t,P)},(P,w,k)=>{P>L&&b(L,P,""),b(P,w,k),L=w}),b(L,f.length,"")}else b(0,f.length,"");return p.firstChild||p.appendChild(document.createElement("br")),d},s=Ke.widget({block:!0,side:-1,widget:new ff(a)});return AC.set(e.changes,s),s}function RF(t,e){let{state:n}=t,r=e??n.selection.main.head,a=t.state.field(nr).find(l=>l.fromB<=r&&l.endB>=r);if(!a)return!1;let s=t.state.sliceDoc(a.fromB,Math.max(a.fromB,a.toB-1)),i=t.state.field(qo);a.fromB!=a.toB&&a.toA<=i.length&&(s+=t.state.lineBreak);let o=Nn.of({from:a.fromA,to:Math.min(i.length,a.toA),insert:s},i.length);return t.dispatch({effects:Cg.of({doc:o.apply(i),changes:o}),userEvent:"accept"}),!0}function MF(t,e){let{state:n}=t,r=e??n.selection.main.head,a=n.field(nr).find(o=>o.fromB<=r&&o.endB>=r);if(!a)return!1;let i=n.field(qo).sliceString(a.fromA,Math.max(a.fromA,a.toA-1));return a.fromA!=a.toA&&a.toB<=n.doc.length&&(i+=n.lineBreak),t.dispatch({changes:{from:a.fromB,to:Math.min(n.doc.length,a.toB),insert:i},userEvent:"revert"}),!0}function PC(t){let e=new qn;for(let n of t.field(nr)){let r=t.facet(pr).overrideChunk&&$C(t,n);e.add(n.fromB,n.fromB,NF(t,n,!!r))}return e.finish()}var TF=vn.define({create:t=>PC(t),update(t,e){return e.state.field(nr,!1)!=e.startState.field(nr,!1)?PC(e.state):t},provide:t=>Pe.decorations.from(t)}),NC=new WeakMap;function $C(t,e){let n=NC.get(e);if(n!==void 0)return n;n=null;let r=t.field(qo),a=t.doc,s=r.lineAt(e.endA).number-r.lineAt(e.fromA).number+1,i=a.lineAt(e.endB).number-a.lineAt(e.fromB).number+1;e:if(s==i&&s<10){let o=[],l=0,u=e.fromA,c=e.fromB;for(let d of e.changes){if(d.fromA<d.toA){l+=d.toA-d.fromA;let f=r.sliceString(u+d.fromA,u+d.toA);if(/\n/.test(f))break e;o.push(Ke.widget({widget:new wg(f),side:-1}).range(c+d.fromB))}d.fromB<d.toB&&o.push(jC.range(c+d.fromB,c+d.toB))}l<e.endA-e.fromA-s*2&&(n=o)}return NC.set(e,n),n}var wg=class extends Ir{constructor(e){super(),this.text=e}eq(e){return this.text==e.text}toDOM(e){let n=document.createElement("del");return n.className="cm-deletedText",n.textContent=this.text,n}},DF=new class extends Bn{constructor(){super(...arguments),this.elementClass="cm-inlineChangedLineGutter"}},FF=Ke.line({class:"cm-inlineChangedLine"});function EF(t,e,n,r){let a=$C(t,e),s=0;if(!a)return!1;for(let i=t.doc.lineAt(e.fromB);;){for(r&&r.add(i.from,i.from,DF),n.add(i.from,i.from,FF);s<a.length&&a[s].to<=i.to;){let o=a[s++];n.add(o.from,o.to,o.value)}if(i.to>=e.endB)break;i=t.doc.lineAt(i.to+1)}return!0}function KC(t,e){if(!t||!e)return!1;let n=t.getInternalStack(),r=e.getInternalStack();return!n||!r?!1:n.equals(r)}function OF(t,e){return{from:t,to:e,lines:null,startState:null,endState:null,final:!1,stateKnown:!1,lastUsed:0}}var pf=class{constructor(e,n,r,a,s=64,i=4096){this.hl=e;this.lang=n;this.theme=r;this.targetLines=s;this.targetChars=i;this.chunks=[];this.tick=0;this.warned=!1;this.layoutDirty=!0;this.layout(a)}pieces(e,n,r){let a=[],s=n;for(;s<=r;){let i=e.line(s),o=i,l=1,u=i.length;for(;s+l<=r&&l<this.targetLines;){let c=e.line(s+l);if(u+1+c.length>this.targetChars)break;o=c,u+=1+c.length,l+=1}a.push(OF(i.from,o.to)),s+=l}return a}layout(e){this.chunks.length=0,this.chunks.push(...this.pieces(e,1,e.lines))}chunkIndexAt(e){let n=0,r=this.chunks.length-1;for(;n<r;){let a=n+r+1>>1;this.chunks[a].from<=e?n=a:r=a-1}return n}firstLineOf(e,n){return e.lineAt(n.from).number}tokensAt(e,n){return e.lines?.[n]??null}tokensForLine(e,n){let r=e.line(n),a=this.chunks[this.chunkIndexAt(r.from)];return{chunk:a,tokens:this.tokensAt(a,n-this.firstLineOf(e,a))}}lineCountOf(e,n){return e.lineAt(n.to).number-e.lineAt(n.from).number+1}hasPendingWork(e,n){let r=this.firstNonFinal(0);return r>=0&&r<=n||this.rebalanceTarget(e)!==null}firstNonFinal(e){for(let n=Math.max(0,e);n<this.chunks.length;n++)if(!this.chunks[n].final)return n;return-1}tokenize(e,n,r=!0){let a=this.chunks[n],s=n>0?this.chunks[n-1]:null,i=s?.endState??null,o=n===0||!!(s&&s.final&&s.stateKnown),l=e.sliceString(a.from,a.to),u=a.endState,c,d;try{let f=this.hl.codeToTokensBase(l,{lang:this.lang,theme:this.theme,includeExplanation:!1,tokenizeMaxLineLength:2e4,...i?{grammarState:i}:{}});d=this.hl.getLastGrammarState(f)??null,c=f}catch(f){this.warned||(this.warned=!0,console.warn("[Filesystem] shiki chunk tokenization failed",this.lang,f)),c=[],d=null}return a.lines=c,a.startState=i,a.endState=d,a.final=o,a.stateKnown=!0,r&&(a.lastUsed=++this.tick),this.trimWindow(),o&&KC(u,d)}ensureRange(e,n,r,a=16384){let s=!1,i=0,o=this.chunkIndexAt(n),l=Math.min(this.chunks.length-1,this.chunkIndexAt(r)+1);for(let u=o;u<=l;u++){let c=this.chunks[u];if(c.lines){c.lastUsed=++this.tick;continue}if(s&&i+(c.to-c.from)>a)break;this.tokenize(e,u,!0),i+=c.to-c.from,s=!0}return s}idleStep(e,n,r,a=()=>performance.now()){let s=a(),i=null,o=u=>{i=i?{from:Math.min(i.from,u.from),to:Math.max(i.to,u.to)}:{from:u.from,to:u.to}};this.rebalanceOnce(e);let l=this.firstNonFinal(0);for(;l>=0&&l<this.chunks.length&&l<=r;){let u=this.tokenize(e,l,!1);if(o(this.chunks[l]),u){let c=l+1;for(;c<this.chunks.length;c++){let d=this.chunks[c];if(!d.final)if(d.startState&&KC(d.startState,this.chunks[c-1].endState))d.final=!0;else break}l=this.firstNonFinal(c)}else{if(l+1<this.chunks.length&&(this.chunks[l+1].final=!1),l>=r)for(let c=l+2;c<this.chunks.length;c++)this.chunks[c].final=!1;l+=1}if(a()-s>=n)break}return{more:this.hasPendingWork(e,r),touched:i}}applyChanges(e,n){let r=new Set;if(e.iterChangedRanges((o,l)=>{let u=this.chunkIndexAt(o);for(;u<this.chunks.length&&this.chunks[u].from<=l;)r.add(this.chunks[u]),u++}),n.length===0){this.layout(n);return}let a=[],s=0;for(let o=0;o<this.chunks.length;o++){let l=this.chunks[o],u=e.mapPos(l.to,1);if(u>n.length&&(u=n.length),u=n.lineAt(u).to,u<s){let c=a[a.length-1];c&&r.add(c);continue}l.from=s,l.to=u,a.push(l),s=u+1}let i=a[a.length-1];i&&i.to<n.length&&(i.to=n.length,r.add(i));for(let o of r)o.lines=null,o.startState=null,o.final=!1,o.stateKnown=!1;this.chunks.length=0,this.chunks.push(...a),this.layoutDirty=!0,this.splitOversized(n,r)}splitOversized(e,n){for(let r=0;r<this.chunks.length;r++){let a=this.chunks[r];if(!n.has(a))continue;let s=e.lineAt(a.from).number,i=e.lineAt(a.to).number;if(i-s+1<=this.targetLines*2&&a.to-a.from<=this.targetChars*2)continue;let l=this.pieces(e,s,i);if(l.length<2)continue;let u=l[l.length-1];u.endState=a.endState,this.chunks.splice(r,1,...l),r+=l.length-1}}rebalanceTarget(e){if(!this.layoutDirty)return null;let n=this.targetLines;for(let r=0;r+1<this.chunks.length;r++){let a=this.chunks[r],s=this.chunks[r+1],i=this.lineCountOf(e,a),o=a.to-a.from;if(!(i>=n/2||o>=this.targetChars/2)&&!(i+this.lineCountOf(e,s)>n*2)&&!(s.to-a.from>this.targetChars*2))return r}return this.layoutDirty=!1,null}rebalanceOnce(e){let n=this.rebalanceTarget(e);if(n===null)return!1;let r=this.chunks[n],a=this.chunks[n+1];return r.to=a.to,r.endState=a.endState,r.lines=null,r.startState=null,r.final=!1,r.stateKnown=!1,this.chunks.splice(n+1,1),this.layoutDirty=!0,!0}trimWindow(){let e=this.chunks.filter(n=>n.lines);if(!(e.length<=32)){e.sort((n,r)=>n.lastUsed-r.lastUsed);for(let n=0;n<e.length-32;n++)e[n].lines=null}}};var Ks=Me.define({combine:t=>t.length?t[t.length-1]:{theme:"dark-plus"}}),JC=pt.define(),HF=8;function XC(t){setTimeout(()=>{try{t.dispatch({effects:JC.of(null)})}catch{}},0)}function UF(t){let e=globalThis;if(typeof e.requestIdleCallback=="function"){let r=e.requestIdleCallback(t,{timeout:250});return{cancel:()=>e.cancelIdleCallback?.(r)}}let n=setTimeout(t,0);return{cancel:()=>clearTimeout(n)}}var YC=new Map;function GF(t){let e=YC.get(t);return e||(e=Ke.mark({attributes:{style:`color:${t}`}}),YC.set(t,e)),e}var Ig=class{constructor(e){this.decorations=Ke.none;this.engine=null;this.engineKey="";this.idle=null;this.disposed=!1;this.loadKicked=null;this.horizon=0;this.decorations=this.build(e)}update(e){e.docChanged&&this.engine&&this.engine.applyChanges(e.changes,e.state.doc);let n=e.startState.facet(Ks),r=e.state.facet(Ks),a=n.lang!==r.lang||n.theme!==r.theme,s=e.transactions.some(i=>i.effects.some(o=>o.is(JC)));(e.docChanged||e.viewportChanged||a||s)&&(this.decorations=this.build(e.view))}destroy(){this.disposed=!0,this.idle?.cancel(),this.idle=null,this.engine=null}build(e){let n=e.state.facet(Ks),r=So(n.lang);if(!r)return this.engine=null,Ke.none;let a=e.state.doc;if(a.length>2e6)return this.engine=null,Ke.none;let s=r1(r);if(!s)return this.loadKicked!==r&&(this.loadKicked=r,au().then(()=>nd(r)).then(c=>{c&&!this.disposed&&XC(e)})),Ke.none;let i=`${r} ${n.theme}`;(!this.engine||this.engineKey!==i)&&(this.engine=new pf(s,r,n.theme,a),this.engineKey=i);let o=this.engine,l=new qn,u=0;for(let{from:c,to:d}of e.visibleRanges){o.ensureRange(a,c,d);let f=a.lineAt(c).number,h=a.lineAt(d).number,p=o.chunkIndexAt(d);u=Math.max(u,p+4);for(let g=o.chunkIndexAt(c);g<=p;g++){let m=o.chunks[g],x=o.firstLineOf(a,m),y=a.lineAt(m.to).number;for(let b=Math.max(f,x);b<=Math.min(h,y);b++){let C=o.tokensAt(m,b-x);if(!C)continue;let L=a.line(b);for(let P of C){if(!P.content||!P.color)continue;let w=m.from+P.offset,k=w+P.content.length;w<L.from||w>=k||k>L.to||l.add(w,k,GF(P.color))}}}}return this.horizon=u,o.hasPendingWork(a,u)&&this.scheduleIdle(e),l.finish()}scheduleIdle(e){this.idle||this.disposed||(this.idle=UF(()=>{if(this.idle=null,this.disposed||!this.engine)return;let n=this.engine.idleStep(e.state.doc,HF,this.horizon),r=n.touched;!!r&&e.visibleRanges.some(s=>r.from<=s.to&&r.to>=s.from)?XC(e):n.more&&this.scheduleIdle(e)}))}},mf=hr.fromClass(Ig,{decorations:t=>t.decorations});var gf=Pe.theme({"&":{backgroundColor:"transparent",color:"#d4d4d4",height:"100%"},"&.cm-focused":{outline:"none"},".cm-scroller":{fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace',fontSize:"12px",lineHeight:"18px"},".cm-content":{padding:"6px 0",caretColor:"#e5e7eb"},".cm-gutters":{backgroundColor:"transparent",border:"none",color:"rgba(255,255,255,0.25)"},".cm-lineNumbers .cm-gutterElement":{padding:"0 10px 0 12px",minWidth:"2ch"},".cm-activeLine":{backgroundColor:"rgba(255,255,255,0.035)"},".cm-activeLineGutter":{backgroundColor:"transparent",color:"rgba(255,255,255,0.5)"},".cm-cursor, .cm-dropCursor":{borderLeftColor:"#e5e7eb"},".cm-selectionBackground, .cm-content ::selection":{backgroundColor:"rgba(96,130,255,0.28)"},"&.cm-focused .cm-selectionBackground":{backgroundColor:"rgba(96,130,255,0.34)"},".cm-placeholder":{color:"rgba(255,255,255,0.22)"}},{dark:!0}),ZC=Pe.theme({".cm-changedLine":{backgroundColor:"rgba(16,185,129,0.10)"},".cm-changedText":{background:"rgba(16,185,129,0.24)"},".cm-insertedLine":{backgroundColor:"rgba(16,185,129,0.12)"},".cm-deletedChunk":{backgroundColor:"rgba(244,63,94,0.10)"},".cm-deletedChunk .cm-deletedText, .cm-deletedText":{background:"rgba(244,63,94,0.30)"},".cm-changeGutter":{width:"3px"},".cm-changedLineGutter":{backgroundColor:"rgba(16,185,129,0.45)"},".cm-deletedLineGutter":{backgroundColor:"rgba(244,63,94,0.45)"},".cm-merge-a, .cm-merge-b":{backgroundColor:"transparent"},".cm-mergeSpacer":{backgroundColor:"rgba(255,255,255,0.02)"},".cm-merge-revert":{display:"none"}});var QC=j(ie(),1);function Lg(t,e){return[Kd(),It.readOnly.of(!0),Pe.editable.of(!1),gf,ZC,Ks.of({lang:t,theme:e}),mf]}function Ag({oldContent:t,newContent:e,language:n,viewMode:r="unified",className:a,theme:s="dark-plus"}){let i=(0,xf.useRef)(null);return(0,xf.useEffect)(()=>{let o=i.current;if(!o)return;let l;if(r==="split"){let u=new df({a:{doc:t,extensions:Lg(n,s)},b:{doc:e,extensions:Lg(n,s)},parent:o,gutter:!0,highlightChanges:!0,revertControls:void 0});l=()=>u.destroy()}else{let u=It.create({doc:e,extensions:[...Lg(n,s),qC({original:t,mergeControls:!1,gutter:!0,highlightChanges:!0,syntaxHighlightDeletions:!1})]}),c=new Pe({state:u,parent:o});l=()=>c.destroy()}return l},[t,e,n,r,s]),(0,QC.jsx)("div",{ref:i,className:a})}var Kn=j($e(),1);var WF=t=>{let{state:e}=t,n=e.doc.lineAt(e.selection.main.from),r=Fg(t.state,n.from);return r.line?zF(t):r.block?VF(t):!1};function Dg(t,e){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let a=t(e,n);return a?(r(n.update(a)),!0):!1}}var zF=Dg(KF,0);var jF=Dg(lI,0);var VF=Dg((t,e)=>lI(t,e,$F(e)),0);function Fg(t,e){let n=t.languageDataAt("commentTokens",e,1);return n.length?n[0]:{}}var ju=50;function qF(t,{open:e,close:n},r,a){let s=t.sliceDoc(r-ju,r),i=t.sliceDoc(a,a+ju),o=/\s*$/.exec(s)[0].length,l=/^\s*/.exec(i)[0].length,u=s.length-o;if(s.slice(u-e.length,u)==e&&i.slice(l,l+n.length)==n)return{open:{pos:r-o,margin:o&&1},close:{pos:a+l,margin:l&&1}};let c,d;a-r<=2*ju?c=d=t.sliceDoc(r,a):(c=t.sliceDoc(r,r+ju),d=t.sliceDoc(a-ju,a));let f=/^\s*/.exec(c)[0].length,h=/\s*$/.exec(d)[0].length,p=d.length-h-n.length;return c.slice(f,f+e.length)==e&&d.slice(p,p+n.length)==n?{open:{pos:r+f+e.length,margin:/\s/.test(c.charAt(f+e.length))?1:0},close:{pos:a-h-n.length,margin:/\s/.test(d.charAt(p-1))?1:0}}:null}function $F(t){let e=[];for(let n of t.selection.ranges){let r=t.doc.lineAt(n.from),a=n.to<=r.to?r:t.doc.lineAt(n.to);a.from>r.from&&a.from==n.to&&(a=n.to==r.to+1?r:t.doc.lineAt(n.to-1));let s=e.length-1;s>=0&&e[s].to>r.from?e[s].to=a.to:e.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:a.to})}return e}function lI(t,e,n=e.selection.ranges){let r=n.map(s=>Fg(e,s.from).block);if(!r.every(s=>s))return null;let a=n.map((s,i)=>qF(e,r[i],s.from,s.to));if(t!=2&&!a.every(s=>s))return{changes:e.changes(n.map((s,i)=>a[i]?[]:[{from:s.from,insert:r[i].open+" "},{from:s.to,insert:" "+r[i].close}]))};if(t!=1&&a.some(s=>s)){let s=[];for(let i=0,o;i<a.length;i++)if(o=a[i]){let l=r[i],{open:u,close:c}=o;s.push({from:u.pos-l.open.length,to:u.pos+u.margin},{from:c.pos-c.margin,to:c.pos+l.close.length})}return{changes:s}}return null}function KF(t,e,n=e.selection.ranges){let r=[],a=-1;e:for(let{from:s,to:i}of n){let o=r.length,l=1e9,u;for(let c=s;c<=i;){let d=e.doc.lineAt(c);if(u==null&&(u=Fg(e,d.from).line,!u))continue e;if(d.from>a&&(s==i||i>d.from)){a=d.from;let f=/^\s*/.exec(d.text)[0].length,h=f==d.length,p=d.text.slice(f,f+u.length)==u?f:-1;f<d.text.length&&f<l&&(l=f),r.push({line:d,comment:p,token:u,indent:f,empty:h,single:!1})}c=d.to+1}if(l<1e9)for(let c=o;c<r.length;c++)r[c].indent<r[c].line.text.length&&(r[c].indent=l);r.length==o+1&&(r[o].single=!0)}if(t!=2&&r.some(s=>s.comment<0&&(!s.empty||s.single))){let s=[];for(let{line:o,token:l,indent:u,empty:c,single:d}of r)(d||!c)&&s.push({from:o.from+u,insert:l+" "});let i=e.changes(s);return{changes:i,selection:e.selection.map(i,1)}}else if(t!=1&&r.some(s=>s.comment>=0)){let s=[];for(let{line:i,comment:o,token:l}of r)if(o>=0){let u=i.from+o,c=u+l.length;i.text[c-i.from]==" "&&c++,s.push({from:u,to:c})}return{changes:s}}return null}var Ng=Hr.define(),XF=Hr.define(),YF=Me.define(),uI=Me.define({combine(t){return No(t,{minDepth:100,newGroupDelay:500,joinToEvent:(e,n)=>n},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,n)=>(r,a)=>e(r,a)||n(r,a)})}}),cI=vn.define({create(){return Gi.empty},update(t,e){let n=e.state.facet(uI),r=e.annotation(Ng);if(r){let l=da.fromTransaction(e,r.selection),u=r.side,c=u==0?t.undone:t.done;return l?c=bf(c,c.length,n.minDepth,l):c=pI(c,e.startState.selection),new Gi(u==0?r.rest:c,u==0?c:r.rest)}let a=e.annotation(XF);if((a=="full"||a=="before")&&(t=t.isolate()),e.annotation(An.addToHistory)===!1)return e.changes.empty?t:t.addMapping(e.changes.desc);let s=da.fromTransaction(e),i=e.annotation(An.time),o=e.annotation(An.userEvent);return s?t=t.addChanges(s,i,o,n,e):e.selection&&(t=t.addSelection(e.startState.selection,i,o,n.newGroupDelay)),(a=="full"||a=="after")&&(t=t.isolate()),t},toJSON(t){return{done:t.done.map(e=>e.toJSON()),undone:t.undone.map(e=>e.toJSON())}},fromJSON(t){return new Gi(t.done.map(da.fromJSON),t.undone.map(da.fromJSON))}});function dI(t={}){return[cI,uI.of(t),Pe.domEventHandlers({beforeinput(e,n){let r=e.inputType=="historyUndo"?fI:e.inputType=="historyRedo"?Rg:null;return r?(e.preventDefault(),r(n)):!1}})]}function wf(t,e){return function({state:n,dispatch:r}){if(!e&&n.readOnly)return!1;let a=n.field(cI,!1);if(!a)return!1;let s=a.pop(t,n,e);return s?(r(s),!0):!1}}var fI=wf(0,!1),Rg=wf(1,!1),JF=wf(0,!0),ZF=wf(1,!0);var da=class t{constructor(e,n,r,a,s){this.changes=e,this.effects=n,this.mapped=r,this.startSelection=a,this.selectionsAfter=s}setSelAfter(e){return new t(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,n,r;return{changes:(e=this.changes)===null||e===void 0?void 0:e.toJSON(),mapped:(n=this.mapped)===null||n===void 0?void 0:n.toJSON(),startSelection:(r=this.startSelection)===null||r===void 0?void 0:r.toJSON(),selectionsAfter:this.selectionsAfter.map(a=>a.toJSON())}}static fromJSON(e){return new t(e.changes&&Nn.fromJSON(e.changes),[],e.mapped&&rs.fromJSON(e.mapped),e.startSelection&&se.fromJSON(e.startSelection),e.selectionsAfter.map(se.fromJSON))}static fromTransaction(e,n){let r=jr;for(let a of e.startState.facet(YF)){let s=a(e);s.length&&(r=r.concat(s))}return!r.length&&e.changes.empty?null:new t(e.changes.invert(e.startState.doc),r,void 0,n||e.startState.selection,jr)}static selection(e){return new t(void 0,jr,void 0,void 0,e)}};function bf(t,e,n,r){let a=e+1>n+20?e-n-1:0,s=t.slice(a,e);return s.push(r),s}function QF(t,e){let n=[],r=!1;return t.iterChangedRanges((a,s)=>n.push(a,s)),e.iterChangedRanges((a,s,i,o)=>{for(let l=0;l<n.length;){let u=n[l++],c=n[l++];o>=u&&i<=c&&(r=!0)}}),r}function e5(t,e){return t.ranges.length==e.ranges.length&&t.ranges.filter((n,r)=>n.empty!=e.ranges[r].empty).length===0}function hI(t,e){return t.length?e.length?t.concat(e):t:e}var jr=[],t5=200;function pI(t,e){if(t.length){let n=t[t.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-t5));return r.length&&r[r.length-1].eq(e)?t:(r.push(e),bf(t,t.length-1,1e9,n.setSelAfter(r)))}else return[da.selection([e])]}function n5(t){let e=t[t.length-1],n=t.slice();return n[t.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),n}function Pg(t,e){if(!t.length)return t;let n=t.length,r=jr;for(;n;){let a=r5(t[n-1],e,r);if(a.changes&&!a.changes.empty||a.effects.length){let s=t.slice(0,n);return s[n-1]=a,s}else e=a.mapped,n--,r=a.selectionsAfter}return r.length?[da.selection(r)]:jr}function r5(t,e,n){let r=hI(t.selectionsAfter.length?t.selectionsAfter.map(o=>o.map(e)):jr,n);if(!t.changes)return da.selection(r);let a=t.changes.map(e),s=e.mapDesc(t.changes,!0),i=t.mapped?t.mapped.composeDesc(s):s;return new da(a,pt.mapEffects(t.effects,e),i,t.startSelection.map(s),r)}var a5=/^(input\.type|delete)($|\.)/,Gi=class t{constructor(e,n,r=0,a=void 0){this.done=e,this.undone=n,this.prevTime=r,this.prevUserEvent=a}isolate(){return this.prevTime?new t(this.done,this.undone):this}addChanges(e,n,r,a,s){let i=this.done,o=i[i.length-1];return o&&o.changes&&!o.changes.empty&&e.changes&&(!r||a5.test(r))&&(!o.selectionsAfter.length&&n-this.prevTime<a.newGroupDelay&&a.joinToEvent(s,QF(o.changes,e.changes))||r=="input.type.compose")?i=bf(i,i.length-1,a.minDepth,new da(e.changes.compose(o.changes),hI(pt.mapEffects(e.effects,o.changes),o.effects),o.mapped,o.startSelection,jr)):i=bf(i,i.length,a.minDepth,e),new t(i,jr,n,r)}addSelection(e,n,r,a){let s=this.done.length?this.done[this.done.length-1].selectionsAfter:jr;return s.length>0&&n-this.prevTime<a&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&e5(s[s.length-1],e)?this:new t(pI(this.done,e),this.undone,n,r)}addMapping(e){return new t(Pg(this.done,e),Pg(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,n,r){let a=e==0?this.done:this.undone;if(a.length==0)return null;let s=a[a.length-1],i=s.selectionsAfter[0]||(s.startSelection?s.startSelection.map(s.changes.invertedDesc,1):n.selection);if(r&&s.selectionsAfter.length)return n.update({selection:s.selectionsAfter[s.selectionsAfter.length-1],annotations:Ng.of({side:e,rest:n5(a),selection:i}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(s.changes){let o=a.length==1?jr:a.slice(0,a.length-1);return s.mapped&&(o=Pg(o,s.mapped)),n.update({changes:s.changes,selection:s.startSelection,effects:s.effects,annotations:Ng.of({side:e,rest:o,selection:i}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}};Gi.empty=new Gi(jr,jr);var mI=[{key:"Mod-z",run:fI,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:Rg,preventDefault:!0},{linux:"Ctrl-Shift-z",run:Rg,preventDefault:!0},{key:"Mod-u",run:JF,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:ZF,preventDefault:!0}];function $o(t,e){return se.create(t.ranges.map(e),t.mainIndex)}function fa(t,e){return t.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function ha({state:t,dispatch:e},n){let r=$o(t.selection,n);return r.eq(t.selection,!0)?!1:(e(fa(t,r)),!0)}function vf(t,e){return se.cursor(e?t.to:t.from)}function gI(t,e){return ha(t,n=>n.empty?t.moveByChar(n,e):vf(n,e))}function $n(t){return t.textDirectionAt(t.state.selection.main.head)==Vt.LTR}var xI=t=>gI(t,!$n(t)),yI=t=>gI(t,$n(t));function bI(t,e){return ha(t,n=>n.empty?t.moveByGroup(n,e):vf(n,e))}var s5=t=>bI(t,!$n(t)),i5=t=>bI(t,$n(t));var V6=typeof Intl<"u"&&Intl.Segmenter?new Intl.Segmenter(void 0,{granularity:"word"}):null;function o5(t,e,n){if(e.type.prop(n))return!0;let r=e.to-e.from;return r&&(r>2||/[^\s,.;:]/.test(t.sliceDoc(e.from,e.to)))||e.firstChild}function kf(t,e,n){let r=ls(t).resolveInner(e.head),a=n?rt.closedBy:rt.openedBy;for(let l=e.head;;){let u=n?r.childAfter(l):r.childBefore(l);if(!u)break;o5(t,u,a)?r=u:l=n?u.to:u.from}let s=r.type.prop(a),i,o;return s&&(i=n?_i(t,r.from,1):_i(t,r.to,-1))&&i.matched?o=n?i.end.to:i.end.from:o=n?r.to:r.from,se.cursor(o,n?-1:1)}var l5=t=>ha(t,e=>kf(t.state,e,!$n(t))),u5=t=>ha(t,e=>kf(t.state,e,$n(t)));function wI(t,e){return ha(t,n=>{if(!n.empty)return vf(n,e);let r=t.moveVertically(n,e);return r.head!=n.head?r:t.moveToLineBoundary(n,e)})}var vI=t=>wI(t,!1),kI=t=>wI(t,!0);function SI(t){let e=t.scrollDOM.clientHeight<t.scrollDOM.scrollHeight-2,n=0,r=0,a;if(e){for(let s of t.state.facet(Pe.scrollMargins)){let i=s(t);i?.top&&(n=Math.max(i?.top,n)),i?.bottom&&(r=Math.max(i?.bottom,r))}a=t.scrollDOM.clientHeight-n-r}else a=(t.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:e,height:Math.max(t.defaultLineHeight,a-5)}}function CI(t,e){let n=SI(t),{state:r}=t,a=$o(r.selection,i=>i.empty?t.moveVertically(i,e,n.height):vf(i,e));if(a.eq(r.selection))return!1;let s;if(n.selfScroll){let i=t.coordsAtPos(r.selection.main.head),o=t.scrollDOM.getBoundingClientRect(),l=o.top+n.marginTop,u=o.bottom-n.marginBottom;i&&i.top>l&&i.bottom<u&&(s=Pe.scrollIntoView(a.main.head,{y:"start",yMargin:i.top-l}))}return t.dispatch(fa(r,a),{effects:s}),!0}var eI=t=>CI(t,!1),Mg=t=>CI(t,!0);function Xs(t,e,n){let r=t.lineBlockAt(e.head),a=t.moveToLineBoundary(e,n);if(a.head==e.head&&a.head!=(n?r.to:r.from)&&(a=t.moveToLineBoundary(e,n,!1)),!n&&a.head==r.from&&r.length){let s=/^\s*/.exec(t.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;s&&e.head!=r.from+s&&(a=se.cursor(r.from+s))}return a}var c5=t=>ha(t,e=>Xs(t,e,!0)),d5=t=>ha(t,e=>Xs(t,e,!1)),f5=t=>ha(t,e=>Xs(t,e,!$n(t))),h5=t=>ha(t,e=>Xs(t,e,$n(t))),p5=t=>ha(t,e=>t.moveToLineBoundary(e,!1,!1)),m5=t=>ha(t,e=>t.moveToLineBoundary(e,!0,!1));function g5(t,e,n){let r=!1,a=$o(t.selection,s=>{let i=_i(t,s.head,-1)||_i(t,s.head,1)||s.head>0&&_i(t,s.head-1,1)||s.head<t.doc.length&&_i(t,s.head+1,-1);if(!i||!i.end)return s;r=!0;let o=i.start.from==s.head?i.end.to:i.end.from;return n?se.range(s.anchor,o):se.cursor(o)});return r?(e(fa(t,a)),!0):!1}var x5=({state:t,dispatch:e})=>g5(t,e,!1);function Vr(t,e,n){let r=$o(t.state.selection,a=>{a.undirectional&&a.head>=a.anchor!=e&&(a=se.range(a.head,a.anchor));let s=n(a);return se.range(a.anchor,s.head,s.goalColumn,s.bidiLevel||void 0,s.assoc)});return r.eq(t.state.selection)?!1:(t.dispatch(fa(t.state,r)),!0)}function II(t,e){return Vr(t,e,n=>t.moveByChar(n,e))}var LI=t=>II(t,!$n(t)),AI=t=>II(t,$n(t));function PI(t,e){return Vr(t,e,n=>t.moveByGroup(n,e))}var y5=t=>PI(t,!$n(t)),b5=t=>PI(t,$n(t));var w5=t=>{let e=!$n(t);return Vr(t,e,n=>kf(t.state,n,e))},v5=t=>{let e=$n(t);return Vr(t,e,n=>kf(t.state,n,e))};function NI(t,e){return Vr(t,e,n=>t.moveVertically(n,e))}var RI=t=>NI(t,!1),MI=t=>NI(t,!0);function TI(t,e){return Vr(t,e,n=>t.moveVertically(n,e,SI(t).height))}var tI=t=>TI(t,!1),nI=t=>TI(t,!0),k5=t=>Vr(t,!0,e=>Xs(t,e,!0)),S5=t=>Vr(t,!1,e=>Xs(t,e,!1)),C5=t=>{let e=!$n(t);return Vr(t,e,n=>Xs(t,n,e))},I5=t=>{let e=$n(t);return Vr(t,e,n=>Xs(t,n,e))},L5=t=>Vr(t,!1,e=>se.cursor(t.lineBlockAt(e.head).from)),A5=t=>Vr(t,!0,e=>se.cursor(t.lineBlockAt(e.head).to)),rI=({state:t,dispatch:e})=>(e(fa(t,{anchor:0})),!0),aI=({state:t,dispatch:e})=>(e(fa(t,{anchor:t.doc.length})),!0),sI=({state:t,dispatch:e})=>(e(fa(t,{anchor:t.selection.main.anchor,head:0})),!0),iI=({state:t,dispatch:e})=>(e(fa(t,{anchor:t.selection.main.anchor,head:t.doc.length})),!0),P5=({state:t,dispatch:e})=>(e(t.update({selection:{anchor:0,head:t.doc.length},userEvent:"select"})),!0),N5=({state:t,dispatch:e})=>{let n=Sf(t).map(({from:r,to:a})=>se.undirectionalRange(r,Math.min(a+1,t.doc.length)));return e(t.update({selection:se.create(n),userEvent:"select"})),!0},R5=({state:t,dispatch:e})=>{let n=$o(t.selection,r=>{let a=ls(t),s=a.resolveStack(r.from,1);if(r.empty){let i=a.resolveStack(r.from,-1);i.node.from>=s.node.from&&i.node.to<=s.node.to&&(s=i)}for(let i=s;i;i=i.next){let{node:o}=i;if((o.from<r.from&&o.to>=r.to||o.to>r.to&&o.from<=r.from)&&i.next)return se.undirectionalRange(o.from,o.to)}return r});return n.eq(t.selection)?!1:(e(fa(t,n)),!0)};function DI(t,e){let{state:n}=t,r=n.selection,a=n.selection.ranges.slice();for(let s of n.selection.ranges){let i=n.doc.lineAt(s.head);if(e?i.to<t.state.doc.length:i.from>0)for(let o=s;;){let l=t.moveVertically(o,e);if(l.head<i.from||l.head>i.to){a.some(u=>u.head==l.head)||a.push(l);break}else{if(l.head==o.head)break;o=l}}}return a.length==r.ranges.length?!1:(t.dispatch(fa(n,se.create(a,a.length-1))),!0)}var M5=t=>DI(t,!1),T5=t=>DI(t,!0),D5=({state:t,dispatch:e})=>{let n=t.selection,r=null;return n.ranges.length>1?r=se.create([n.main]):n.main.empty||(r=se.create([se.cursor(n.main.head)])),r?(e(fa(t,r)),!0):!1};function Vu(t,e){if(t.state.readOnly)return!1;let n="delete.selection",{state:r}=t,a=r.changeByRange(s=>{let{from:i,to:o}=s;if(i==o){let l=e(s);l<i?(n="delete.backward",l=yf(t,l,!1)):l>i&&(n="delete.forward",l=yf(t,l,!0)),i=Math.min(i,l),o=Math.max(o,l)}else i=yf(t,i,!1),o=yf(t,o,!0);return i==o?{range:s}:{changes:{from:i,to:o},range:se.cursor(i,i<s.head?-1:1)}});return a.changes.empty?!1:(t.dispatch(r.update(a,{scrollIntoView:!0,userEvent:n,effects:n=="delete.selection"?Pe.announce.of(r.phrase("Selection deleted")):void 0})),!0)}function yf(t,e,n){if(t instanceof Pe)for(let r of t.state.facet(Pe.atomicRanges).map(a=>a(t)))r.between(e,e,(a,s)=>{a<e&&s>e&&(e=n?s:a)});return e}var FI=(t,e,n)=>Vu(t,r=>{let a=r.from,{state:s}=t,i=s.doc.lineAt(a),o,l;if(n&&!e&&a>i.from&&a<i.from+200&&!/[^ \t]/.test(o=i.text.slice(0,a-i.from))){if(o[o.length-1]==" ")return a-1;let u=Li(o,s.tabSize),c=u%Hu(s)||Hu(s);for(let d=0;d<c&&o[o.length-1-d]==" ";d++)a--;l=a}else l=Pn(i.text,a-i.from,e,e)+i.from,l==a&&i.number!=(e?s.doc.lines:1)?l+=e?1:-1:!e&&/[\ufe00-\ufe0f]/.test(i.text.slice(l-i.from,a-i.from))&&(l=Pn(i.text,l-i.from,!1,!1)+i.from);return l}),Tg=t=>FI(t,!1,!0);var EI=t=>FI(t,!0,!1),OI=(t,e)=>Vu(t,n=>{let r=n.head,{state:a}=t,s=a.doc.lineAt(r),i=a.charCategorizer(r);for(let o=null;;){if(r==(e?s.to:s.from)){r==n.head&&s.number!=(e?a.doc.lines:1)&&(r+=e?1:-1);break}let l=Pn(s.text,r-s.from,e)+s.from,u=s.text.slice(Math.min(r,l)-s.from,Math.max(r,l)-s.from),c=i(u);if(o!=null&&c!=o)break;(u!=" "||r!=n.head)&&(o=c),r=l}return r}),BI=t=>OI(t,!1),F5=t=>OI(t,!0);var E5=t=>Vu(t,e=>{let n=t.lineBlockAt(e.head).to;return e.head<n?n:Math.min(t.state.doc.length,e.head+1)});var O5=t=>Vu(t,e=>{let n=t.moveToLineBoundary(e,!1).head;return e.head>n?n:Math.max(0,e.head-1)}),B5=t=>Vu(t,e=>{let n=t.moveToLineBoundary(e,!0).head;return e.head<n?n:Math.min(t.state.doc.length,e.head+1)});var _5=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let n=t.changeByRange(r=>({changes:{from:r.from,to:r.to,insert:st.of(["",""])},range:se.cursor(r.from)}));return e(t.update(n,{scrollIntoView:!0,userEvent:"input"})),!0},H5=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let n=t.changeByRange(r=>{if(!r.empty||r.from==0||r.from==t.doc.length)return{range:r};let a=r.from,s=t.doc.lineAt(a),i=a==s.from?a-1:Pn(s.text,a-s.from,!1)+s.from,o=a==s.to?a+1:Pn(s.text,a-s.from,!0)+s.from;return{changes:{from:i,to:o,insert:t.doc.slice(a,o).append(t.doc.slice(i,a))},range:se.cursor(o)}});return n.changes.empty?!1:(e(t.update(n,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function Sf(t){let e=[],n=-1;for(let r of t.selection.ranges){let a=t.doc.lineAt(r.from),s=t.doc.lineAt(r.to);if(!r.empty&&r.to==s.from&&(s=t.doc.lineAt(r.to-1)),n>=a.number){let i=e[e.length-1];i.to=s.to,i.ranges.push(r)}else e.push({from:a.from,to:s.to,ranges:[r]});n=s.number+1}return e}function _I(t,e,n){if(t.readOnly)return!1;let r=[],a=[];for(let s of Sf(t)){if(n?s.to==t.doc.length:s.from==0)continue;let i=t.doc.lineAt(n?s.to+1:s.from-1),o=i.length+1;if(n){r.push({from:s.to,to:i.to},{from:s.from,insert:i.text+t.lineBreak});for(let l of s.ranges)a.push(se.range(Math.min(t.doc.length,l.anchor+o),Math.min(t.doc.length,l.head+o)))}else{r.push({from:i.from,to:s.from},{from:s.to,insert:t.lineBreak+i.text});for(let l of s.ranges)a.push(se.range(l.anchor-o,l.head-o))}}return r.length?(e(t.update({changes:r,scrollIntoView:!0,selection:se.create(a,t.selection.mainIndex),userEvent:"move.line"})),!0):!1}var U5=({state:t,dispatch:e})=>_I(t,e,!1),G5=({state:t,dispatch:e})=>_I(t,e,!0);function HI(t,e,n){if(t.readOnly)return!1;let r=[];for(let s of Sf(t))n?r.push({from:s.from,insert:t.doc.slice(s.from,s.to)+t.lineBreak}):r.push({from:s.to,insert:t.lineBreak+t.doc.slice(s.from,s.to)});let a=t.changes(r);return e(t.update({changes:a,selection:t.selection.map(a,n?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}var W5=({state:t,dispatch:e})=>HI(t,e,!1),z5=({state:t,dispatch:e})=>HI(t,e,!0),j5=t=>{if(t.state.readOnly)return!1;let{state:e}=t,n=e.changes(Sf(e).map(({from:a,to:s})=>(a>0?a--:s<e.doc.length&&s++,{from:a,to:s}))),r=$o(e.selection,a=>{let s;if(t.lineWrapping){let i=t.lineBlockAt(a.head),o=t.coordsAtPos(a.head,a.assoc||1);o&&(s=i.bottom+t.documentTop-o.bottom+t.defaultLineHeight/2)}return t.moveVertically(a,!0,s)}).map(n);return t.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:"delete.line"}),!0};function V5(t,e){if(/\(\)|\[\]|\{\}/.test(t.sliceDoc(e-1,e+1)))return{from:e,to:e};let n=ls(t).resolveInner(e),r=n.childBefore(e),a=n.childAfter(e),s;return r&&a&&r.to<=e&&a.from>=e&&(s=r.type.prop(rt.closedBy))&&s.indexOf(a.name)>-1&&t.doc.lineAt(r.to).from==t.doc.lineAt(a.from).from&&!/\S/.test(t.sliceDoc(r.to,a.from))?{from:r.to,to:a.from}:null}var oI=UI(!1),q5=UI(!0);function UI(t){return({state:e,dispatch:n})=>{if(e.readOnly)return!1;let r=e.changeByRange(a=>{let{from:s,to:i}=a,o=e.doc.lineAt(s),l=!t&&s==i&&V5(e,s);t&&(s=i=(i<=o.to?o:e.doc.lineAt(i)).to);let u=new Bi(e,{simulateBreak:s,simulateDoubleBreak:!!l}),c=fg(u,s);for(c==null&&(c=Li(/^\s*/.exec(e.doc.lineAt(s).text)[0],e.tabSize));i<o.to&&/\s/.test(o.text[i-o.from]);)i++;l?{from:s,to:i}=l:s>o.from&&s<o.from+100&&!/\S/.test(o.text.slice(0,s))&&(s=o.from);let d=["",Uu(e,c)];return l&&d.push(Uu(e,u.lineIndent(o.from,-1))),{changes:{from:s,to:i,insert:st.of(d)},range:se.cursor(s+1+d[1].length)}});return n(e.update(r,{scrollIntoView:!0,userEvent:"input"})),!0}}function Eg(t,e){let n=-1;return t.changeByRange(r=>{let a=[];for(let i=r.from;i<=r.to;){let o=t.doc.lineAt(i);o.number>n&&(r.empty||r.to>o.from)&&(e(o,a,r),n=o.number),i=o.to+1}let s=t.changes(a);return{changes:a,range:se.range(s.mapPos(r.anchor,1),s.mapPos(r.head,1))}})}var $5=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let n=Object.create(null),r=new Bi(t,{overrideIndentation:s=>{let i=n[s];return i??-1}}),a=Eg(t,(s,i,o)=>{let l=fg(r,s.from);if(l==null)return;/\S/.test(s.text)||(l=0);let u=/^\s*/.exec(s.text)[0],c=Uu(t,l);(u!=c||o.from<s.from+u.length)&&(n[s.from]=l,i.push({from:s.from,to:s.from+u.length,insert:c}))});return a.changes.empty||e(t.update(a,{userEvent:"indent"})),!0},GI=({state:t,dispatch:e})=>t.readOnly?!1:(e(t.update(Eg(t,(n,r)=>{r.push({from:n.from,insert:t.facet(rf)})}),{userEvent:"input.indent"})),!0),WI=({state:t,dispatch:e})=>t.readOnly?!1:(e(t.update(Eg(t,(n,r)=>{let a=/^\s*/.exec(n.text)[0];if(!a)return;let s=Li(a,t.tabSize),i=0,o=Uu(t,Math.max(0,s-Hu(t)));for(;i<a.length&&i<o.length&&a.charCodeAt(i)==o.charCodeAt(i);)i++;r.push({from:n.from+i,to:n.from+a.length,insert:o.slice(i)})}),{userEvent:"delete.dedent"})),!0),K5=t=>(t.setTabFocusMode(),!0);var X5=[{key:"Ctrl-b",run:xI,shift:LI,preventDefault:!0},{key:"Ctrl-f",run:yI,shift:AI},{key:"Ctrl-p",run:vI,shift:RI},{key:"Ctrl-n",run:kI,shift:MI},{key:"Ctrl-a",run:p5,shift:L5},{key:"Ctrl-e",run:m5,shift:A5},{key:"Ctrl-d",run:EI},{key:"Ctrl-h",run:Tg},{key:"Ctrl-k",run:E5},{key:"Ctrl-Alt-h",run:BI},{key:"Ctrl-o",run:_5},{key:"Ctrl-t",run:H5},{key:"Ctrl-v",run:Mg}],Y5=[{key:"ArrowLeft",run:xI,shift:LI,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:s5,shift:y5,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:f5,shift:C5,preventDefault:!0},{key:"ArrowRight",run:yI,shift:AI,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:i5,shift:b5,preventDefault:!0},{mac:"Cmd-ArrowRight",run:h5,shift:I5,preventDefault:!0},{key:"ArrowUp",run:vI,shift:RI,preventDefault:!0},{mac:"Cmd-ArrowUp",run:rI,shift:sI},{mac:"Ctrl-ArrowUp",run:eI,shift:tI},{key:"ArrowDown",run:kI,shift:MI,preventDefault:!0},{mac:"Cmd-ArrowDown",run:aI,shift:iI},{mac:"Ctrl-ArrowDown",run:Mg,shift:nI},{key:"PageUp",run:eI,shift:tI},{key:"PageDown",run:Mg,shift:nI},{key:"Home",run:d5,shift:S5,preventDefault:!0},{key:"Mod-Home",run:rI,shift:sI},{key:"End",run:c5,shift:k5,preventDefault:!0},{key:"Mod-End",run:aI,shift:iI},{key:"Enter",run:oI,shift:oI},{key:"Mod-a",run:P5},{key:"Backspace",run:Tg,shift:Tg,preventDefault:!0},{key:"Delete",run:EI,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:BI,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:F5,preventDefault:!0},{mac:"Mod-Backspace",run:O5,preventDefault:!0},{mac:"Mod-Delete",run:B5,preventDefault:!0}].concat(X5.map(t=>({mac:t.key,run:t.run,shift:t.shift}))),zI=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:l5,shift:w5},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:u5,shift:v5},{key:"Alt-ArrowUp",run:U5},{key:"Shift-Alt-ArrowUp",run:W5},{key:"Alt-ArrowDown",run:G5},{key:"Shift-Alt-ArrowDown",run:z5},{key:"Mod-Alt-ArrowUp",run:M5},{key:"Mod-Alt-ArrowDown",run:T5},{key:"Escape",run:D5},{key:"Mod-Enter",run:q5},{key:"Alt-l",mac:"Ctrl-l",run:N5},{key:"Mod-i",run:R5,preventDefault:!0},{key:"Mod-[",run:WI},{key:"Mod-]",run:GI},{key:"Mod-Alt-\\",run:$5},{key:"Shift-Mod-k",run:j5},{key:"Shift-Mod-\\",run:x5},{key:"Mod-/",run:WF},{key:"Alt-A",mac:"Ctrl-A",run:jF},{key:"Ctrl-m",mac:"Shift-Alt-m",run:K5}].concat(Y5),jI={key:"Tab",run:GI,shift:WI};var J5={lines:new Map,deletedBefore:new Set},VI=pt.define(),qI=vn.define({create:()=>J5,update(t,e){for(let n of e.effects)if(n.is(VI))return n.value;return t}}),qu=class extends Bn{constructor(n){super();this.kind=n}eq(n){return n.kind===this.kind}toDOM(){let n=document.createElement("div");return this.kind==="deleted"?n.style.cssText="width:0;height:0;margin-left:2px;border-left:4px solid rgba(244,63,94,0.85);border-top:3px solid transparent;border-bottom:3px solid transparent;":n.style.cssText=`width:2px;height:100%;margin-left:3px;border-radius:1px;background:${this.kind==="added"?"rgba(16,185,129,0.9)":"rgba(59,130,246,0.9)"};`,n}},Z5=new qu("added"),Q5=new qu("modified"),eE=new qu("deleted"),tE=zo({class:"nrs-cm-git-gutter",lineMarker(t,e){let n=t.state.field(qI,!1);if(!n)return null;let r=t.state.doc.lineAt(e.from).number,a=n.lines.get(r);return a==="added"?Z5:a==="modified"?Q5:n.deletedBefore.has(r)?eE:null},lineMarkerChange:t=>t.transactions.some(e=>e.effects.some(n=>n.is(VI)))});function $I(t){return[qI.init(()=>t),tE]}var KI=j(ie(),1);function Og({value:t,language:e,readOnly:n=!1,wrap:r=!1,onChange:a,className:s,placeholder:i,ariaLabel:o,theme:l="dark-plus",gitLineStatus:u}){let c=(0,Kn.useRef)(null),d=(0,Kn.useRef)(null),f=(0,Kn.useRef)(a),h=(0,Kn.useRef)(!1),p=(0,Kn.useRef)(new _r),g=(0,Kn.useRef)(new _r),m=(0,Kn.useRef)(new _r),x=(0,Kn.useRef)(new _r);return f.current=a,(0,Kn.useEffect)(()=>{let y=c.current;if(!y)return;let b=It.create({doc:t,extensions:[Kd(),jS(),$S(),WS(),dI(),jm.of([...zI,...mI,jI]),gf,p.current.of(Ks.of({lang:e,theme:l})),mf,g.current.of([It.readOnly.of(n),Pe.editable.of(!n)]),m.current.of(r?Pe.lineWrapping:[]),x.current.of([]),i?VS(i):[],Pe.updateListener.of(L=>{L.docChanged&&!h.current&&f.current?.(L.state.doc.toString())}),Pe.contentAttributes.of(o?{"aria-label":o}:{})]}),C=new Pe({state:b,parent:y});return d.current=C,()=>{C.destroy(),d.current=null}},[]),(0,Kn.useEffect)(()=>{let y=d.current;if(!y)return;let b=y.state.doc.toString();t!==b&&(h.current=!0,y.dispatch({changes:{from:0,to:b.length,insert:t}}),h.current=!1)},[t]),(0,Kn.useEffect)(()=>{let y=d.current;y&&y.dispatch({effects:p.current.reconfigure(Ks.of({lang:e,theme:l}))})},[e,l]),(0,Kn.useEffect)(()=>{let y=d.current;y&&y.dispatch({effects:g.current.reconfigure([It.readOnly.of(n),Pe.editable.of(!n)])})},[n]),(0,Kn.useEffect)(()=>{let y=d.current;y&&y.dispatch({effects:m.current.reconfigure(r?Pe.lineWrapping:[])})},[r]),(0,Kn.useEffect)(()=>{let y=d.current;if(!y)return;let b=u&&!ld(u)?$I(u):[];y.dispatch({effects:x.current.reconfigure(b)})},[u]),(0,KI.jsx)("div",{ref:c,className:s})}var Ko=j($e(),1);var XI=j(ie(),1);function Bg({target:t,agentId:e,projectId:n}){let r=H(l=>l.client),[a,s]=(0,Ko.useState)(!1),i=H(l=>l.sourceChangeRevision[t.source]??0);(0,Ko.useEffect)(()=>{let l=!0;return s(!1),e&&Ki({agentId:e,...n?{projectId:n}:{},source:t.source},r).then(u=>{l&&s(u.repos.find(c=>c.rel===(t.repo??""))?.canWrite===!0)}).catch(()=>{l&&s(!1)}),()=>{l=!1}},[e,n,t.source,t.repo,i]);let o=(0,Ko.useMemo)(()=>Xv(t),[t]);return(0,XI.jsx)(bi,{source:t.source,repo:t.repo??"",path:t.path,mode:o,agentId:e,projectId:n,variant:"tab",canWrite:a,revision:i})}var _a=j($e(),1);var lt=j(ie(),1),YI="brain://docs",_g=$("h-7 w-full rounded-md px-2 text-[10px] outline-none transition font-mono","bg-white/[0.04] border border-white/[0.08] text-white/86","focus:border-white/[0.18] focus:bg-white/[0.06]","placeholder:text-white/28"),nE=$(_g,"pr-6");function Hg(t){let{agentId:e,projectId:n}=t,r=H(w=>w.workspacePanels.upload),a=H(w=>w.setWorkspacePanelOpen),s=H(w=>w.uploading),i=H(w=>w.uploadMany),o=H(w=>w.files),l=H(w=>w.activeFolderPath),u=H(w=>w.setActiveFolderPath),[c,d]=(0,_a.useState)(""),[f,h]=(0,_a.useState)(""),[p,g]=(0,_a.useState)(!1),[m,x]=(0,_a.useState)(!1),y=(0,_a.useRef)(null),b=(0,_a.useMemo)(()=>{let w=c.trim();return w||l||YI},[l,c]),C=(0,_a.useMemo)(()=>{let w=new Set;for(let k of Object.values(o||{})){if(k?.type!=="folder")continue;let _=String(k.uri||"");_&&w.add(_)}return w.add(YI),Array.from(w).sort((k,_)=>k.localeCompare(_))},[o]),L=w=>{let k=w.trim();k&&(d(k),u(k))},P=async w=>{if(w.length!==0)try{await i({agentId:e,projectId:n,files:w,uri:b})}finally{y.current&&(y.current.value=""),g(!1),a("upload",!1)}};return r?(0,lt.jsxs)("div",{className:"w-full px-5 pt-3 pb-6 text-white/85",children:[(0,lt.jsx)("input",{ref:y,type:"file",multiple:!0,className:"hidden",onChange:async w=>{let k=Array.from(w.target.files||[]);await P(k)}}),(0,lt.jsxs)("div",{className:"flex items-center justify-between gap-2 pb-2 border-b border-white/[0.06]",children:[(0,lt.jsxs)("div",{className:"flex items-center gap-2",children:[s?(0,lt.jsx)(We,{className:"h-4 w-4 animate-spin text-cyan-300/70 shrink-0"}):(0,lt.jsx)(Ia,{className:"h-4 w-4 text-cyan-300/70 shrink-0"}),(0,lt.jsx)("span",{className:"text-sm font-semibold tracking-wide text-white/92",children:"Upload"}),(0,lt.jsx)("span",{className:"rounded px-1.5 py-0.5 text-[10px] font-medium text-white/45 bg-white/[0.04] font-mono truncate max-w-[160px]",children:b})]}),(0,lt.jsx)("button",{type:"button",onClick:()=>a("upload",!1),className:"h-7 px-2.5 rounded-md text-[10px] font-medium text-white/50 hover:text-white/80 hover:bg-white/[0.05] transition",children:"Close"})]}),(0,lt.jsx)("div",{className:$("mt-2 rounded-md border border-dashed px-4 py-5 text-center transition",p?"border-cyan-300/40 bg-cyan-400/[0.04]":"border-white/[0.10] bg-white/[0.02]",s&&"opacity-60"),onDragEnter:w=>{s||(w.preventDefault(),g(!0))},onDragOver:w=>{s||(w.preventDefault(),w.dataTransfer.dropEffect="copy",g(!0))},onDragLeave:w=>{w.currentTarget.contains(w.relatedTarget)||g(!1)},onDrop:async w=>{s||(w.preventDefault(),await P(Array.from(w.dataTransfer.files||[])))},children:(0,lt.jsxs)("div",{className:"flex items-center justify-center gap-3",children:[s?(0,lt.jsx)(We,{className:"h-4 w-4 animate-spin text-cyan-200/80"}):(0,lt.jsx)(Ia,{className:"h-4 w-4 text-cyan-200/70"}),(0,lt.jsx)("span",{className:"text-[11px] text-white/60",children:s?"Uploading...":"Drop files here"}),(0,lt.jsxs)("button",{type:"button",onClick:()=>y.current?.click(),disabled:s,className:"h-6 px-2.5 rounded-md bg-cyan-500/12 border border-cyan-400/20 text-[9px] font-semibold text-cyan-200/90 hover:bg-cyan-500/20 transition disabled:opacity-40 disabled:cursor-not-allowed inline-flex items-center gap-1",children:[(0,lt.jsx)(Ml,{className:"h-2.5 w-2.5"}),"Choose files"]})]})}),(0,lt.jsxs)("div",{className:"mt-1",children:[(0,lt.jsxs)("button",{type:"button",onClick:()=>x(w=>!w),className:"w-full flex items-center gap-2 py-1.5 text-left hover:bg-white/[0.02] rounded-md px-1 transition",children:[(0,lt.jsx)(br,{className:"h-3.5 w-3.5 text-violet-400/70 shrink-0"}),(0,lt.jsx)("span",{className:"text-[11px] font-semibold text-white/88",children:"Destination"}),(0,lt.jsx)("span",{className:"text-[9px] text-white/35 font-mono truncate",children:b}),(0,lt.jsx)(Et,{className:$("ml-auto h-3 w-3 text-white/25 shrink-0 transition-transform",m&&"rotate-180")})]}),(0,lt.jsx)("div",{className:$("overflow-hidden transition-all duration-200",m?"max-h-[300px] opacity-100":"max-h-0 opacity-0"),children:(0,lt.jsxs)("div",{className:"rounded-md bg-white/[0.02] p-2.5 ml-5 mb-1 space-y-2",children:[(0,lt.jsxs)("div",{className:"space-y-1",children:[(0,lt.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Folder"}),(0,lt.jsx)("select",{value:b,onChange:w=>L(w.target.value),disabled:s,className:nE,children:C.map(w=>(0,lt.jsx)("option",{value:w,className:"bg-[#1a1a1f]",children:w},w))})]}),(0,lt.jsxs)("div",{className:"space-y-1",children:[(0,lt.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Override"}),(0,lt.jsx)("input",{value:c,onChange:w=>d(w.target.value),placeholder:b,disabled:s,className:_g})]}),(0,lt.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,lt.jsx)("input",{value:f,onChange:w=>h(w.target.value),onKeyDown:w=>{w.key==="Enter"&&(w.preventDefault(),L(f),h(""))},placeholder:"brain://docs/new-folder",disabled:s,className:$(_g,"flex-1")}),(0,lt.jsxs)("button",{type:"button",disabled:s||!f.trim(),onClick:()=>{L(f),h("")},className:"h-7 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-white/60 hover:text-white/85 transition disabled:opacity-35 disabled:cursor-not-allowed inline-flex items-center gap-1 shrink-0",children:[(0,lt.jsx)(br,{className:"h-2.5 w-2.5"}),"Use"]})]})]})})]})]}):null}var Ie=j($e(),1);var qg=j(Wn(),1);function rE(t){let e=t?.configSchema??{};return{required:Array.isArray(e.required)?e.required:[],properties:e.properties&&typeof e.properties=="object"?e.properties:{}}}var aE=new Set(["path","container-path","host-path"]);function JI(t){let e=rE(t),n=e.properties.root,r=n?.["x-neuralis"]?.ui,a=typeof r?.control=="string"?r.control:void 0;return{needed:!!(n&&(e.required.includes("root")||a&&aE.has(a))),container:a!=="host-path",label:typeof r?.label=="string"?r.label:"Path",placeholder:typeof r?.placeholder=="string"?r.placeholder:""}}var sn=j($e(),1);var QI=j(Wn(),1);var Ce=j(ie(),1);function ZI(t){if(!t)return null;let e=`${t.missing} missing \xB7 ${t.stale} stale`;return t.enabled?t.mode!=="dense"?`Semantic: metadata only \u2014 no embedding model active (${e})`:`Semantic: dense (${e})`:`Semantic: off \u2014 text and field search only (${e} if turned on)`}var Xo={gc:{label:"GC",explainer:"Removes records marked as deleted, older than the retention window.",tooltip:"Garbage-collect deleted records past the retention threshold (default 24h). Keeps recent deletions in case you want to restore.",destructive:!0},"repair-orphans":{label:"Repair",explainer:"Removes chunks whose parent document no longer exists or is deleted.",tooltip:"Drops orphaned chunks (parent file gone / deleted). Safe to run anytime \u2014 these chunks have no path back to a real file.",destructive:!0},"repair-pending":{label:"Repair pending",explainer:"Discards your pending changes whose file is gone with nothing to restore; counts older changes that need a review in Changes.",tooltip:"Run with Dry run first to see the counts. Only your own visible pending changes are touched; older changes with an unknown original are only reported \u2014 confirm them in the Changes panel. Nothing is reindexed.",destructive:!0},deduplicate:{label:"Deduplicate",explainer:"Reports document groups with identical content hash (read-only \u2014 no delete).",tooltip:"Lists documents that share a content hash. Read-only; nothing is removed.",destructive:!1}};function eL({agentId:t,projectId:e}){let n=H(A=>A.client),r=hn(),a=Ja({grantedFeatures:[...r.grantedFeatures??[]]},"drive.write"),[s,i]=(0,sn.useState)(null),[o,l]=(0,sn.useState)(null),[u,c]=(0,sn.useState)(!1),[d,f]=(0,sn.useState)(!1),[h,p]=(0,sn.useState)(null),[g,m]=(0,sn.useState)(null),[x,y]=(0,sn.useState)(null),[b,C]=(0,sn.useState)(null),[L,P]=(0,sn.useState)(!1),[w,k]=(0,sn.useState)(!1),[_,M]=(0,sn.useState)(24),[R,U]=(0,sn.useState)(null),v=(0,sn.useRef)(null),T=(0,sn.useCallback)(async()=>{c(!0),y(null);try{let[A,B]=await Promise.all([tx({agentId:t,...e?{projectId:e}:{}},n),fx({agentId:t,...e?{projectId:e}:{}},n).catch(()=>[])]),K=new Map;for(let ne of B)K.set(ne.source,{...ne.last_sync?{last_sync:ne.last_sync}:{},sync_status:ne.sync_status});let te=A;te.perSource&&(te.perSource=te.perSource.map(ne=>{let pe=K.get(ne.source);return pe?{...ne,...pe}:ne})),i(te)}catch(A){y(A instanceof Error?A.message:"Failed to fetch health report")}finally{c(!1)}},[t,e]),V=(0,sn.useCallback)(async()=>{P(!0),y(null);try{let A=await nx({agentId:t,...e?{projectId:e}:{}},n);C({orphanChunkCount:A.orphanChunkCount??0,duplicateGroups:A.duplicateGroups??0})}catch(A){y(A instanceof Error?A.message:"Scan failed")}finally{P(!1)}},[t,e]),Y=(0,sn.useCallback)(async A=>{if(!w&&Xo[A].destructive&&R!==A){U(A),v.current&&clearTimeout(v.current),v.current=setTimeout(()=>U(null),3e3);return}v.current&&(clearTimeout(v.current),v.current=null),U(null),f(!0),p(null),m(A),y(null),l(w?null:s);try{let B=await rx({agentId:t,...e?{projectId:e}:{},action:A,dryRun:w,retentionHours:_},n);p(B),w||(T(),b&&V())}catch(B){y(B instanceof Error?B.message:"Action failed")}finally{f(!1)}},[t,e,w,_,T,R,s,b,V]);(0,sn.useEffect)(()=>{T()},[T]),(0,sn.useEffect)(()=>()=>{v.current&&clearTimeout(v.current)},[]);function N(A){if(!o||!s)return null;let B=o[A]??0,K=s[A]??0;if(B===K)return null;let te=B-K,ne=te>0?"\u2212":"+";return`${B} \u2192 ${K} (${ne}${Math.abs(te)})`}return(0,Ce.jsxs)("div",{className:"space-y-3 px-2 pb-2",children:[(0,Ce.jsxs)("div",{className:"text-[10px] text-white/40 italic leading-relaxed",children:["Cleanup tool for the vector index. Removes leftover records:"," ",(0,Ce.jsx)("span",{className:"text-white/60",children:"deleted documents past retention"}),","," ",(0,Ce.jsx)("span",{className:"text-white/60",children:"orphaned chunks (no parent file)"}),", and reports"," ",(0,Ce.jsx)("span",{className:"text-white/60",children:"duplicate documents"})," (same content hash). To clear ALL vectors of a single source, use the"," ",(0,Ce.jsx)("span",{className:"text-rose-300/80",children:"Delete"})," button on that source instead."]}),u&&(0,Ce.jsxs)("div",{className:"text-[10px] text-white/40 flex items-center gap-1.5",children:[(0,Ce.jsx)(_t,{className:"h-3 w-3 animate-spin text-blue-400"})," Loading..."]}),x&&(0,Ce.jsx)("div",{className:"rounded-md bg-red-500/8 px-2.5 py-1.5 text-[10px] text-red-200/80",children:x}),s&&(0,Ce.jsxs)(Ce.Fragment,{children:[(0,Ce.jsx)("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-1.5",children:[{label:"Documents",value:s.documentCount??0,color:"text-emerald-400",delta:null},{label:"Chunks",value:s.chunkCount??0,color:"text-cyan-400",delta:null},{label:"Deleted",value:s.deletedCount??0,color:(s.deletedCount??0)>0?"text-red-400":"text-white/60",delta:g==="gc"?N("deletedCount"):null},{label:"Orphans",value:b?b.orphanChunkCount??0:"\u2014",color:(b?.orphanChunkCount??0)>0?"text-amber-400":"text-white/60",delta:null}].map(A=>(0,Ce.jsxs)("div",{className:"bg-white/[0.04] border border-white/[0.06] rounded-lg px-2 py-1.5 text-center",children:[(0,Ce.jsx)("div",{className:$("text-sm font-semibold",A.color),children:A.value}),(0,Ce.jsx)("div",{className:"text-[9px] text-white/40",children:A.label}),A.delta&&(0,Ce.jsx)("div",{className:"text-[8px] text-emerald-300/70 mt-0.5 tabular-nums",children:A.delta})]},A.label))}),ZI(s.embedding)&&(0,Ce.jsx)("div",{className:"text-[9px] text-white/45",role:"status",children:ZI(s.embedding)}),(0,Ce.jsxs)("div",{className:"flex items-center gap-3 text-[9px] text-white/35",children:[(0,Ce.jsxs)("span",{children:["Total points: ",s.totalPoints??"-"]}),(0,Ce.jsxs)("span",{children:["Duplicate groups: ",b?b.duplicateGroups??0:"\u2014"]}),s.generatedAt&&(()=>{let A=Date.now()-new Date(s.generatedAt).getTime(),B=Math.floor(A/6e4),K=Math.floor(B/60),te=B<1?"just now":K<1?`${B}m ago`:`${K}h ${B%60}m ago`,ne=K<1?"text-emerald-400/60":"text-amber-400/60";return(0,Ce.jsxs)("span",{className:ne,children:["Generated: ",te]})})()]}),s.perSource&&s.perSource.length>0&&(0,Ce.jsx)("div",{className:"bg-white/[0.04] border border-white/[0.06] rounded-lg overflow-hidden",children:(0,Ce.jsxs)("table",{className:"w-full text-[10px]",children:[(0,Ce.jsx)("thead",{children:(0,Ce.jsxs)("tr",{className:"border-b border-white/[0.06]",children:[(0,Ce.jsx)("th",{className:"text-left px-2 py-1.5 text-white/40 font-medium",children:"Source"}),(0,Ce.jsx)("th",{className:"text-right px-2 py-1.5 text-white/40 font-medium",children:"Docs"}),(0,Ce.jsx)("th",{className:"text-right px-2 py-1.5 text-white/40 font-medium",children:"Chunks"}),(0,Ce.jsx)("th",{className:"text-right px-2 py-1.5 text-white/40 font-medium",children:"Deleted"}),(0,Ce.jsx)("th",{className:"text-right px-2 py-1.5 text-white/40 font-medium",children:"Last sync"})]})}),(0,Ce.jsx)("tbody",{children:s.perSource.map((A,B)=>{let K=A.source.includes(":")?A.source.split(":")[0]:A.source,te=K==="local"?"text-cyan-400/60":K==="github"?"text-amber-400/60":"text-violet-400/60",ne=(()=>{if(!A.last_sync)return A.sync_status==="idle"?"\u2014":A.sync_status??"\u2014";let Se=new Date(A.last_sync).getTime();if(Number.isNaN(Se))return A.last_sync;let le=Math.floor((Date.now()-Se)/6e4);if(le<1)return"just now";if(le<60)return`${le}m ago`;let re=Math.floor(le/60);return re<24?`${re}h ago`:`${Math.floor(re/24)}d ago`})(),pe=A.last_sync?A.sync_status==="error"?"text-rose-300/60":A.sync_status==="paused"?"text-amber-300/60":"text-emerald-300/60":"text-white/35";return(0,Ce.jsxs)("tr",{className:$("border-b border-white/[0.03] last:border-0",B%2===1&&"bg-white/[0.02]"),children:[(0,Ce.jsxs)("td",{className:"px-2 py-1 text-white/70 font-mono flex items-center gap-1.5",children:[(0,Ce.jsx)(zn,{className:$("h-2.5 w-2.5 shrink-0",te)}),A.source]}),(0,Ce.jsx)("td",{className:"px-2 py-1 text-right text-emerald-300/60",children:A.documents}),(0,Ce.jsx)("td",{className:"px-2 py-1 text-right text-cyan-300/60",children:A.chunks}),(0,Ce.jsx)("td",{className:$("px-2 py-1 text-right",A.deleted>0?"text-red-300/60":"text-white/40"),children:A.deleted}),(0,Ce.jsx)("td",{className:$("px-2 py-1 text-right",pe),title:A.last_sync??`status: ${A.sync_status??"unknown"}`,children:ne})]},A.source)})})]})}),(0,Ce.jsxs)("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[(0,Ce.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,Ce.jsxs)("button",{type:"button",onClick:()=>{T()},disabled:u,title:"Refresh the cheap count stats for this project.",className:"px-2 py-1 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[10px] text-white/70 transition inline-flex items-center gap-1 disabled:opacity-40",children:[(0,Ce.jsx)(_t,{className:$("h-3 w-3 text-blue-400",u&&"animate-spin")}),"Refresh"]}),(0,Ce.jsxs)("button",{type:"button",onClick:()=>{V()},disabled:L,title:"Scan the whole index for orphan chunks and duplicate documents. Expensive \u2014 walks every point, so it runs only when you ask.",className:"px-2 py-1 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[10px] text-white/70 transition inline-flex items-center gap-1 disabled:opacity-40",children:[(0,Ce.jsx)(Ya,{className:$("h-3 w-3 text-amber-400",L&&"animate-pulse")}),b?"Re-scan":"Scan for problems"]}),(0,Ce.jsx)("span",{className:"text-white/10",children:"|"}),["gc","repair-orphans",...a?["repair-pending"]:[],"deduplicate"].map(A=>{let B=Xo[A],K=A==="gc"?Nt:A==="repair-orphans"?Rl:A==="repair-pending"?ws:na,te=A==="gc"?"text-amber-400":A==="repair-orphans"?"text-cyan-400":A==="repair-pending"?"text-rose-300":"text-violet-400",ne=R===A;return(0,Ce.jsxs)("button",{type:"button",onClick:()=>{Y(A)},disabled:d,title:B.tooltip,className:$("px-2 py-1 rounded-md text-[10px] transition inline-flex items-center gap-1 disabled:opacity-40",ne?"bg-rose-500/15 hover:bg-rose-500/25 text-rose-100 border border-rose-400/40":"bg-white/[0.04] hover:bg-white/[0.08] text-white/70"),children:[(0,Ce.jsx)(K,{className:$("h-3 w-3",te)}),ne?"Click again to confirm":B.label]},A)}),(0,Ce.jsx)("span",{className:"text-white/10",children:"|"}),(0,Ce.jsx)(QI.SkillLauncher,{variant:"icon",size:"sm",skill:"manage-sources",packageId:"@neuralis/brain-core",scripts:["scripts/sync-status.sh","scripts/reindex.sh"],label:"Inspect sync status or reindex a source with the agent",icon:"Database"})]}),(0,Ce.jsxs)("div",{className:"flex items-center gap-3",children:[(0,Ce.jsxs)("label",{className:"inline-flex items-center gap-1 text-[10px] text-white/60 cursor-pointer",title:"Preview only \u2014 nothing will be deleted.",children:[(0,Ce.jsx)("input",{type:"checkbox",checked:w,onChange:A=>k(A.target.checked),className:"accent-emerald-400 h-3 w-3"}),"Dry run"]}),(0,Ce.jsxs)("label",{className:"inline-flex items-center gap-1 text-[10px] text-white/60",title:"Records marked as deleted within this many hours are kept (GC ignores them).",children:["Retention:",(0,Ce.jsx)("input",{type:"number",min:1,value:_,onChange:A=>M(Math.max(1,Number(A.target.value)||24)),className:"w-12 h-5 rounded px-1 text-[10px] bg-white/[0.04] border border-white/[0.08] text-white/80 outline-none"}),"h"]})]})]}),(0,Ce.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-1.5 text-[9px] text-white/40 leading-snug",children:[(0,Ce.jsxs)("div",{children:[(0,Ce.jsx)("span",{className:"text-amber-300/70 font-medium",children:"GC:"})," ",Xo.gc.explainer]}),(0,Ce.jsxs)("div",{children:[(0,Ce.jsx)("span",{className:"text-cyan-300/70 font-medium",children:"Repair:"})," ",Xo["repair-orphans"].explainer]}),(0,Ce.jsxs)("div",{children:[(0,Ce.jsx)("span",{className:"text-violet-300/70 font-medium",children:"Deduplicate:"})," ",Xo.deduplicate.explainer]}),a?(0,Ce.jsxs)("div",{children:[(0,Ce.jsx)("span",{className:"text-rose-300/70 font-medium",children:"Repair pending:"})," ",Xo["repair-pending"].explainer]}):null]}),h&&(0,Ce.jsxs)("div",{className:"bg-white/[0.04] border border-white/[0.06] rounded-lg px-2.5 py-2 text-[10px] text-white/60 space-y-0.5",children:[(0,Ce.jsxs)("div",{className:"text-[10px] text-white/50 font-medium mb-1 flex items-center justify-between",children:[(0,Ce.jsx)("span",{children:"Last Action Result"}),typeof h.removed=="number"&&(0,Ce.jsxs)("span",{className:$("font-mono tabular-nums",h.dryRun?"text-amber-300/80":"text-emerald-300/85"),children:[h.dryRun?"Would remove":"Removed",": ",h.removed]})]}),Object.entries(h).map(([A,B])=>(0,Ce.jsxs)("div",{className:"flex justify-between",children:[(0,Ce.jsx)("span",{className:"text-white/40",children:A}),(0,Ce.jsx)("span",{className:"text-white/70 font-mono",children:typeof B=="object"?JSON.stringify(B):String(B)})]},A))]})]})]})}var nn=j($e(),1);var De=j(ie(),1),sE=["member","owner","admin"],Cf=["read","write","exec"];function iE(t){return{default:{...t.default},...t.byRole?{byRole:Ug(t.byRole)}:{},...t.byUser?{byUser:Ug(t.byUser)}:{},...t.byAgent?{byAgent:Ug(t.byAgent)}:{},paths:(t.paths??[]).map(e=>({...e,permissions:{...e.permissions},...e.roles?{roles:[...e.roles]}:{},...e.agents?{agents:[...e.agents]}:{},...e.users?{users:[...e.users]}:{}}))}}function Ug(t){let e={};for(let[n,r]of Object.entries(t))e[n]={...r};return e}function oE(t){return{pattern:`${t}://`,permissions:{read:!0,write:!1,exec:!1}}}function Gg({letter:t,state:e,onClick:n,disabled:r,title:a}){let s=e===!0?"bg-emerald-500/20 text-emerald-200 border-emerald-400/30":e===!1?"bg-rose-500/15 text-rose-200/80 border-rose-400/25":"bg-white/[0.04] text-white/35 border-white/[0.08]";return(0,De.jsx)("button",{type:"button",title:a??`${t} \u2014 ${e===!0?"allow":e===!1?"deny":"inherit"}`,disabled:r,onClick:n,className:$("inline-flex items-center justify-center w-5 h-5 rounded text-[9px] font-bold tabular-nums border transition disabled:cursor-default",s,!r&&"hover:brightness-125"),children:t})}function Wg(t){return t==="read"?"R":t==="write"?"W":"X"}function tL(t,e){if(!e)return!t;if(t===void 0)return!0;if(t===!0)return!1}function zg({source:t,permissions:e,mode:n,onSave:r,knownRoles:a=sE}){let[s,i]=(0,nn.useState)(()=>iE(e)),[o,l]=(0,nn.useState)(!1),[u,c]=(0,nn.useState)(null),[d,f]=(0,nn.useState)(""),[h,p]=(0,nn.useState)(""),[g,m]=(0,nn.useState)(""),x=(0,nn.useMemo)(()=>JSON.stringify(s)!==JSON.stringify(e),[s,e]),y=n==="view",b=(0,nn.useCallback)((N,A)=>{i(B=>({...B,default:{...B.default,[N]:A}}))},[]),C=N=>N,L=(0,nn.useCallback)((N,A)=>{let B=A.trim();B&&i(K=>{let te={...K[C(N)]??{}};return B in te?K:(te[B]={},{...K,[C(N)]:te})})},[]),P=(0,nn.useCallback)((N,A)=>{i(B=>{let K={...B[C(N)]??{}};return delete K[A],Object.keys(K).length===0?{...B,[C(N)]:void 0}:{...B,[C(N)]:K}})},[]),w=(0,nn.useCallback)((N,A,B)=>{i(K=>{let te={...K[C(N)]??{}},ne=te[A]??{},pe=tL(ne[B],!0),Se={...ne};return pe===void 0?delete Se[B]:Se[B]=pe,te[A]=Se,{...K,[C(N)]:te}})},[]),k=(0,nn.useCallback)((N,A)=>{i(B=>{let K=[...B.paths??[]];return K[N]={...K[N],...A},{...B,paths:K}})},[]),_=(0,nn.useCallback)((N,A)=>{i(B=>{let K=[...B.paths??[]],te=K[N],ne=tL(te.permissions[A],!0),pe={...te.permissions};return ne===void 0?delete pe[A]:pe[A]=ne,K[N]={...te,permissions:pe},{...B,paths:K}})},[]),M=(0,nn.useCallback)((N,A)=>{i(B=>{let K=[...B.paths??[]],te=K[N],ne=new Set(te.roles??[]);return ne.has(A)?ne.delete(A):ne.add(A),K[N]=ne.size>0?{...te,roles:[...ne]}:{...te,roles:void 0},{...B,paths:K}})},[]),R=(0,nn.useCallback)((N,A,B)=>{let K=B.trim();K&&i(te=>{let ne=[...te.paths??[]],pe=ne[N],Se=new Set(pe[A]??[]);return Se.add(K),ne[N]={...pe,[A]:[...Se]},{...te,paths:ne}})},[]),U=(0,nn.useCallback)((N,A,B)=>{i(K=>{let te=[...K.paths??[]],ne=te[N],pe=(ne[A]??[]).filter(Se=>Se!==B);return te[N]={...ne,[A]:pe.length>0?pe:void 0},{...K,paths:te}})},[]),v=(0,nn.useCallback)(()=>{i(N=>({...N,paths:[oE(t),...N.paths??[]]}))},[t]),T=(0,nn.useCallback)(N=>{i(A=>({...A,paths:(A.paths??[]).filter((B,K)=>K!==N)}))},[]),V=(0,nn.useCallback)(async()=>{if(r){l(!0),c(null);try{await r(s)}catch(N){c(N instanceof Error?N.message:String(N))}finally{l(!1)}}},[s,r]),Y=(N,A,B,K,te)=>{let ne=s[C(N)]??{},pe=Object.entries(ne),[Se,le]=te;return(0,De.jsxs)("div",{className:"space-y-1",children:[(0,De.jsxs)("div",{className:"flex items-center gap-2",children:[(0,De.jsx)("span",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/40",children:A}),(0,De.jsx)("span",{className:"text-[9px] text-white/30 italic flex-1 truncate",children:B})]}),pe.length===0&&y?(0,De.jsx)("div",{className:"text-[9px] text-white/25 italic",children:"No overrides."}):null,pe.map(([re,he])=>(0,De.jsxs)("div",{className:"flex items-center gap-1.5 text-[10px]",children:[(0,De.jsx)("span",{className:"font-mono text-white/70 truncate min-w-[72px]",children:re}),Cf.map(Ne=>(0,De.jsx)(Gg,{letter:Wg(Ne),state:he[Ne],onClick:y?void 0:()=>w(N,re,Ne),disabled:y},Ne)),!y&&(0,De.jsx)("button",{type:"button",onClick:()=>P(N,re),className:"ml-auto text-white/30 hover:text-rose-300 transition",title:"Remove override",children:(0,De.jsx)(Nt,{className:"w-3 h-3"})})]},re)),!y&&(0,De.jsxs)("div",{className:"flex items-center gap-1.5 pt-0.5",children:[(0,De.jsx)("input",{type:"text",value:Se,onChange:re=>le(re.target.value),onKeyDown:re=>{re.key==="Enter"&&(re.preventDefault(),L(N,Se),le(""))},placeholder:K,className:"h-6 flex-1 rounded bg-white/[0.04] border border-white/[0.08] px-2 text-[10px] text-white/80 placeholder:text-white/25 outline-none focus:border-white/20"}),(0,De.jsxs)("button",{type:"button",onClick:()=>{L(N,Se),le("")},className:"h-6 px-2 rounded bg-white/[0.05] border border-white/[0.08] text-[9px] font-semibold text-white/65 hover:text-white/90 hover:bg-white/[0.08] transition inline-flex items-center gap-1",children:[(0,De.jsx)(Fn,{className:"w-2.5 h-2.5"}),"Add"]})]})]})};return(0,De.jsxs)("div",{className:"flex flex-col gap-3 text-[10px]",children:[(0,De.jsx)("div",{className:"space-y-1",children:(0,De.jsxs)("div",{className:"flex items-center gap-2",children:[(0,De.jsx)("span",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/40",children:"Default"}),(0,De.jsxs)("span",{className:"text-[9px] text-white/30 italic flex-1 truncate",children:["Base access for ",t,"://*"]}),(0,De.jsx)("div",{className:"flex items-center gap-1",children:Cf.map(N=>(0,De.jsx)(Gg,{letter:Wg(N),state:s.default[N],onClick:y?void 0:()=>b(N,!s.default[N]),disabled:y},N))})]})}),Y("byRole","By Role","Override default for specific roles.","role (e.g. admin)",[d,f]),Y("byUser","By User","Override for specific users (highest priority after paths).","userId",[h,p]),Y("byAgent","By Agent","$self = the agent owning the file.","$self or agentId",[g,m]),(0,De.jsxs)("div",{className:"space-y-1",children:[(0,De.jsxs)("div",{className:"flex items-center gap-2",children:[(0,De.jsx)("span",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/40",children:"Path Rules"}),(0,De.jsx)("span",{className:"text-[9px] text-white/30 italic flex-1 truncate",children:"Fine-grained rules per path/glob \u2014 first match wins."}),!y&&(0,De.jsxs)("button",{type:"button",onClick:v,className:"h-6 px-2 rounded bg-white/[0.05] border border-white/[0.08] text-[9px] font-semibold text-white/65 hover:text-white/90 hover:bg-white/[0.08] transition inline-flex items-center gap-1",children:[(0,De.jsx)(Fn,{className:"w-2.5 h-2.5"}),"Rule"]})]}),(s.paths??[]).length===0?(0,De.jsx)("div",{className:"text-[9px] text-white/25 italic",children:"No rules \u2014 Default applies everywhere."}):(0,De.jsx)("ul",{className:"space-y-1",children:(s.paths??[]).map((N,A)=>(0,De.jsxs)("li",{className:"rounded bg-white/[0.02] border border-white/[0.05] px-2 py-1.5 space-y-1.5",children:[(0,De.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,De.jsx)("input",{type:"text",disabled:y,value:N.pattern,onChange:B=>k(A,{pattern:B.target.value}),placeholder:`${t}://path/**`,className:"flex-1 min-w-0 h-6 rounded bg-white/[0.04] border border-white/[0.08] px-2 text-[10px] font-mono text-white/85 outline-none focus:border-white/20 disabled:opacity-70"}),Cf.map(B=>(0,De.jsx)(Gg,{letter:Wg(B),state:N.permissions[B],onClick:y?void 0:()=>_(A,B),disabled:y},B)),(0,De.jsx)("button",{type:"button",disabled:y,onClick:()=>k(A,{override:N.override?void 0:!0}),title:"Override deny-wins precedence",className:$("h-5 px-1.5 rounded text-[8px] font-semibold border transition disabled:cursor-default",N.override?"bg-amber-500/15 text-amber-200 border-amber-400/30":"bg-white/[0.04] text-white/35 border-white/[0.08] hover:text-white/65"),children:"OVR"}),!y&&(0,De.jsx)("button",{type:"button",onClick:()=>T(A),title:"Remove rule",className:"text-white/30 hover:text-rose-300 transition",children:(0,De.jsx)(Nt,{className:"w-3 h-3"})})]}),(0,De.jsxs)("div",{className:"flex flex-wrap items-center gap-1 text-[9px] text-white/50",children:[(0,De.jsx)("span",{className:"text-white/35 mr-0.5",children:"Roles:"}),a.map(B=>{let K=(N.roles??[]).includes(B);return(0,De.jsx)("button",{type:"button",disabled:y,onClick:()=>M(A,B),className:$("h-5 px-1.5 rounded border text-[9px] font-medium capitalize transition disabled:cursor-default",K?"bg-cyan-500/15 text-cyan-200 border-cyan-400/30":"bg-white/[0.04] text-white/40 border-white/[0.08] hover:text-white/70"),children:B},B)}),(N.roles??[]).length===0&&(0,De.jsx)("span",{className:"italic text-white/30",children:"all roles"})]}),(0,De.jsx)(nL,{label:"Agents",values:N.agents??[],emptyLabel:"any agent",placeholder:"$self / agentId",readOnly:y,onAdd:B=>R(A,"agents",B),onRemove:B=>U(A,"agents",B)}),(0,De.jsx)(nL,{label:"Users",values:N.users??[],emptyLabel:"any user",placeholder:"$owner / userId",readOnly:y,onAdd:B=>R(A,"users",B),onRemove:B=>U(A,"users",B)}),(N.users??[]).length>0&&!lE(N)&&(0,De.jsx)("div",{className:"text-[9px] text-amber-200/80",children:"Users apply only to an allow rule: turn on OVR and set every bit to allow."})]},A))})]}),!y&&(0,De.jsxs)("div",{className:"flex items-center justify-between gap-2 pt-1",children:[u&&(0,De.jsx)("span",{className:"text-[9px] text-rose-300/80",children:u}),(0,De.jsxs)("button",{type:"button",onClick:V,disabled:!x||o,className:$("ml-auto inline-flex items-center gap-1 h-6 px-2.5 rounded bg-emerald-500/15 border border-emerald-400/30 text-[10px] font-semibold text-emerald-200 hover:bg-emerald-500/25 transition",(!x||o)&&"opacity-40 cursor-default"),children:[(0,De.jsx)(li,{className:"w-3 h-3"}),o?"Saving\u2026":"Save policy"]})]})]})}function lE(t){let e=Cf.map(n=>t.permissions[n]).filter(n=>n!==void 0);return t.override===!0&&e.length>0&&e.every(n=>n===!0)}function nL({label:t,values:e,emptyLabel:n,placeholder:r,readOnly:a,onAdd:s,onRemove:i}){return(0,De.jsxs)("div",{className:"flex flex-wrap items-center gap-1 text-[9px] text-white/50",children:[(0,De.jsxs)("span",{className:"text-white/35 mr-0.5",children:[t,":"]}),e.map(o=>(0,De.jsxs)("span",{className:"inline-flex items-center gap-1 h-5 px-1.5 rounded bg-violet-500/12 text-violet-200 border border-violet-400/25",children:[(0,De.jsx)("span",{className:"font-mono",children:o}),!a&&(0,De.jsx)("button",{type:"button",onClick:()=>i(o),className:"text-violet-200/60 hover:text-rose-300",title:`Remove ${o}`,children:"\xD7"})]},o)),e.length===0&&(0,De.jsx)("span",{className:"italic text-white/30",children:n}),!a&&(0,De.jsx)(uE,{placeholder:r,onAdd:s})]})}function uE({placeholder:t,onAdd:e}){let[n,r]=(0,nn.useState)("");return(0,De.jsxs)("div",{className:"inline-flex items-center gap-1",children:[(0,De.jsx)("input",{type:"text",value:n,onChange:a=>r(a.target.value),onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),e(n),r(""))},placeholder:t,className:"h-5 rounded bg-white/[0.04] border border-white/[0.08] px-1.5 text-[9px] font-mono text-white/75 placeholder:text-white/25 outline-none focus:border-white/20 w-[120px]"}),(0,De.jsx)("button",{type:"button",onClick:()=>{e(n),r("")},className:"text-white/40 hover:text-white/80 transition",title:"Add",children:(0,De.jsx)(Fn,{className:"w-3 h-3"})})]})}var rL=j($e(),1);var Kt=j(ie(),1);function aL({source:t,vectorCount:e,isDockerMount:n,busy:r,onCancel:a,onConfirm:s}){let[i,o]=(0,rL.useState)(!1);return(0,Kt.jsxs)("div",{className:"rounded-md border border-rose-400/30 bg-rose-500/5 p-2.5 mt-1.5 ml-5 mb-1 space-y-2",children:[(0,Kt.jsxs)("div",{className:"flex items-start gap-2",children:[(0,Kt.jsx)(ot,{className:"h-3.5 w-3.5 text-rose-300 shrink-0 mt-0.5"}),(0,Kt.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,Kt.jsxs)("div",{className:"text-[11px] font-semibold text-white/90",children:["Delete ",(0,Kt.jsx)("span",{className:"font-mono text-rose-200",children:t}),"?"]}),(0,Kt.jsxs)("div",{className:"text-[10px] text-white/55 mt-0.5",children:["The source config and connector binding are removed."," ",(0,Kt.jsx)("span",{className:"text-white/75",children:"The host folder is not touched"})," ","\u2014 your files stay where they are."]})]})]}),(0,Kt.jsxs)("label",{className:"flex items-start gap-2 cursor-pointer rounded px-1.5 py-1 hover:bg-white/[0.03]",children:[(0,Kt.jsx)("input",{type:"checkbox",checked:i,onChange:l=>o(l.target.checked),className:"accent-rose-400 h-3 w-3 mt-0.5"}),(0,Kt.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,Kt.jsxs)("div",{className:"text-[10px] font-medium text-white/80",children:["Purge vector index entries",e!==null&&(0,Kt.jsxs)("span",{className:"text-white/40 ml-1.5 tabular-nums",children:["(~",e," point",e===1?"":"s",")"]})]}),(0,Kt.jsxs)("div",{className:"text-[9px] text-white/40 leading-relaxed",children:["Removes every Qdrant point whose URI maps back to"," ",(0,Kt.jsxs)("code",{className:"font-mono text-white/55",children:[t,"://"]}),". Otherwise the vectors stay and Vector Health \u2192 Repair will mop them up later."]})]})]}),n&&(0,Kt.jsxs)("div",{className:"rounded bg-amber-500/8 border border-amber-400/20 px-2 py-1.5 text-[9px] italic text-amber-100/70 leading-relaxed",children:["Docker bind-mount source. This deletes the source config (and vectors, if checked). To also drop the underlying compose bind, run the infra-only:"," ",(0,Kt.jsxs)("code",{className:"font-mono not-italic text-amber-100/90",children:["neuralis mount remove ",t]})]}),(0,Kt.jsxs)("div",{className:"flex items-center justify-end gap-1.5 pt-0.5",children:[(0,Kt.jsxs)("button",{type:"button",onClick:a,disabled:r,className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[10px] font-medium text-white/70 transition disabled:opacity-40 inline-flex items-center gap-1",children:[(0,Kt.jsx)(Ht,{className:"h-2.5 w-2.5"}),"Cancel"]}),(0,Kt.jsxs)("button",{type:"button",onClick:()=>s({purgeVectors:i}),disabled:r,className:$("h-6 px-2.5 rounded-md text-[10px] font-semibold transition disabled:opacity-40 inline-flex items-center gap-1","bg-rose-500/20 hover:bg-rose-500/30 border border-rose-400/40 text-rose-100"),children:[r?(0,Kt.jsx)(We,{className:"h-2.5 w-2.5 animate-spin"}):(0,Kt.jsx)(Nt,{className:"h-2.5 w-2.5"}),"Delete",i?" + Purge":""]})]})]})}var S=j(ie(),1),jg={exclude:[],trigger:"manual"},cE=[{value:"manual",label:"Manual"},{value:"auto",label:"Auto (watch + reconcile)"},{value:"interval",label:"On schedule"}],dE=[{value:"s",label:"sec"},{value:"m",label:"min"},{value:"h",label:"hr"},{value:"d",label:"day"}],$g="Mounted (user-added)";function fE(t){return t&&t.trim().length>0?t:$g}function hE(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,24)||"agent"}function Pf(t){return t.toLowerCase().replace(/[^a-z0-9-]+/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"").slice(0,40)}function pE(t){return t.split(/[/\\]/).filter(Boolean).pop()??null}function mE(t){if(t?.name){let e=Pf(t.name);if(e)return e}if(t?.email){let e=Pf(t.email.split("@")[0]??"");if(e)return e}return"user"}function lL(t){let{baseName:e,meta:n,scope:r,ids:a}=t,i=(e?Pf(e):"")||(n?.urlScheme||n?.kind||"source").toLowerCase().replace(/[^a-z0-9-]+/g,"-");return r==="project"?i:r==="user"?`${i}-${a.userSlug||"user"}`:`${i}-${a.agentSlug||hE(a.agentId)}`}function gE(t){return t?.allowedScopes?.length?t.allowedScopes:["project","user","agent"]}function Kg(t){return!!t?.capabilities.includes("scanDelta")}function Xg(t){let e=t?.configSchema??{};return{required:Array.isArray(e.required)?e.required:[],properties:e.properties&&typeof e.properties=="object"?e.properties:{}}}function xE(t){let e=Xg(t),n={};for(let[r,a]of Object.entries(e.properties)){if(r==="root")continue;let s=a.default;(typeof s=="string"||typeof s=="number"||typeof s=="boolean")&&(n[r]=s)}return n}function uL(t){let e=t?.defaultPermissions?.default;return{read:typeof e?.read=="boolean"?e.read:!0,write:typeof e?.write=="boolean"?e.write:!1,exec:typeof e?.exec=="boolean"?e.exec:!1}}function $u(t,e){let n=t?.defaultScope??"project",r=uL(t);return{key:lL({baseName:null,meta:t,scope:n,ids:e}),path:"",scope:n,...r,syncEnabled:Kg(t),exclude:Lf(t?.defaultSyncExcludes??[]),include:"",trigger:"manual",description:"",config:xE(t),policies:[],recognizesPackages:!1}}function Ku(t){return t.split(/\r?\n|,/).map(e=>e.trim()).filter(Boolean)}function Lf(t){return Array.isArray(t)?t.join(`
44
+ `):""}function yE(t){return t&&t.default&&typeof t.default=="object"?t:t&&typeof t.read=="boolean"?{default:{read:t.read,write:t.write??!1,exec:t.exec??!1}}:{default:{read:!0,write:!1,exec:!1}}}function Yo(t){return{source:t.source,permissions:yE(t.permissions),description:t.description??"",recognizesPackages:t.recognizesPackages??!1,...t.sync?{sync:{exclude:[...t.sync.exclude??[]],trigger:t.sync.trigger??"manual",...t.sync.include&&t.sync.include.length>0?{include:[...t.sync.include]}:{},...t.sync.alwaysActive!==void 0?{alwaysActive:t.sync.alwaysActive}:{},...t.sync.maxScanFiles!==void 0?{maxScanFiles:t.sync.maxScanFiles}:{},...t.sync.media?{media:{...t.sync.media}}:{}}}:{}}}var bE=[{key:"images",label:"Images",on:!0},{key:"pdf",label:"PDF pages",on:!0},{key:"video",label:"Video",on:!1},{key:"audio",label:"Audio",on:!1}];function sL(t){if(!t)return null;let e=[];return t.textOnlyModel>0&&e.push(`${t.textOnlyModel} media file${t.textOnlyModel===1?"":"s"} not embedded \u2014 the active embedding model is text-only`),t.off>0&&e.push(`${t.off} off in media settings`),t.tooLarge>0&&e.push(`${t.tooLarge} over the media size limit`),t.invalid>0&&e.push(`${t.invalid} structurally invalid PNG file${t.invalid===1?"":"s"}`),t.unavailable>0&&e.push(`${t.unavailable} unreadable as media`),e.length>0?e.join(" \xB7 "):null}function wE(t,e){if(e===!1)return{text:"Semantic embedding off \u2014 text and field search only",attention:!1};let n=(t??[]).filter(r=>r!=="disabled");return n.length===0?null:{text:`Semantic embedding pending: ${n.join(", ")} \u2014 files are indexed and text-searchable`,attention:!0}}function iL(t){return t?`${t} binary file${t===1?"":"s"} not indexed`:null}function vE(t,e,n){if(n)return!0;let r=t.sync,a=e.sync;if(!r||!a)return!!r!=!!a;let s=i=>(i??[]).join(`
45
+ `);return s(r.exclude)!==s(a.exclude)||s(r.include)!==s(a.include)||r.maxScanFiles!==a.maxScanFiles}function cL(t){if(t==="auto"||t==="on_change")return{mode:"auto",val:"5",unit:"m"};let e=/^interval:(\d+)([smhd])$/.exec(t);return e?{mode:"interval",val:e[1],unit:e[2]}:{mode:"manual",val:"5",unit:"m"}}function Af(t){return t==="s"?30:1}function Vg(t,e,n){if(t!=="interval")return t;let r=Number.parseInt(e,10);return`interval:${Number.isFinite(r)?Math.max(r,Af(n)):5}${n}`}function kE(t){let e=cL(t);return e.mode==="manual"?"Manual":e.mode==="auto"?"Auto":`Every ${e.val}${e.unit}`}function SE(t,e){let n=t.connection.config??{};for(let[r,a]of Object.entries(n)){if(typeof a=="string"&&a.length>0)return a;if(typeof a=="number")return String(a)}return e?.label??t.connection.kind}function CE(t,e){let n=t.permissions??uL(e);return{source:qe(t.uri_root),source_kind:t.source_kind,scope:{kind:"project"},createdBy:"runtime",connection:{kind:t.source_kind,config:{}},permissions:{default:n},sync_status:t.sync_status,last_updated:t.last_updated,kind_label:e?.label??t.source_kind,kind_trust:e?.trust??null,observed:!0,...t.origin_package?{origin_package:t.origin_package}:{},...t.live!==void 0?{live:t.live}:{},...t.live_reason?{live_reason:t.live_reason}:{}}}function IE(t,e){return JSON.stringify(Yo(t))!==JSON.stringify(e)}function oL(t){if(!t)return"never";let e=Date.now()-new Date(t).getTime();return e<6e4?"just now":e<36e5?`${Math.floor(e/6e4)}m ago`:e<864e5?`${Math.floor(e/36e5)}h ago`:`${Math.floor(e/864e5)}d ago`}var Wi=$("h-7 w-full rounded-md px-2 text-[10px] outline-none transition","bg-white/[0.04] border border-white/[0.08] text-white/86","focus:border-white/[0.18] focus:bg-white/[0.06]","placeholder:text-white/28"),If=$(Wi,"pr-6 font-mono"),Xu=$("w-full rounded-md px-2 py-1.5 text-[10px] font-mono outline-none resize-y transition","bg-white/[0.04] border border-white/[0.08] text-white/86","focus:border-white/[0.18] focus:bg-white/[0.06]","placeholder:text-white/28");function dL(t){let e=H(E=>E.client),{agentId:n,projectId:r,isDocker:a}=t,s=H(E=>E.workspacePanels.sources),i=H(E=>E.setWorkspacePanelOpen),o=H(E=>E.pendingSourceSuggestion),l=H(E=>E.setPendingSourceSuggestion),u=H(E=>E.refresh),c=H(E=>E.sources),d=hn(),f=d.useAgents(),h=(0,Ie.useMemo)(()=>mE(d.currentUser),[d.currentUser]),p=(d.currentRole?.priority??99)<=2,g=(0,Ie.useMemo)(()=>oo({grantedFeatures:[...d.grantedFeatures??[]]},{features:["drive.mount"]}),[d.grantedFeatures]),m=(0,Ie.useMemo)(()=>{let E=f.byId[n]?.name;return E?Pf(E):void 0},[f,n]),x=(0,Ie.useMemo)(()=>({userSlug:h,agentSlug:m,agentId:n}),[h,m,n]),[y,b]=(0,Ie.useState)([]),[C,L]=(0,Ie.useState)({}),[P,w]=(0,Ie.useState)({}),[k,_]=(0,Ie.useState)({}),[M,R]=(0,Ie.useState)(new Set),[U,v]=(0,Ie.useState)({}),[T,V]=(0,Ie.useState)(!1),[Y,N]=(0,Ie.useState)(null),[A,B]=(0,Ie.useState)(null),[K,te]=(0,Ie.useState)(null),[ne,pe]=(0,Ie.useState)(null),[Se,le]=(0,Ie.useState)(null),[re,he]=(0,Ie.useState)(null),[Ne,Ee]=(0,Ie.useState)(null),[ze,ct]=(0,Ie.useState)(null),[it,Qe]=(0,Ie.useState)(null),[Ye,Lt]=(0,Ie.useState)(null),[Le,at]=(0,Ie.useState)({}),[ft,bt]=(0,Ie.useState)(null),[At,Tt]=(0,Ie.useState)("source"),[Ue,me]=(0,Ie.useState)(""),[Ot,Jt]=(0,Ie.useState)(!0),[ue,be]=(0,Ie.useState)(null),[Ge,Re]=(0,Ie.useState)(!1),Te=(0,Ie.useRef)(0);(0,Ie.useEffect)(()=>{Te.current++,bt(null),be(null)},[n,r]);let[vt,mt]=(0,Ie.useState)(null),[Gt,je]=(0,Ie.useState)(!1),[kt,on]=(0,Ie.useState)("project"),[Oe,ee]=(0,Ie.useState)(()=>$u(null,x)),oe=(0,Ie.useRef)(Oe.key),He=(0,Ie.useRef)(!0);(0,Ie.useEffect)(()=>(He.current=!0,()=>{He.current=!1}),[]);let[Ve,Ae]=(0,Ie.useState)(!1),ce=H(E=>E.vectorHealthOpen),Pt=H(E=>E.setVectorHealthOpen),[Ft,Zt]=(0,Ie.useState)(!1),[dn,rr]=(0,Ie.useState)(!1),[qr,Mn]=(0,Ie.useState)([]),[Yn,$r]=(0,Ie.useState)("/"),[ar,Pr]=(0,Ie.useState)(!1),[Kr,ln]=(0,Ie.useState)(null),[Jn,Wt]=(0,Ie.useState)([]),[gr,Un]=(0,Ie.useState)(!1),[Nr,pa]=(0,Ie.useState)([]),[fn,Xr]=(0,Ie.useState)("local"),[ma,xn]=(0,Ie.useState)(null),[Tn,z]=(0,Ie.useState)([]);(0,Ie.useEffect)(()=>{let E=!1;return hx(e).then(Q=>{if(E)return;pa(Q.kinds??[]),xn(null);let O=Q.kinds?.find(ge=>ge.kind==="local")??Q.kinds?.[0]??null;if(O){Xr(O.kind);let ge=$u(O,x);oe.current=ge.key,ee(ge)}}).catch(Q=>{E||xn(Q instanceof Error?Q.message:"Failed to load source kinds")}),()=>{E=!0}},[n]);let I=(0,Ie.useMemo)(()=>{let E=new Map;for(let Q of Nr)E.set(Q.kind,Q);return E},[Nr]),q=I.get(fn)??null,F=Kg(q),de=JI(q),D=de.needed,xe=D&&de.container,Mt=(0,Ie.useCallback)(E=>{let Q=$u(I.get(E.suggestedKind)??null,x),O=E.suggestedConfig.root??"",ge=E.suggestedConfig.hostRoot;Xr(E.suggestedKind),oe.current=E.suggestedScheme,ee({...Q,key:E.suggestedScheme,path:O,...E.suggestedScope?{scope:E.suggestedScope}:{},...E.syncDisabled?{syncEnabled:!1}:{},...E.suggestedSync?.include?{include:Lf(E.suggestedSync.include)}:{},...E.suggestedSync?.trigger?{trigger:E.suggestedSync.trigger}:{},...E.suggestedPolicies?.length?{policies:E.suggestedPolicies}:{},...E.description?{description:E.description}:{},...E.suggestedAccess??{},config:{...Q.config,...ge&&Xg(I.get(E.suggestedKind)??null).properties.hostRoot?{hostRoot:ge}:{}}}),je(!0)},[I,x]);(0,Ie.useEffect)(()=>{o&&I.size!==0&&(l(null),Mt(o))},[o,I,Mt,l]);let zt=(0,Ie.useCallback)((E,Q)=>lL({baseName:Q?pE(Q):null,meta:q,scope:E,ids:x}),[q,x]),yn=E=>E===""||E===oe.current,Sn=(0,Ie.useCallback)(async()=>{if(r){V(!0),N(null);try{let[E,Q]=await Promise.all([P0({agentId:n,projectId:r,scope:kt},e),ic({agentId:n,projectId:r},e).catch(()=>({suggestions:[]}))]);b(E),L(Object.fromEntries(E.map(O=>[O.source,Yo(O)]))),w(O=>Object.fromEntries(E.map(ge=>[ge.source,O[ge.source]??!1]))),z(Q.suggestions??[])}catch(E){N(E instanceof Error?E.message:"Failed to load sources")}finally{V(!1)}}},[kt,n,r]);(0,Ie.useEffect)(()=>{s&&Sn()},[s,Sn]),(0,Ie.useEffect)(()=>{s&&n&&u({agentId:n,projectId:r})},[s,n,r,u]);let nc=(0,Ie.useCallback)(async E=>{if(!n||k[E])return;let Q=!1;if(R(O=>{if(O.has(E))return Q=!0,O;let ge=new Set(O);return ge.add(E),ge}),!Q)try{let O=await A0(n,r??void 0,E,e);O&&_(ge=>({...ge,[E]:O}))}catch{}finally{R(O=>{if(!O.has(E))return O;let ge=new Set(O);return ge.delete(E),ge})}},[n,r,k]),ll=(0,Ie.useCallback)(E=>{_(Q=>{if(!(E in Q))return Q;let O={...Q};return delete O[E],O})},[]),w2=(0,Ie.useCallback)(E=>{w(Q=>{let O=!Q[E];return O&&nc(E),{...Q,[E]:O}})},[nc]);(0,Ie.useEffect)(()=>{if(!Ne)return;let E=setTimeout(()=>Ee(null),4e3);return()=>clearTimeout(E)},[Ne]),(0,Ie.useEffect)(()=>{!Gt||!a||!g||(Un(!0),eh({path:"/mounts",agentId:n,...r?{projectId:r}:{}},e).then(E=>{let Q=new Set(y.map(ge=>ge.source)),O=E.entries.filter(ge=>!Q.has(ge.name));Wt(O)}).catch(()=>Wt([])).finally(()=>Un(!1)))},[Gt,a,g,n,r,y]);let rc=(0,Ie.useMemo)(()=>{let E=new Set,Q=y.map(O=>{E.add(O.source);let ge=c.find(Qt=>qe(Qt.uri_root)===O.source),qt=k[O.source]??ge;return{...O,connector_count:qt?.on_disk,connector_truncated:qt?.truncated,indexed_count:qt?.indexed_count,unindexed_count:qt?.unindexed,last_updated:ge?.last_updated??O.last_updated,sync_status:O.sync?.status??ge?.sync_status??O.sync_status,live:ge?.live,live_reason:ge?.live_reason,kind_icon:ge?.kind_icon}});if(kt==="project")for(let O of c){let ge=qe(O.uri_root);if(!ge||E.has(ge))continue;let qt=I.get(O.source_kind)??null,Qt=k[ge]??O;Q.push({...CE(O,qt),connector_count:Qt.on_disk,connector_truncated:Qt.truncated,indexed_count:Qt.indexed_count,unindexed_count:Qt.unindexed,kind_icon:O.kind_icon})}return Q},[kt,y,I,c,k]),v2=(0,Ie.useMemo)(()=>{let E=new Map;for(let Q of rc){let O=fE(Q.origin_package),ge=E.get(O);ge?ge.push(Q):E.set(O,[Q])}return[...E.entries()].sort(([Q],[O])=>Q===$g?1:O===$g?-1:Q.localeCompare(O))},[rc]),Yr=(E,Q)=>{L(O=>({...O,[E]:Q(O[E])}))},Wf=(E,Q)=>{v(O=>({...O,[E]:{...O[E]??{},[Q]:!(O[E]?.[Q]??!1)}}))},k2=async(E,Q)=>{B(E.source),N(null);try{let O=!Q.sync&&!!E.sync,ge=p&&E.connection.kind==="local",{recognizesPackages:qt,...Qt}=Q,Jr=await Zf({agentId:n,...r?{projectId:r}:{},config:{...ge?Q:Qt,...O?{clearSync:!0}:{}}},e);b(za=>za.map(ja=>ja.source===Jr.source?Jr:ja)),L(za=>({...za,[Jr.source]:Yo(Jr)})),vE(E,Q,O)?(await u({agentId:n,projectId:r,withCounts:!0}),ll(E.source)):await u({agentId:n,projectId:r})}catch(O){N(O instanceof Error?O.message:"Save failed")}finally{B(null)}},S2=(0,Ie.useCallback)(async(E,Q)=>{let O=C[E.source]??Yo(E);B(E.source),N(null);try{let ge=await Zf({agentId:n,...r?{projectId:r}:{},config:{...O,permissions:Q}},e);b(qt=>qt.map(Qt=>Qt.source===ge.source?ge:Qt)),L(qt=>({...qt,[ge.source]:Yo(ge)})),await u({agentId:n,projectId:r})}catch(ge){throw N(ge instanceof Error?ge.message:"Save failed"),ge}finally{B(null)}},[n,C,r,u]),c0=(0,Ie.useCallback)(async E=>{for(let ge=0;ge<2400;ge++){if(await new Promise(Wa=>setTimeout(Wa,1500)),!He.current)return null;let Qt=(await R0({agentId:n,...r?{projectId:r}:{},source:E},e)).job;if(!Qt)return null;if(!(Qt.status==="pending"||Qt.status==="running")){if(Qt.status==="failed")throw new Error(Qt.error??Qt.result?.error??"Sync failed");return Qt}}return null},[n,r]);if(!s)return null;let C2=async E=>{te(E),N(null);try{await N0({agentId:n,...r?{projectId:r}:{},source:E},e),await c0(E),await Sn(),await u({agentId:n,projectId:r,withCounts:!0}),ll(E)}catch(Q){N(Q instanceof Error?Q.message:"Sync failed")}finally{te(null)}},I2=async E=>{try{await dx({agentId:n,...r?{projectId:r}:{},...E?{source:E}:{}},e),te(null),pe(null)}catch(Q){N(Q instanceof Error?Q.message:"Cancel failed")}},ac=async(E,Q,O)=>{pe(E),N(null);try{await Q();let ge=await c0(E),qt=ge?.status==="paused"?ge.result?.embedding?.pausedReason??"paused":null;at(Qt=>{let{[E]:Wa,...Jr}=Qt;return qt?{...Jr,[E]:qt}:Jr}),await Sn(),await u({agentId:n,projectId:r,withCounts:!0}),ll(E)}catch(ge){N(ge instanceof Error?ge.message:O)}finally{pe(null)}},L2=E=>ac(E,()=>hc({agentId:n,...r?{projectId:r}:{},source:E},"pending",e),"Embedding failed"),A2=E=>ac(E,()=>ox({agentId:n,...r?{projectId:r}:{},source:E},e),"Rescan failed"),d0=async(E,Q)=>{let O=++Te.current,ge=At==="source"?{kind:"source"}:{kind:At,uri:Ue};Re(!0),N(null);try{let qt=await lx({agentId:n,...r?{projectId:r}:{},source:E,selector:ge,mode:Q,obsoleteOnly:Ot},e);if(O!==Te.current)return;Q==="estimate"?be(qt):(bt(null),be(null),ll(E),await Sn(),await u({agentId:n,projectId:r,withCounts:!0}))}catch(qt){O===Te.current&&N(qt instanceof Error?qt.message:"Index cleanup failed")}finally{O===Te.current&&Re(!1)}},P2=async E=>{ct(E),N(null);try{await ix({agentId:n,...r?{projectId:r}:{},source:E},e),await Sn()}catch(Q){N(Q instanceof Error?Q.message:"Reset failed")}finally{ct(null)}},N2=async(E,Q)=>{mt(E),N(null);try{await M0({agentId:n,...r?{projectId:r}:{},source:E,enabled:Q},e),await Sn()}catch(O){N(O instanceof Error?O.message:"Toggle failed")}finally{mt(null)}},R2=async(E,Q)=>{le(E),N(null);try{let O=await sx({agentId:n,...r?{projectId:r}:{},source:E,...Q.purgeVectors?{purgeVectors:!0}:{}},e);await Sn(),await u({agentId:n,projectId:r}),ll(E),Ee(Q.purgeVectors&&O?.purgeJob?`Deleted "${E}" (vector purge running in background)`:`Deleted "${E}"`),he(null)}catch(O){N(O instanceof Error?O.message:"Delete failed")}finally{le(null)}},zf=async E=>{rr(!0),Pr(!0),ln(null);try{let Q=await eh({path:E,agentId:n,...r?{projectId:r}:{}},e);Mn(Q.entries),$r(E)}catch{ln("That path is not available."),Mn([])}finally{Pr(!1)}},f0=E=>{ee(Q=>{if(!yn(Q.key))return{...Q,path:E};let O=zt(Q.scope,E);return oe.current=O,{...Q,path:E,key:O}}),rr(!1)},M2=async()=>{if(!(!Oe.key||D&&!Oe.path)){Ae(!0),N(null);try{let E={...Oe.config,...D?{root:Oe.path}:{}};await ax({agentId:n,...r?{projectId:r}:{},source:Oe.key,scope:Oe.scope,connection:{kind:fn,config:E},permissions:{default:{read:Oe.read,write:Oe.write,exec:Oe.exec},...Oe.policies.length>0?{paths:Oe.policies}:{}},...Oe.description.trim()?{description:Oe.description.trim()}:{},...F&&Oe.syncEnabled?{sync:{exclude:Ku(Oe.exclude),trigger:Oe.trigger,...Ku(Oe.include).length>0?{include:Ku(Oe.include)}:{}}}:{},...p&&fn==="local"&&Oe.recognizesPackages?{recognizesPackages:!0}:{}},e),je(!1);{let Q=$u(q,x);oe.current=Q.key,ee(Q)}await Sn(),await u({agentId:n,projectId:r})}catch(E){N(E instanceof Error?E.message:"Add source failed")}finally{Ae(!1)}}},T2=E=>E==="data"||E==="packages";return(0,S.jsxs)("div",{className:"w-full px-5 pt-3 pb-6 text-white/85",children:[(0,S.jsxs)("div",{className:"flex items-center justify-between gap-2 pb-2 border-b border-white/[0.06]",children:[(0,S.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,S.jsx)(ir,{className:"h-4 w-4 text-cyan-400 shrink-0"}),(0,S.jsx)("span",{className:"text-sm font-semibold tracking-wide text-white/92",children:"Sources"}),(0,S.jsx)("span",{className:"rounded px-1.5 py-0.5 text-[10px] font-medium text-cyan-300 bg-cyan-500/20",children:rc.length})]}),(0,S.jsxs)("div",{className:"flex items-center gap-1",children:[(0,S.jsxs)("div",{className:"inline-flex items-center gap-0.5",children:[(0,S.jsxs)("button",{type:"button",onClick:()=>je(E=>!E),className:"h-7 px-2 rounded-l-md rounded-r-none text-cyan-300 hover:text-cyan-200 hover:bg-white/[0.05] transition inline-flex items-center gap-1 text-[10px] font-medium",title:"Add source",children:[(0,S.jsx)(Fn,{className:"h-3 w-3"}),"Source"]}),(0,S.jsx)(qg.SkillLauncher,{variant:"icon",attached:"left",skill:"manage-sources",packageId:"@neuralis/brain-core",scripts:["scripts/sync.sh","scripts/reindex.sh","scripts/set-enabled.sh"],label:"Manage sources with the agent"})]}),(0,S.jsx)("button",{type:"button",onClick:()=>{Sn()},disabled:T,className:"h-7 w-7 rounded-md text-white/35 hover:text-white/70 hover:bg-white/[0.05] transition",title:"Refresh",children:(0,S.jsx)(_t,{className:$("mx-auto h-3 w-3",T&&"animate-spin")})}),(0,S.jsx)("button",{type:"button",onClick:()=>i("sources",!1),className:"h-7 px-2.5 rounded-md text-[10px] font-medium text-white/50 hover:text-white/80 hover:bg-white/[0.05] transition",children:"Close"})]})]}),(0,S.jsxs)("div",{className:"mt-2 text-[10px] text-white/35 italic",children:["Add filesystem-style sources from Neuralis packages. A source URI such as ",(0,S.jsx)("code",{className:"font-mono",children:"neuralis://"})," or ",(0,S.jsx)("code",{className:"font-mono",children:"machine-user://"})," is the stable handle agents use with fs_* tools."]}),(0,S.jsx)("div",{className:"mt-2 flex items-center gap-1 rounded-md bg-white/[0.025] p-1",children:[{id:"project",label:"Project"},{id:"user",label:"User"},{id:"agent",label:"Agent"}].map(E=>(0,S.jsx)("button",{type:"button",onClick:()=>on(E.id),className:$("h-6 rounded px-2 text-[9px] font-semibold transition",kt===E.id?"bg-cyan-500/15 text-cyan-200 border border-cyan-400/20":"text-white/35 hover:text-white/65 hover:bg-white/[0.04]"),children:E.label},E.id))}),Y&&(0,S.jsx)("div",{className:"mt-2 rounded-md bg-red-500/8 px-3 py-2 text-[10px] text-red-200/80",children:Y}),Gt&&(0,S.jsxs)("div",{className:"mt-2 rounded-lg bg-white/[0.03] border border-white/[0.08] p-3 space-y-2",children:[(0,S.jsx)("div",{className:"text-[11px] font-semibold text-white/80",children:"Add Source"}),ma&&(0,S.jsxs)("div",{className:"text-[9px] text-rose-300/80 bg-rose-500/10 rounded px-2 py-1",children:["Could not load source kinds: ",ma,'. Falling back to "local".']}),Nr.length>1&&(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Kind"}),(0,S.jsx)("select",{value:fn,onChange:E=>{let Q=E.target.value,O=I.get(Q)??null;Xr(Q);let ge=$u(O,x);oe.current=ge.key,ee(ge)},className:If,children:Nr.map(E=>(0,S.jsxs)("option",{value:E.kind,children:[E.label," \u2014 ",E.trust," (",E.packageId,")"]},E.kind))}),(0,S.jsx)("div",{className:"text-[9px] text-white/30 italic",children:q?.description??""})]}),q?.scopeSelectable&&(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Scope"}),(0,S.jsx)("select",{value:Oe.scope,onChange:E=>{let Q=E.target.value;ee(O=>{if(!yn(O.key))return{...O,scope:Q};let ge=zt(Q,O.path);return oe.current=ge,{...O,scope:Q,key:ge}})},className:If,children:gE(q).map(E=>(0,S.jsx)("option",{value:E,children:E},E))})]}),xe&&a?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)("div",{className:"text-[10px] text-amber-300/70 bg-amber-500/8 rounded px-2 py-1.5",children:["Docker mode: host folders still need the CLI mount script:"," ",(0,S.jsx)("code",{className:"text-amber-200/90 font-mono",children:"neuralis mount add"})," ","on the host, then restart the container. Package sources like Machine do not require a host path here."]}),gr?(0,S.jsxs)("div",{className:"flex items-center gap-1.5 py-1",children:[(0,S.jsx)(We,{className:"h-3 w-3 animate-spin text-white/30"}),(0,S.jsx)("span",{className:"text-[9px] text-white/35",children:"Scanning volume mounts..."})]}):Jn.length>0?(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Available volume mounts (not yet configured)"}),Jn.map(E=>(0,S.jsxs)("div",{className:"flex items-center gap-2 rounded px-2 py-1.5 bg-white/[0.02] hover:bg-white/[0.04] transition",children:[(0,S.jsx)(Tr,{className:"h-3 w-3 text-cyan-400/70 shrink-0"}),(0,S.jsx)("span",{className:"text-[10px] text-white/75 font-medium flex-1 truncate",children:E.name}),(0,S.jsx)("span",{className:"text-[9px] text-white/30 font-mono truncate max-w-[120px]",children:E.path}),(0,S.jsx)("button",{type:"button",onClick:()=>{ee(Q=>({...Q,key:E.name,path:E.path}))},className:"px-2 py-0.5 rounded text-[8px] font-semibold text-cyan-300/80 bg-cyan-500/10 hover:bg-cyan-500/20 border border-cyan-400/20 transition shrink-0",children:"+ Add"})]},E.path))]}):(0,S.jsx)("div",{className:"text-[9px] text-white/30 italic",children:"All volume mounts are configured as sources."})]}):(0,S.jsx)("div",{className:"text-[10px] text-white/35 italic",children:D?de.container?"Mount any folder from your system. The path must be accessible to the server process.":"A path on the operator\u2019s host machine, reached through the host broker. It needs no volume mount here, and the broker ceiling still clamps what is reachable.":"This connector does not need a local path. Choose the scope and URI scheme; the package owns the runtime binding."}),(0,S.jsxs)("div",{className:"space-y-2",children:[(0,S.jsxs)("div",{className:$("grid gap-2",D?"grid-cols-2":"grid-cols-1"),children:[(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"URI scheme"}),(0,S.jsx)("input",{type:"text",value:Oe.key,onChange:E=>ee(Q=>({...Q,key:E.target.value})),placeholder:zt(Oe.scope,Oe.path),className:Wi}),(0,S.jsxs)("div",{className:"text-[8px] text-white/25 font-mono",children:[Oe.key||zt(Oe.scope,Oe.path),"://"]})]}),D&&(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:de.label}),(0,S.jsxs)("div",{className:"flex gap-1",children:[(0,S.jsx)("input",{type:"text",value:Oe.path,onChange:E=>ee(Q=>({...Q,path:E.target.value})),placeholder:de.placeholder,className:$(Wi,"flex-1")}),de.container&&!a&&g&&(0,S.jsx)("button",{type:"button",onClick:()=>{zf(Oe.path||"/")},className:"h-7 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] border border-white/[0.08] text-white/60 hover:text-white/90 transition shrink-0",title:"Browse directories",children:(0,S.jsx)(Is,{className:"h-3.5 w-3.5"})})]})]})]}),Object.entries(Xg(q).properties).filter(([E])=>E!=="root").map(([E,Q])=>(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:Q?.["x-neuralis"]?.ui?.label??E}),(0,S.jsx)("input",{type:Q.type==="number"||Q.type==="integer"?"number":"text",value:String(Oe.config[E]??""),onChange:O=>ee(ge=>({...ge,config:{...ge.config,[E]:O.target.value}})),placeholder:Q?.["x-neuralis"]?.ui?.placeholder??Q?.description??E,className:Wi})]},E)),xe&&!a&&dn&&(0,S.jsxs)("div",{className:"rounded-md bg-white/[0.03] border border-white/[0.1] overflow-hidden",children:[(0,S.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1.5 bg-white/[0.02] border-b border-white/[0.06]",children:[(0,S.jsx)(Is,{className:"h-3 w-3 text-cyan-400 shrink-0"}),(0,S.jsx)("span",{className:"text-[9px] font-mono text-white/60 truncate flex-1",children:Yn}),(0,S.jsx)("button",{type:"button",onClick:()=>rr(!1),className:"text-[9px] text-white/40 hover:text-white/70 px-1",children:"Close"})]}),Kr&&(0,S.jsx)("div",{className:"px-2 py-1 text-[9px] text-red-300/80",children:Kr}),ar?(0,S.jsx)("div",{className:"flex items-center justify-center py-3",children:(0,S.jsx)(We,{className:"h-3 w-3 animate-spin text-white/30"})}):(0,S.jsxs)("div",{className:"max-h-[180px] overflow-y-auto",children:[Yn!=="/"&&(0,S.jsxs)("button",{type:"button",onClick:()=>{let E=Yn.replace(/[/\\][^/\\]+$/,"")||"/";zf(E)},className:"w-full flex items-center gap-1.5 px-2 py-1 text-left hover:bg-white/[0.04] transition",children:[(0,S.jsx)(qa,{className:"h-3 w-3 text-white/30"}),(0,S.jsx)("span",{className:"text-[10px] text-white/50",children:".."})]}),qr.length===0&&!ar&&(0,S.jsx)("div",{className:"px-2 py-2 text-[9px] text-white/30 italic",children:"No subdirectories"}),qr.map(E=>(0,S.jsxs)("div",{className:"flex items-center gap-0.5 hover:bg-white/[0.04] transition",children:[(0,S.jsxs)("button",{type:"button",onClick:()=>{zf(E.path)},className:"flex items-center gap-1.5 px-2 py-1 flex-1 text-left min-w-0",children:[(0,S.jsx)(Tr,{className:"h-3 w-3 text-cyan-400/70 shrink-0"}),(0,S.jsx)("span",{className:"text-[10px] text-white/75 truncate",children:E.name})]}),(0,S.jsx)("button",{type:"button",onClick:()=>f0(E.path),className:"px-2 py-1 text-[8px] font-medium text-cyan-300/70 hover:text-cyan-200 shrink-0",children:"Select"})]},E.path)),(0,S.jsxs)("button",{type:"button",onClick:()=>f0(Yn),className:"w-full flex items-center gap-1.5 px-2 py-1.5 text-left bg-cyan-500/5 hover:bg-cyan-500/10 border-t border-white/[0.06] transition",children:[(0,S.jsx)(Qr,{className:"h-3 w-3 text-cyan-400 shrink-0"}),(0,S.jsx)("span",{className:"text-[10px] font-medium text-cyan-300/80",children:"Select this folder"}),(0,S.jsx)("span",{className:"text-[9px] text-white/30 font-mono truncate ml-auto",children:Yn})]})]})]})]}),(0,S.jsxs)("div",{className:"flex items-center gap-2",children:[(0,S.jsx)("span",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35 w-16 shrink-0",children:"Access"}),[{key:"read",label:"Read",icon:Sl},{key:"write",label:"Write",icon:si},{key:"exec",label:"Exec",icon:io}].map(({key:E,label:Q,icon:O})=>(0,S.jsxs)("label",{className:$("inline-flex items-center gap-1 rounded px-2 py-1 text-[9px] cursor-pointer transition",Oe[E]?"bg-white/[0.06] text-white/85":"bg-white/[0.02] text-white/40"),children:[(0,S.jsx)("input",{type:"checkbox",className:"sr-only",checked:Oe[E],onChange:ge=>ee(qt=>({...qt,[E]:ge.target.checked}))}),(0,S.jsx)(O,{className:"h-2.5 w-2.5"}),Q,(0,S.jsx)("span",{className:$("h-1.5 w-1.5 rounded-full",Oe[E]?"bg-emerald-300/80":"bg-white/20")})]},E))]}),(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsxs)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:["Description ",(0,S.jsx)("span",{className:"text-white/20 normal-case font-normal",children:"(optional \u2014 shown to the agent)"})]}),(0,S.jsx)("input",{value:Oe.description,onChange:E=>ee(Q=>({...Q,description:E.target.value})),className:Wi,placeholder:q?.description??"What this source is for\u2026",maxLength:200})]}),F&&(0,S.jsx)("div",{className:"flex items-center gap-2",children:(0,S.jsxs)("label",{className:"inline-flex items-center gap-1.5 text-[10px] text-white/80 cursor-pointer",children:[(0,S.jsx)("input",{type:"checkbox",checked:Oe.syncEnabled,onChange:E=>ee(Q=>({...Q,syncEnabled:E.target.checked})),className:"accent-emerald-400 h-3 w-3"}),"Enable sync"]})}),F&&Oe.syncEnabled&&(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Exclude patterns"}),(0,S.jsx)("textarea",{value:Oe.exclude,onChange:E=>ee(Q=>({...Q,exclude:E.target.value})),rows:2,className:Xu,placeholder:"node_modules/**"})]}),F&&Oe.syncEnabled&&(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Include (allowlist)"}),(0,S.jsx)("textarea",{value:Oe.include,onChange:E=>ee(Q=>({...Q,include:E.target.value})),rows:2,className:$(Xu,"font-mono"),placeholder:`# empty = everything
46
+ skills/**`}),(0,S.jsx)("div",{className:"text-[8px] text-white/25 italic",children:"Non-empty: only matching files sync. Excludes always win \u2014 an excluded path can never be re-included. This narrows the INDEX, not what the agent can read: the source root does that."})]}),fn==="local"&&p&&(0,S.jsx)("div",{className:"space-y-1",children:(0,S.jsxs)("label",{className:"inline-flex items-start gap-1.5 text-[10px] text-white/80 cursor-pointer",children:[(0,S.jsx)("input",{type:"checkbox",checked:Oe.recognizesPackages,onChange:E=>ee(Q=>({...Q,recognizesPackages:E.target.checked})),className:"accent-emerald-400 h-3 w-3 mt-0.5"}),(0,S.jsxs)("span",{children:["Recognize packages",(0,S.jsxs)("span",{className:"block text-[9px] text-white/35 normal-case font-normal",children:["Load packages found in this folder (in addition to ",(0,S.jsx)("code",{children:"_packages/"}),") as soon as the source is added. Advertised only within this source's scope."]})]})]})}),(0,S.jsxs)("div",{className:"flex items-center gap-1.5 pt-1",children:[(0,S.jsx)("button",{type:"button",onClick:()=>je(!1),className:"h-6 px-2.5 rounded-md text-[9px] font-medium text-white/50 hover:text-white/80 hover:bg-white/[0.05] transition",children:"Cancel"}),(0,S.jsxs)("button",{type:"button",onClick:()=>{M2()},disabled:Ve||!Oe.key||D&&!Oe.path,className:"h-6 px-2.5 rounded-md bg-cyan-500/12 border border-cyan-400/25 text-[9px] font-semibold text-cyan-200/90 hover:bg-cyan-500/20 transition disabled:opacity-35 inline-flex items-center gap-1",children:[Ve?(0,S.jsx)(We,{className:"h-2.5 w-2.5 animate-spin"}):(0,S.jsx)(Fn,{className:"h-2.5 w-2.5"}),"Create source"]})]})]}),rc.length===0&&!T?(0,S.jsx)("div",{className:"mt-3 text-[10px] text-white/40",children:"No sources configured."}):null,(0,S.jsx)("div",{className:"mt-1 space-y-3",children:v2.map(([E,Q])=>(0,S.jsxs)("div",{children:[(0,S.jsxs)("div",{className:"-ml-0.5 mb-0.5 flex items-center gap-1.5 px-1",children:[(0,S.jsx)(wr,{className:"h-3 w-3 shrink-0 text-white/30"}),(0,S.jsx)("span",{className:"truncate font-mono text-[10px] font-medium text-white/40",children:E}),(0,S.jsx)("span",{className:"text-[9px] tabular-nums text-white/25",children:Q.length})]}),(0,S.jsx)("div",{className:"space-y-0.5 pl-2",children:Q.map(O=>{let ge=C[O.source]??Yo(O),qt=A===O.source,Qt=K===O.source,Wa=ne===O.source,Jr=Se===O.source,za=I.get(O.connection.kind)??null,ja=Kg(za),sc=ja&&!!ge.sync,Gn=ge.sync??jg,h0=(0,lr.resolveIconWithFallback)(O.kind_icon??za?.icon??void 0,zn),p0=Ic(O),m0=O.live===!1,D2=m0||O.enabled===!1||O.enabled==="auto"&&O.enabled_effective===!1,jf=!!P[O.source],hs=!O.observed,Vf=hs&&IE(O,ge),Rr=cL(Gn.trigger),Ys=U[O.source]??{};return(0,S.jsxs)("div",{className:"rounded-sm",children:[(0,S.jsxs)("div",{className:"w-full flex items-center gap-2 py-2 text-left group hover:bg-white/[0.02] rounded-md px-1 transition",children:[(0,S.jsxs)("button",{type:"button",onClick:()=>w2(O.source),"aria-expanded":jf,title:m0?wh(O.live_reason):void 0,className:"min-w-0 flex-1 flex items-center gap-2",children:[O.git?.isRepo?(0,S.jsxs)("span",{className:"relative inline-flex shrink-0 items-center justify-center",children:[(0,S.jsx)(h0,{className:$("h-4 w-4",p0.iconClassName)}),(0,S.jsx)(Cn,{className:"absolute -right-1.5 -top-1.5 h-2.5 w-2.5 rounded-full bg-black/80 p-[1px] text-violet-300/90"})]}):(0,S.jsx)(h0,{className:$("h-4 w-4 shrink-0",p0.iconClassName)}),(0,S.jsx)("span",{className:$("min-w-0 flex-1 truncate text-[12.5px] font-semibold",D2?"text-white/45":"text-white/90"),children:O.source}),O.git?.isRepo&&O.git.branch?(0,S.jsxs)("span",{className:"inline-flex max-w-[96px] shrink-0 items-center gap-0.5 text-[10px] text-violet-300/70",title:`Git branch: ${O.git.branch}`,children:[(0,S.jsx)(Cn,{className:"h-2.5 w-2.5 shrink-0"}),(0,S.jsx)("span",{className:"truncate",children:O.git.branch})]}):null,O.observed&&(0,S.jsx)("span",{className:"shrink-0 rounded px-1 py-0.5 text-[8px] font-medium text-orange-200/90 bg-orange-500/5 ring-1 ring-orange-300/30",children:"observed"}),O.orphan&&(0,S.jsx)("span",{className:"shrink-0 rounded px-1 py-0.5 text-[8px] font-medium text-rose-300/80 bg-rose-500/15",title:O.orphan_hint??"Package missing",children:"orphan"}),Vf&&(0,S.jsx)("span",{className:"shrink-0 rounded px-1 py-0.5 text-[8px] font-medium text-amber-300/80 bg-amber-500/10",children:"unsaved"})]}),(()=>{let Fe=O.enabled??!0,Bt=O.enabled_effective??Fe===!0,Zn=(za?.kind??O.connection.kind)==="webtop",Js=vt===O.source,F2=()=>Zn?Fe===!0?!1:Fe===!1?"auto":!0:Fe===!1,g0=Fe==="auto"?`Auto \xB7 ${Bt?"Live":"Stopped"}`:Fe===!1?"Off":"On",E2=Fe===!1?"text-rose-300/85 bg-rose-500/10 border-rose-400/25":Fe==="auto"?"text-amber-200/85 bg-amber-500/10 border-amber-400/25":"text-emerald-300/85 bg-emerald-500/10 border-emerald-400/25";return(0,S.jsx)("button",{type:"button",title:`Source ${g0} \u2014 click to cycle`,onClick:O2=>{O2.stopPropagation(),!Js&&N2(O.source,F2())},disabled:Js||!!O.observed,className:$("shrink-0 rounded px-1 py-0.5 text-[8px] font-semibold border transition disabled:opacity-50",E2),children:Js?"\u2026":g0})})(),(0,S.jsx)("span",{className:"text-[9px] text-white/30 truncate max-w-[140px] hidden sm:inline",children:SE(O,za)}),(0,S.jsx)(Et,{className:$("h-3 w-3 text-white/25 shrink-0 transition-transform",jf&&"rotate-180")})]}),(0,S.jsx)("div",{className:$("transition-all duration-200",jf?"opacity-100":"max-h-0 opacity-0 overflow-hidden"),children:(0,S.jsxs)("div",{className:"rounded-md bg-white/[0.02] p-3 ml-5 mb-1 space-y-2.5",children:[(0,S.jsxs)("div",{className:"flex items-center gap-3 text-[9px] text-white/40",children:[M.has(O.source)&&typeof O.indexed_count!="number"&&(0,S.jsx)("span",{className:"text-white/30",children:"Loading counts\u2026"}),typeof O.connector_count=="number"&&(0,S.jsxs)("span",{children:[(0,S.jsxs)("span",{className:"text-white/60 tabular-nums",children:[O.connector_count,O.connector_truncated?"+":""]})," connector"]}),typeof O.indexed_count=="number"&&(0,S.jsxs)("span",{children:[(0,S.jsx)("span",{className:"text-cyan-300/70 tabular-nums",children:O.indexed_count})," indexed"]}),typeof O.unindexed_count=="number"&&O.unindexed_count>0&&(0,S.jsxs)("span",{children:[(0,S.jsx)("span",{className:"text-amber-300/70 tabular-nums",children:O.unindexed_count})," unindexed"]}),ja&&O.sync?.lastSync&&(0,S.jsxs)("span",{children:["Last sync: ",oL(O.sync.lastSync)]}),O.updatedAt&&(0,S.jsxs)("span",{children:["Updated: ",oL(O.updatedAt)]})]}),ja&&!O.sync?.lastSync?(0,S.jsx)("div",{className:"rounded-md border border-sky-300/15 bg-sky-500/5 px-2 py-1.5 text-[10px] text-sky-100/70",children:"Never synced \u2014 run a sync to index this source and load its packages (skills, rules, instructions) for agents."}):null,O.observed?(0,S.jsx)("div",{className:"rounded-md border border-orange-300/15 bg-orange-500/5 px-2 py-1.5 text-[10px] text-orange-100/70",children:"Runtime-observed source. Create a source config to edit permissions, sync, or persistence settings."}):null,(0,S.jsxs)("div",{children:[(0,S.jsxs)("button",{type:"button",onClick:()=>Wf(O.source,"description"),className:"flex items-center gap-1.5 py-1 w-full text-left",children:[(0,S.jsx)(va,{className:"h-3 w-3 text-violet-400 shrink-0"}),(0,S.jsx)("span",{className:"text-[10px] font-semibold text-white/70 flex-1",children:"Description"}),!Ys.description&&((ge.description??"").trim()||O.description_effective)&&(0,S.jsx)("span",{className:$("text-[9px] truncate max-w-[200px]",(ge.description??"").trim()?"text-white/35":"text-white/25 italic"),children:(ge.description??"").trim()||`${O.description_effective} (from the package)`}),(0,S.jsx)(un,{className:$("h-2.5 w-2.5 text-white/25 transition-transform",Ys.description&&"rotate-90")})]}),Ys.description&&(0,S.jsxs)("div",{className:"pl-5 pt-1 space-y-1",children:[(0,S.jsx)("div",{className:"text-[10px] text-white/35 italic",children:"A one-line summary shown to the agent in its runtime source list."}),hs?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("textarea",{value:ge.description??"",onChange:Fe=>Yr(O.source,Bt=>({...Bt,description:Fe.target.value})),rows:2,className:Xu,placeholder:O.description_effective??"What this source is for\u2026",maxLength:200}),!(ge.description??"").trim()&&O.description_effective&&(0,S.jsx)("div",{className:"text-[9px] text-white/25 italic",children:"Shown above from the package. Leave this empty to keep following it."})]}):(0,S.jsx)("div",{className:"text-[10px] text-white/70",children:(ge.description??"").trim()||(O.description_effective?(0,S.jsxs)("span",{className:"text-white/40 italic",children:[O.description_effective," ",(0,S.jsx)("span",{className:"text-white/25 not-italic",children:"(from the package)"})]}):(0,S.jsx)("span",{className:"text-white/30 italic",children:"No description"}))})]})]}),hs&&p&&(za?.kind??O.connection.kind)==="local"&&(0,S.jsx)("div",{className:"pl-0",children:(0,S.jsxs)("label",{className:"flex items-start gap-1.5 py-1 cursor-pointer",children:[(0,S.jsx)(wr,{className:"h-3 w-3 text-cyan-400 shrink-0 mt-0.5"}),(0,S.jsx)("input",{type:"checkbox",checked:ge.recognizesPackages??!1,onChange:Fe=>Yr(O.source,Bt=>({...Bt,recognizesPackages:Fe.target.checked})),className:"accent-cyan-400 h-3 w-3 mt-0.5"}),(0,S.jsxs)("span",{className:"text-[10px] text-white/70 leading-tight",children:["Recognize packages",(0,S.jsxs)("span",{className:"block text-[9px] text-white/35 normal-case font-normal",children:["Load packages found in this folder (in addition to ",(0,S.jsx)("code",{children:"_packages/"}),") \u2014 applied on save; advertised only within this source's scope."]})]})]})}),(0,S.jsxs)("div",{children:[(0,S.jsxs)("div",{className:"flex items-center gap-1.5 py-1",children:[(0,S.jsxs)("button",{type:"button",onClick:()=>Wf(O.source,"perms"),className:"flex items-center gap-1.5 flex-1 text-left",children:[(0,S.jsx)(Ps,{className:"h-3 w-3 text-emerald-400 shrink-0"}),(0,S.jsx)("span",{className:"text-[10px] font-semibold text-white/70 flex-1",children:"Permissions"}),(0,S.jsx)(un,{className:$("h-2.5 w-2.5 text-white/25 transition-transform",Ys.perms&&"rotate-90")})]}),(0,S.jsx)(qg.SkillLauncher,{variant:"icon",size:"sm",skill:"manage-uri-policy",packageId:"@neuralis/brain-core",scripts:["scripts/show-uri.sh","scripts/set-uri.sh","scripts/manifests.sh"],label:`Edit URI policy for "${O.source}" with the agent`,icon:"shield"})]}),Ys.perms&&(0,S.jsx)("div",{className:"pl-5 pt-1",children:(0,S.jsx)(zg,{source:O.source,permissions:O.permissions,mode:hs?"edit":"view",onSave:hs?Fe=>S2(O,Fe):void 0})})]}),ja&&(0,S.jsxs)("div",{children:[(0,S.jsxs)("button",{type:"button",onClick:()=>Wf(O.source,"sync"),className:"flex items-center gap-1.5 py-1 w-full text-left",children:[(0,S.jsx)(_t,{className:"h-3 w-3 text-blue-400 shrink-0"}),(0,S.jsx)("span",{className:"text-[10px] font-semibold text-white/70 flex-1",children:"Sync"}),sc&&(0,S.jsx)("span",{className:"text-[9px] text-white/35",children:kE(Gn.trigger)}),(0,S.jsx)(un,{className:$("h-2.5 w-2.5 text-white/25 transition-transform",Ys.sync&&"rotate-90")})]}),Ys.sync&&(0,S.jsxs)("div",{className:"pl-5 space-y-2 pt-1",children:[(0,S.jsx)("div",{className:"text-[10px] text-white/35 italic",children:"Sync indexes files for AI search. Excluded patterns (logs/, node_modules/) are skipped automatically."}),(0,S.jsxs)("label",{className:"inline-flex items-center gap-1.5 text-[10px] text-white/80 cursor-pointer",children:[(0,S.jsx)("input",{type:"checkbox",checked:sc,onChange:Fe=>Yr(O.source,Bt=>({...Bt,...Fe.target.checked?{sync:{...jg,exclude:[...O.defaultSyncExclude??jg.exclude]}}:{sync:void 0}})),className:"accent-emerald-400 h-3 w-3"}),"Enable sync"]}),sc&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsxs)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35 flex items-center gap-1",children:[(0,S.jsx)(wa,{className:"h-2.5 w-2.5 text-cyan-300/60"})," Trigger"]}),(0,S.jsx)("select",{value:Rr.mode,onChange:Fe=>{let Bt=Fe.target.value;Yr(O.source,Zn=>({...Zn,sync:{...Gn,trigger:Vg(Bt,Rr.val,Rr.unit)}}))},className:If,children:cE.map(Fe=>(0,S.jsx)("option",{value:Fe.value,children:Fe.label},Fe.value))}),Rr.mode==="interval"&&(0,S.jsxs)("div",{className:"flex gap-1",children:[(0,S.jsx)("input",{type:"number",min:Af(Rr.unit),value:Rr.val,onChange:Fe=>{let Bt=Fe.target.value.replace(/\D/g,"")||String(Af(Rr.unit));Yr(O.source,Zn=>({...Zn,sync:{...Gn,trigger:Vg("interval",Bt,Rr.unit)}}))},className:$(Wi,"w-16")}),(0,S.jsx)("select",{value:Rr.unit,onChange:Fe=>{let Bt=Fe.target.value,Zn=String(Math.max(Number.parseInt(Rr.val,10)||1,Af(Bt)));Yr(O.source,Js=>({...Js,sync:{...Gn,trigger:Vg("interval",Zn,Bt)}}))},className:$(If,"flex-1"),children:dE.map(Fe=>(0,S.jsx)("option",{value:Fe.value,children:Fe.label},Fe.value))})]}),(0,S.jsx)("div",{className:"text-[8px] text-white/35 italic leading-relaxed",children:Rr.mode==="manual"?"Manual: nothing triggers it automatically \u2014 indexes only when you click Sync below.":Rr.mode==="auto"?"Auto: re-indexes on file changes (host edits, git, shell \u2014 anything) + a periodic full reconcile.":"Scheduled: runs a full reconcile every interval above."})]}),(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Exclude"}),(0,S.jsx)("textarea",{value:Lf(Gn.exclude),onChange:Fe=>{let Bt=Ku(Fe.target.value);Yr(O.source,Zn=>({...Zn,sync:{...Gn,exclude:Bt}}))},rows:5,className:$(Xu,"font-mono"),placeholder:`# .gitignore syntax
47
47
  node_modules/**
48
48
  .git/**
49
- dist/**`}),(0,S.jsx)("div",{className:"text-[8px] text-white/25 italic",children:"Uses .gitignore syntax. Lines starting with # are comments."})]}),(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Include (allowlist)"}),(0,S.jsx)("textarea",{value:Sf(Un.include??[]),onChange:We=>{let _t=ju(We.target.value);Zr(F.source,Zn=>({...Zn,sync:{...Un,..._t.length>0?{include:_t}:{include:void 0}}}))},rows:3,className:q(qu,"font-mono"),placeholder:`# empty = everything
49
+ dist/**`}),(0,S.jsx)("div",{className:"text-[8px] text-white/25 italic",children:"Uses .gitignore syntax. Lines starting with # are comments."})]}),(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Include (allowlist)"}),(0,S.jsx)("textarea",{value:Lf(Gn.include??[]),onChange:Fe=>{let Bt=Ku(Fe.target.value);Yr(O.source,Zn=>({...Zn,sync:{...Gn,...Bt.length>0?{include:Bt}:{include:void 0}}}))},rows:3,className:$(Xu,"font-mono"),placeholder:`# empty = everything
50
50
  docs/**
51
- packages/*/skills/**`}),(0,S.jsx)("div",{className:"text-[8px] text-white/25 italic",children:"Non-empty: only matching files sync. Excludes always win \u2014 an excluded path can never be re-included."})]}),(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Max scan files"}),(0,S.jsx)("input",{type:"number",min:1,step:1e3,value:Un.maxScanFiles??"",onChange:We=>{let _t=Number(We.target.value),Zn=Number.isFinite(_t)&&_t>0?Math.floor(_t):void 0;Zr(F.source,Zs=>({...Zs,sync:{...Un,maxScanFiles:Zn}}))},className:q(zo,"w-28 font-mono"),placeholder:"200000"}),(0,S.jsx)("div",{className:"text-[8px] text-white/25 italic",children:"Per-source cap on files walked during sync/count. Empty = inherit the platform default. When a walk hits the cap the count shows N+."})]}),(0,S.jsxs)("label",{className:"inline-flex items-center gap-1.5 text-[10px] text-white/80 cursor-pointer",children:[(0,S.jsx)("input",{type:"checkbox",checked:Un.alwaysActive??(F.source==="data"||F.source==="packages"),onChange:We=>Zr(F.source,_t=>({..._t,sync:{...Un,alwaysActive:We.target.checked}})),className:"accent-cyan-400 h-3 w-3"}),"Always active",(0,S.jsx)("span",{className:"text-[8px] text-white/30 normal-case",children:'(pins this source in the auto-sync pool even when the platform Auto-Sync Mode is "packages-only"; no effect with the Manual trigger)'})]}),(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Media"}),(0,S.jsx)("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:Q5.map(We=>(0,S.jsxs)("label",{className:"inline-flex items-center gap-1.5 text-[10px] text-white/80 cursor-pointer",children:[(0,S.jsx)("input",{type:"checkbox",checked:Un.media?.[We.key]??We.on,onChange:_t=>Zr(F.source,Zn=>({...Zn,sync:{...Un,media:{...Un.media??{},[We.key]:_t.target.checked}}})),className:"accent-cyan-400 h-3 w-3"}),We.label]},We.key))}),(0,S.jsx)("div",{className:"text-[8px] text-white/25 italic",children:"Embeds these files from their bytes \u2014 only while the active embedding model is multimodal (a text-only model skips them and the last-sync line says so). Each image or PDF page is one provider call; video and audio cost the most. Unticking a kind clears its searchable cache at the next full sync while preserving recovery content."})]}),F.sync?.lastSyncResult&&(0,S.jsxs)("div",{className:"text-[9px] text-white/40 flex items-center gap-2",children:[(0,S.jsxs)("span",{children:["Last sync: +",F.sync.lastSyncResult.filesAdded," -",F.sync.lastSyncResult.filesRemoved," ~",F.sync.lastSyncResult.filesUpdated]}),(0,S.jsxs)("span",{children:["(",(F.sync.lastSyncResult.durationMs/1e3).toFixed(1),"s)"]}),F.sync.lastSyncResult.error&&(0,S.jsx)("span",{className:"text-rose-300/80 truncate max-w-[200px]",title:F.sync.lastSyncResult.error,children:"err"})]}),tI(F.sync?.lastSyncResult?.mediaSkipped)&&(0,S.jsx)("div",{className:"text-[9px] text-amber-200/70",role:"status",children:tI(F.sync?.lastSyncResult?.mediaSkipped)})]})]})]}),(0,S.jsxs)("div",{className:"flex items-center justify-between gap-2 pt-1.5 border-t border-white/[0.06]",children:[(0,S.jsx)("span",{className:"text-[9px] text-white/30",children:F.observed?"Observed runtime source":jf?"Unsaved changes":"No pending changes"}),(0,S.jsxs)("div",{className:"flex items-center gap-1.5",children:[cs&&za&&(fn||qo)?(0,S.jsxs)("button",{type:"button",onClick:()=>{m2(F.source)},className:"h-6 px-2 rounded-md bg-rose-500/10 hover:bg-rose-500/20 border border-rose-400/25 text-[9px] font-medium text-rose-300/80 hover:text-rose-200 transition inline-flex items-center gap-1",children:[(0,S.jsx)(Ol,{className:"h-2.5 w-2.5"}),"Cancel"]}):cs&&za?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)("button",{type:"button",disabled:!Ju,onClick:()=>{p2(F.source)},className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-blue-300/80 hover:text-blue-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[(0,S.jsx)(Tl,{className:"h-2.5 w-2.5"}),"Sync"]}),(0,S.jsxs)("button",{type:"button",disabled:qo,onClick:()=>{g2(F.source)},className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-cyan-300/80 hover:text-cyan-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[(0,S.jsx)(br,{className:"h-2.5 w-2.5"}),"Rescan changes"]}),(0,S.jsxs)("button",{type:"button",disabled:qo,onClick:()=>at(F.source),title:"Embed every file of this source again with the active model \u2014 shows the estimated cost first",className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-cyan-300/80 hover:text-cyan-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[(0,S.jsx)(wa,{className:"h-2.5 w-2.5"}),"Re-embed\u2026"]}),(0,S.jsxs)("button",{type:"button",disabled:je===F.source,onClick:()=>{x2(F.source)},title:"Forgets what the last sync saw \u2014 the next sync compares every file again. Deletes no file and no vector.",className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-amber-300/80 hover:text-amber-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[je===F.source?(0,S.jsx)(ze,{className:"h-2.5 w-2.5 animate-spin"}):(0,S.jsx)(oo,{className:"h-2.5 w-2.5"}),"Forget sync state"]})]}):null,F.canMaintain===!0&&(0,S.jsx)("button",{type:"button",onClick:()=>{de.current++,Pt(F.source),Ne("source"),Je(""),Mt(!0),oe(null),Kt(!1)},className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] text-amber-300/80",children:"Clean index\u2026"}),cs&&!v2(F.source)&&(0,S.jsxs)("button",{type:"button",disabled:us,onClick:()=>ue(F.source),className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-red-300/80 hover:text-red-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[us?(0,S.jsx)(ze,{className:"h-2.5 w-2.5 animate-spin"}):(0,S.jsx)(It,{className:"h-2.5 w-2.5"}),"Delete"]}),(0,S.jsxs)("button",{type:"button",disabled:an||!jf,onClick:()=>{f2(F,ge)},className:"h-6 px-2.5 rounded-md bg-emerald-500/12 border border-emerald-400/25 text-[9px] font-semibold text-emerald-200/90 hover:bg-emerald-500/20 transition disabled:opacity-35 inline-flex items-center gap-1",children:[an?(0,S.jsx)(ze,{className:"h-2.5 w-2.5 animate-spin"}):(0,S.jsx)(io,{className:"h-2.5 w-2.5"}),"Save"]})]})]})]})}),vt===F.source&&F.canMaintain===!0&&(0,S.jsxs)("fieldset",{disabled:jt,className:"ml-5 mb-2 rounded-md border border-amber-400/20 p-3 space-y-2 text-[10px] text-white/70",children:[(0,S.jsxs)("legend",{children:["Clean index for ",F.source]}),(0,S.jsx)("p",{children:"The source, files, pending changes and recovery history stay available. Cleanup makes no embedding calls."}),(0,S.jsxs)("label",{children:["Selection ",(0,S.jsxs)("select",{"aria-label":"Index cleanup selection",value:Ye,onChange:We=>{de.current++,Ne(We.target.value),oe(null)},className:"bg-[#15151d]",children:[(0,S.jsx)("option",{value:"source",children:"Whole source"}),(0,S.jsx)("option",{value:"folder",children:"Folder"}),(0,S.jsx)("option",{value:"file",children:"File"})]})]}),Ye!=="source"&&(0,S.jsx)("input",{"aria-label":"Index cleanup URI",placeholder:`${F.source}://path`,value:tt,onChange:We=>{de.current++,Je(We.target.value),oe(null)},className:"block w-full bg-white/5 rounded px-2 py-1"}),(0,S.jsxs)("label",{className:"block",children:[(0,S.jsx)("input",{type:"checkbox",checked:Ft,onChange:We=>{de.current++,Mt(We.target.checked),oe(null)}})," Only excluded files and disabled media lanes"]}),!Ft&&(0,S.jsx)("p",{children:"All selected searchable cache will be cleared. A later sync can rebuild it."}),Te&&(0,S.jsxs)("p",{children:[Te.removedParents," parents removed \xB7 ",Te.removedChunks," chunks removed \xB7 ",Te.retained," recovery payloads retained \xB7 ",Te.unresolved," unresolved points kept"]}),(0,S.jsxs)("div",{className:"flex gap-2",children:[(0,S.jsx)("button",{type:"button",onClick:()=>{de.current++,Pt(null),oe(null)},children:"Cancel"}),(0,S.jsx)("button",{type:"button",onClick:()=>{p0(F.source,"estimate")},children:jt?"Working\u2026":"Preview counts"}),Te?.canMaintain&&(0,S.jsx)("button",{type:"button",onClick:()=>{p0(F.source,"apply")},children:"Confirm cleanup"})]})]}),ce===F.source&&(0,S.jsx)(eI,{source:F.source,vectorCount:typeof F.indexed_count=="number"?F.indexed_count:null,isDockerMount:!!F.connection?.config?.hostRoot,busy:us,onCancel:()=>ue(null),onConfirm:We=>{b2(F.source,We)}}),Dt===F.source&&(0,S.jsx)(kc,{agentId:e,...t?{projectId:t}:{},target:{source:F.source,label:F.source},onClose:()=>at(null),onStarted:()=>{h0(F.source,()=>Promise.resolve(),"Re-embed failed")}})]},wx(rr(F.source)))})})]},T))}),He&&(0,S.jsx)("div",{className:"mt-2 rounded-md bg-emerald-500/10 border border-emerald-400/25 px-2.5 py-1.5 text-[10px] text-emerald-200/85",children:He}),(0,S.jsxs)("div",{className:"border-t border-white/[0.06] pt-2 mt-3",children:[(0,S.jsxs)("button",{type:"button",onClick:()=>Ge(T=>!T),className:"flex items-center gap-2 py-1.5 w-full text-left",children:[(0,S.jsx)(br,{className:"h-4 w-4 text-cyan-400 shrink-0"}),(0,S.jsx)("span",{className:"text-sm font-semibold text-white/92 flex-1",children:"Vector Health"}),(0,S.jsx)(Tt,{className:q("h-3 w-3 text-white/25 transition-transform",Ce&&"rotate-180")})]}),(0,S.jsx)("div",{className:q("overflow-hidden transition-all duration-200",Ce?"max-h-[1600px] opacity-100":"max-h-0 opacity-0"),children:Ce&&(0,S.jsx)(YL,{agentId:e,projectId:t})})]}),(0,S.jsxs)("div",{className:"border-t border-white/[0.06] pt-2 mt-3",children:[(0,S.jsxs)("button",{type:"button",onClick:()=>Ae(T=>!T),className:"flex items-center gap-2 py-1.5 w-full text-left",children:[(0,S.jsx)(si,{className:"h-4 w-4 text-cyan-400 shrink-0"}),(0,S.jsx)("span",{className:"text-sm font-semibold text-white/92 flex-1",children:"Mount & Discover"}),(0,S.jsx)(Tt,{className:q("h-3 w-3 text-white/25 transition-transform",Ke&&"rotate-180")})]}),(0,S.jsx)("div",{className:q("overflow-hidden transition-all duration-200",Ke?"max-h-[1600px] opacity-100":"max-h-0 opacity-0"),children:(0,S.jsxs)("div",{className:"mt-3 rounded-md bg-white/[0.02] border border-white/[0.06] p-3 space-y-2",children:[(0,S.jsx)("p",{className:"text-[10px] leading-relaxed text-white/55",children:"CLI helper for exposing host folders to the brain. Run it with no arguments to print usage:"}),(0,S.jsx)("div",{className:"rounded bg-black/30 border border-white/[0.05] p-2",children:(0,S.jsx)("pre",{className:"text-[11px] font-mono text-white/85 whitespace-pre-wrap break-all",children:"pnpm neuralis:mount"})}),(0,S.jsxs)("div",{className:"rounded bg-black/30 border border-white/[0.05] p-2 space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] uppercase tracking-wider text-white/40 font-semibold",children:"Example \u2014 expose a host folder as a mount"}),(0,S.jsx)("pre",{className:"text-[10px] font-mono text-white/80 whitespace-pre-wrap break-all",children:"pnpm neuralis:mount add <host-path> --slug <name>"}),(0,S.jsx)("div",{className:"text-[9px] text-white/35 italic",children:"The CLI is infra-only: it registers the bind mount + host-pair env in the machine-local compose override, never a source. After the container restarts, the mount appears in the Discoverable list below \u2014 click it to attach the source with a chosen scope (the host path resolves automatically)."})]}),Jr.length>0?(0,S.jsxs)("div",{className:"pt-1.5",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/40 mb-1",children:"Discoverable"}),(0,S.jsx)("ul",{className:"space-y-1",children:Jr.map(T=>{let Z=yc("unattached"),F=(0,sr.resolveLucideIcon)(T.icon??null)||Gn;return(0,S.jsx)("li",{children:(0,S.jsxs)("button",{type:"button",onClick:()=>O(T),className:q("flex items-start gap-2 w-full text-left px-2 py-1.5 rounded-md hover:bg-white/[0.04] transition",Z.containerClassName),title:Z.title,children:[(0,S.jsx)(F,{className:q("h-3.5 w-3.5 mt-0.5 shrink-0",Z.iconClassName)}),(0,S.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,S.jsxs)("div",{className:q("text-[11px] font-semibold truncate",Z.labelClassName),children:[T.label,(0,S.jsxs)("span",{className:"text-[9px] text-white/30 font-mono ml-1.5",children:[T.suggestedScheme,"://"]})]}),(0,S.jsx)("div",{className:q("text-[9px] truncate",Z.detailClassName),children:T.description}),(0,S.jsx)("div",{className:"text-[8px] text-white/25 font-mono truncate",children:T.root})]}),(0,S.jsx)(Fn,{className:"h-3 w-3 text-white/40 shrink-0 mt-1"})]})},T.id)})})]}):(0,S.jsx)("div",{className:"pt-1 text-[9px] italic text-white/35",children:"No discoverable mounts at the moment."})]})})]})]})}var Rt=W($e(),1),t0=W(Ya(),1);var hI=W(mr(),1);async function Xi(n){let e=await n.text();try{return JSON.parse(e)}catch{throw new Error(`Invalid JSON response (HTTP ${n.status}): ${e.slice(0,200)}`)}}async function iI(n){let e=await fetch("/api/packages/runtime",{method:"GET",headers:{"x-project-id":n},credentials:"same-origin"});if(!e.ok)throw new Error(`Failed to load packages snapshot: HTTP ${e.status}`);let t=await Xi(e),r=[...t.skills,...t.instructions,...t.rules,...t.agents,...t.docs],a=Qg(t.tools,i=>i.packageId),s=Qg(r,i=>i.packageId),o=Qg(t.commands,i=>i.packageId);return t.packages.map(i=>({slug:i.id,packageId:i.id,name:i.name,version:i.version,description:i.description,source:i.source,runtime:i.runtime,access:i.access,status:i.status,partialReason:i.partialReason,toolCount:a.get(i.id)??0,fileCount:s.get(i.id)??0,commandCount:o.get(i.id)??0,...i.accessFeature?{accessFeature:i.accessFeature,accessFeatureSource:i.accessFeatureSource}:{}}))}async function lI(n,e){let t=await fetch(`/api/projects/${encodeURIComponent(n)}/packages/${encodeURIComponent(e)}/build`,{method:"POST",credentials:"same-origin"});return Xi(t)}async function uI(n,e,t){let r=await fetch(`/api/projects/${encodeURIComponent(n)}/packages/${encodeURIComponent(e)}/trust`,{method:"PUT",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({trust:t})});if(!r.ok){let a=await r.text();throw new Error(`Failed to set trust (HTTP ${r.status}): ${a.slice(0,200)}`)}return Xi(r)}async function cI(n,e,t){let r=await fetch(`/api/projects/${encodeURIComponent(n)}/packages/${encodeURIComponent(e)}/access-feature`,{method:"PUT",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({featureId:t})});if(!r.ok){let a=await r.text();throw new Error(`Failed to set access feature (HTTP ${r.status}): ${a.slice(0,200)}`)}return Xi(r)}async function dI(n){let e=await fetch("/api/admin/feature-catalog",{method:"GET",headers:{"x-project-id":n},credentials:"same-origin"});if(!e.ok)throw new Error(`Failed to load feature catalog: HTTP ${e.status}`);let t=await Xi(e),r=new Set;for(let a of t.groups??[])for(let s of a.features??[])r.add(s);return Array.from(r).sort()}async function fI(n){let e=await fetch("/api/packages/agent-core/packages/diagnostics",{method:"GET",headers:{"x-project-id":n},credentials:"same-origin"});if(!e.ok)throw new Error(`Failed to load packages diagnostics: HTTP ${e.status}`);return Xi(e)}function Qg(n,e){let t=new Map;for(let r of n){let a=e(r);t.set(a,(t.get(a)??0)+1)}return t}var Y=W(le(),1),sE={"build-missing":{label:"Needs build",hint:"The package has server-side code (src/) but the WASM binary is missing. Click Build to compile it."},"runtime-unavailable":{label:"Runtime unavailable",hint:"MCP subprocess failed to spawn or the code runtime crashed. Check host logs."},"untrusted-node":{label:"Declarative only",hint:'Untrusted packages cannot execute in-process code. Declare `runtime.type: "wasm"` in the manifest to enable handlers.'},"untrusted-mcp":{label:"Declarative only",hint:'The "mcp" runtime spawns a subprocess as the host user and needs first-party trust, so no subprocess was started. Declare `runtime.type: "wasm"` in the manifest to enable handlers.'}};function pI({projectId:n}){let t=(hn().currentRole?.priority??99)<=2,[r,a]=(0,Rt.useState)([]),[s,o]=(0,Rt.useState)(!0),[i,l]=(0,Rt.useState)(null),[u,c]=(0,Rt.useState)({}),[d,f]=(0,Rt.useState)({}),[h,p]=(0,Rt.useState)(null),[m,g]=(0,Rt.useState)(!1);(0,Rt.useEffect)(()=>{g(!0)},[]);let[x,w]=(0,Rt.useState)(null),[y,C]=(0,Rt.useState)([]),[k,v]=(0,Rt.useState)(null),[b,P]=(0,Rt.useState)([]),N=(0,Rt.useCallback)(async()=>{o(!0),l(null);try{let L=await iI(n);a(L)}catch(L){l(L instanceof Error?L.message:String(L))}finally{o(!1)}try{let L=await fI(n);C(L.entries),v(null)}catch(L){C([]),v(L instanceof Error?L.message:String(L))}},[n]);(0,Rt.useEffect)(()=>{N()},[N]),(0,Rt.useEffect)(()=>{if(!t)return;let L=!1;return dI(n).then(R=>{L||P(R)}).catch(()=>{}),()=>{L=!0}},[n,t]);let M=(0,Rt.useCallback)(L=>{c(R=>({...R,[L]:!R[L]}))},[]),U=(0,Rt.useCallback)(async L=>{let R=L.access?.trust??"untrusted";if(R==="first-party")return;let z=R==="trusted"?"untrusted":"trusted";f(J=>({...J,[L.slug]:"trust"}));try{await uI(n,L.slug,z),p(`Trust: ${L.slug} \u2192 ${z}`),await N()}catch(J){p(J instanceof Error?J.message:"Failed to set trust")}finally{f(J=>({...J,[L.slug]:"none"}))}},[n,N]),I=(0,Rt.useCallback)(async(L,R)=>{f(z=>({...z,[L.slug]:"access-feature"}));try{await cI(n,L.packageId,R),p(R?`Access feature: ${L.slug} \u2192 ${R}`:`Access feature cleared: ${L.slug}`),await N()}catch(z){p(z instanceof Error?z.message:"Failed to set access feature")}finally{f(z=>({...z,[L.slug]:"none"}))}},[n,N]),A=(0,Rt.useCallback)(async L=>{f(z=>({...z,[L.slug]:"build"})),w({slug:L.slug,logs:["Starting build\u2026"]});let R=null;try{R=await lI(n,L.slug),w({slug:L.slug,logs:R.logs,ok:R.ok,error:R.error,durationMs:R.durationMs}),R.ok?(p(`Build complete: ${L.slug} (${R.durationMs}ms)`),await N()):p(`Build failed: ${R.error??"unknown"}`)}catch(z){let J=z instanceof Error?z.message:String(z);w({slug:L.slug,logs:[`Request failed: ${J}`],ok:!1,error:J}),p(`Build request failed: ${J}`)}finally{f(z=>({...z,[L.slug]:"none"}))}},[n,N]),G=(0,Rt.useMemo)(()=>[...r].sort((L,R)=>L.name.localeCompare(R.name)),[r]),V=(0,Rt.useMemo)(()=>{let L=new Set(r.map(R=>R.packageId));return y.filter(R=>!L.has(R.packageId)||R.status==="missing"||R.status==="error")},[y,r]),K=(0,Rt.useMemo)(()=>{let L=new Map;for(let R of y)L.set(R.packageId,R);return L},[y]);return s?(0,Y.jsxs)("div",{className:"h-full flex items-center justify-center text-white/50 text-sm",children:[(0,Y.jsx)(ze,{className:"w-4 h-4 animate-spin mr-2"})," Loading packages\u2026"]}):i?(0,Y.jsx)("div",{className:"p-4",children:(0,Y.jsxs)("div",{className:"rounded-lg border border-red-500/25 bg-red-500/10 p-3 text-xs text-red-100/85",children:[(0,Y.jsx)("div",{className:"font-semibold mb-1",children:"Failed to load packages"}),(0,Y.jsx)("div",{className:"font-mono opacity-80",children:i}),(0,Y.jsxs)("button",{className:"mt-2 inline-flex items-center gap-1 rounded-md bg-white/10 px-2 py-1 text-[11px] text-white/80 hover:bg-white/15",onClick:()=>{N()},children:[(0,Y.jsx)(Ht,{className:"w-3 h-3"})," Retry"]})]})}):(0,Y.jsxs)("div",{className:"p-3 space-y-2",children:[(0,Y.jsxs)("div",{className:"flex items-center justify-between px-1 pb-2",children:[(0,Y.jsxs)("div",{className:"flex items-center gap-2",children:[(0,Y.jsx)(vr,{className:"w-4 h-4 text-violet-300"}),(0,Y.jsx)("h2",{className:"text-sm font-semibold text-white/85",children:"Packages"}),(0,Y.jsxs)("span",{className:"text-[10px] text-white/45",children:[G.length," installed"]})]}),(0,Y.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,Y.jsx)(hI.SkillLauncher,{variant:"label",size:"sm",skill:"create-package",packageId:"@neuralis/brain-core",alsoRequires:["packages.author"],label:"Scaffold a package with the agent",icon:"package"}),(0,Y.jsxs)("button",{className:"inline-flex items-center gap-1 rounded-md bg-white/5 px-2 py-1 text-[11px] text-white/60 hover:bg-white/10 hover:text-white/85",onClick:()=>{N()},children:[(0,Y.jsx)(Ht,{className:"w-3 h-3"}),"Refresh"]})]})]}),(0,Y.jsxs)("div",{className:"mx-1 rounded-lg border border-violet-500/15 bg-violet-500/5 px-3 py-2 text-[11px] text-violet-100/80 flex items-start gap-2",children:[(0,Y.jsx)(Ll,{className:"w-3.5 h-3.5 shrink-0 mt-0.5 text-violet-300/80"}),(0,Y.jsxs)("div",{className:"space-y-1",children:[(0,Y.jsx)("div",{children:"Untrusted packages register their declarative content (skills, tool schemas, commands) but cannot execute in-process code or call other packages."}),(0,Y.jsxs)("div",{className:"text-violet-100/60",children:["Flip trust when you know the author. Run Build only for packages with server-side code in ",(0,Y.jsx)("span",{className:"font-mono",children:"src/"}),"."]})]})]}),V.length>0&&(0,Y.jsxs)("div",{className:"mx-1 rounded-lg border border-rose-500/25 bg-rose-500/[0.06] px-3 py-2 text-[11px] text-rose-100/85 space-y-1",children:[(0,Y.jsxs)("div",{className:"flex items-center gap-1.5 text-rose-200/95 font-semibold",children:[(0,Y.jsx)(dt,{className:"w-3 h-3"}),V.length," package",V.length===1?"":"s"," failed to load"]}),V.map(L=>(0,Y.jsxs)("div",{className:"rounded border border-rose-500/15 bg-rose-500/[0.04] px-2 py-1",children:[(0,Y.jsxs)("div",{className:"font-mono text-[10px] text-rose-200/95",children:[L.packageId," ",(0,Y.jsxs)("span",{className:"text-rose-300/80",children:["\xB7 ",L.status]}),L.reason&&(0,Y.jsxs)("span",{className:"text-rose-300/55",children:[" (",L.reason,")"]})]}),L.error&&(0,Y.jsx)("div",{className:"mt-0.5 font-mono text-[10px] text-rose-100/70 whitespace-pre-wrap break-all",children:L.error}),L.sourceRoot&&(0,Y.jsx)("div",{className:"mt-0.5 text-[9px] text-rose-200/50",children:(0,Y.jsx)("span",{className:"font-mono",children:L.sourceRoot})})]},L.packageId))]}),k&&(0,Y.jsxs)("div",{className:"mx-1 rounded-md border border-amber-500/25 bg-amber-500/[0.06] px-2 py-1 text-[10px] text-amber-100/80",children:[(0,Y.jsx)("span",{className:"font-mono",children:"/packages/diagnostics"})," unreachable: ",k]}),G.length===0?(0,Y.jsxs)("div",{className:"mx-1 mt-6 rounded-lg border border-white/10 bg-white/[0.02] p-6 text-center text-white/50 text-sm",children:["No packages installed yet. Drop packages into"," ",(0,Y.jsx)("span",{className:"font-mono text-white/70",children:"_packages/"})," to see them here."]}):(0,Y.jsx)("div",{className:"space-y-1",children:G.map(L=>(0,Y.jsx)(oE,{row:L,expanded:!!u[L.slug],pending:d[L.slug]??"none",canGovern:t,featureIds:b,onToggle:()=>M(L.slug),onFlipTrust:()=>{U(L)},onBuild:()=>{A(L)},onSetAccessFeature:R=>{I(L,R)}},L.slug))}),h&&m?(0,t0.createPortal)((0,Y.jsx)("div",{className:"fixed bottom-4 right-4 z-[100000] rounded-lg border border-white/15 bg-neutral-900/95 px-3 py-2 text-[11px] text-white/85 shadow-lg",onClick:()=>p(null),children:h}),document.body):null,x&&m?(0,t0.createPortal)((0,Y.jsx)("div",{className:"fixed inset-0 z-[100000] flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:()=>w(null),children:(0,Y.jsxs)("div",{className:"w-full max-w-xl rounded-lg border border-white/15 bg-neutral-900/95 p-4 shadow-xl",onClick:L=>L.stopPropagation(),children:[(0,Y.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,Y.jsxs)("div",{className:"flex items-center gap-2",children:[x.ok===void 0?(0,Y.jsx)(ze,{className:"w-4 h-4 animate-spin text-white/60"}):x.ok?(0,Y.jsx)(ea,{className:"w-4 h-4 text-emerald-400"}):(0,Y.jsx)(dt,{className:"w-4 h-4 text-amber-300"}),(0,Y.jsxs)("span",{className:"text-sm font-semibold text-white/85",children:["Build \u2014 ",x.slug]}),x.durationMs!==void 0?(0,Y.jsxs)("span",{className:"text-[10px] text-white/45",children:[x.durationMs,"ms"]}):null]}),(0,Y.jsx)("button",{className:"text-white/50 hover:text-white/80 text-xs",onClick:()=>w(null),children:"Close"})]}),(0,Y.jsx)("pre",{className:"max-h-80 overflow-y-auto rounded-md bg-black/40 border border-white/10 p-2 text-[11px] font-mono text-white/75 whitespace-pre-wrap",children:x.logs.join(`
52
- `)})]})}),document.body):null]})}function oE(n){let{row:e,expanded:t,pending:r,canGovern:a,featureIds:s,onToggle:o,onFlipTrust:i,onBuild:l,onSetAccessFeature:u}=n,c=e.access?.trust??"untrusted",d=e.runtime?.type??"node",f=e.partialReason,h=f?sE[f]:void 0,p=d==="wasm"&&e.status==="partial"&&f==="build-missing",m=c==="first-party";return(0,Y.jsxs)("div",{className:"rounded-lg border border-white/10 bg-white/[0.02] hover:bg-white/[0.035] transition-colors",children:[(0,Y.jsxs)("button",{type:"button",className:"w-full flex items-start gap-2 px-3 py-2 text-left",onClick:o,children:[t?(0,Y.jsx)(Tt,{className:"mt-0.5 w-3.5 h-3.5 shrink-0 text-white/50"}):(0,Y.jsx)(un,{className:"mt-0.5 w-3.5 h-3.5 shrink-0 text-white/50"}),(0,Y.jsx)(vr,{className:"mt-0.5 w-4 h-4 shrink-0 text-violet-300/80"}),(0,Y.jsxs)("div",{className:"min-w-0 flex-1 space-y-1",children:[(0,Y.jsxs)("div",{className:"flex items-baseline gap-1.5",children:[(0,Y.jsx)("span",{className:"min-w-0 flex-1 text-sm font-semibold text-white/90 truncate",children:e.name}),e.version?(0,Y.jsxs)("span",{className:"text-[10px] font-mono text-white/40 shrink-0",children:["v",e.version]}):null]}),e.description?(0,Y.jsx)("div",{className:"text-[10px] text-white/45 truncate",children:e.description}):null,(0,Y.jsxs)("div",{className:"flex flex-wrap items-center gap-1 pt-0.5",children:[(0,Y.jsx)(lE,{status:e.status,partialLabel:h?.label}),(0,Y.jsx)(uE,{trust:c}),(0,Y.jsx)(cE,{type:d})]})]})]}),t?(0,Y.jsxs)("div",{className:"px-3 pb-3 pt-1 border-t border-white/5 space-y-3",children:[f&&h?(0,Y.jsxs)("div",{className:"rounded-md border border-amber-500/20 bg-amber-500/5 p-2 text-[11px] text-amber-100/80 flex items-start gap-2",children:[(0,Y.jsx)(dt,{className:"w-3.5 h-3.5 shrink-0 mt-0.5 text-amber-300/80"}),(0,Y.jsxs)("div",{children:[(0,Y.jsx)("div",{className:"font-semibold",children:h.label}),(0,Y.jsx)("div",{className:"text-amber-100/60",children:h.hint})]})]}):null,(0,Y.jsxs)("div",{className:"grid grid-cols-3 gap-2 text-[10px]",children:[(0,Y.jsx)(e0,{label:"Tools",value:e.toolCount}),(0,Y.jsx)(e0,{label:"Skills / files",value:e.fileCount}),(0,Y.jsx)(e0,{label:"Commands",value:e.commandCount})]}),(0,Y.jsxs)("div",{className:"text-[10px] text-white/50 font-mono",children:[e.source?.kind?`source: ${e.source.kind}`:"",e.source?.kind&&d?" \xB7 ":"",`runtime: ${d}`]}),(0,Y.jsxs)("div",{className:"flex items-center gap-2 pt-1",children:[(0,Y.jsxs)("button",{type:"button",className:["inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-[11px] transition",m?"bg-white/5 text-white/35 cursor-not-allowed":c==="trusted"?"bg-emerald-500/15 border border-emerald-500/25 text-emerald-100 hover:bg-emerald-500/20":"bg-white/5 border border-white/10 text-white/70 hover:bg-white/10"].join(" "),disabled:m||r!=="none",onClick:i,title:m?"First-party packages are trust-locked":void 0,children:[r==="trust"?(0,Y.jsx)(ze,{className:"w-3 h-3 animate-spin"}):c==="trusted"?(0,Y.jsx)(ai,{className:"w-3 h-3"}):(0,Y.jsx)(El,{className:"w-3 h-3"}),c==="trusted"?"Revert to untrusted":"Mark as trusted"]}),(0,Y.jsxs)("button",{type:"button",className:["inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-[11px] transition",p?"bg-violet-500/15 border border-violet-500/25 text-violet-100 hover:bg-violet-500/20":"bg-white/5 text-white/35 cursor-not-allowed"].join(" "),disabled:!p||r!=="none",onClick:l,title:p?"Compile src/ \u2192 dist/package.wasm on the server":d!=="wasm"?'Build is only required for runtime.type: "wasm" packages':"Build is only needed when status is partial / build-missing",children:[r==="build"?(0,Y.jsx)(ze,{className:"w-3 h-3 animate-spin"}):(0,Y.jsx)(uo,{className:"w-3 h-3"}),"Build"]}),(0,Y.jsx)(dE,{trust:c})]}),a?(0,Y.jsx)(iE,{row:e,featureIds:s,pending:r==="access-feature",disabled:r!=="none",onSetAccessFeature:u}):e.accessFeature?(0,Y.jsxs)("div",{className:"mt-2 text-[10px] text-white/45",children:["Access feature: ",(0,Y.jsx)("span",{className:"font-mono text-white/65",children:e.accessFeature}),(0,Y.jsxs)("span",{className:"text-white/30",children:[" (",e.accessFeatureSource,")"]})]}):null]}):null]})}function iE(n){let{row:e,featureIds:t,pending:r,disabled:a,onSetAccessFeature:s}=n,[o,i]=(0,Rt.useState)(e.accessFeature??""),l=`af-${e.slug}`;(0,Rt.useEffect)(()=>{i(e.accessFeature??"")},[e.accessFeature]);let u=e.accessFeatureSource==="manifest",c=o.trim(),d=e.accessFeatureSource==="override"?e.accessFeature??"":"",f=c!==d;return(0,Y.jsxs)("div",{className:"mt-2 rounded-md border border-white/10 bg-white/[0.02] px-2.5 py-2 space-y-1.5",children:[(0,Y.jsxs)("div",{className:"flex items-center gap-1.5 text-[10px] font-semibold text-white/60",children:[(0,Y.jsx)(Is,{className:"w-3 h-3 text-cyan-300/80"}),"Base-access feature",e.accessFeature?(0,Y.jsxs)("span",{className:"ml-auto font-mono text-[9px] text-white/45",children:[e.accessFeature," ",(0,Y.jsxs)("span",{className:"text-white/30",children:["(",e.accessFeatureSource,")"]})]}):null]}),(0,Y.jsx)("div",{className:"text-[9px] text-white/40 leading-snug",children:u?"Declared in the manifest (requires.accessFeature) \u2014 not editable here. An override below adds an ADDITIONAL required feature.":"Pick a feature to hide this package from anyone who lacks it (restrict-only), then grant that feature to a role in Admin \u2192 Roles. Clear to remove."}),(0,Y.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,Y.jsx)("input",{list:l,value:o,onChange:h=>i(h.target.value),placeholder:"feature.id (e.g. labs.access)",disabled:a,className:"flex-1 min-w-0 rounded bg-black/30 border border-white/10 px-2 py-1 text-[10px] font-mono text-white/80 placeholder:text-white/25 focus:outline-none focus:border-cyan-400/40"}),(0,Y.jsx)("datalist",{id:l,children:t.map(h=>(0,Y.jsx)("option",{value:h},h))}),(0,Y.jsxs)("button",{type:"button",disabled:a||!f||c.length===0,onClick:()=>s(c),className:"inline-flex items-center gap-1 rounded-md bg-cyan-500/15 border border-cyan-400/25 px-2 py-1 text-[10px] text-cyan-100 hover:bg-cyan-500/20 transition disabled:opacity-35",children:[r?(0,Y.jsx)(ze,{className:"w-3 h-3 animate-spin"}):null,"Set"]}),(0,Y.jsx)("button",{type:"button",disabled:a||e.accessFeatureSource!=="override",onClick:()=>s(null),title:e.accessFeatureSource==="manifest"?"Manifest-declared features cannot be cleared here":"Clear the override",className:"inline-flex items-center gap-1 rounded-md bg-white/5 border border-white/10 px-2 py-1 text-[10px] text-white/65 hover:bg-white/10 transition disabled:opacity-35",children:"Clear"})]})]})}function lE(n){let{status:e,partialLabel:t}=n;return e==="partial"?(0,Y.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-amber-500/25 bg-amber-500/10 px-2 py-0.5 text-[10px] text-amber-100/85",children:[(0,Y.jsx)(dt,{className:"w-2.5 h-2.5"})," ",t??"Partial"]}):e==="error"?(0,Y.jsx)("span",{className:"inline-flex items-center gap-1 rounded-full border border-red-500/25 bg-red-500/10 px-2 py-0.5 text-[10px] text-red-100/85",children:"Error"}):e==="disabled"?(0,Y.jsx)("span",{className:"rounded-full bg-white/10 px-2 py-0.5 text-[10px] text-white/55",children:"Disabled"}):(0,Y.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-emerald-500/25 bg-emerald-500/10 px-2 py-0.5 text-[10px] text-emerald-100/85",children:[(0,Y.jsx)(ea,{className:"w-2.5 h-2.5"})," Active"]})}function uE(n){let{trust:e}=n;return e==="first-party"?(0,Y.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-sky-500/25 bg-sky-500/10 px-2 py-0.5 text-[10px] text-sky-100/85",children:[(0,Y.jsx)(Is,{className:"w-2.5 h-2.5"})," First-party"]}):e==="trusted"?(0,Y.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-emerald-500/25 bg-emerald-500/10 px-2 py-0.5 text-[10px] text-emerald-100/85",children:[(0,Y.jsx)(ai,{className:"w-2.5 h-2.5"})," Trusted"]}):(0,Y.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/15 bg-white/5 px-2 py-0.5 text-[10px] text-white/60",children:[(0,Y.jsx)(va,{className:"w-2.5 h-2.5"})," Untrusted"]})}function cE(n){let{type:e}=n;return(0,Y.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full bg-white/5 px-2 py-0.5 text-[10px] font-mono text-white/55 border border-white/10",children:[(0,Y.jsx)(Gl,{className:"w-2.5 h-2.5 text-violet-300/70"}),e]})}function e0(n){return(0,Y.jsxs)("div",{className:"rounded-md bg-white/[0.03] border border-white/5 px-2 py-1.5",children:[(0,Y.jsx)("div",{className:"text-white/45",children:n.label}),(0,Y.jsx)("div",{className:"text-white/85 font-mono mt-0.5",children:n.value})]})}function dE(n){let[e,t]=(0,Rt.useState)(!1);return(0,Y.jsxs)("div",{className:"relative",children:[(0,Y.jsx)("button",{type:"button",className:"inline-flex items-center rounded-md bg-white/5 p-1 text-white/40 hover:text-white/70 hover:bg-white/10",onClick:()=>t(r=>!r),children:(0,Y.jsx)(ta,{className:"w-3 h-3"})}),e?(0,Y.jsxs)("div",{className:"absolute right-0 bottom-full mb-2 w-64 rounded-lg border border-white/15 bg-neutral-900/95 p-2.5 text-[11px] text-white/75 shadow-xl z-10",children:[(0,Y.jsx)("div",{className:"font-semibold text-white/85 mb-1",children:n.trust==="trusted"?"Trusted":n.trust==="first-party"?"First-party":"Untrusted"}),(0,Y.jsx)("div",{className:"text-white/60",children:n.trust==="first-party"?"Built-in package, full access \u2014 trust is locked.":n.trust==="trusted"?"Full fs / network / cross-package API. Only flip this when you trust the author.":"Data-only filesystem, no network, no cross-package API. Safe default for unknown packages."})]}):null]})}function Wo(n){let e=n.trim();if(!e)return"";let t=e.indexOf("://"),r=t>=1?e.slice(0,t+3):"",a=t>=1?e.slice(t+3):e,s=a.length>0&&a.endsWith("/"),o=[];for(let l of a.split("/"))if(!(l===""||l===".")){if(l===".."){o.pop();continue}o.push(l)}let i=o.join("/");return i?`${r}${i}${s?"/":""}`:r}var Ff=W(Qr(),1);var fr=W($e(),1);function mI(n){let{agentId:e,projectId:t,sources:r,revisions:a,resetKey:s}=n,[o,i]=(0,fr.useState)([]),[l,u]=(0,fr.useState)(!1),c=(0,fr.useRef)(Promise.resolve()),d=(0,fr.useRef)(0),f=(0,fr.useRef)([]),h=(0,fr.useRef)({}),p=(0,fr.useRef)(!0),m=(0,fr.useCallback)(async g=>{if(!e)return;g&&(p.current=!0);let x=++d.current,w=t?{projectId:t}:{},y=c.current.then(async()=>{if(x!==d.current)return;let C=[...f.current],k=p.current;p.current=!1;let v=()=>{f.current=[...C],i([...C])};u(!0);try{for(let b of r){if(!b.git?.isRepo&&!b.git?.containsRepos)continue;let P=b.uri_root.replace("://",""),N=a[P]??0;if(!(!k&&h.current[P]===N))try{let M=await Xo({agentId:e,...w,source:P});if(x!==d.current)return;for(let U=C.length-1;U>=0;U--)C[U].source===P&&!M.repos.some(I=>I.rel===C[U].repo.rel)&&C.splice(U,1);for(let U of M.repos){let I={source:P,repo:U};try{let G=await Qu({agentId:e,...w,source:P,repo:U.rel});if(x!==d.current)return;G.ok===!1?I.error="Git status unavailable":I.status=G.status}catch(G){I.error=G instanceof Error?G.message:"Git status failed"}let A=C.findIndex(G=>G.source===P&&G.repo.rel===U.rel);A<0?C.push(I):C[A]=I,v()}h.current[P]=N}catch(M){if(x!==d.current)return;let U={source:P,repo:{rel:"",name:P},error:M instanceof Error?M.message:"Repository discovery failed"},I=C.findIndex(A=>A.source===P&&A.repo.rel==="");I>=0?C[I]=U:C.push(U),h.current[P]=N,v()}}x===d.current&&v()}finally{x===d.current&&u(!1)}});c.current=y.catch(()=>{}),await y},[e,t,r,a]);return(0,fr.useEffect)(()=>{d.current++,f.current=[],h.current={},p.current=!0,i([])},[s]),(0,fr.useEffect)(()=>(m(!1),()=>{d.current++}),[m]),{groups:o,loading:l,refresh:m}}var ve=W($e(),1);var _I=W(mr(),1);var If=W($e(),1);var gI=W($e(),1),Vu=W(le(),1),fE={add:"bg-emerald-500/12",remove:"bg-red-500/18",context:""},xI=(0,gI.memo)(function({lineNo:e,type:t,content:r}){return(0,Vu.jsxs)("div",{className:`flex h-[18px] min-w-full w-max ${fE[t]}`,children:[(0,Vu.jsx)("span",{className:"shrink-0 w-10 text-right pr-2 select-none text-white/25 tabular-nums",children:e??""}),(0,Vu.jsx)("span",{className:"shrink-0 whitespace-pre pr-3 text-white/78",children:r||" "})]})});var Ks=W(le(),1),Yi=(0,If.memo)(function({hunks:e,isStreaming:t,maxLines:r=200}){let{elements:a,truncated:s}=(0,If.useMemo)(()=>{let o=[],i=0,l=0,u=!1,c=1,d=1;for(let f of e){if(f.skippedBefore!==0){let h=f.skippedBefore>0?`\xB7\xB7\xB7 ${f.skippedBefore} lines skipped \xB7\xB7\xB7`:"\xB7\xB7\xB7 \xB7\xB7\xB7 \xB7\xB7\xB7";o.push((0,Ks.jsx)(hE,{label:h},`skip-${i}`)),f.skippedBefore>0&&(c+=f.skippedBefore,d+=f.skippedBefore)}for(let h of f.lines){if(l>=r){u=!0;break}let p=t?"add":h.type,m=p==="remove"?c:d;p==="remove"?c++:(p==="add"||c++,d++),o.push((0,Ks.jsx)(xI,{lineNo:m,type:p,content:h.content},`line-${i}`)),i++,l++}if(u)break}return{elements:o,truncated:u}},[e,t,r]);return a.length===0?(0,Ks.jsx)("div",{className:"px-3 py-2 text-[11px] text-white/40 italic",children:"No content"}):(0,Ks.jsxs)("div",{className:"font-mono text-[11px] leading-[18px] overflow-x-auto overflow-y-clip",children:[a,s&&(0,Ks.jsxs)("div",{className:"text-[10px] text-white/40 bg-white/4 px-3 py-1 text-center",children:["\xB7\xB7\xB7 ",e.reduce((o,i)=>o+i.lines.length,0)-r," more lines \xB7\xB7\xB7"]})]})},(n,e)=>{if(n.isStreaming!==e.isStreaming||n.maxLines!==e.maxLines||n.language!==e.language)return!1;if(n.hunks===e.hunks)return!0;if(n.hunks.length!==e.hunks.length)return!1;for(let t=0;t<n.hunks.length;t++){let r=n.hunks[t],a=e.hunks[t];if(r===a)continue;if(r.skippedBefore!==a.skippedBefore||r.lines.length!==a.lines.length)return!1;let s=r.lines[0],o=a.lines[0];if(s?.type!==o?.type||s?.content!==o?.content)return!1;let i=r.lines[r.lines.length-1],l=a.lines[a.lines.length-1];if(i?.type!==l?.type||i?.content!==l?.content)return!1}return!0});function hE({label:n}){return(0,Ks.jsx)("div",{className:"text-[10px] text-white/35 bg-white/[0.03] px-3 py-0.5 text-center border-y border-white/6 select-none",children:n})}var Pf=W(Qr(),1);function yI(n){return n.snapshotHash?null:"originalDraftUnknown"}function n0(n){return String(n||"").replace(/\r\n/g,`
51
+ packages/*/skills/**`}),(0,S.jsx)("div",{className:"text-[8px] text-white/25 italic",children:"Non-empty: only matching files sync. Excludes always win \u2014 an excluded path can never be re-included."})]}),(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Max scan files"}),(0,S.jsx)("input",{type:"number",min:1,step:1e3,value:Gn.maxScanFiles??"",onChange:Fe=>{let Bt=Number(Fe.target.value),Zn=Number.isFinite(Bt)&&Bt>0?Math.floor(Bt):void 0;Yr(O.source,Js=>({...Js,sync:{...Gn,maxScanFiles:Zn}}))},className:$(Wi,"w-28 font-mono"),placeholder:"200000"}),(0,S.jsx)("div",{className:"text-[8px] text-white/25 italic",children:"Per-source cap on files walked during sync/count. Empty = inherit the platform default. When a walk hits the cap the count shows N+."})]}),(0,S.jsxs)("label",{className:"inline-flex items-center gap-1.5 text-[10px] text-white/80 cursor-pointer",children:[(0,S.jsx)("input",{type:"checkbox",checked:Gn.alwaysActive??(O.source==="data"||O.source==="packages"),onChange:Fe=>Yr(O.source,Bt=>({...Bt,sync:{...Gn,alwaysActive:Fe.target.checked}})),className:"accent-cyan-400 h-3 w-3"}),"Always active",(0,S.jsx)("span",{className:"text-[8px] text-white/30 normal-case",children:'(pins this source in the auto-sync pool even when the platform Auto-Sync Mode is "packages-only"; no effect with the Manual trigger)'})]}),(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Media"}),(0,S.jsx)("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:bE.map(Fe=>(0,S.jsxs)("label",{className:"inline-flex items-center gap-1.5 text-[10px] text-white/80 cursor-pointer",children:[(0,S.jsx)("input",{type:"checkbox",checked:Gn.media?.[Fe.key]??Fe.on,onChange:Bt=>Yr(O.source,Zn=>({...Zn,sync:{...Gn,media:{...Gn.media??{},[Fe.key]:Bt.target.checked}}})),className:"accent-cyan-400 h-3 w-3"}),Fe.label]},Fe.key))}),(0,S.jsx)("div",{className:"text-[8px] text-white/25 italic",children:"Embeds these files from their bytes \u2014 only while the active embedding model is multimodal (a text-only model skips them and the last-sync line says so). Each image or PDF page is one provider call; video and audio cost the most. Unticking a kind clears its searchable cache at the next full sync while preserving recovery content."})]}),O.sync?.lastSyncResult&&(0,S.jsxs)("div",{className:"text-[9px] text-white/40 flex items-center gap-2",children:[(0,S.jsxs)("span",{children:["Last sync: +",O.sync.lastSyncResult.filesAdded," -",O.sync.lastSyncResult.filesRemoved," ~",O.sync.lastSyncResult.filesUpdated]}),(0,S.jsxs)("span",{children:["(",(O.sync.lastSyncResult.durationMs/1e3).toFixed(1),"s)"]}),O.sync.lastSyncResult.error&&(0,S.jsx)("span",{className:"text-rose-300/80 truncate max-w-[200px]",title:O.sync.lastSyncResult.error,children:"err"})]}),sL(O.sync?.lastSyncResult?.mediaSkipped)&&(0,S.jsx)("div",{className:"text-[9px] text-amber-200/70",role:"status",children:sL(O.sync?.lastSyncResult?.mediaSkipped)}),iL(O.sync?.lastSyncResult?.binarySkipped)&&(0,S.jsx)("div",{className:"text-[9px] text-white/40",role:"status",children:iL(O.sync?.lastSyncResult?.binarySkipped)}),(()=>{let Fe=wE(O.sync?.lastSyncResult?.embeddingDegraded,O.embedding_enabled);return Fe?(0,S.jsx)("div",{className:Fe.attention?"text-[9px] text-amber-200/70":"text-[9px] text-white/40",role:"status",children:Fe.text}):null})(),Le[O.source]&&(0,S.jsxs)("div",{className:"text-[9px] text-amber-200/70 flex items-center gap-2",role:"status",children:[(0,S.jsxs)("span",{children:["Embedding paused: ",Le[O.source]]}),(0,S.jsx)("button",{type:"button",disabled:Wa,onClick:()=>{L2(O.source)},className:"h-5 px-1.5 rounded bg-white/[0.04] hover:bg-white/[0.08] text-amber-200/90 disabled:opacity-35",children:"Resume"})]})]})]})]}),(0,S.jsxs)("div",{className:"flex items-center justify-between gap-2 pt-1.5 border-t border-white/[0.06]",children:[(0,S.jsx)("span",{className:"text-[9px] text-white/30",children:O.observed?"Observed runtime source":Vf?"Unsaved changes":"No pending changes"}),(0,S.jsxs)("div",{className:"flex items-center gap-1.5",children:[hs&&ja&&(Qt||Wa)?(0,S.jsxs)("button",{type:"button",onClick:()=>{I2(O.source)},className:"h-6 px-2 rounded-md bg-rose-500/10 hover:bg-rose-500/20 border border-rose-400/25 text-[9px] font-medium text-rose-300/80 hover:text-rose-200 transition inline-flex items-center gap-1",children:[(0,S.jsx)(Ul,{className:"h-2.5 w-2.5"}),"Cancel"]}):hs&&ja?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)("button",{type:"button",disabled:!sc,onClick:()=>{C2(O.source)},className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-blue-300/80 hover:text-blue-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[(0,S.jsx)(El,{className:"h-2.5 w-2.5"}),"Sync"]}),(0,S.jsxs)("button",{type:"button",disabled:Wa,onClick:()=>{A2(O.source)},className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-cyan-300/80 hover:text-cyan-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[(0,S.jsx)(ir,{className:"h-2.5 w-2.5"}),"Rescan changes"]}),(0,S.jsxs)("button",{type:"button",disabled:Wa||O.embedding_enabled===!1,onClick:()=>Qe(O.source),title:O.embedding_enabled===!1?"Semantic embedding is off \u2014 turn it on in the platform settings first":"Embed every file of this source again with the active model \u2014 shows the estimated cost first",className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-cyan-300/80 hover:text-cyan-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[(0,S.jsx)(ka,{className:"h-2.5 w-2.5"}),"Re-embed\u2026"]}),(()=>{let Fe=O.embedding_enabled===!1;return(0,S.jsxs)("button",{type:"button",disabled:Wa||Fe,onClick:()=>Lt(O.source),title:Fe?"Semantic embedding is off \u2014 turn it on in the platform settings first":"Embed only the files whose semantic embedding is missing or stale \u2014 shows the estimate first",className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-cyan-300/80 hover:text-cyan-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[(0,S.jsx)(ir,{className:"h-2.5 w-2.5"}),"Embed pending\u2026"]})})(),(0,S.jsxs)("button",{type:"button",disabled:ze===O.source,onClick:()=>{P2(O.source)},title:"Forgets what the last sync saw \u2014 the next sync compares every file again. Deletes no file and no vector.",className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-amber-300/80 hover:text-amber-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[ze===O.source?(0,S.jsx)(We,{className:"h-2.5 w-2.5 animate-spin"}):(0,S.jsx)(oi,{className:"h-2.5 w-2.5"}),"Forget sync state"]})]}):null,O.canMaintain===!0&&(0,S.jsx)("button",{type:"button",onClick:()=>{Te.current++,bt(O.source),Tt("source"),me(""),Jt(!0),be(null),Re(!1)},className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] text-amber-300/80",children:"Clean index\u2026"}),hs&&!T2(O.source)&&(0,S.jsxs)("button",{type:"button",disabled:Jr,onClick:()=>he(O.source),className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-red-300/80 hover:text-red-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[Jr?(0,S.jsx)(We,{className:"h-2.5 w-2.5 animate-spin"}):(0,S.jsx)(Nt,{className:"h-2.5 w-2.5"}),"Delete"]}),(0,S.jsxs)("button",{type:"button",disabled:qt||!Vf,onClick:()=>{k2(O,ge)},className:"h-6 px-2.5 rounded-md bg-emerald-500/12 border border-emerald-400/25 text-[9px] font-semibold text-emerald-200/90 hover:bg-emerald-500/20 transition disabled:opacity-35 inline-flex items-center gap-1",children:[qt?(0,S.jsx)(We,{className:"h-2.5 w-2.5 animate-spin"}):(0,S.jsx)(li,{className:"h-2.5 w-2.5"}),"Save"]})]})]})]})}),ft===O.source&&O.canMaintain===!0&&(0,S.jsxs)("fieldset",{disabled:Ge,className:"ml-5 mb-2 rounded-md border border-amber-400/20 p-3 space-y-2 text-[10px] text-white/70",children:[(0,S.jsxs)("legend",{children:["Clean index for ",O.source]}),(0,S.jsx)("p",{children:"The source, files, pending changes and recovery history stay available. Cleanup makes no embedding calls."}),(0,S.jsxs)("label",{children:["Selection ",(0,S.jsxs)("select",{"aria-label":"Index cleanup selection",value:At,onChange:Fe=>{Te.current++,Tt(Fe.target.value),be(null)},className:"bg-[#15151d]",children:[(0,S.jsx)("option",{value:"source",children:"Whole source"}),(0,S.jsx)("option",{value:"folder",children:"Folder"}),(0,S.jsx)("option",{value:"file",children:"File"})]})]}),At!=="source"&&(0,S.jsx)("input",{"aria-label":"Index cleanup URI",placeholder:`${O.source}://path`,value:Ue,onChange:Fe=>{Te.current++,me(Fe.target.value),be(null)},className:"block w-full bg-white/5 rounded px-2 py-1"}),(0,S.jsxs)("label",{className:"block",children:[(0,S.jsx)("input",{type:"checkbox",checked:Ot,onChange:Fe=>{Te.current++,Jt(Fe.target.checked),be(null)}})," Only excluded files and disabled media lanes"]}),!Ot&&(0,S.jsx)("p",{children:"All selected searchable cache will be cleared. A later sync can rebuild it."}),ue&&(0,S.jsxs)("p",{children:[ue.removedParents," parents removed \xB7 ",ue.removedChunks," chunks removed \xB7 ",ue.retained," recovery payloads retained \xB7 ",ue.unresolved," unresolved points kept"]}),(0,S.jsxs)("div",{className:"flex gap-2",children:[(0,S.jsx)("button",{type:"button",onClick:()=>{Te.current++,bt(null),be(null)},children:"Cancel"}),(0,S.jsx)("button",{type:"button",onClick:()=>{d0(O.source,"estimate")},children:Ge?"Working\u2026":"Preview counts"}),ue?.canMaintain&&(0,S.jsx)("button",{type:"button",onClick:()=>{d0(O.source,"apply")},children:"Confirm cleanup"})]})]}),re===O.source&&(0,S.jsx)(aL,{source:O.source,vectorCount:typeof O.indexed_count=="number"?O.indexed_count:null,isDockerMount:!!O.connection?.config?.hostRoot,busy:Jr,onCancel:()=>he(null),onConfirm:Fe=>{R2(O.source,Fe)}}),Ye===O.source&&(0,S.jsx)(Xl,{kind:"pending",agentId:n,...r?{projectId:r}:{},target:{source:O.source,label:O.source},onClose:()=>Lt(null),onStarted:()=>{ac(O.source,()=>Promise.resolve(),"Embedding failed")}}),it===O.source&&(0,S.jsx)(Xl,{agentId:n,...r?{projectId:r}:{},target:{source:O.source,label:O.source},onClose:()=>Qe(null),onStarted:()=>{ac(O.source,()=>Promise.resolve(),"Re-embed failed")}})]},px(sr(O.source)))})})]},E))}),Ne&&(0,S.jsx)("div",{className:"mt-2 rounded-md bg-emerald-500/10 border border-emerald-400/25 px-2.5 py-1.5 text-[10px] text-emerald-200/85",children:Ne}),(0,S.jsxs)("div",{className:"border-t border-white/[0.06] pt-2 mt-3",children:[(0,S.jsxs)("button",{type:"button",onClick:()=>Pt(!ce),className:"flex items-center gap-2 py-1.5 w-full text-left",children:[(0,S.jsx)(ir,{className:"h-4 w-4 text-cyan-400 shrink-0"}),(0,S.jsx)("span",{className:"text-sm font-semibold text-white/92 flex-1",children:"Vector Health"}),(0,S.jsx)(Et,{className:$("h-3 w-3 text-white/25 transition-transform",ce&&"rotate-180")})]}),(0,S.jsx)("div",{className:$("overflow-hidden transition-all duration-200",ce?"max-h-[1600px] opacity-100":"max-h-0 opacity-0"),children:ce&&(0,S.jsx)(eL,{agentId:n,projectId:r})})]}),(0,S.jsxs)("div",{className:"border-t border-white/[0.06] pt-2 mt-3",children:[(0,S.jsxs)("button",{type:"button",onClick:()=>Zt(E=>!E),className:"flex items-center gap-2 py-1.5 w-full text-left",children:[(0,S.jsx)(io,{className:"h-4 w-4 text-cyan-400 shrink-0"}),(0,S.jsx)("span",{className:"text-sm font-semibold text-white/92 flex-1",children:"Mount & Discover"}),(0,S.jsx)(Et,{className:$("h-3 w-3 text-white/25 transition-transform",Ft&&"rotate-180")})]}),(0,S.jsx)("div",{className:$("overflow-hidden transition-all duration-200",Ft?"max-h-[1600px] opacity-100":"max-h-0 opacity-0"),children:(0,S.jsxs)("div",{className:"mt-3 rounded-md bg-white/[0.02] border border-white/[0.06] p-3 space-y-2",children:[(0,S.jsx)("p",{className:"text-[10px] leading-relaxed text-white/55",children:"CLI helper for exposing host folders to the brain. Run it with no arguments to print usage:"}),(0,S.jsx)("div",{className:"rounded bg-black/30 border border-white/[0.05] p-2",children:(0,S.jsx)("pre",{className:"text-[11px] font-mono text-white/85 whitespace-pre-wrap break-all",children:"neuralis mount"})}),(0,S.jsxs)("div",{className:"rounded bg-black/30 border border-white/[0.05] p-2 space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] uppercase tracking-wider text-white/40 font-semibold",children:"Example \u2014 expose a host folder as a mount"}),(0,S.jsx)("pre",{className:"text-[10px] font-mono text-white/80 whitespace-pre-wrap break-all",children:"neuralis mount add <host-path> --slug <name>"}),(0,S.jsx)("div",{className:"text-[9px] text-white/35 italic",children:"The CLI is infra-only: it registers the bind mount + host-pair env in the machine-local compose override, never a source. After the container restarts, the mount appears in the Discoverable list below \u2014 click it to attach the source with a chosen scope (the host path resolves automatically)."})]}),Tn.length>0?(0,S.jsxs)("div",{className:"pt-1.5",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/40 mb-1",children:"Discoverable"}),(0,S.jsx)("ul",{className:"space-y-1",children:Tn.map(E=>{let Q=Cc("unattached"),O=(0,lr.resolveLucideIcon)(E.icon??null)||zn;return(0,S.jsx)("li",{children:(0,S.jsxs)("button",{type:"button",onClick:()=>Mt(E),className:$("flex items-start gap-2 w-full text-left px-2 py-1.5 rounded-md hover:bg-white/[0.04] transition",Q.containerClassName),title:Q.title,children:[(0,S.jsx)(O,{className:$("h-3.5 w-3.5 mt-0.5 shrink-0",Q.iconClassName)}),(0,S.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,S.jsxs)("div",{className:$("text-[11px] font-semibold truncate",Q.labelClassName),children:[E.label,(0,S.jsxs)("span",{className:"text-[9px] text-white/30 font-mono ml-1.5",children:[E.suggestedScheme,"://"]})]}),(0,S.jsx)("div",{className:$("text-[9px] truncate",Q.detailClassName),children:E.description}),(0,S.jsx)("div",{className:"text-[8px] text-white/25 font-mono truncate",children:E.root})]}),(0,S.jsx)(Fn,{className:"h-3 w-3 text-white/40 shrink-0 mt-1"})]})},E.id)})})]}):(0,S.jsx)("div",{className:"pt-1 text-[9px] italic text-white/35",children:"No discoverable mounts at the moment."})]})})]})]})}var Dt=j($e(),1),Zg=j(Za(),1);var yL=j(Wn(),1);async function Jo(t){let e=await t.text();try{return JSON.parse(e)}catch{throw new Error(`Invalid JSON response (HTTP ${t.status}): ${e.slice(0,200)}`)}}async function fL(t){let e=await fetch("/api/packages/runtime",{method:"GET",headers:{"x-project-id":t},credentials:"same-origin"});if(!e.ok)throw new Error(`Failed to load packages snapshot: HTTP ${e.status}`);let n=await Jo(e),r=[...n.skills,...n.instructions,...n.rules,...n.agents,...n.docs],a=Yg(n.tools,o=>o.packageId),s=Yg(r,o=>o.packageId),i=Yg(n.commands,o=>o.packageId);return n.packages.map(o=>({slug:o.id,packageId:o.id,name:o.name,version:o.version,description:o.description,source:o.source,runtime:o.runtime,access:o.access,status:o.status,partialReason:o.partialReason,toolCount:a.get(o.id)??0,fileCount:s.get(o.id)??0,commandCount:i.get(o.id)??0,...o.accessFeature?{accessFeature:o.accessFeature,accessFeatureSource:o.accessFeatureSource}:{}}))}async function hL(t,e){let n=await fetch(`/api/projects/${encodeURIComponent(t)}/packages/${encodeURIComponent(e)}/build`,{method:"POST",credentials:"same-origin"});return Jo(n)}async function pL(t,e,n){let r=await fetch(`/api/projects/${encodeURIComponent(t)}/packages/${encodeURIComponent(e)}/trust`,{method:"PUT",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({trust:n})});if(!r.ok){let a=await r.text();throw new Error(`Failed to set trust (HTTP ${r.status}): ${a.slice(0,200)}`)}return Jo(r)}async function mL(t,e,n){let r=await fetch(`/api/projects/${encodeURIComponent(t)}/packages/${encodeURIComponent(e)}/access-feature`,{method:"PUT",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({featureId:n})});if(!r.ok){let a=await r.text();throw new Error(`Failed to set access feature (HTTP ${r.status}): ${a.slice(0,200)}`)}return Jo(r)}async function gL(t){let e=await fetch("/api/admin/feature-catalog",{method:"GET",headers:{"x-project-id":t},credentials:"same-origin"});if(!e.ok)throw new Error(`Failed to load feature catalog: HTTP ${e.status}`);let n=await Jo(e),r=new Set;for(let a of n.groups??[])for(let s of a.features??[])r.add(s);return Array.from(r).sort()}async function xL(t){let e=await fetch("/api/packages/agent-core/packages/diagnostics",{method:"GET",headers:{"x-project-id":t},credentials:"same-origin"});if(!e.ok)throw new Error(`Failed to load packages diagnostics: HTTP ${e.status}`);return Jo(e)}function Yg(t,e){let n=new Map;for(let r of t){let a=e(r);n.set(a,(n.get(a)??0)+1)}return n}var Z=j(ie(),1),LE={"build-missing":{label:"Needs build",hint:"The package has server-side code (src/) but the WASM binary is missing. Click Build to compile it."},"runtime-unavailable":{label:"Runtime unavailable",hint:"MCP subprocess failed to spawn or the code runtime crashed. Check host logs."},"untrusted-node":{label:"Declarative only",hint:'Untrusted packages cannot execute in-process code. Declare `runtime.type: "wasm"` in the manifest to enable handlers.'},"untrusted-mcp":{label:"Declarative only",hint:'The "mcp" runtime spawns a subprocess as the host user and needs first-party trust, so no subprocess was started. Declare `runtime.type: "wasm"` in the manifest to enable handlers.'}};function bL({projectId:t}){let n=(hn().currentRole?.priority??99)<=2,[r,a]=(0,Dt.useState)([]),[s,i]=(0,Dt.useState)(!0),[o,l]=(0,Dt.useState)(null),[u,c]=(0,Dt.useState)({}),[d,f]=(0,Dt.useState)({}),[h,p]=(0,Dt.useState)(null),[g,m]=(0,Dt.useState)(!1);(0,Dt.useEffect)(()=>{m(!0)},[]);let[x,y]=(0,Dt.useState)(null),[b,C]=(0,Dt.useState)([]),[L,P]=(0,Dt.useState)(null),[w,k]=(0,Dt.useState)([]),_=(0,Dt.useCallback)(async()=>{i(!0),l(null);try{let N=await fL(t);a(N)}catch(N){l(N instanceof Error?N.message:String(N))}finally{i(!1)}try{let N=await xL(t);C(N.entries),P(null)}catch(N){C([]),P(N instanceof Error?N.message:String(N))}},[t]);(0,Dt.useEffect)(()=>{_()},[_]),(0,Dt.useEffect)(()=>{if(!n)return;let N=!1;return gL(t).then(A=>{N||k(A)}).catch(()=>{}),()=>{N=!0}},[t,n]);let M=(0,Dt.useCallback)(N=>{c(A=>({...A,[N]:!A[N]}))},[]),R=(0,Dt.useCallback)(async N=>{let A=N.access?.trust??"untrusted";if(A==="first-party")return;let B=A==="trusted"?"untrusted":"trusted";f(K=>({...K,[N.slug]:"trust"}));try{await pL(t,N.slug,B),p(`Trust: ${N.slug} \u2192 ${B}`),await _()}catch(K){p(K instanceof Error?K.message:"Failed to set trust")}finally{f(K=>({...K,[N.slug]:"none"}))}},[t,_]),U=(0,Dt.useCallback)(async(N,A)=>{f(B=>({...B,[N.slug]:"access-feature"}));try{await mL(t,N.packageId,A),p(A?`Access feature: ${N.slug} \u2192 ${A}`:`Access feature cleared: ${N.slug}`),await _()}catch(B){p(B instanceof Error?B.message:"Failed to set access feature")}finally{f(B=>({...B,[N.slug]:"none"}))}},[t,_]),v=(0,Dt.useCallback)(async N=>{f(B=>({...B,[N.slug]:"build"})),y({slug:N.slug,logs:["Starting build\u2026"]});let A=null;try{A=await hL(t,N.slug),y({slug:N.slug,logs:A.logs,ok:A.ok,error:A.error,durationMs:A.durationMs}),A.ok?(p(`Build complete: ${N.slug} (${A.durationMs}ms)`),await _()):p(`Build failed: ${A.error??"unknown"}`)}catch(B){let K=B instanceof Error?B.message:String(B);y({slug:N.slug,logs:[`Request failed: ${K}`],ok:!1,error:K}),p(`Build request failed: ${K}`)}finally{f(B=>({...B,[N.slug]:"none"}))}},[t,_]),T=(0,Dt.useMemo)(()=>[...r].sort((N,A)=>N.name.localeCompare(A.name)),[r]),V=(0,Dt.useMemo)(()=>{let N=new Set(r.map(A=>A.packageId));return b.filter(A=>!N.has(A.packageId)||A.status==="missing"||A.status==="error")},[b,r]),Y=(0,Dt.useMemo)(()=>{let N=new Map;for(let A of b)N.set(A.packageId,A);return N},[b]);return s?(0,Z.jsxs)("div",{className:"h-full flex items-center justify-center text-white/50 text-sm",children:[(0,Z.jsx)(We,{className:"w-4 h-4 animate-spin mr-2"})," Loading packages\u2026"]}):o?(0,Z.jsx)("div",{className:"p-4",children:(0,Z.jsxs)("div",{className:"rounded-lg border border-red-500/25 bg-red-500/10 p-3 text-xs text-red-100/85",children:[(0,Z.jsx)("div",{className:"font-semibold mb-1",children:"Failed to load packages"}),(0,Z.jsx)("div",{className:"font-mono opacity-80",children:o}),(0,Z.jsxs)("button",{className:"mt-2 inline-flex items-center gap-1 rounded-md bg-white/10 px-2 py-1 text-[11px] text-white/80 hover:bg-white/15",onClick:()=>{_()},children:[(0,Z.jsx)(_t,{className:"w-3 h-3"})," Retry"]})]})}):(0,Z.jsxs)("div",{className:"p-3 space-y-2",children:[(0,Z.jsxs)("div",{className:"flex items-center justify-between px-1 pb-2",children:[(0,Z.jsxs)("div",{className:"flex items-center gap-2",children:[(0,Z.jsx)(wr,{className:"w-4 h-4 text-violet-300"}),(0,Z.jsx)("h2",{className:"text-sm font-semibold text-white/85",children:"Packages"}),(0,Z.jsxs)("span",{className:"text-[10px] text-white/45",children:[T.length," installed"]})]}),(0,Z.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,Z.jsx)(yL.SkillLauncher,{variant:"label",size:"sm",skill:"create-package",packageId:"@neuralis/brain-core",alsoRequires:["packages.author"],label:"Scaffold a package with the agent",icon:"package"}),(0,Z.jsxs)("button",{className:"inline-flex items-center gap-1 rounded-md bg-white/5 px-2 py-1 text-[11px] text-white/60 hover:bg-white/10 hover:text-white/85",onClick:()=>{_()},children:[(0,Z.jsx)(_t,{className:"w-3 h-3"}),"Refresh"]})]})]}),(0,Z.jsxs)("div",{className:"mx-1 rounded-lg border border-violet-500/15 bg-violet-500/5 px-3 py-2 text-[11px] text-violet-100/80 flex items-start gap-2",children:[(0,Z.jsx)(Pl,{className:"w-3.5 h-3.5 shrink-0 mt-0.5 text-violet-300/80"}),(0,Z.jsxs)("div",{className:"space-y-1",children:[(0,Z.jsx)("div",{children:"Untrusted packages register their declarative content (skills, tool schemas, commands) but cannot execute in-process code or call other packages."}),(0,Z.jsxs)("div",{className:"text-violet-100/60",children:["Flip trust when you know the author. Run Build only for packages with server-side code in ",(0,Z.jsx)("span",{className:"font-mono",children:"src/"}),"."]})]})]}),V.length>0&&(0,Z.jsxs)("div",{className:"mx-1 rounded-lg border border-rose-500/25 bg-rose-500/[0.06] px-3 py-2 text-[11px] text-rose-100/85 space-y-1",children:[(0,Z.jsxs)("div",{className:"flex items-center gap-1.5 text-rose-200/95 font-semibold",children:[(0,Z.jsx)(ot,{className:"w-3 h-3"}),V.length," package",V.length===1?"":"s"," failed to load"]}),V.map(N=>(0,Z.jsxs)("div",{className:"rounded border border-rose-500/15 bg-rose-500/[0.04] px-2 py-1",children:[(0,Z.jsxs)("div",{className:"font-mono text-[10px] text-rose-200/95",children:[N.packageId," ",(0,Z.jsxs)("span",{className:"text-rose-300/80",children:["\xB7 ",N.status]}),N.reason&&(0,Z.jsxs)("span",{className:"text-rose-300/55",children:[" (",N.reason,")"]})]}),N.error&&(0,Z.jsx)("div",{className:"mt-0.5 font-mono text-[10px] text-rose-100/70 whitespace-pre-wrap break-all",children:N.error}),N.sourceRoot&&(0,Z.jsx)("div",{className:"mt-0.5 text-[9px] text-rose-200/50",children:(0,Z.jsx)("span",{className:"font-mono",children:N.sourceRoot})})]},N.packageId))]}),L&&(0,Z.jsxs)("div",{className:"mx-1 rounded-md border border-amber-500/25 bg-amber-500/[0.06] px-2 py-1 text-[10px] text-amber-100/80",children:[(0,Z.jsx)("span",{className:"font-mono",children:"/packages/diagnostics"})," unreachable: ",L]}),T.length===0?(0,Z.jsxs)("div",{className:"mx-1 mt-6 rounded-lg border border-white/10 bg-white/[0.02] p-6 text-center text-white/50 text-sm",children:["No packages installed yet. Drop packages into"," ",(0,Z.jsx)("span",{className:"font-mono text-white/70",children:"_packages/"})," to see them here."]}):(0,Z.jsx)("div",{className:"space-y-1",children:T.map(N=>(0,Z.jsx)(AE,{row:N,expanded:!!u[N.slug],pending:d[N.slug]??"none",canGovern:n,featureIds:w,onToggle:()=>M(N.slug),onFlipTrust:()=>{R(N)},onBuild:()=>{v(N)},onSetAccessFeature:A=>{U(N,A)}},N.slug))}),h&&g?(0,Zg.createPortal)((0,Z.jsx)("div",{className:"fixed bottom-4 right-4 z-[100000] rounded-lg border border-white/15 bg-neutral-900/95 px-3 py-2 text-[11px] text-white/85 shadow-lg",onClick:()=>p(null),children:h}),document.body):null,x&&g?(0,Zg.createPortal)((0,Z.jsx)("div",{className:"fixed inset-0 z-[100000] flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:()=>y(null),children:(0,Z.jsxs)("div",{className:"w-full max-w-xl rounded-lg border border-white/15 bg-neutral-900/95 p-4 shadow-xl",onClick:N=>N.stopPropagation(),children:[(0,Z.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,Z.jsxs)("div",{className:"flex items-center gap-2",children:[x.ok===void 0?(0,Z.jsx)(We,{className:"w-4 h-4 animate-spin text-white/60"}):x.ok?(0,Z.jsx)(Qr,{className:"w-4 h-4 text-emerald-400"}):(0,Z.jsx)(ot,{className:"w-4 h-4 text-amber-300"}),(0,Z.jsxs)("span",{className:"text-sm font-semibold text-white/85",children:["Build \u2014 ",x.slug]}),x.durationMs!==void 0?(0,Z.jsxs)("span",{className:"text-[10px] text-white/45",children:[x.durationMs,"ms"]}):null]}),(0,Z.jsx)("button",{className:"text-white/50 hover:text-white/80 text-xs",onClick:()=>y(null),children:"Close"})]}),(0,Z.jsx)("pre",{className:"max-h-80 overflow-y-auto rounded-md bg-black/40 border border-white/10 p-2 text-[11px] font-mono text-white/75 whitespace-pre-wrap",children:x.logs.join(`
52
+ `)})]})}),document.body):null]})}function AE(t){let{row:e,expanded:n,pending:r,canGovern:a,featureIds:s,onToggle:i,onFlipTrust:o,onBuild:l,onSetAccessFeature:u}=t,c=e.access?.trust??"untrusted",d=e.runtime?.type??"node",f=e.partialReason,h=f?LE[f]:void 0,p=d==="wasm"&&e.status==="partial"&&f==="build-missing",g=c==="first-party";return(0,Z.jsxs)("div",{className:"rounded-lg border border-white/10 bg-white/[0.02] hover:bg-white/[0.035] transition-colors",children:[(0,Z.jsxs)("button",{type:"button",className:"w-full flex items-start gap-2 px-3 py-2 text-left",onClick:i,children:[n?(0,Z.jsx)(Et,{className:"mt-0.5 w-3.5 h-3.5 shrink-0 text-white/50"}):(0,Z.jsx)(un,{className:"mt-0.5 w-3.5 h-3.5 shrink-0 text-white/50"}),(0,Z.jsx)(wr,{className:"mt-0.5 w-4 h-4 shrink-0 text-violet-300/80"}),(0,Z.jsxs)("div",{className:"min-w-0 flex-1 space-y-1",children:[(0,Z.jsxs)("div",{className:"flex items-baseline gap-1.5",children:[(0,Z.jsx)("span",{className:"min-w-0 flex-1 text-sm font-semibold text-white/90 truncate",children:e.name}),e.version?(0,Z.jsxs)("span",{className:"text-[10px] font-mono text-white/40 shrink-0",children:["v",e.version]}):null]}),e.description?(0,Z.jsx)("div",{className:"text-[10px] text-white/45 truncate",children:e.description}):null,(0,Z.jsxs)("div",{className:"flex flex-wrap items-center gap-1 pt-0.5",children:[(0,Z.jsx)(NE,{status:e.status,partialLabel:h?.label}),(0,Z.jsx)(RE,{trust:c}),(0,Z.jsx)(ME,{type:d})]})]})]}),n?(0,Z.jsxs)("div",{className:"px-3 pb-3 pt-1 border-t border-white/5 space-y-3",children:[f&&h?(0,Z.jsxs)("div",{className:"rounded-md border border-amber-500/20 bg-amber-500/5 p-2 text-[11px] text-amber-100/80 flex items-start gap-2",children:[(0,Z.jsx)(ot,{className:"w-3.5 h-3.5 shrink-0 mt-0.5 text-amber-300/80"}),(0,Z.jsxs)("div",{children:[(0,Z.jsx)("div",{className:"font-semibold",children:h.label}),(0,Z.jsx)("div",{className:"text-amber-100/60",children:h.hint})]})]}):null,(0,Z.jsxs)("div",{className:"grid grid-cols-3 gap-2 text-[10px]",children:[(0,Z.jsx)(Jg,{label:"Tools",value:e.toolCount}),(0,Z.jsx)(Jg,{label:"Skills / files",value:e.fileCount}),(0,Z.jsx)(Jg,{label:"Commands",value:e.commandCount})]}),(0,Z.jsxs)("div",{className:"text-[10px] text-white/50 font-mono",children:[e.source?.kind?`source: ${e.source.kind}`:"",e.source?.kind&&d?" \xB7 ":"",`runtime: ${d}`]}),(0,Z.jsxs)("div",{className:"flex items-center gap-2 pt-1",children:[(0,Z.jsxs)("button",{type:"button",className:["inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-[11px] transition",g?"bg-white/5 text-white/35 cursor-not-allowed":c==="trusted"?"bg-emerald-500/15 border border-emerald-500/25 text-emerald-100 hover:bg-emerald-500/20":"bg-white/5 border border-white/10 text-white/70 hover:bg-white/10"].join(" "),disabled:g||r!=="none",onClick:o,title:g?"First-party packages are trust-locked":void 0,children:[r==="trust"?(0,Z.jsx)(We,{className:"w-3 h-3 animate-spin"}):c==="trusted"?(0,Z.jsx)(so,{className:"w-3 h-3"}):(0,Z.jsx)(_l,{className:"w-3 h-3"}),c==="trusted"?"Revert to untrusted":"Mark as trusted"]}),(0,Z.jsxs)("button",{type:"button",className:["inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-[11px] transition",p?"bg-violet-500/15 border border-violet-500/25 text-violet-100 hover:bg-violet-500/20":"bg-white/5 text-white/35 cursor-not-allowed"].join(" "),disabled:!p||r!=="none",onClick:l,title:p?"Compile src/ \u2192 dist/package.wasm on the server":d!=="wasm"?'Build is only required for runtime.type: "wasm" packages':"Build is only needed when status is partial / build-missing",children:[r==="build"?(0,Z.jsx)(We,{className:"w-3 h-3 animate-spin"}):(0,Z.jsx)(ci,{className:"w-3 h-3"}),"Build"]}),(0,Z.jsx)(TE,{trust:c})]}),a?(0,Z.jsx)(PE,{row:e,featureIds:s,pending:r==="access-feature",disabled:r!=="none",onSetAccessFeature:u}):e.accessFeature?(0,Z.jsxs)("div",{className:"mt-2 text-[10px] text-white/45",children:["Access feature: ",(0,Z.jsx)("span",{className:"font-mono text-white/65",children:e.accessFeature}),(0,Z.jsxs)("span",{className:"text-white/30",children:[" (",e.accessFeatureSource,")"]})]}):null]}):null]})}function PE(t){let{row:e,featureIds:n,pending:r,disabled:a,onSetAccessFeature:s}=t,[i,o]=(0,Dt.useState)(e.accessFeature??""),l=`af-${e.slug}`;(0,Dt.useEffect)(()=>{o(e.accessFeature??"")},[e.accessFeature]);let u=e.accessFeatureSource==="manifest",c=i.trim(),d=e.accessFeatureSource==="override"?e.accessFeature??"":"",f=c!==d;return(0,Z.jsxs)("div",{className:"mt-2 rounded-md border border-white/10 bg-white/[0.02] px-2.5 py-2 space-y-1.5",children:[(0,Z.jsxs)("div",{className:"flex items-center gap-1.5 text-[10px] font-semibold text-white/60",children:[(0,Z.jsx)(Ps,{className:"w-3 h-3 text-cyan-300/80"}),"Base-access feature",e.accessFeature?(0,Z.jsxs)("span",{className:"ml-auto font-mono text-[9px] text-white/45",children:[e.accessFeature," ",(0,Z.jsxs)("span",{className:"text-white/30",children:["(",e.accessFeatureSource,")"]})]}):null]}),(0,Z.jsx)("div",{className:"text-[9px] text-white/40 leading-snug",children:u?"Declared in the manifest (requires.accessFeature) \u2014 not editable here. An override below adds an ADDITIONAL required feature.":"Pick a feature to hide this package from anyone who lacks it (restrict-only), then grant that feature to a role in Admin \u2192 Roles. Clear to remove."}),(0,Z.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,Z.jsx)("input",{list:l,value:i,onChange:h=>o(h.target.value),placeholder:"feature.id (e.g. labs.access)",disabled:a,className:"flex-1 min-w-0 rounded bg-black/30 border border-white/10 px-2 py-1 text-[10px] font-mono text-white/80 placeholder:text-white/25 focus:outline-none focus:border-cyan-400/40"}),(0,Z.jsx)("datalist",{id:l,children:n.map(h=>(0,Z.jsx)("option",{value:h},h))}),(0,Z.jsxs)("button",{type:"button",disabled:a||!f||c.length===0,onClick:()=>s(c),className:"inline-flex items-center gap-1 rounded-md bg-cyan-500/15 border border-cyan-400/25 px-2 py-1 text-[10px] text-cyan-100 hover:bg-cyan-500/20 transition disabled:opacity-35",children:[r?(0,Z.jsx)(We,{className:"w-3 h-3 animate-spin"}):null,"Set"]}),(0,Z.jsx)("button",{type:"button",disabled:a||e.accessFeatureSource!=="override",onClick:()=>s(null),title:e.accessFeatureSource==="manifest"?"Manifest-declared features cannot be cleared here":"Clear the override",className:"inline-flex items-center gap-1 rounded-md bg-white/5 border border-white/10 px-2 py-1 text-[10px] text-white/65 hover:bg-white/10 transition disabled:opacity-35",children:"Clear"})]})]})}function NE(t){let{status:e,partialLabel:n}=t;return e==="partial"?(0,Z.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-amber-500/25 bg-amber-500/10 px-2 py-0.5 text-[10px] text-amber-100/85",children:[(0,Z.jsx)(ot,{className:"w-2.5 h-2.5"})," ",n??"Partial"]}):e==="error"?(0,Z.jsx)("span",{className:"inline-flex items-center gap-1 rounded-full border border-red-500/25 bg-red-500/10 px-2 py-0.5 text-[10px] text-red-100/85",children:"Error"}):e==="disabled"?(0,Z.jsx)("span",{className:"rounded-full bg-white/10 px-2 py-0.5 text-[10px] text-white/55",children:"Disabled"}):(0,Z.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-emerald-500/25 bg-emerald-500/10 px-2 py-0.5 text-[10px] text-emerald-100/85",children:[(0,Z.jsx)(Qr,{className:"w-2.5 h-2.5"})," Active"]})}function RE(t){let{trust:e}=t;return e==="first-party"?(0,Z.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-sky-500/25 bg-sky-500/10 px-2 py-0.5 text-[10px] text-sky-100/85",children:[(0,Z.jsx)(Ps,{className:"w-2.5 h-2.5"})," First-party"]}):e==="trusted"?(0,Z.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-emerald-500/25 bg-emerald-500/10 px-2 py-0.5 text-[10px] text-emerald-100/85",children:[(0,Z.jsx)(so,{className:"w-2.5 h-2.5"})," Trusted"]}):(0,Z.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/15 bg-white/5 px-2 py-0.5 text-[10px] text-white/60",children:[(0,Z.jsx)(Sa,{className:"w-2.5 h-2.5"})," Untrusted"]})}function ME(t){let{type:e}=t;return(0,Z.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full bg-white/5 px-2 py-0.5 text-[10px] font-mono text-white/55 border border-white/10",children:[(0,Z.jsx)(jl,{className:"w-2.5 h-2.5 text-violet-300/70"}),e]})}function Jg(t){return(0,Z.jsxs)("div",{className:"rounded-md bg-white/[0.03] border border-white/5 px-2 py-1.5",children:[(0,Z.jsx)("div",{className:"text-white/45",children:t.label}),(0,Z.jsx)("div",{className:"text-white/85 font-mono mt-0.5",children:t.value})]})}function TE(t){let[e,n]=(0,Dt.useState)(!1);return(0,Z.jsxs)("div",{className:"relative",children:[(0,Z.jsx)("button",{type:"button",className:"inline-flex items-center rounded-md bg-white/5 p-1 text-white/40 hover:text-white/70 hover:bg-white/10",onClick:()=>n(r=>!r),children:(0,Z.jsx)(ea,{className:"w-3 h-3"})}),e?(0,Z.jsxs)("div",{className:"absolute right-0 bottom-full mb-2 w-64 rounded-lg border border-white/15 bg-neutral-900/95 p-2.5 text-[11px] text-white/75 shadow-xl z-10",children:[(0,Z.jsx)("div",{className:"font-semibold text-white/85 mb-1",children:t.trust==="trusted"?"Trusted":t.trust==="first-party"?"First-party":"Untrusted"}),(0,Z.jsx)("div",{className:"text-white/60",children:t.trust==="first-party"?"Built-in package, full access \u2014 trust is locked.":t.trust==="trusted"?"Full fs / network / cross-package API. Only flip this when you trust the author.":"Data-only filesystem, no network, no cross-package API. Safe default for unknown packages."})]}):null]})}function zi(t){let e=t.trim();if(!e)return"";let n=e.indexOf("://"),r=n>=1?e.slice(0,n+3):"",a=n>=1?e.slice(n+3):e,s=a.length>0&&a.endsWith("/"),i=[];for(let l of a.split("/"))if(!(l===""||l===".")){if(l===".."){i.pop();continue}i.push(l)}let o=i.join("/");return o?`${r}${o}${s?"/":""}`:r}var Of=j(Zr(),1);var mr=j($e(),1);function wL(t){let e=H(x=>x.client),{agentId:n,projectId:r,sources:a,revisions:s,resetKey:i}=t,[o,l]=(0,mr.useState)([]),[u,c]=(0,mr.useState)(!1),d=(0,mr.useRef)(Promise.resolve()),f=(0,mr.useRef)(0),h=(0,mr.useRef)([]),p=(0,mr.useRef)({}),g=(0,mr.useRef)(!0),m=(0,mr.useCallback)(async x=>{if(!n)return;x&&(g.current=!0);let y=++f.current,b=r?{projectId:r}:{},C=d.current.then(async()=>{if(y!==f.current)return;let L=[...h.current],P=g.current;g.current=!1;let w=()=>{h.current=[...L],l([...L])};c(!0);try{for(let k of a){if(!k.git?.isRepo&&!k.git?.containsRepos)continue;let _=k.uri_root.replace("://",""),M=s[_]??0;if(!(!P&&p.current[_]===M))try{let R=await Ki({agentId:n,...b,source:_},e);if(y!==f.current)return;for(let U=L.length-1;U>=0;U--)L[U].source===_&&!R.repos.some(v=>v.rel===L[U].repo.rel)&&L.splice(U,1);for(let U of R.repos){let v={source:_,repo:U};try{let V=await oc({agentId:n,...b,source:_,repo:U.rel},e);if(y!==f.current)return;V.ok===!1?v.error="Git status unavailable":v.status=V.status}catch(V){v.error=V instanceof Error?V.message:"Git status failed"}let T=L.findIndex(V=>V.source===_&&V.repo.rel===U.rel);T<0?L.push(v):L[T]=v,w()}p.current[_]=M}catch(R){if(y!==f.current)return;let U={source:_,repo:{rel:"",name:_},error:R instanceof Error?R.message:"Repository discovery failed"},v=L.findIndex(T=>T.source===_&&T.repo.rel==="");v>=0?L[v]=U:L.push(U),p.current[_]=M,w()}}y===f.current&&w()}finally{y===f.current&&c(!1)}});d.current=C.catch(()=>{}),await C},[n,r,a,s]);return(0,mr.useEffect)(()=>{f.current++,h.current=[],p.current={},g.current=!0,l([])},[i]),(0,mr.useEffect)(()=>(m(!1),()=>{f.current++}),[m]),{groups:o,loading:u,refresh:m}}var fe=j($e(),1);var zL=j(Wn(),1);var Nf=j($e(),1);var vL=j($e(),1),Yu=j(ie(),1),DE={add:"bg-emerald-500/12",remove:"bg-red-500/18",context:""},kL=(0,vL.memo)(function({lineNo:e,type:n,content:r}){return(0,Yu.jsxs)("div",{className:`flex h-[18px] w-full ${DE[n]}`,children:[(0,Yu.jsx)("span",{className:"shrink-0 w-10 text-right pr-2 select-none text-white/25 tabular-nums",children:e??""}),(0,Yu.jsx)("span",{className:"shrink-0 whitespace-pre pr-3 text-white/78",children:r||" "})]})});var cs=j(ie(),1),Zo=(0,Nf.memo)(function({hunks:e,isStreaming:n,maxLines:r=200}){let{elements:a,truncated:s}=(0,Nf.useMemo)(()=>{let i=[],o=0,l=0,u=!1,c=1,d=1;for(let f of e){if(f.skippedBefore!==0){let h=f.skippedBefore>0?`\xB7\xB7\xB7 ${f.skippedBefore} lines skipped \xB7\xB7\xB7`:"\xB7\xB7\xB7 \xB7\xB7\xB7 \xB7\xB7\xB7";i.push((0,cs.jsx)(FE,{label:h},`skip-${o}`)),f.skippedBefore>0&&(c+=f.skippedBefore,d+=f.skippedBefore)}for(let h of f.lines){if(l>=r){u=!0;break}let p=n?"add":h.type,g=p==="remove"?c:d;p==="remove"?c++:(p==="add"||c++,d++),i.push((0,cs.jsx)(kL,{lineNo:g,type:p,content:h.content},`line-${o}`)),o++,l++}if(u)break}return{elements:i,truncated:u}},[e,n,r]);return a.length===0?(0,cs.jsx)("div",{className:"px-3 py-2 text-[11px] text-white/40 italic",children:"No content"}):(0,cs.jsx)("div",{className:"font-mono text-[11px] leading-[18px] overflow-x-auto overflow-y-clip",children:(0,cs.jsxs)("div",{className:"min-w-full w-max",children:[a,s&&(0,cs.jsxs)("div",{className:"w-full text-[10px] text-white/40 bg-white/4 px-3 py-1 text-center",children:["\xB7\xB7\xB7 ",e.reduce((i,o)=>i+o.lines.length,0)-r," more lines \xB7\xB7\xB7"]})]})})},(t,e)=>{if(t.isStreaming!==e.isStreaming||t.maxLines!==e.maxLines||t.language!==e.language)return!1;if(t.hunks===e.hunks)return!0;if(t.hunks.length!==e.hunks.length)return!1;for(let n=0;n<t.hunks.length;n++){let r=t.hunks[n],a=e.hunks[n];if(r===a)continue;if(r.skippedBefore!==a.skippedBefore||r.lines.length!==a.lines.length)return!1;let s=r.lines[0],i=a.lines[0];if(s?.type!==i?.type||s?.content!==i?.content)return!1;let o=r.lines[r.lines.length-1],l=a.lines[a.lines.length-1];if(o?.type!==l?.type||o?.content!==l?.content)return!1}return!0});function FE({label:t}){return(0,cs.jsx)("div",{className:"w-full text-[10px] text-white/35 bg-white/[0.03] px-3 py-0.5 text-center border-y border-white/6 select-none",children:t})}var Mf=j(Zr(),1);function SL(t){return t.snapshotHash?null:"originalDraftUnknown"}function Qg(t,e){return t.op!=="delete"&&t.op!=="create"&&!t.baselineMissing&&e.current.state==="missing"&&e.baselineProvenance==="journal-latest-write"&&(e.baseline.state==="text"||e.baseline.state==="binary"||e.baseline.state==="too-large")}function e0(t){return String(t||"").replace(/\r\n/g,`
53
53
  `).split(`
54
- `)}function r0(n){let e=Pr(n);return e.length===0?[]:[{skippedBefore:0,lines:e.map(t=>({type:"add",content:t}))}]}function bI(n,e){let t=Pr(n).map(a=>({type:"remove",content:a})),r=Pr(e).map(a=>({type:"add",content:a}));return[{skippedBefore:0,lines:[...t,...r]}]}function wI(n){return n.map((e,t)=>{let r=Pr(e.find).map(s=>({type:"remove",content:s})),a=Pr(e.replace??"").map(s=>({type:"add",content:s}));return{skippedBefore:t>0?-1:0,lines:[...r,...a]}}).filter(e=>e.lines.length>0)}function vI(n){return r0(n)}function kI(n){let e=Pr(n);return e.length===0?[]:[{skippedBefore:0,lines:e.map(t=>({type:"add",content:t}))}]}function Ku(n){let e=n.action;if(!e){let t=$u(n);return t!=null?{added:Pr(t).length,removed:0}:null}if(e==="replace_text"){let t=n.edits;if(Array.isArray(t)){let s=0,o=0;for(let i of t){if(!i||typeof i!="object")continue;let l=i;typeof l.find=="string"&&(o+=Pr(l.find).length),typeof l.replace=="string"&&(s+=Pr(l.replace).length)}return{added:s,removed:o}}let r=typeof n.find=="string"?n.find:"",a=typeof n.replace=="string"?n.replace:"";return{added:Pr(a).length,removed:Pr(r).length}}if(e==="update"||e==="replace_lines"){let t=$u(n);return t!=null?{added:Pr(t).length,removed:0}:null}if(e==="append_text"||e==="prepend_text"||e==="insert"){let t=typeof n.text=="string"?n.text:"";return{added:Pr(t).length,removed:0}}return null}var pE={".ts":"typescript",".tsx":"tsx",".js":"javascript",".jsx":"jsx",".json":"json",".md":"markdown",".py":"python",".css":"css",".html":"html",".yaml":"yaml",".yml":"yaml",".sh":"bash",".sql":"sql",".rs":"rust",".go":"go",".java":"java",".xml":"xml",".toml":"toml",".env":"bash",".scss":"scss",".less":"less",".graphql":"graphql",".vue":"markup",".svelte":"markup",".txt":"text"};function Ji(n){let e=n.match(/(\.[a-zA-Z0-9]+)$/)?.[1]?.toLowerCase();return e?pE[e]:void 0}var mE=new Set(["update","replace_text","append_text","prepend_text","insert","replace_lines"]);function Zi(n){return!!n&&mE.has(n)}function Pr(n){return n?n.split(`
55
- `):[]}function Qi(n){return xE((0,Pf.parseSettledObject)(n))}function Nf(n,e){let t=n0(n),r=n0(e),a=t.length,s=r.length,o=Array.from({length:a+1},()=>new Array(s+1).fill(0));for(let c=a-1;c>=0;c--)for(let d=s-1;d>=0;d--)o[c][d]=t[c]===r[d]?o[c+1][d+1]+1:Math.max(o[c+1][d],o[c][d+1]);let i=[],l=0,u=0;for(;l<a&&u<s;)t[l]===r[u]?(i.push({type:"context",content:t[l]}),l++,u++):o[l+1][u]>=o[l][u+1]?(i.push({type:"remove",content:t[l]}),l++):(i.push({type:"add",content:r[u]}),u++);for(;l<a;)i.push({type:"remove",content:t[l++]});for(;u<s;)i.push({type:"add",content:r[u++]});return[{skippedBefore:0,lines:i}]}function Rf(n){let e=0,t=0;for(let r of n)for(let a of r.lines)a.type==="add"?e++:a.type==="remove"&&t++;return{added:e,removed:t}}function $u(n){for(let e of["content","file_content","text"]){let t=n[e];if(typeof t=="string")return t}if(typeof n.content=="object"&&n.content!==null)try{return JSON.stringify(n.content,null,2)}catch{}return null}function a0(n){if(!n||typeof n!="object"||Array.isArray(n))return null;let e=n;if(e.ok===!1)return null;let t=e.version;if(!t||typeof t!="object"||Array.isArray(t))return null;let r=t.diff;if(!r||typeof r!="object"||Array.isArray(r))return null;let a=r,s=typeof a.added=="number"?a.added:null,o=typeof a.removed=="number"?a.removed:null;return s==null||o==null?null:{added:s,removed:o}}function gE(n){let e=(0,Pf.extractPathsFromToolCall)(n);if(e.length===0){let r=Qi(n.input),a=typeof r?.uri=="string"&&r.uri||typeof r?.path=="string"&&r.path||"";if(!a)return[];e=[a]}let t=a0(n.structuredContent);return e.map((r,a)=>a===0&&t?{path:r,diff:t}:{path:r})}var SI={tab:"changes",changes:gE},CI=["fs_write","fs_create","fs_modify"];function xE(n){if(!n||typeof n.action=="string"||!bE(n))return n;let e={};if(typeof n.uri=="string"&&(e.uri=n.uri),typeof n.id=="string"&&(e.id=n.id),typeof n.move=="string")return{...e,action:"move",destination:n.move};if(typeof n.copy=="string")return{...e,action:"copy",destination:n.copy};if(n.mkdir!==void 0)return{...e,action:"create_folder"};if(n.revert!==void 0)return{...e,action:"revert"};if(n.delete!==void 0)return{...e,action:"delete"};let t=Array.isArray(n.edit)?n.edit.filter(i=>!!i&&typeof i=="object").map(i=>({find:typeof i.old_string=="string"?i.old_string:"",replace:typeof i.new_string=="string"?i.new_string:""})).filter(i=>i.find.length>0):[];if(t.length>0)return{...e,action:"replace_text",edits:t};let r=Af(n.lines);if(r&&typeof r.content=="string")return{...e,action:"replace_lines",content:r.content};let a=Af(n.insert);if(a&&typeof a.insert_text=="string")return{...e,action:"insert",text:a.insert_text};let s=Af(n.overwrite);if(s&&s.content!==void 0)return{...e,action:"update",content:s.content};let o=Af(n.create);return o&&o.content!==void 0?{...e,content:o.content}:n.fields!==void 0?{...e,action:"set_fields",fields:n.fields}:n}var yE=["create","overwrite","edit","insert","lines","fields","move","copy","mkdir","revert","delete"];function bE(n){return yE.some(e=>n[e]!==void 0)}function Af(n){return n&&typeof n=="object"&&!Array.isArray(n)?n:null}function II(n){let e=new Map;for(let t of n)if(t.status)for(let[r,a]of[[!0,t.status.staged],[!1,[...t.status.unstaged,...t.status.untracked]]])for(let s of a){let o=`${t.source}://${[t.repo.rel,s.path].filter(Boolean).join("/")}`,i=e.get(o)??new Map,l=JSON.stringify([t.source,t.repo.rel,s.path]),u=i.get(l);u?(u.staged||=r,u.unstaged||=!r):i.set(l,{group:t,path:s.path,staged:r,unstaged:!r}),e.set(o,i)}return e}function Xu(n){return`${n.source}://${n.repo.rel}`}function s0(n){let e=Ts(n.source,n.repo.name);return e.prefix?`${e.prefix} ${e.name}`:e.name}function AI(n,e){return e.kind==="pending"?[]:n.filter(t=>(!e.source||t.source===e.source)&&(!e.repo||Xu(t)===e.repo)&&(!e.branch||t.status?.branch===e.branch))}function PI(n,e,t){return t.kind==="git"?[]:n.filter(r=>!(t.source&&r.sourceSlug!==t.source||t.agent&&r.agentId!==t.agent||t.origin&&r.origin!==t.origin||(t.repo||t.branch)&&!e.some(s=>r.sourceSlug===s.source&&Wo(r.uri).startsWith(`${s.source}://${s.repo.rel?`${s.repo.rel}/`:""}`)&&(!t.repo||Xu(s)===t.repo)&&(!t.branch||s.status?.branch===t.branch)))).sort((r,a)=>r.createdAt<a.createdAt?-1:r.createdAt>a.createdAt?1:0)}function NI(n,e,t,r){let a=new Set(n.map(o=>Wo(o.uri))),s=[];for(let o of e.keys())(t==="git"||!a.has(o))&&s.push({kind:"git",key:`git:${o}`,uri:o});return n.forEach((o,i)=>s.push({kind:r==="cards"?"pending-card":"pending-row",key:o.id,rec:o,index:i})),s}var wE=32,vE=346;function RI(n){return n==="pending-row"?wE:vE}function MI(n){return n!=="pending-row"}function TI(n,e,t=100){let r=[],a=[];for(let s of n)e.has(s.id)||(yI(s)?a.push(s):r.length<t&&r.push(s));return{approvable:r,needsAck:a}}function o0(n){let e=n instanceof Error?n.message:String(n??"");return e.includes("PENDING_STATE_CHANGED")?"changed":e.includes("CURRENT_STATE_ACKNOWLEDGEMENT_REQUIRED")?"needs-ack":"error"}var LI=new WeakMap;function Mf(n){if(n.diffState!=="readable")return null;let e=LI.get(n);return e||(e=Nf(n.baseline.state==="text"?n.baseline.text:"",n.current.state==="text"?n.current.text:""),LI.set(n,e)),e}var Yr=W($e(),1),EI=W(Ya(),1);var mt=W(le(),1),DI={originalDraftUnknown:{label:"Older change \u2014 original draft unknown",chip:"bg-amber-500/15 text-amber-200 border-amber-400/30"},externalChanged:{label:"Changed outside the review",chip:"bg-rose-500/15 text-rose-200 border-rose-400/30"},unreviewable:{label:"Diff not readable",chip:"bg-sky-500/15 text-sky-200 border-sky-400/30"},fresh:{label:"No confirmation needed now",chip:"bg-emerald-500/15 text-emerald-200 border-emerald-400/30"}},FI={ok:{label:"Done",tone:"text-emerald-300"},changed:{label:"Changed since the preview \u2014 reopen it",tone:"text-amber-300"},"needs-ack":{label:"Still needs a confirmation",tone:"text-amber-300"},error:{label:"Refused",tone:"text-rose-300"}};async function Tf(n,e,t,r,a){let s={agentId:n.agentId,...n.projectId?{projectId:n.projectId}:{},id:e.id,expectedFingerprint:t.expectedFingerprint,...a?{acknowledgeCurrentState:!0}:{}};try{let o=r==="approve"?await ac({...s,uri:e.uri}):r==="revert"?await nx(s):await ax(s);if(o&&o.ok===!1){let i="error"in o&&o.error?String(o.error):"Review refused";return{id:e.id,uri:e.uri,action:r,outcome:o0(i),detail:i}}return{id:e.id,uri:e.uri,action:r,outcome:"ok"}}catch(o){return{id:e.id,uri:e.uri,action:r,outcome:o0(o),detail:o instanceof Error?o.message:"Review refused"}}}function kE({rec:n,preview:e}){let t=(0,Yr.useMemo)(()=>Mf(e),[e]);return t?(0,mt.jsx)("div",{className:"max-h-56 overflow-auto overlay-scroll",style:{scrollbarGutter:"auto"},children:(0,mt.jsx)(Yi,{hunks:t,language:Ji(n.uri),maxLines:400})}):(0,mt.jsxs)("div",{className:"px-2.5 py-2 text-[10.5px] text-white/50",children:["Diff ",e.diffState,": current ",e.current.state,", baseline ",e.baseline.state," (",e.baselineProvenance,")."]})}var Yu="h-7 px-2.5 rounded-md text-[11px] font-medium transition disabled:opacity-40 inline-flex items-center gap-1.5";function BI({request:n,agentId:e,projectId:t,run:r,onClose:a,onDone:s,next:o=0,onNext:i}){let l=(0,Yr.useMemo)(()=>n.kind==="single"?[n.rec]:n.records,[n]),[u,c]=(0,Yr.useState)(()=>n.kind==="single"&&n.preview?{[n.rec.id]:n.preview}:{}),[d,f]=(0,Yr.useState)(!1),[h,p]=(0,Yr.useState)({});(0,Yr.useEffect)(()=>{let C=!0;for(let k of l)u[k.id]||r(()=>il({agentId:e,...t?{projectId:t}:{},id:k.id}),()=>C).then(v=>{C&&v&&c(b=>({...b,[k.id]:v}))},v=>{C&&c(b=>({...b,[k.id]:v instanceof Error?v:new Error("Preview failed")}))});return()=>{C=!1}},[l,e,t,r]);let m=(0,Yr.useMemo)(()=>{let C=new Map;for(let k of l){let v=u[k.id];if(!v||v instanceof Error)continue;let b=v.requiresAcknowledgement[0]??"fresh";C.set(b,[...C.get(b)??[],k])}return C},[l,u]),g=l.filter(C=>!u[C.id]).length,x=n.kind==="group"&&g===0&&!d&&l.every(C=>h[C.id]||u[C.id]instanceof Error),w=(0,Yr.useCallback)(async(C,k)=>{f(!0);let v=[];for(let b of C){let P=u[b.id];if(!P||P instanceof Error||h[b.id]?.outcome==="ok")continue;let N=await Tf({agentId:e,projectId:t},b,P,k,P.requiresAcknowledgement.length>0);v.push(N),p(M=>({...M,[b.id]:N}))}f(!1),s(v)},[u,h,e,t,s]);if(typeof document>"u")return null;let y=n.kind==="single"?n:null;return(0,EI.createPortal)((0,mt.jsx)("div",{className:"fixed inset-0 z-[1100] flex items-center justify-center bg-black/40 backdrop-blur-[1px]",onMouseDown:d?void 0:a,children:(0,mt.jsxs)("div",{role:"dialog","aria-modal":"true","aria-label":"Review pending changes",onMouseDown:C=>C.stopPropagation(),className:"w-[min(640px,92vw)] max-h-[82vh] flex flex-col rounded-xl border border-amber-400/25 bg-[#15151d] shadow-[0_30px_80px_-24px_rgba(0,0,0,0.85)]",children:[(0,mt.jsxs)("div",{className:"flex items-start gap-2.5 p-4 pb-2 shrink-0",children:[(0,mt.jsx)(va,{className:"h-4 w-4 text-amber-300 shrink-0 mt-0.5"}),(0,mt.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,mt.jsx)("div",{className:"text-[12px] font-semibold text-white/90",children:y?`Review the current state \u2014 ${y.action}`:n.kind==="group"&&n.total>l.length?`${l.length} of ${n.total} changes need your confirmation`:`${l.length} changes need your confirmation`}),(0,mt.jsx)("div",{className:"mt-1 text-[10.5px] text-white/55 leading-relaxed",children:"Each change is checked against its own fresh preview. Confirming accepts the state shown here; a change that moves again before you confirm is refused and stays in the list."}),g>0?(0,mt.jsxs)("div",{className:"mt-1.5 inline-flex items-center gap-1.5 text-[10.5px] text-white/45",children:[(0,mt.jsx)(ze,{className:"h-3 w-3 animate-spin"})," Loading ",g," preview",g>1?"s":"","\u2026"]}):null]})]}),(0,mt.jsxs)("div",{className:"min-h-0 flex-1 overflow-auto overlay-scroll px-4 space-y-3",children:[[...m].map(([C,k])=>(0,mt.jsxs)("section",{className:"rounded-lg border border-white/8 bg-black/20",children:[(0,mt.jsxs)("div",{className:"flex items-center gap-2 px-2.5 py-1.5 border-b border-white/5",children:[(0,mt.jsxs)("span",{className:`inline-flex items-center rounded-full border px-2 py-0.5 text-[10px] font-semibold ${DI[C].chip}`,children:[DI[C].label," \xB7 ",k.length]}),y?null:(0,mt.jsxs)("div",{className:"ml-auto flex items-center gap-1.5",children:[(0,mt.jsxs)("button",{type:"button",disabled:d||k.every(v=>h[v.id]),onClick:()=>{w(k,"dismiss")},className:`${Yu} bg-white/[0.04] hover:bg-white/[0.08] text-white/70`,children:[(0,mt.jsx)(na,{className:"h-3 w-3"})," Confirm & dismiss ",k.length]}),(0,mt.jsxs)("button",{type:"button",disabled:d||k.every(v=>h[v.id]),onClick:()=>{w(k,"approve")},className:`${Yu} bg-emerald-500/20 hover:bg-emerald-500/30 border border-emerald-400/40 text-emerald-100 font-semibold`,children:[(0,mt.jsx)(ps,{className:"h-3 w-3"})," Confirm & approve ",k.length]})]})]}),k.map(v=>{let b=u[v.id],P=h[v.id];return(0,mt.jsxs)("div",{className:"border-b border-white/5 last:border-0",children:[(0,mt.jsxs)("div",{className:"flex items-center gap-2 px-2.5 py-1 text-[10.5px]",children:[(0,mt.jsx)("span",{className:"min-w-0 flex-1 truncate font-mono text-white/70",title:v.uri,children:v.uri}),P?(0,mt.jsx)("span",{className:FI[P.outcome].tone,title:P.detail,children:FI[P.outcome].label}):null]}),(0,mt.jsx)(kE,{rec:v,preview:b})]},v.id)})]},C)),l.filter(C=>u[C.id]instanceof Error).map(C=>(0,mt.jsxs)("div",{className:"rounded-md bg-rose-500/10 px-2.5 py-1.5 text-[10.5px] text-rose-200/90",children:[C.uri,": ",u[C.id].message]},C.id))]}),(0,mt.jsxs)("div",{className:"flex items-center justify-end gap-2 p-4 pt-3 shrink-0",children:[(0,mt.jsxs)("button",{type:"button",onClick:a,disabled:d,className:`${Yu} bg-white/[0.04] hover:bg-white/[0.08] text-white/70`,children:[(0,mt.jsx)(Ut,{className:"h-3 w-3"})," ",Object.keys(h).length?"Close":"Cancel"]}),x&&i&&o>0?(0,mt.jsxs)("button",{type:"button",onClick:()=>i(l.map(C=>C.id)),className:`${Yu} border border-amber-400/40 bg-amber-500/15 hover:bg-amber-500/25 text-amber-100 font-semibold`,children:[(0,mt.jsx)(va,{className:"h-3 w-3"})," Next batch (",o," left)"]}):null,y?["revert","dismiss","approve"].map(C=>{let k=C===y.action,v=C==="approve"?Dn:C==="revert"?ka:na,b=C==="revert"?"border border-rose-400/40 bg-rose-500/15 hover:bg-rose-500/25 text-rose-100":k?"border border-emerald-400/40 bg-emerald-500/20 hover:bg-emerald-500/30 text-emerald-100 font-semibold":"bg-white/[0.04] hover:bg-white/[0.08] text-white/70";return(0,mt.jsxs)("button",{type:"button",disabled:d||g>0||h[y.rec.id]?.outcome==="ok",onClick:()=>{w([y.rec],C)},className:`${Yu} ${b}`,children:[(0,mt.jsx)(v,{className:"h-3 w-3"})," ",k?`Confirm & ${C}`:C[0].toUpperCase()+C.slice(1)]},C)}):null]})]})}),document.body)}var X=W(le(),1),HI={create:(0,X.jsx)(vs,{className:"w-3.5 h-3.5 text-emerald-300/80"}),modify:(0,X.jsx)(bs,{className:"w-3.5 h-3.5 text-sky-300/80"}),delete:(0,X.jsx)(It,{className:"w-3.5 h-3.5 text-red-300/80"}),move:(0,X.jsx)(Nl,{className:"w-3.5 h-3.5 text-violet-300/80"})},UI=n=>n==="approved"?"bg-emerald-400":n==="reverted"?"bg-white/30":"bg-amber-400";function GI({diff:n}){return!n||n.added===0&&n.removed===0?null:(0,X.jsxs)("span",{className:"font-mono text-[10px] shrink-0",children:[n.added>0?(0,X.jsxs)("span",{className:"text-emerald-300",children:["+",n.added]}):null,n.added>0&&n.removed>0?" ":null,n.removed>0?(0,X.jsxs)("span",{className:"text-red-300",children:["\u2212",n.removed]}):null]})}var zI=(0,X.jsxs)("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded bg-rose-500/15 text-rose-200/90 text-[10px] shrink-0",title:"The backing file no longer exists \u2014 this change can only be discarded.",children:[(0,X.jsx)(Ul,{className:"w-3 h-3"})," Orphaned"]});function WI({orphaned:n,busy:e,onApprove:t,onRevert:r,onDiscard:a,onDismiss:s,className:o}){let i=(0,X.jsx)(Ff.LiveSpinner,{className:"w-3.5 h-3.5"});return(0,X.jsx)("div",{className:o,children:n?(0,X.jsx)("button",{type:"button",onClick:a,disabled:e,title:"Discard (remove this un-actionable change)",className:"p-1 rounded hover:bg-rose-500/15 text-rose-300/80 disabled:opacity-40",children:e?i:(0,X.jsx)(It,{className:"w-3.5 h-3.5"})}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)("button",{type:"button",onClick:t,disabled:e,title:"Approve",className:"p-1 rounded hover:bg-emerald-500/15 text-emerald-300/80 disabled:opacity-40",children:e?i:(0,X.jsx)(Dn,{className:"w-3.5 h-3.5"})}),(0,X.jsx)("button",{type:"button",onClick:r,disabled:e,title:"Revert",className:"p-1 rounded hover:bg-red-500/15 text-red-300/80 disabled:opacity-40",children:(0,X.jsx)(ka,{className:"w-3.5 h-3.5"})}),(0,X.jsx)("button",{type:"button",onClick:s,disabled:e,title:"Dismiss (stop reviewing \u2014 keep the change, no revert)",className:"p-1 rounded hover:bg-white/10 text-white/50 hover:text-white/80 disabled:opacity-40",children:(0,X.jsx)(na,{className:"w-3.5 h-3.5"})})]})})}function OI({uri:n,rows:e,agentId:t,projectId:r,canWrite:a,revisions:s,queue:o}){let i=e.get(Wo(n));return i?(0,X.jsx)(X.Fragment,{children:[...i.values()].map(l=>(0,X.jsx)(ve.default.Fragment,{children:[!0,!1].filter(u=>u?l.staged:l.unstaged).map(u=>(0,X.jsxs)("div",{children:[(0,X.jsxs)("div",{className:"px-3 py-1 text-[10px] text-white/40",children:[l.group.repo.name," (",l.group.repo.rel||"root",") \xB7 ",u?"Git HEAD \u2192 index (staged)":"Git index \u2192 working file (unstaged/untracked)"]}),(0,X.jsx)("div",{className:"max-h-72 overflow-auto overlay-scroll",style:{scrollbarGutter:"auto"},children:(0,X.jsx)(bo,{source:l.group.source,repo:l.group.repo.rel,path:l.path,mode:{kind:"working",staged:u},agentId:t,projectId:r,variant:"card",canWrite:a&&l.group.repo.canWrite===!0,revision:s[l.group.source]??0,runContent:o.run,peekContent:o.peek})})]},String(u)))},`${l.group.source}/${l.group.repo.rel}/${l.path}`))}):null}var SE=n=>2*((n.baseline.state==="text"?n.baseline.text.length:0)+(n.current.state==="text"?n.current.text.length:0))+256,CE=(0,ve.memo)(function({rec:e,agentId:t,projectId:r,focused:a,orphaned:s,onOpen:o,onApprove:i,onRevert:l,onDiscard:u,onDismiss:c,onFocus:d,busy:f,queue:h,revision:p,canWrite:m,onPreview:g,peekPreview:x,extra:w}){let[y,C]=(0,ve.useState)(!0),[k,v]=(0,ve.useState)(()=>x(e.id)??null),[b,P]=(0,ve.useState)(!1),[N,M]=(0,ve.useState)(null),[U,I]=(0,ve.useState)(""),A=(0,ve.useRef)(0),G=h.visible.has(e.id),V=(0,ve.useRef)(!1);V.current=y&&G;let K=`preview\0${e.id}\0${e.updatedAt}\0${p}`,L=(0,ve.useRef)("");(0,ve.useEffect)(()=>{let ee=++A.current;if(!y||!G||L.current===K){P(!1);return}return P(!0),h.run(()=>il({agentId:t,...r?{projectId:r}:{},id:e.id}),()=>ee===A.current&&V.current,{key:K,bytes:SE}).then(ce=>{!ce||ee!==A.current||!V.current||(g(ce),v(ce),M(null),I(K),L.current=K,P(!1))}).catch(ce=>{ee===A.current&&(M(ce instanceof Error?ce.message:"Failed to load review"),P(!1))}),()=>{A.current++}},[t,r,e.id,K,y,G,h.run]);let R=(0,ve.useMemo)(()=>k?Mf(k):null,[k]),z=(0,ve.useMemo)(()=>R?Rf(R):null,[R]),J=U===K?k?.indexState??null:null,Q=N??(k&&k.diffState!=="readable"?`Review diff unavailable: ${k.diffState}; current ${k.current.state}, baseline ${k.baseline.state}.`:null),re=(0,ve.useCallback)(()=>C(ee=>!ee),[]),pe=e.diff&&(e.diff.added>0||e.diff.removed>0)?e.diff:z??void 0;return(0,X.jsxs)("div",{ref:ee=>h.register(e.id,ee),onMouseDown:d,className:`rounded-lg border overflow-hidden transition-colors ${s?"border-rose-400/30 bg-rose-500/[0.04]":a?"border-amber-400/40 ring-1 ring-amber-400/25 bg-amber-400/[0.03]":"border-white/8 bg-black/20"}`,children:[(0,X.jsxs)("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 px-2.5 py-1.5",children:[(0,X.jsx)("button",{type:"button",onClick:re,"aria-expanded":y,className:"text-white/40 hover:text-white/80 shrink-0",children:y?(0,X.jsx)(Tt,{className:"w-3.5 h-3.5"}):(0,X.jsx)(un,{className:"w-3.5 h-3.5"})}),HI[e.op],(0,X.jsxs)("button",{type:"button",onClick:()=>o(e.uri),className:"min-w-[6rem] flex-1 text-left truncate text-xs text-white/85 hover:text-white",title:e.uri,children:[yt(e.uri)||e.uri,(0,X.jsxs)("span",{className:"ml-1.5 text-[10px] text-white/30 font-mono",children:[ot(e.uri),"/"]})]}),(0,X.jsx)(GI,{diff:pe}),J&&J!=="stored"?(0,X.jsx)("span",{className:"text-[10px] text-amber-200/80 shrink-0",children:J==="missing"?"Index missing":J==="stale"?"Index stale":"Recovery only"}):null,s?zI:e.status==="approved"||e.status==="reverted"?(0,X.jsx)("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${UI(e.status)}`,title:e.status}):null,m?(0,X.jsx)(WI,{orphaned:s,busy:f,onApprove:i,onRevert:l,onDiscard:u,onDismiss:c,className:"ml-auto flex items-center gap-1 shrink-0"}):null]}),y?(0,X.jsxs)("div",{className:"border-t border-white/5",children:[(0,X.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-1 text-[10px] text-white/40",children:["Review baseline \u2192 current file",b&&k?(0,X.jsx)(Ff.LiveSpinner,{className:"w-3 h-3"}):null]}),(0,X.jsx)("div",{className:"max-h-72 overflow-auto overlay-scroll",style:{scrollbarGutter:"auto"},children:b&&!k?(0,X.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-xs text-white/40",children:[(0,X.jsx)(Ff.LiveSpinner,{className:"w-3.5 h-3.5"})," Loading diff\u2026"]}):Q?(0,X.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-xs text-red-300/80",children:[(0,X.jsx)(dt,{className:"w-3.5 h-3.5"})," ",Q]}):R?(0,X.jsx)(Yi,{hunks:R,language:Ji(e.uri),maxLines:600}):null})]}):null,y?w:null]})}),el="bg-transparent border border-white/8 rounded px-1.5 py-0.5 text-white/70",tl={background:"var(--w-composer-bg-rgb, rgba(20,20,28,1))"},LE={kind:"all",source:"",repo:"",branch:"",agent:"",origin:""},Df=100;function jI({agentId:n,projectId:e}){let t=hn(),r=Xa({grantedFeatures:[...t.grantedFeatures??[]]},"drive.write"),a=B(j=>j.sources),s=B(j=>j.sourceChangeRevision),o=B(j=>j.pendingPanelFilter),i=B(j=>j.setPendingPanelFilter),l=B(j=>j.openFile),u=B(j=>j.removeFilePath),c=B(j=>j.setActiveWorkspaceTab),d=B(j=>j.refreshPendingCount),f=o.conversationId??"",[h,p]=(0,ve.useState)(null),m=Sc(h),g=(0,ve.useRef)(new Map),x=(0,ve.useCallback)(j=>g.current.get(j),[]),[w,y]=(0,ve.useState)(LE),C=j=>ie=>y(Ue=>({...Ue,[j]:ie.target.value})),[k,v]=(0,ve.useState)("cards"),[b,P]=(0,ve.useState)([]),[N,M]=(0,ve.useState)(new Set),[U,I]=(0,ve.useState)(!1),[A,G]=(0,ve.useState)(null),[V,K]=(0,ve.useState)(null),[L,R]=(0,ve.useState)(0),[z,J]=(0,ve.useState)(0),[Q,re]=(0,ve.useState)(null),[pe,ee]=(0,ve.useState)([]),[ce,ue]=(0,ve.useState)(!1),[He,De]=(0,ve.useState)(!1),[je,et]=(0,ve.useState)(!1),[Dt,at]=(0,ve.useState)(!1),[vt,Pt]=(0,ve.useState)(new Set),Ye=(0,ve.useRef)(null),Ne=(0,ve.useRef)(0),tt=mI({agentId:n,projectId:e,sources:a,revisions:s,resetKey:`${n}\0${e}\0${f}`}),Je=(0,ve.useCallback)(async j=>{if(!n)return;let ie=++Ne.current;I(!0),G(null);try{let Ue=await ex({agentId:n,...e?{projectId:e}:{},...f?{conversationId:f}:{},...j?{include_orphans:!0}:{}});if(ie!==Ne.current)return;let Bt=new Set(Ue.changes.map(Xt=>Xt.id));return P(Ue.changes),M(Xt=>j?new Set(Ue.orphanIds):new Set([...Xt].filter(dn=>Bt.has(dn)))),Ue.changes}catch(Ue){ie===Ne.current&&G(Ue instanceof Error?Ue.message:"Failed to load changes");return}finally{ie===Ne.current&&I(!1)}},[n,e,f]),Ft=(0,ve.useCallback)(async()=>{await Promise.all([Je(!0),tt.refresh(!0)]),d({agentId:n,projectId:e})},[Je,tt.refresh,d,n,e]);(0,ve.useEffect)(()=>(g.current.clear(),re(null),P([]),M(new Set),ee([]),Je(!0),()=>{Ne.current++,g.current.clear()}),[Je]);let Mt=(0,ve.useRef)(Je);Mt.current=Je;let Te=(0,ve.useRef)(!0);(0,ve.useEffect)(()=>{if(Te.current){Te.current=!1;return}Mt.current(!1)},[s]);let oe=tt.groups,jt=(0,ve.useMemo)(()=>Array.from(new Set([...b.map(j=>j.sourceSlug),...oe.map(j=>j.source)])).sort(),[b,oe]),Kt=(0,ve.useMemo)(()=>Array.from(new Set(b.map(j=>j.agentId).filter(Boolean))).sort(),[b]),de=(0,ve.useMemo)(()=>Array.from(new Set(b.map(j=>j.origin).filter(Boolean))).sort(),[b]),fe=(0,ve.useMemo)(()=>PI(b,oe,w),[b,oe,w]),qe=(0,ve.useMemo)(()=>AI(oe,w),[oe,w]),Re=(0,ve.useMemo)(()=>II(qe),[qe]),Fe=(0,ve.useMemo)(()=>NI(fe,Re,w.kind,k),[fe,Re,w.kind,k]),{approvable:Lt,needsAck:st}=(0,ve.useMemo)(()=>TI(fe,N,Df),[fe,N]),Le=(0,ve.useRef)(new Set),Ee=st.filter(j=>!Le.current.has(j.id)),Et=(0,ve.useCallback)(j=>{for(let Ue of j)Le.current.add(Ue);let ie=st.filter(Ue=>!Le.current.has(Ue.id));re({kind:"group",records:ie.slice(0,Df),total:ie.length})},[st]),qt=(0,ve.useRef)(Fe);qt.current=Fe;let Tn=(0,ve.useCallback)(j=>RI(qt.current[j]?.kind??"pending-card"),[]),te=(0,ve.useCallback)(j=>qt.current[j]?.key??j,[]),Ce=ii({count:Fe.length,getScrollElement:()=>h,estimateSize:Tn,getItemKey:te,overscan:4});Ce.shouldAdjustScrollPositionOnItemSizeChange=IE,(0,ve.useEffect)(()=>{J(j=>fe.length===0?0:Math.min(j,fe.length-1))},[fe.length]);let Ge=Fe.length-fe.length;(0,ve.useEffect)(()=>{fe.length>0&&Ce.scrollToIndex(Ge+z,{align:"auto"})},[z,k]);let Ke=(0,ve.useCallback)(j=>{l({agentId:n,projectId:e,uri:j}),c("file")},[n,e,l,c]),Ae=(0,ve.useCallback)(j=>{if(j.op!=="delete"||!j.uri)return;let ie=B.getState().files[j.uri];(!ie||ie.status==="deleted")&&u(j.uri)},[u]),he=(0,ve.useCallback)(async j=>{for(let ie of j){let Ue=b.find(Bt=>Bt.id===ie.id);Ue&&ie.outcome==="ok"&&ie.action!=="revert"&&Ae(Ue),ie.outcome!=="ok"&&g.current.delete(ie.id)}j.some(ie=>ie.outcome!=="ok")&&R(ie=>ie+1),ee(j),await Je(!1),d({agentId:n,projectId:e})},[b,Ae,Je,d,n,e]),ut=(0,ve.useCallback)(async(j,ie)=>{if(!r)return;let Ue=g.current.get(j.id);if(!Ue||Ue.requiresAcknowledgement.length){re({kind:"single",rec:j,action:ie,...Ue?{preview:Ue}:{}});return}K(j.id);try{await he([await Tf({agentId:n,projectId:e},j,Ue,ie,!1)])}finally{K(null)}},[r,n,e,he]),Qt=(0,ve.useCallback)(async j=>{K(j.id);try{let ie=await rx({agentId:n,...e?{projectId:e}:{},id:j.id});ie.ok?Ae(j):G(ie.error||"Discard failed"),await Je(!1),d({agentId:n,projectId:e})}catch(ie){G(ie instanceof Error?ie.message:"Discard failed")}finally{K(null)}},[n,e,Je,Ae,d]),xn=(0,ve.useCallback)(async()=>{Ye.current&&(clearTimeout(Ye.current),Ye.current=null),at(!0),et(!1),G(null);try{await sx({agentId:n,...e?{projectId:e}:{},...f?{conversationId:f}:{}});let j=b.filter(Ue=>N.has(Ue.id)),ie=await Je(!0);if(ie){let Ue=new Set(ie.map(Bt=>Bt.id));for(let Bt of j)Ue.has(Bt.id)||Ae(Bt)}d({agentId:n,projectId:e})}catch(j){G(j instanceof Error?j.message:"Repair failed")}finally{at(!1)}},[n,e,f,Je,b,N,Ae,d]),yn=(0,ve.useCallback)(()=>{if(je){xn();return}et(!0),Ye.current&&clearTimeout(Ye.current),Ye.current=setTimeout(()=>et(!1),3e3)},[je,xn]);(0,ve.useEffect)(()=>()=>{Ye.current&&clearTimeout(Ye.current)},[]);let Nr=(0,ve.useCallback)(async()=>{ue(!0),De(!1),G(null);let j=[];try{for(let ie of Lt){let Ue=g.current.get(ie.id);if(!Ue)try{Ue=await il({agentId:n,...e?{projectId:e}:{},id:ie.id})}catch(Bt){j.push({id:ie.id,uri:ie.uri,action:"approve",outcome:"error",detail:Bt instanceof Error?Bt.message:"Preview failed"});continue}if(Ue.requiresAcknowledgement.length){j.push({id:ie.id,uri:ie.uri,action:"approve",outcome:"needs-ack"});continue}j.push(await Tf({agentId:n,projectId:e},ie,Ue,"approve",!1))}}finally{ue(!1),await he(j)}},[Lt,n,e,he]),Kn=(0,ve.useCallback)(j=>J(ie=>fe.length===0?0:Math.max(0,Math.min(fe.length-1,ie+j))),[fe.length]),Xn=(0,ve.useCallback)(j=>{if(V||ce||!r||Q)return;let ie=fe[z],Ue=ie?N.has(ie.id):!1;j.key==="ArrowDown"||j.key==="ArrowRight"?(j.preventDefault(),Kn(1)):j.key==="ArrowUp"||j.key==="ArrowLeft"?(j.preventDefault(),Kn(-1)):Ue&&ie&&(j.key==="d"||j.key==="r"||j.key==="Enter")?(j.preventDefault(),Qt(ie)):(j.key==="a"||j.key==="Enter")&&ie?(j.preventDefault(),ut(ie,"approve")):j.key==="r"&&ie?(j.preventDefault(),ut(ie,"revert")):j.key==="x"&&!Ue&&ie&&(j.preventDefault(),ut(ie,"dismiss"))},[V,ce,r,Q,fe,z,N,Kn,Qt,ut]),Rr=j=>{if(j.kind==="git"){let dn=!vt.has(j.uri);return(0,X.jsxs)("div",{ref:Sn=>m.register(j.uri,Sn),className:"rounded-lg border border-white/8 bg-black/20",children:[(0,X.jsx)("button",{type:"button","aria-expanded":dn,className:"px-3 py-2 text-xs text-white/85",onClick:()=>Pt(Sn=>{let hr=new Set(Sn);return hr.has(j.uri)?hr.delete(j.uri):hr.add(j.uri),hr}),children:j.uri}),dn?(0,X.jsx)(OI,{uri:j.uri,rows:Re,agentId:n,projectId:e,canWrite:r,revisions:s,queue:m}):null]})}let{rec:ie,index:Ue}=j,Bt=N.has(ie.id),Xt={onApprove:()=>{ut(ie,"approve")},onRevert:()=>{ut(ie,"revert")},onDiscard:()=>{Qt(ie)},onDismiss:()=>{ut(ie,"dismiss")}};return j.kind==="pending-card"?(0,X.jsx)(CE,{rec:ie,agentId:n,projectId:e,focused:Ue===z,orphaned:Bt,onOpen:Ke,...Xt,onFocus:()=>J(Ue),busy:V===ie.id,queue:m,revision:L+(s[ie.sourceSlug]??0),canWrite:r,onPreview:dn=>{g.current.set(ie.id,dn)},peekPreview:x,extra:w.kind==="all"?(0,X.jsx)(OI,{uri:ie.uri,rows:Re,agentId:n,projectId:e,canWrite:r,revisions:s,queue:m}):null}):(0,X.jsxs)("div",{onMouseDown:()=>J(Ue),className:`group h-8 flex items-center gap-2 px-2 rounded-lg ${Ue===z?"bg-amber-400/[0.06] ring-1 ring-amber-400/20":"hover:bg-white/5"}`,children:[HI[ie.op],(0,X.jsxs)("button",{type:"button",onClick:()=>Ke(ie.uri),className:"min-w-0 flex-1 text-left truncate text-xs text-white/85 hover:text-white",title:ie.uri,children:[yt(ie.uri)||ie.uri,(0,X.jsxs)("span",{className:"ml-1.5 text-[10px] text-white/30 font-mono",children:[ot(ie.uri),"/"]})]}),(0,X.jsx)(GI,{diff:ie.diff}),Bt?zI:(0,X.jsx)("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${UI(ie.status)}`,title:ie.status}),r?(0,X.jsx)(WI,{orphaned:Bt,busy:V===ie.id,...Xt,className:"hidden group-hover:flex items-center gap-0.5 shrink-0"}):null]})},Yn=pe.filter(j=>j.outcome!=="ok"),Mr=U||tt.loading;return(0,X.jsxs)("div",{className:"w-full h-full flex flex-col min-h-0 outline-none",tabIndex:0,onKeyDown:Xn,children:[r&&Q?(0,X.jsx)(BI,{request:Q,agentId:n,projectId:e,run:m.run,onClose:()=>re(null),next:Q.kind==="group"?Ee.filter(j=>!Q.records.some(ie=>ie.id===j.id)).length:0,onNext:Et,onDone:j=>{for(let ie of j)Le.current.add(ie.id);he(j)}},Q.kind==="group"?`group\0${Q.records[0]?.id??""}`:`single\0${Q.rec.id}`):null,(0,X.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5 px-3 py-2 border-b border-white/5 shrink-0",children:[(0,X.jsx)("span",{className:"text-xs font-semibold text-white/80",children:"Changes"}),(0,X.jsx)("span",{className:"text-[10px] text-white/35",children:fe.length>0?`${Math.min(z+1,fe.length)}/${fe.length}`:"0"}),(0,X.jsxs)("div",{className:"ml-auto flex flex-wrap items-center justify-end gap-1",children:[(0,X.jsxs)("div",{className:"flex items-center rounded-lg border border-white/8 overflow-hidden",children:[(0,X.jsx)("button",{type:"button",onClick:()=>Kn(-1),disabled:fe.length===0||z===0,className:"p-1.5 text-white/45 hover:text-white/80 disabled:opacity-30",title:"Previous (\u2191)",children:(0,X.jsx)(gl,{className:"w-3.5 h-3.5"})}),(0,X.jsx)("button",{type:"button",onClick:()=>Kn(1),disabled:fe.length===0||z>=fe.length-1,className:"p-1.5 text-white/45 hover:text-white/80 disabled:opacity-30",title:"Next (\u2193)",children:(0,X.jsx)(un,{className:"w-3.5 h-3.5"})})]}),r?He?(0,X.jsxs)("button",{type:"button",onClick:()=>{Nr()},disabled:ce||Lt.length===0,className:"inline-flex shrink-0 whitespace-nowrap items-center gap-1 rounded-lg border border-emerald-500/30 bg-emerald-500/15 px-2 py-1 text-[10px] text-emerald-100 hover:bg-emerald-500/20 disabled:opacity-40",title:`Approve ${Lt.length} visible change(s) that need no confirmation`,children:[ce?(0,X.jsx)(ze,{className:"w-3 h-3 animate-spin"}):(0,X.jsx)(ps,{className:"w-3 h-3"})," Approve ",Lt.length,"?"]}):(0,X.jsxs)("button",{type:"button",onClick:()=>De(!0),disabled:Lt.length===0,className:"inline-flex shrink-0 whitespace-nowrap items-center gap-1 rounded-lg border border-white/8 px-2 py-1 text-[10px] text-white/55 hover:text-white/85 hover:bg-white/5 disabled:opacity-30",title:"Approve every visible change that needs no confirmation",children:[(0,X.jsx)(ps,{className:"w-3 h-3"})," Approve ",Lt.length]}):null,r&&st.length>0?(0,X.jsxs)("button",{type:"button",onClick:()=>{Le.current.clear(),re({kind:"group",records:st.slice(0,Df),total:st.length})},className:"inline-flex shrink-0 whitespace-nowrap items-center gap-1 rounded-lg border border-amber-400/30 px-2 py-1 text-[10px] text-amber-200/90 hover:bg-amber-500/10",title:`Review the changes that need your confirmation, grouped by reason (up to ${Df} at a time)`,children:[(0,X.jsx)(va,{className:"w-3 h-3"})," ",st.length," need confirmation"]}):null,(0,X.jsxs)("div",{className:"flex items-center rounded-lg border border-white/8 overflow-hidden",children:[(0,X.jsx)("button",{type:"button",onClick:()=>v("list"),title:"Compact list",className:`p-1.5 ${k==="list"?"bg-white/10 text-white":"text-white/45 hover:text-white/80"}`,children:(0,X.jsx)(to,{className:"w-3.5 h-3.5"})}),(0,X.jsx)("button",{type:"button",onClick:()=>v("cards"),title:"Diff cards",className:`p-1.5 ${k==="cards"?"bg-white/10 text-white":"text-white/45 hover:text-white/80"}`,children:(0,X.jsx)(Va,{className:"w-3.5 h-3.5"})})]}),r&&N.size>0?(0,X.jsxs)("button",{type:"button",onClick:yn,disabled:Dt,className:je?"inline-flex shrink-0 whitespace-nowrap items-center gap-1 rounded-lg border border-rose-500/40 bg-rose-500/15 px-2 py-1 text-[10px] text-rose-100 hover:bg-rose-500/25 disabled:opacity-40":"inline-flex shrink-0 whitespace-nowrap items-center gap-1 rounded-lg border border-rose-400/25 px-2 py-1 text-[10px] text-rose-200/80 hover:text-rose-100 hover:bg-rose-500/10 disabled:opacity-40",title:je?`Discard all ${N.size} orphaned change(s)`:"Repair \u2014 discard orphaned changes whose backing file no longer exists",children:[Dt?(0,X.jsx)(ze,{className:"w-3 h-3 animate-spin"}):je?(0,X.jsx)(It,{className:"w-3 h-3"}):(0,X.jsx)(uo,{className:"w-3 h-3"}),je?`Discard ${N.size}?`:`Repair ${N.size}`]}):null,(0,X.jsx)("button",{type:"button",onClick:()=>{Ft()},disabled:Mr,title:"Refresh",className:"p-1.5 rounded-lg text-white/45 hover:text-white/80 hover:bg-white/5 disabled:opacity-40",children:(0,X.jsx)(Ht,{className:`w-3.5 h-3.5 ${Mr?"animate-spin":""}`})}),(0,X.jsx)(_I.SkillLauncher,{variant:"icon",size:"sm",skill:"manage-files",packageId:"@neuralis/brain-core",scripts:["scripts/pending.sh","scripts/approve.sh"],label:"Review or approve pending changes with the agent",icon:"FileText"})]})]}),(0,X.jsxs)("div",{className:"flex flex-wrap items-center gap-2 px-3 py-1.5 border-b border-white/5 shrink-0 text-[11px]",children:[f?(0,X.jsxs)("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded bg-violet-500/15 text-violet-200/90",title:f,children:["conversation ",(0,X.jsx)("button",{type:"button",onClick:()=>i({}),className:"rounded hover:bg-violet-400/20 -mr-0.5",title:"Clear conversation filter",children:(0,X.jsx)(Ut,{className:"w-3 h-3"})})]}):null,(0,X.jsxs)("select",{"aria-label":"Change type",value:w.kind,onChange:C("kind"),className:el,style:tl,children:[(0,X.jsx)("option",{value:"all",children:"All changes"}),(0,X.jsx)("option",{value:"pending",children:"Pending review"}),(0,X.jsx)("option",{value:"git",children:"Git"})]}),(0,X.jsxs)("select",{"aria-label":"Source",value:w.source,onChange:C("source"),className:el,style:tl,children:[(0,X.jsx)("option",{value:"",children:"All sources"}),jt.map(j=>(0,X.jsx)("option",{value:j,children:j},j))]}),(0,X.jsxs)("select",{"aria-label":"Repository",value:w.repo,onChange:C("repo"),className:el,style:tl,children:[(0,X.jsx)("option",{value:"",children:"All repositories"}),oe.map(j=>(0,X.jsx)("option",{value:Xu(j),children:s0(j)},Xu(j)))]}),(0,X.jsxs)("select",{"aria-label":"Checked-out branch",value:w.branch,onChange:C("branch"),className:el,style:tl,children:[(0,X.jsx)("option",{value:"",children:"All checked-out branches"}),[...new Set(oe.map(j=>j.status?.branch).filter(Boolean))].map(j=>(0,X.jsx)("option",{value:j,children:j},j))]}),Kt.length>1?(0,X.jsxs)("select",{"aria-label":"Agent",value:w.agent,onChange:C("agent"),className:el,style:tl,children:[(0,X.jsx)("option",{value:"",children:"All agents"}),Kt.map(j=>(0,X.jsx)("option",{value:j,children:j},j))]}):null,de.length>1?(0,X.jsxs)("select",{"aria-label":"Origin",value:w.origin,onChange:C("origin"),className:el,style:tl,children:[(0,X.jsx)("option",{value:"",children:"All origins"}),de.map(j=>(0,X.jsx)("option",{value:j,children:j},j))]}):null]}),qe.filter(j=>j.error).map(j=>(0,X.jsxs)("div",{className:"px-3 py-2 text-xs text-red-300 shrink-0",children:[s0(j),": ",j.error]},`${j.source}/${j.repo.rel}`)),A?(0,X.jsxs)("div",{className:"mx-3 mt-2 flex items-center gap-2 rounded-lg border border-red-500/25 bg-red-500/10 px-2.5 py-1.5 text-[11px] text-red-200/85 shrink-0",children:[(0,X.jsx)(dt,{className:"w-3.5 h-3.5"})," ",A]}):null,Yn.length?(0,X.jsxs)("div",{className:"mx-3 mt-2 max-h-28 overflow-auto overlay-scroll rounded-lg border border-amber-500/25 bg-amber-500/[0.06] px-2.5 py-1.5 text-[10.5px] text-amber-100/85 shrink-0",children:[(0,X.jsxs)("div",{className:"flex items-center gap-2 font-semibold",children:[pe.length-Yn.length," done \xB7 ",Yn.length," not done",(0,X.jsx)("button",{type:"button",onClick:()=>ee([]),className:"ml-auto rounded hover:bg-white/10",title:"Dismiss",children:(0,X.jsx)(Ut,{className:"w-3 h-3"})})]}),Yn.map(j=>(0,X.jsxs)("div",{className:"truncate font-mono",title:j.detail,children:[j.action," ",j.uri,": ",j.outcome==="changed"?"changed since the preview (409)":j.outcome==="needs-ack"?"needs confirmation":j.detail??"refused"]},j.id))]}):null,(0,X.jsx)("div",{ref:p,className:"flex-1 min-h-0 overflow-auto overlay-scroll px-2 py-2",style:{overflowAnchor:"none"},children:Mr&&Fe.length===0?(0,X.jsxs)("div",{className:"flex items-center gap-2 px-3 py-6 text-xs text-white/40",children:[(0,X.jsx)(ze,{className:"w-3.5 h-3.5 animate-spin"})," Loading\u2026"]}):Fe.length===0?(0,X.jsx)("div",{className:"px-3 py-8 text-center text-xs text-white/35",children:"No pending review changes."}):(0,X.jsx)("div",{style:{height:Ce.getTotalSize(),width:"100%",position:"relative"},children:Ce.getVirtualItems().map(j=>{let ie=Fe[j.index];return ie?(0,X.jsx)("div",{"data-index":j.index,ref:MI(ie.kind)?Ce.measureElement:void 0,className:ie.kind==="pending-row"?"":"pb-1.5",style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${j.start}px)`},children:Rr(ie)},j.key):null})})})]})}var IE=(n,e,t)=>n.end<=(t.scrollOffset??0);var $=W(le(),1),AE=2e5,PE=2500,NE=12e3;function qI(n,e){let t=String(n||"").trim().replace(/\\/g,"/");if(!t)return e;if(t.includes("://")){let s=t.indexOf("://"),o=t.slice(0,s),i=t.slice(s+3).replace(/\/+/g,"/").replace(/^\/+/,"");return`${o}://${i}`}let r=rr(e),a=t.replace(/\/+/g,"/").replace(/^\/+/,"");return a?`${r}${a}`:e}function i0(){let n=B(O=>O.openFiles),e=B(O=>O.activeFile),t=B(O=>O.files),r=B(O=>O.fileContentByPath),a=B(O=>O.fileBaseContentByPath),s=B(O=>O.fileErrorByPath),o=B(O=>O.openFile),i=B(O=>O.patchFileNode),l=B(O=>O.saveFileInPlace),u=B(O=>O.markFileDeleted),c=B(O=>O.clearFilePrev),d=B(O=>O.refresh),f=B(O=>O.activeProjectId),h=B(O=>O.workspacePanels),p=B(O=>O.setWorkspacePanelOpen),m=B(O=>O.activeWorkspaceTab),g=B(O=>O.setActiveWorkspaceTab),x=B(O=>O.gitDiffTarget),w=B(O=>O.setGitDiffTarget),y=B(O=>O.gitCommitTarget),C=B(O=>O.setGitCommitTarget),k=B(O=>O.diffViewMode),v=B(O=>O.activeAgentId),b=hn(),P=b.useAgents(),N=(0,bt.useMemo)(()=>Ns(P),[P]),M=v?N.byId.get(v)??null:null,U=b.MarkdownRenderer,I=e?t[e]:null,A=e?r[e]??"":"",G=I?.uri??"",V=I?RE(G):!1,K=I?ME(G):!1,L=I?TE(G):!1,R=I?DE(G):!1,z=I?EE(G):!1,J=I?Zc(G):void 0,Q=I?FE(G):"Binary file",re=V,[pe,ee]=(0,bt.useState)(!1),[ce,ue]=(0,bt.useState)(""),[He,De]=(0,bt.useState)(""),[je,et]=(0,bt.useState)(!1),[Dt,at]=(0,bt.useState)(null),[vt,Pt]=(0,bt.useState)(!1),[Ye,Ne]=(0,bt.useState)(!1),[tt,Je]=(0,bt.useState)(!1),[Ft,Mt]=(0,bt.useState)(!1),[Te,oe]=(0,bt.useState)(!0),[jt,Kt]=(0,bt.useState)(!1),de=B(O=>O.filePrevByPath),fe=e?de[e]:void 0,qe=!!fe&&I?.status==="pending_review",Re=!!fe,Fe=(0,bt.useMemo)(()=>I?I.sourceAgentId?N.byId.get(I.sourceAgentId)??null:M:null,[I,N,M]),Lt=e?s[e]:void 0,st=!!e&&!oc({fileBaseContentByPath:a,fileErrorByPath:s},e),Le=Lt?`Read failed: ${Lt}`:st?"Loading\u2026":"Empty file",Ee=I?.status==="deleted",Et=h.upload&&m==="upload",qt=h.sources&&m==="sources",Tn=h.packages&&m==="packages",te=h.pending&&m==="pending",Ce=m==="git-diff"&&!!x,Ge=m==="git-commit"&&!!y,Ke=!Et&&!qt&&!Tn&&!te&&!Ce&&!Ge,Ae=I?.sourceAgentId??v??void 0,he=I?.sourceAgentId??v??null,ut=(0,bt.useMemo)(()=>!I?.uri||!Ae?null:ox(Ae,I.uri,f??void 0),[I?.uri,Ae,f]),Qt=(0,bt.useRef)(null),xn=(0,bt.useRef)(null),yn=ed(xn),Nr=k==="auto"?yn?"split":"unified":k,[Kn,Xn]=(0,bt.useState)(void 0),Rr=I?.git;(0,bt.useEffect)(()=>{let O=!1;if(!he||!G||!Rr||K||L||R){Xn(void 0);return}let Pe=Ve(G),D=G.indexOf("://"),me=D>=0?G.slice(D+3):"";if(!Pe||!me){Xn(void 0);return}return(async()=>{try{let Yt=await ec({agentId:he,...f?{projectId:f}:{},source:Pe,path:me,staged:!1});if(O)return;if(Yt&&Yt.ok===!1){Xn(void 0);return}let Ot=typeof Yt?.diff=="string"?Yt.diff:"",Cn=T1(Ot);Xn(sd(Cn)?void 0:Cn)}catch{O||Xn(void 0)}})(),()=>{O=!0}},[he,f,G,Rr,K,L,R]);let Yn=fo(I?.version?.changedAt),Mr=I?.version?.sync,j=!0,ie=!!I&&pe&&(He!==A||qI(ce,I.uri)!==I.uri),Ue=I?.version?.diff,Bt=!!Ue&&(Ue.added>0||Ue.removed>0),Xt=!!I&&vp(I),dn=(0,bt.useMemo)(()=>{if(!I)return"/";if(I.parentUri&&I.parentUri!==I.uri)return I.parentUri;let O=ot(I.uri);return O===I.uri?rr(I.uri):O},[I]),Sn=(0,bt.useMemo)(()=>BE(A),[A]),hr=I?.readSource==="live",Ua=!!I&&!pe&&!K&&!L&&(z||Sn.charCount>=AE||Sn.lineCount>=PE||hr&&Sn.charCount>=NE),Jr=(0,bt.useCallback)(async()=>{if(!(!he||!I||vt)){Pt(!0),at(null);try{await u({agentId:he,projectId:f??null,node:I})}catch(O){console.error("[Filesystem] delete failed",O),at(O instanceof Error?O.message:"Delete failed")}finally{Pt(!1)}}},[he,I,vt,f,u]),Ys=(0,bt.useCallback)(async()=>{if(!(!he||!I||Ye)){Ne(!0);try{let O=await yr({agentId:he,...f?{projectId:f}:{},id:I.id,uri:I.uri,fields:{status:"active"}});if(O&&O.ok===!1){at(ma(O,"Restore failed"));return}d({agentId:he,projectId:f??null}),o({agentId:he,projectId:f??null,uri:I.uri,readAgentId:Fe?.id,force:!0})}catch(O){console.error("[Filesystem] restore failed",O)}finally{Ne(!1)}}},[he,I,Ye,f,d,o,Fe?.id]),Hn=(0,bt.useCallback)(async()=>{if(!(!he||!I||tt)){if(I.status==="pending_review"){p("pending",!0),g("pending");return}Je(!0);try{let O=await ac({agentId:he,...f?{projectId:f}:{},id:I.id,uri:I.uri});if(O&&O.ok){let Pe=I.storeKey||e||Wa(I);Pe&&(i(Pe,{status:"active"}),c(Pe)),o({agentId:he,projectId:f??null,uri:I.uri,readAgentId:Fe?.id,force:!0})}}catch(O){console.error("[Filesystem] approve failed",O)}finally{Je(!1)}}},[he,I,tt,f,o,Fe?.id,e,i,c]),rn=(0,bt.useCallback)(async()=>{if(!(!he||!I||Ft)){if(I.status==="pending_review"){p("pending",!0),g("pending");return}Mt(!0);try{let O=await yr({agentId:he,...f?{projectId:f}:{},id:I.id,uri:I.uri,revert:!0});if(O&&O.ok===!1){at(ma(O,"Revert failed"));return}if(O&&O.ok){let Pe=I.storeKey||e||Wa(I);Pe&&(i(Pe,{status:fe?.status||"active"}),c(Pe)),o({agentId:he,projectId:f??null,uri:I.uri,readAgentId:Fe?.id,force:!0})}}catch(O){console.error("[Filesystem] revert failed",O)}finally{Mt(!1)}}},[he,I,Ft,f,o,Fe?.id,e,fe,i,c]);(0,bt.useEffect)(()=>{if(!I){Qt.current=null,ee(!1),Kt(!1),ue(""),De(""),at(null);return}let O=I.storeKey||e||Wa(I),Pe=Qt.current!==O;if(Qt.current=O,Pe){ee(!1),Kt(!1),oe(!0),ue(I.uri),De(A),at(null);return}pe||(ue(I.uri),De(A),at(null))},[I?.storeKey,I?.uri,A,e,pe]);let Jn=(0,bt.useCallback)(()=>{Xt&&Kt(O=>!O)},[Xt]),pr=(0,bt.useCallback)(()=>{!I||Ee||(ue(I.uri),De(A),at(null),ee(!0))},[I,A,Ee]),E=(0,bt.useCallback)(()=>{I&&(ue(I.uri),De(A),at(null),ee(!1))},[I,A]),ne=(0,bt.useCallback)(async()=>{if(!I||!he||je)return;let O=I.uri,Pe=qI(ce,O);if(!Pe){at("Invalid target URI");return}et(!0),at(null);try{await l({agentId:he,projectId:f??null,readAgentId:Fe?.id,node:I,targetUri:Pe,content:He,currentContent:A}),oe(!0),ee(!1)}catch(D){at(D instanceof Error?D.message:"Save failed")}finally{et(!1)}},[I,he,je,ce,He,A,f,Fe?.id,l]);return(0,$.jsxs)("div",{className:"h-full w-full flex flex-col min-w-0 min-h-0",children:[n.length>0||h.upload||j&&h.sources||h.packages||h.pending||x||y?(0,$.jsxs)("div",{className:"flex shrink-0 items-stretch",style:{backgroundColor:"transparent",borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[(0,$.jsxs)("div",{[od]:"",className:"flex min-w-0 flex-1 overflow-x-auto overflow-y-hidden",children:[(0,$.jsx)(E1,{}),h.upload?(0,$.jsxs)("button",{type:"button",className:q("group flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",Et?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>g("upload"),children:[(0,$.jsx)(Sa,{className:"w-3.5 h-3.5 shrink-0"}),(0,$.jsx)("span",{className:"truncate flex-1",children:"Upload"}),(0,$.jsx)("span",{className:"opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:O=>{O.stopPropagation(),p("upload",!1)},children:(0,$.jsx)(Ut,{className:"w-3 h-3"})})]}):null,j&&h.sources?(0,$.jsxs)("button",{type:"button",className:q("group flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",qt?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>g("sources"),children:[(0,$.jsx)(lo,{className:"w-3.5 h-3.5 shrink-0"}),(0,$.jsx)("span",{className:"truncate flex-1",children:"Sources"}),(0,$.jsx)("span",{className:"opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:O=>{O.stopPropagation(),p("sources",!1)},children:(0,$.jsx)(Ut,{className:"w-3 h-3"})})]}):null,h.packages?(0,$.jsxs)("button",{type:"button",className:q("group flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",Tn?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>g("packages"),children:[(0,$.jsx)(vr,{className:"w-3.5 h-3.5 shrink-0"}),(0,$.jsx)("span",{className:"truncate flex-1",children:"Packages"}),(0,$.jsx)("span",{className:"opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:O=>{O.stopPropagation(),p("packages",!1)},children:(0,$.jsx)(Ut,{className:"w-3 h-3"})})]}):null,h.pending?(0,$.jsxs)("button",{type:"button",className:q("group flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",te?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>g("pending"),children:[(0,$.jsx)(Va,{className:"w-3.5 h-3.5 shrink-0"}),(0,$.jsx)("span",{className:"truncate flex-1",children:"Changes"}),(0,$.jsx)("span",{className:"opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:O=>{O.stopPropagation(),p("pending",!1)},children:(0,$.jsx)(Ut,{className:"w-3 h-3"})})]}):null,x?(0,$.jsxs)("button",{type:"button",className:q("group flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",Ce?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>g("git-diff"),title:`Diff: ${xo(x.repo,x.path)} (${Zv(x)})`,children:[(0,$.jsx)(ar,{className:"w-3.5 h-3.5 shrink-0 text-violet-300/80"}),(0,$.jsx)("span",{className:"truncate flex-1",children:xo(x.repo,yt(x.path)||x.path)}),(0,$.jsx)("span",{className:"opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:O=>{O.stopPropagation(),w(null),Ce&&g("file")},children:(0,$.jsx)(Ut,{className:"w-3 h-3"})})]}):null,y?(0,$.jsxs)("button",{type:"button",className:q("group flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",Ge?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>g("git-commit"),title:y.kind==="commit"?xo(y.repo,`Commit ${tn(y.sha)}: ${y.subject}`):xo(y.repo,`Outgoing changes (${tn(y.base)}..${tn(y.head)})`),children:[y.kind==="commit"?(0,$.jsx)(Or,{className:"w-3.5 h-3.5 shrink-0 text-violet-300/80"}):(0,$.jsx)(Er,{className:"w-3.5 h-3.5 shrink-0 text-blue-300/80"}),(0,$.jsx)("span",{className:"truncate flex-1",children:y.kind==="commit"?xo(y.repo,`${tn(y.sha)} ${y.subject}`):xo(y.repo,"Outgoing changes")}),(0,$.jsx)("span",{className:"opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:O=>{O.stopPropagation(),C(null)},children:(0,$.jsx)(Ut,{className:"w-3 h-3"})})]}):null]}),(0,$.jsx)(B1,{})]}):null,Ke&&I?(0,$.jsxs)("div",{className:"flex items-center justify-between gap-2 px-2 py-1.5 text-[11px]",style:{backgroundColor:"transparent",borderBottom:!jt||!Xt?"1px solid rgba(255,255,255,0.05)":"none"},children:[(0,$.jsxs)("div",{className:q("min-w-0 flex-1 flex items-center gap-2 rounded-lg px-1.5 py-1 transition",Xt?"cursor-pointer hover:bg-white/[0.04]":""),role:Xt?"button":void 0,tabIndex:Xt?0:void 0,"aria-expanded":Xt?jt:void 0,onClick:Jn,onKeyDown:O=>{Xt&&(O.key==="Enter"||O.key===" ")&&(O.preventDefault(),Jn())},children:[Bt?(0,$.jsxs)("span",{className:q("inline-flex shrink-0 items-center gap-1 rounded-full border px-2 py-1 text-[10px]",Yn.pillClassName),children:[(0,$.jsx)(ar,{className:q("w-3 h-3",Yn.iconClassName)}),(0,$.jsxs)("span",{className:"text-emerald-200/95",children:["+",Ue.added]}),(0,$.jsx)("span",{className:"text-white/25",children:"/"}),(0,$.jsxs)("span",{className:"text-rose-200/95",children:["-",Ue.removed]})]}):null,(0,$.jsxs)("div",{className:"min-w-0 flex-1",children:[pe?(0,$.jsx)("input",{value:ce,onChange:O=>ue(O.target.value),onClick:O=>O.stopPropagation(),onKeyDown:O=>O.stopPropagation(),className:"h-7 w-full rounded-md bg-white/[0.04] border border-white/[0.12] px-2 text-[11px] font-mono text-white/85 outline-none focus:border-white/[0.2]",disabled:je}):(0,$.jsxs)("div",{className:"min-w-0 flex items-center gap-2",title:`${Ve(I.uri)} \xB7 ${I.uri}`,children:[(0,$.jsx)("span",{className:q("shrink-0 text-white/88 font-medium",I.status==="deleted"?"line-through text-red-200/70":""),children:I.name}),(0,$.jsx)("span",{className:"truncate font-mono text-white/42",children:dn})]}),Lt?(0,$.jsx)("div",{className:"text-[10px] text-red-300/80 truncate",title:Lt,children:"Read failed"}):null,Dt?(0,$.jsx)("div",{className:"text-[10px] text-red-300/80 truncate",title:Dt,children:Dt}):null]}),Xt?(0,$.jsx)(Tt,{className:q("w-3.5 h-3.5 shrink-0 text-white/35 transition-transform",jt&&"rotate-180")}):null]}),(0,$.jsxs)("div",{className:"flex items-center gap-2",children:[pe?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)("button",{type:"button",className:"inline-flex items-center justify-center rounded-md bg-emerald-500/15 border border-emerald-500/25 p-1.5 text-emerald-100 hover:bg-emerald-500/20 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:ne,disabled:je||!he,"aria-label":"Save changes",children:je?(0,$.jsx)(ze,{className:"w-3 h-3 animate-spin"}):(0,$.jsx)(Dn,{className:"w-3 h-3"})}),(0,$.jsx)("button",{type:"button",className:"inline-flex items-center justify-center rounded-md bg-white/5 p-1.5 text-white/70 hover:bg-white/10 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:E,disabled:je,"aria-label":"Cancel edit",children:(0,$.jsx)(Ut,{className:"w-3 h-3"})})]}):(0,$.jsx)("button",{type:"button",className:"inline-flex items-center justify-center rounded-md bg-white/5 p-1.5 text-white/60 hover:text-white/80 hover:bg-white/10 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:pr,disabled:!he||Ee||R,title:R?"Binary files cannot be edited in-place":"Edit in-place","aria-label":"Edit in-place",children:(0,$.jsx)(ao,{className:"w-3 h-3"})}),(0,$.jsx)("button",{type:"button",className:q("inline-flex items-center justify-center rounded-md p-1.5 transition","border border-red-500/15 bg-red-500/10 text-red-300/70 hover:text-red-200 hover:bg-red-500/15","disabled:opacity-40 disabled:cursor-not-allowed"),onClick:Jr,disabled:!he||vt||Ye,title:"Mark as deleted","aria-label":"Mark as deleted",children:vt?(0,$.jsx)(ze,{className:"w-3 h-3 animate-spin"}):(0,$.jsx)(It,{className:"w-3 h-3"})}),(0,$.jsx)("button",{type:"button",className:"inline-flex items-center justify-center rounded-md bg-white/5 p-1.5 text-white/60 hover:text-white/80 hover:bg-white/10 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>{!he||!I||o({agentId:he,projectId:f??null,uri:I.uri,readAgentId:Fe?.id,force:!0})},title:"Reload file","aria-label":"Reload file",children:(0,$.jsx)(Ht,{className:"w-3 h-3"})}),!pe&&Re&&I?.status!=="pending_review"?(0,$.jsx)("button",{type:"button",className:"inline-flex items-center justify-center rounded-md bg-white/5 p-1.5 text-white/60 hover:text-white/80 hover:bg-white/10 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:rn,disabled:Ft||tt||!he,title:"Undo to previous version","aria-label":"Undo to previous version",children:Ft?(0,$.jsx)(ze,{className:"w-3 h-3 animate-spin"}):(0,$.jsx)(ka,{className:"w-3 h-3"})}):null]})]}):null,Ke&&I&&jt&&Xt?(0,$.jsx)(wp,{node:I,hideVersionDiff:!0}):null,Ke&&I&&ie?(0,$.jsxs)("div",{className:"flex items-center justify-between gap-3 px-2 py-2",style:{background:"linear-gradient(90deg, rgba(56,189,248,0.08) 0%, rgba(56,189,248,0.02) 100%)",borderBottom:"1px solid rgba(56,189,248,0.16)"},children:[(0,$.jsxs)("div",{className:"flex items-center gap-2 text-[11px] text-sky-100/85",children:[(0,$.jsx)($a,{className:"w-3.5 h-3.5 text-sky-300/75"}),(0,$.jsx)("span",{children:"Local draft in progress"})]}),(0,$.jsx)("div",{className:"text-[10px] text-sky-100/55",children:"Save or cancel to resolve the draft state"})]}):null,Ke&&I&&qe&&!pe?(0,$.jsxs)("div",{className:"flex items-center justify-between gap-3 px-2 py-2",style:{background:"linear-gradient(90deg, rgba(251,191,36,0.08) 0%, rgba(244,63,94,0.03) 100%)",borderBottom:"1px solid rgba(251,191,36,0.18)"},children:[(0,$.jsxs)("div",{className:"flex items-center gap-2 text-[11px] text-amber-200/80",children:[(0,$.jsx)(ar,{className:"w-3.5 h-3.5 text-amber-400/70"}),(0,$.jsx)("span",{children:"Pending changes \u2014 review and approve or revert"})]}),(0,$.jsxs)("div",{className:"flex items-center gap-2",children:[(0,$.jsxs)("button",{type:"button",className:q("inline-flex items-center gap-1 rounded-md px-2 py-1 text-[11px] transition",Te?"bg-amber-500/15 border border-amber-500/25 text-amber-100":"bg-white/5 text-white/50 hover:bg-white/10 hover:text-white/70"),onClick:()=>oe(!Te),children:[(0,$.jsx)(ar,{className:"w-3 h-3"}),"Diff"]}),Te?(0,$.jsx)(nd,{}):null,(0,$.jsxs)("button",{type:"button",className:"inline-flex items-center gap-1 rounded-md bg-emerald-500/15 border border-emerald-500/25 px-2 py-1 text-[11px] text-emerald-100 hover:bg-emerald-500/20 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:Hn,disabled:tt||Ft||!he,title:"Accept current state",children:[tt?(0,$.jsx)(ze,{className:"w-3 h-3 animate-spin"}):(0,$.jsx)(Dn,{className:"w-3 h-3"}),"Approve"]}),(0,$.jsxs)("button",{type:"button",className:"inline-flex items-center gap-1 rounded-md bg-red-500/10 border border-red-500/20 px-2 py-1 text-[11px] text-red-200/80 hover:bg-red-500/15 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:rn,disabled:tt||Ft||!he,title:"Revert to previous version",children:[Ft?(0,$.jsx)(ze,{className:"w-3 h-3 animate-spin"}):(0,$.jsx)(ka,{className:"w-3 h-3"}),"Revert"]})]})]}):null,Ke&&I&&!pe&&I.presence==="stale_indexed"?(0,$.jsxs)("div",{className:"flex items-center justify-between gap-3 px-2 py-2",style:{background:"linear-gradient(90deg, rgba(244,114,182,0.08) 0%, rgba(251,191,36,0.03) 100%)",borderBottom:"1px solid rgba(244,114,182,0.15)"},children:[(0,$.jsxs)("div",{className:"flex items-center gap-2 text-[11px] text-rose-100/85",children:[(0,$.jsx)(Ka,{className:"w-3.5 h-3.5 text-rose-300/75"}),(0,$.jsx)("span",{children:"This indexed node is missing from the live source"})]}),(0,$.jsx)("div",{className:"text-[10px] text-rose-100/55",children:"Useful for spotting sync drift"})]}):null,Ke&&I&&!pe&&I.presence==="unindexed"?(0,$.jsx)("div",{className:"flex items-center justify-between gap-3 px-2 py-2",style:{background:"linear-gradient(90deg, rgba(251,191,36,0.07) 0%, rgba(255,255,255,0.02) 100%)",borderBottom:"1px solid rgba(251,191,36,0.15)"},children:(0,$.jsxs)("div",{className:"flex items-center gap-2 text-[11px] text-amber-100/82",children:[(0,$.jsx)(dt,{className:"w-3.5 h-3.5 text-amber-300/75"}),(0,$.jsx)("span",{children:"Unindexed \u2014 file exists on the connector but is not yet vector-indexed"})]})}):null,(0,$.jsxs)("div",{ref:xn,className:"flex-1 min-h-0 relative",children:[Et&&v?(0,$.jsx)("div",{className:"w-full h-full overflow-y-auto",children:(0,$.jsx)(zg,{agentId:v,projectId:f??null})}):null,j&&qt&&v?(0,$.jsx)("div",{className:"w-full h-full overflow-y-auto",children:(0,$.jsx)(oI,{agentId:v,projectId:f??null,isDocker:b.isDocker})}):null,Tn&&f?(0,$.jsx)("div",{className:"w-full h-full overflow-y-auto",children:(0,$.jsx)(pI,{projectId:f})}):null,te&&v?(0,$.jsx)("div",{className:"w-full h-full min-h-0",children:(0,$.jsx)(jI,{agentId:v,projectId:f??null})}):null,Ce&&x?(0,$.jsx)("div",{className:"w-full h-full min-h-0",children:(0,$.jsx)(Ug,{target:x,agentId:v,projectId:f??null})}):null,Ge&&y?(0,$.jsx)("div",{className:"w-full h-full min-h-0",children:(0,$.jsx)(lp,{target:y,agentId:v,projectId:f??null})}):null,Ke&&Ee?(0,$.jsxs)("div",{className:"absolute inset-x-4 top-4 z-10 rounded-xl border border-red-500/25 bg-black/70 p-3 backdrop-blur-sm",children:[(0,$.jsx)("div",{className:"text-[11px] text-red-200/85 mb-2",children:"This file is marked as deleted."}),(0,$.jsxs)("div",{className:"flex items-center gap-2",children:[(0,$.jsxs)("button",{type:"button",className:"h-8 px-3 rounded-lg text-xs font-semibold border border-emerald-500/30 bg-emerald-500/15 text-emerald-100 hover:bg-emerald-500/20 disabled:opacity-50 disabled:cursor-not-allowed",onClick:Ys,disabled:!he||Ye||vt,children:[Ye?(0,$.jsx)(ze,{className:"w-3 h-3 animate-spin inline mr-1"}):null,"Restore"]}),(0,$.jsxs)("button",{type:"button",className:"h-8 px-3 rounded-lg text-xs font-semibold border border-red-500/30 bg-red-500/15 text-red-100 hover:bg-red-500/20 disabled:opacity-50 disabled:cursor-not-allowed",onClick:Jr,disabled:!he||vt||Ye,children:[vt?(0,$.jsx)(ze,{className:"w-3 h-3 animate-spin inline mr-1"}):null,"Delete"]})]})]}):null,Ke&&I?qe&&Te&&fe&&!pe?(0,$.jsx)(Rg,{oldContent:fe.content,newContent:A,language:J,viewMode:Nr,className:"w-full h-full min-h-0"}):R&&!K&&!L&&!pe?(0,$.jsx)("div",{className:q("w-full h-full min-h-0 flex items-center justify-center px-6 text-center",Ee&&"blur-[2px] opacity-65"),children:(0,$.jsxs)("div",{className:"max-w-md rounded-2xl border border-white/10 bg-white/[0.035] px-5 py-4 shadow-[0_18px_46px_-26px_rgba(0,0,0,0.65)]",children:[(0,$.jsx)(dt,{className:"w-6 h-6 mx-auto mb-3 text-amber-300/75"}),(0,$.jsxs)("div",{className:"text-sm font-semibold text-white/82",children:[Q," preview disabled"]}),(0,$.jsx)("div",{className:"mt-2 text-xs leading-5 text-white/45",children:"This file is treated as binary, so Neuralis will not decode it into the text editor."})]})}):K&&ut&&!pe?(0,$.jsx)("div",{className:"w-full h-full min-h-0 overflow-auto px-2 py-1.5",children:(0,$.jsxs)("div",{className:q(Ee&&"blur-[2px] opacity-65"),children:[(0,$.jsx)("div",{className:"text-[11px] text-white/45 mb-3",children:"Image preview"}),(0,$.jsx)("img",{src:ut,alt:I.name,className:"max-w-full max-h-[calc(100vh-220px)] rounded-xl bg-black/20 shadow-[0_18px_46px_-26px_rgba(0,0,0,0.65),inset_0_1px_0_rgba(255,255,255,0.06)]"})]})}):L&&ut&&!pe?(0,$.jsx)("div",{className:"w-full h-full min-h-0 overflow-auto px-2 py-1.5",children:(0,$.jsxs)("div",{className:q(Ee&&"blur-[2px] opacity-65"),children:[(0,$.jsx)("div",{className:"text-[11px] text-white/45 mb-3",children:"Video preview"}),(0,$.jsx)("video",{src:ut,controls:!0,className:"w-full max-w-[1100px] rounded-xl bg-black/20 shadow-[0_18px_46px_-26px_rgba(0,0,0,0.65),inset_0_1px_0_rgba(255,255,255,0.06)]"})]})}):V&&U&&!Ua&&!pe?(0,$.jsx)("div",{className:q("w-full h-full min-h-0 overflow-auto px-1 py-1 text-white/80",Ee&&"blur-[2px] opacity-65"),children:A?(0,$.jsx)("div",{className:"min-h-full min-w-0",children:(0,$.jsx)(U,{content:A})}):(0,$.jsx)("div",{className:"px-2 py-1.5 text-sm text-white/30",children:Le})}):(0,$.jsx)(Hg,{value:pe?He:A,language:J,readOnly:!pe||Ee||je,wrap:re,onChange:pe?De:void 0,className:q("w-full h-full min-h-0",Ee&&"opacity-65"),placeholder:Le,ariaLabel:pe?"File content editor":"File content viewer",gitLineStatus:Kn}):Ke?(0,$.jsxs)("div",{className:"absolute inset-0 flex flex-col items-center justify-center text-white/20",children:[(0,$.jsx)(vl,{className:"w-12 h-12 mb-2 opacity-50"}),(0,$.jsx)("div",{className:"text-sm",children:Et?"Upload files using this tab":"No file open"})]}):null,Ke&&I?(0,$.jsxs)("div",{className:"pointer-events-none absolute bottom-2 right-3 z-10 text-[10px] text-white/42",children:[(0,$.jsxs)("span",{children:[Sn.lineCount.toLocaleString()," lines"]}),(0,$.jsxs)("span",{className:"ml-3",children:[Sn.charCount.toLocaleString()," chars"]})]}):null]})]})}function RE(n){let e=yt(n).toLowerCase();return e.endsWith(".md")||e.endsWith(".mdx")||e.endsWith(".markdown")}function ME(n){let e=yt(String(n||"")).toLowerCase();return e.endsWith(".png")||e.endsWith(".jpg")||e.endsWith(".jpeg")||e.endsWith(".webp")||e.endsWith(".gif")}function TE(n){let e=yt(String(n||"")).toLowerCase();return e.endsWith(".mp4")||e.endsWith(".webm")||e.endsWith(".mov")||e.endsWith(".m4v")}function DE(n){let e=yt(String(n||"")).toLowerCase();return/\.(wasm|png|jpe?g|gif|webp|ico|bmp|mp4|webm|avi|mov|m4v|mkv|mp3|wav|ogg|flac|aac|zip|tar|gz|bz2|7z|rar|pdf|docx?|xlsx?|pptx?|exe|dll|so|dylib|ttf|otf|woff2?|eot)$/.test(e)}function FE(n){let e=yt(String(n||"")).toLowerCase();return e.endsWith(".wasm")?"WebAssembly binary":e.endsWith(".pdf")?"PDF":"Binary file"}function EE(n){let e=yt(String(n||"")).toLowerCase();return e.endsWith(".jsonl")||e.endsWith(".ndjson")||e.endsWith(".log")}function BE(n){if(!n)return{charCount:0,lineCount:0};let e=1;for(let t=0;t<n.length;t++)n.charCodeAt(t)===10&&(e+=1);return{charCount:n.length,lineCount:e}}var ls="brain://project-info",b$=[{kind:"docs",label:"Upload Docs",folderUri:`${ls}/docs`,accept:".md,.txt,.pdf,.doc,.docx"},{kind:"requirements",label:"Upload Requirements",folderUri:`${ls}/requirements`,accept:".md,.txt,.pdf"},{kind:"architecture",label:"Upload Architecture",folderUri:`${ls}/architecture`,accept:".md,.txt,.pdf,.drawio,.json,.yaml,.yml"},{kind:"design",label:"Upload Design",folderUri:`${ls}/design`,accept:".md,.txt,.pdf,.fig,.png,.jpg,.jpeg,.webp"},{kind:"assets",label:"Upload Assets",folderUri:`${ls}/assets`,accept:".png,.jpg,.jpeg,.webp,.svg,.gif"},{kind:"datasets",label:"Upload Datasets",folderUri:`${ls}/datasets`,accept:".csv,.json,.jsonl,.parquet,.txt,.zip"},{kind:"other",label:"Upload File",folderUri:`${ls}/misc`}];var cn=W($e(),1);var VI=250,OE=1e3,_E=2e3,HE=6e3,UE=1e3,GE=5e3,zE=["filesystem:created","filesystem:updated","filesystem:deleted","filesystem:reverted","sync:completed","pending:changed"],WE=new Set(zE),jE=["filesAdded","filesUpdated","filesRemoved","filesMoved","chunksRemoved"];function qE(n){return n.mode==="purge"?!1:jE.every(e=>n[e]===0)}function $I(n,e){let t=B(A=>A.refreshTree),r=B(A=>A.refresh),a=B(A=>A.ensureFolderLoaded),s=B(A=>A.reconcileSourceFolders),o=B(A=>A.reconcileFolders),i=B(A=>A.setSourceDirty),l=B(A=>A.upsertFileNodeFromEvent),u=B(A=>A.incrementFolderBadges),c=B(A=>A.replaceFilePath),d=B(A=>A.clearFilePrev),f=B(A=>A.autoExpandToFile),h=B(A=>A.loadGitStatus),p=B(A=>A.notifyGitLogChanged),m=B(A=>A.refreshPendingCount),g=(0,cn.useRef)(0),x=(0,cn.useRef)(new Map),w=(0,cn.useRef)(new Map),y=(0,cn.useRef)(new Map);(0,cn.useEffect)(()=>{let A=x.current,G=y.current;return()=>{for(let V of A.values())clearTimeout(V);A.clear();for(let V of G.values())clearTimeout(V);G.clear()}},[n,e]),(0,cn.useEffect)(()=>{let A=w.current;return()=>{g.current+=1;for(let G of A.values())clearTimeout(G.timer);A.clear()}},[n,e]);let C=(0,cn.useRef)(null),k=(0,cn.useCallback)(()=>{if(!n||!e)return;let A=Date.now(),G=C.current,V=G?G.deadline:A+GE;G&&clearTimeout(G.timer);let K=setTimeout(()=>{C.current=null,!(typeof document<"u"&&document.visibilityState==="hidden")&&m({agentId:n,projectId:e})},Math.max(0,Math.min(UE,V-A)));C.current={timer:K,deadline:V}},[n,e,m]),v=(0,cn.useRef)(k);v.current=k;let b=B(A=>A.activeAgentId===n&&A.activeProjectId===e);(0,cn.useEffect)(()=>{n&&e&&b&&m({agentId:n,projectId:e})},[n,e,b,m]),(0,cn.useEffect)(()=>{if(!n||!e)return;let A=()=>{document.visibilityState!=="hidden"&&v.current()},G=()=>v.current();return document.addEventListener("visibilitychange",A),window.addEventListener("focus",G),()=>{document.removeEventListener("visibilitychange",A),window.removeEventListener("focus",G),C.current&&clearTimeout(C.current.timer),C.current=null}},[n,e,m]);let P=(0,cn.useCallback)(A=>{let{type:G,payload:V}=A,K=ee=>{if(!n||!ee)return;let ce=B.getState().activeSource,ue=typeof ce=="string"&&ce?ce.includes("://")?Ve(ce):ce:"",He=y.current,De=He.get(ee);De&&clearTimeout(De),He.set(ee,setTimeout(()=>{He.delete(ee),B.setState(je=>({sourceChangeRevision:{...je.sourceChangeRevision,[ee]:(je.sourceChangeRevision[ee]??0)+1}})),ue===ee&&h({agentId:n,projectId:e,source:ee})},VI))},L=ee=>{if(!n)return;let ce=w.current,ue=Date.now(),He=ce.get(ee),De=He?He.deadline:ue+HE;He&&clearTimeout(He.timer);let je=setTimeout(()=>{ce.delete(ee),s({agentId:n,projectId:e,source:ee})},Math.max(0,Math.min(_E,De-ue)));ce.set(ee,{timer:je,deadline:De})};if(G==="sync:completed"){if(!n)return;let ee=typeof V.source=="string"?V.source:void 0;if(ee&&qE(V)){K(ee);return}ee?(B.getState().loadedFolders?.[`${ee}://`]?L(ee):i(ee,!0),K(ee)):t({agentId:n,projectId:e});return}if(V.changeType==="badge"){if(!n)return;let ee=B.getState().activeAgentId;if(ee&&ee!==n)return;let ce=typeof V.source=="string"&&V.source?V.source:Ve(typeof V.uri=="string"?V.uri:"");if(!ce)return;let ue=x.current,He=ue.get(ce);He&&clearTimeout(He),ue.set(ce,setTimeout(()=>{ue.delete(ce),B.setState(et=>({sourceChangeRevision:{...et.sourceChangeRevision,[ce]:(et.sourceChangeRevision[ce]??0)+1}})),a({agentId:n,projectId:e,uri:`${ce}://`,force:!0}),r({agentId:n,projectId:e});let De=B.getState().activeSource;(typeof De=="string"&&De?De.includes("://")?Ve(De):De:"")===ce&&h({agentId:n,projectId:e,source:ce}),p(ce)},VI));return}if(V.external===!0){if(!n)return;let ee=B.getState().activeAgentId;if(ee&&ee!==n)return;let ce=typeof V.source=="string"&&V.source?V.source:Ve(typeof V.uri=="string"?V.uri:"");if(!ce)return;if(K(ce),!B.getState().loadedFolders?.[`${ce}://`]){i(ce,!0);return}L(ce);return}let R=V.uri;if(!R)return;let z=V.changeType,J=Array.isArray(V.folder_ancestors)&&V.folder_ancestors.length>0?V.folder_ancestors:ga(R);J.length>0&&u(J),Array.isArray(V.new_folder_ancestors)&&V.new_folder_ancestors.length>0&&u(V.new_folder_ancestors);let Q=typeof V.action=="string"?V.action:void 0,re={id:V.id,uri:R,folder_ancestors:J,sourceAgentId:A.agentId,sourceProjectId:A.projectId},pe=ee=>{if(!n)return;let ce=Array.from(new Set(ee.filter(ue=>typeof ue=="string"&&!!ue).map(ue=>ot(ue))));ce.length>0&&o({agentId:n,projectId:e,folders:ce})};switch(G){case"filesystem:created":case"filesystem:updated":l({...re,status:V.status}),V.status==="pending_review"&&f(R),V.newUri&&(c(R,V.newUri),l({...re,uri:V.newUri,folder_ancestors:V.new_folder_ancestors,status:V.status})),Q==="review_approved"&&V.status==="active"&&d(R),z==="structure"&&pe([R,V.newUri]);break;case"filesystem:deleted":l({...re,status:"deleted"}),z==="structure"&&pe([R]);break;case"filesystem:reverted":l({...re,status:V.status||"active"}),d(R),pe([R]);break}K(Ve(R))},[n,e,t,r,a,s,o,i,l,u,c,d,f,h,p]),N=(0,cn.useRef)(P);N.current=P;let M=(0,cn.useRef)(null),U=(0,cn.useCallback)(()=>{if(!n)return;let A=g.current;M.current&&clearTimeout(M.current),M.current=setTimeout(()=>{M.current=null,A===g.current&&(async()=>{try{await r({agentId:n,projectId:e})}catch{return}if(A!==g.current)return;v.current();let G=B.getState();B.setState(K=>({sourceChangeRevision:Object.fromEntries(K.sources.map(L=>[Ve(L.uri_root),(K.sourceChangeRevision[Ve(L.uri_root)]??0)+1]))}));let V=new Set;for(let[K,L]of Object.entries(G.loadedFolders||{})){if(!L)continue;let R=Ve(K);R&&V.add(R)}await Promise.all(Array.from(V).map(K=>s({agentId:n,projectId:e,source:K})))})()},OE)},[n,e,r,s]),I=(0,cn.useRef)(U);I.current=U,(0,cn.useEffect)(()=>{let A=M;return()=>{A.current&&clearTimeout(A.current)}},[n,e]),(0,cn.useEffect)(()=>{if(!n||!e)return;let A=Zb();if(A?.subscribeFilesystemEvents)return A.subscribeFilesystemEvents(n,e,G=>{let V=G;if(!V||typeof V!="object"||!WE.has(V.type)||!V.payload||typeof V.payload!="object")return;if(V.type==="pending:changed"){v.current();return}let K=V.payload.changeType==="badge",L=V.payload.external===!0;!K&&!L&&V.agentId!==n||N.current(V)},()=>I.current())},[n,e])}var Ef=W(mr(),1);var kn=W(le(),1);function l0(n){let e=B(R=>R.sidebarOpen),t=B(R=>R.sidebarWidth),r=B(R=>R.setSidebarWidth),a=B(R=>R.loadList),s=B(R=>R.refreshTree),o=B(R=>R.applyNav),i=B(R=>R.searchQuery),l=B(R=>R.setSearchQuery),u=B(R=>R.clearSearch),c=B(R=>R.sidebarView),d=B(R=>R.setSidebarView),f=(0,Mn.useRef)(null),h=(0,Mn.useRef)(null),p=(0,Mn.useRef)(null),[m,g]=(0,Mn.useState)(!1),x=hn(),w=(0,Ef.useWorkspaceHostPort)(),y=B(R=>R.activeProjectId),C=n.projectId??y,k=x.useFileMarks(n.agentId),v=x.useAgents(),b=(0,Mn.useMemo)(()=>Ns(v),[v]),P=n.agentId?b.byId.get(n.agentId):null,N=P?.name||P?.slug,M=P?.config?.appearance?.icon,U=ui(P?.id,b),I=(0,Mn.useMemo)(()=>{let R=k||{},z=0;for(let J of Object.keys(R)){let Q=R[J]?.ts??0;Q>z&&(z=Q)}return z},[k]);$I(n.agentId,C),(0,Mn.useEffect)(()=>{n.agentId&&a({agentId:n.agentId,projectId:C,userId:n.userId??null})},[n.agentId,C,n.userId]),(0,Mn.useEffect)(()=>{if(!n.agentId)return;let R=n.state?.nav;if(!R)return;let z=JSON.stringify(R);f.current!==z&&(f.current=z,w&&n.widgetId&&(0,Ef.consumeWidgetNav)(w,{agentId:n.agentId,widgetId:n.widgetId}),o({agentId:n.agentId,projectId:C,nav:R,readAgentId:n.agentId}))},[o,n.agentId,C,n.state,w,n.widgetId]);let A=(0,Mn.useRef)(!1);(0,Mn.useEffect)(()=>{if(!n.agentId||!I||A.current)return;let R=setTimeout(()=>{A.current=!0,s({agentId:n.agentId,projectId:C}).finally(()=>{A.current=!1})},1500);return()=>clearTimeout(R)},[I,C,n.agentId,s]);let G=8,V=(0,Mn.useCallback)(R=>{R.preventDefault(),p.current={startX:R.clientX,startWidth:t},g(!0),R.currentTarget.setPointerCapture(R.pointerId)},[t]),K=(0,Mn.useCallback)(R=>{let z=p.current;if(!z)return;let J=h.current,Q=J?Math.max(ul,J.clientWidth-G):z.startWidth,re=Math.min(Q,Math.max(ul,z.startWidth+(R.clientX-z.startX)));r(re)},[r]),L=(0,Mn.useCallback)(R=>{p.current&&(p.current=null,g(!1),R.currentTarget.releasePointerCapture(R.pointerId))},[]);return(0,kn.jsxs)("div",{className:"flex flex-col w-full h-full overflow-hidden transition-colors duration-300",children:[(0,kn.jsx)(gh,{agentId:n.agentId,agentName:N,agentIcon:M,agentAccent:U,supportsSources:!0,onOpenProjectFiles:()=>{o({agentId:n.agentId,projectId:C,nav:{kind:"filesystem",action:"list",uri:ls}})}}),(0,kn.jsxs)("div",{ref:h,className:`flex-1 min-h-0 flex flex-row ${m?"select-none cursor-col-resize":""}`,children:[(0,kn.jsxs)("div",{className:"h-full flex flex-col min-h-0 shrink-0 overflow-hidden",style:{width:e?t:0,backgroundColor:"transparent",borderRight:e?"1px solid rgba(255,255,255,0.05)":"none"},children:[(0,kn.jsxs)("div",{className:"px-2 pt-2 pb-1 flex items-center justify-between",children:[(0,kn.jsx)("div",{className:"text-[10px] text-white/40 font-bold uppercase tracking-wider shrink-0",children:c==="git"?"Git Control":c==="search"?"Search":"Explorer"}),c==="search"?(0,kn.jsx)("input",{type:"text",value:i,onChange:R=>l(R.target.value),onKeyDown:R=>{R.key==="Escape"&&(u(),d("tree"))},placeholder:"Search\u2026",autoFocus:!0,"aria-label":"Search query",className:"flex-1 min-w-0 mx-2 h-6 bg-transparent border-0 text-xs text-white/85 placeholder:text-white/30 outline-none"}):null,(0,kn.jsxs)("div",{className:"flex items-center gap-0.5 shrink-0",children:[(0,kn.jsx)("button",{type:"button",onClick:()=>{c==="search"?(u(),d("tree")):d("search")},className:`h-6 w-6 rounded-md inline-flex items-center justify-center transition-colors ${c==="search"?"text-white/85":"text-white/40 hover:text-white/70"}`,title:"Search in explorer","aria-label":"Toggle explorer search","aria-pressed":c==="search",children:(0,kn.jsx)(Fl,{className:"w-3.5 h-3.5"})}),(0,kn.jsx)("button",{type:"button",onClick:()=>d(c==="git"?"tree":"git"),className:`h-6 w-6 rounded-md inline-flex items-center justify-center transition-colors ${c==="git"?"text-violet-300/90":"text-white/40 hover:text-white/70"}`,title:"Git Control","aria-label":"Toggle Git Control panel","aria-pressed":c==="git",children:(0,kn.jsx)(Ln,{className:"w-3.5 h-3.5"})})]})]}),(0,kn.jsx)(mp,{agentId:n.agentId,sidebarView:c})]}),e&&(0,kn.jsx)("div",{role:"separator","aria-orientation":"vertical",onPointerDown:V,onPointerMove:K,onPointerUp:L,className:"w-2 shrink-0 cursor-col-resize bg-white/0 hover:bg-white/[0.06] transition relative touch-none",children:(0,kn.jsx)("div",{className:"absolute inset-y-6 left-1/2 -translate-x-1/2 w-[2px] rounded-full bg-white/[0.07]"})}),(0,kn.jsx)("div",{className:"flex-1 min-w-0 min-h-0",children:(0,kn.jsx)(i0,{})})]})]})}var $n=W($e(),1),_f=W(Qr(),1),al=W(Qr(),1),s2=W(YI(),1);var jo=W($e(),1);var Bf=W(Qr(),1);var Oa=W(le(),1),VE=27,d0=90,$E=17,KE=12,XE=1.4,YE=18,c0=32,JI=new WeakMap;function ZI(n,e){let t=JI.get(n);if(t&&t.status===e)return t;let r={status:e};return JI.set(n,r),r}function JE(n,e){let t=ZI(n,e);if(t.compact!==void 0)return t.compact;let r=String(e??"").toLowerCase(),a=r==="pending"||r.includes("pending"),s;if(a)s=c0;else{let o=Qi(n.input),i=o&&typeof o.action=="string"?o.action:void 0;if(i&&!Zi(i))s=c0;else if(Zi(i))s=d0;else{let l=0;try{let u=o?Ku(o):null;l=u?u.added+u.removed:0}catch{l=0}s=l<=0?c0:Math.min(d0,l*YE)}}return t.compact=s,s}function ZE(n,e){let t=ZI(n,e);if(t.expanded!==void 0)return t.expanded;let r=Qi(n.input)??{},a=0;try{let o=Ku(r);a=o?o.added+o.removed:0}catch{a=0}let s=Math.max(d0,KE+Math.ceil(a*XE)*$E);return t.expanded=s,s}function QI(n){let e=n.disclosure===!0?ZE(n.tool,n.status):JE(n.tool,n.status);return VE+e}var Of=(0,jo.memo)(function({uri:e,lineCounts:t,isPending:r,reviewPending:a,isError:s,isInterrupted:o,onUriClick:i,children:l}){let u=(0,jo.useMemo)(()=>r?"pending":o?"interrupted":s?"error":"committed",[r,s,o]),c=a&&u==="committed"?"pending review":u,d=(0,jo.useCallback)(()=>{e&&i&&i(e)},[e,i]),f=(0,jo.useCallback)(()=>(0,Oa.jsxs)("div",{className:`px-3 py-1 flex items-center gap-2 min-w-0 ${e&&i?"cursor-pointer hover:bg-white/[0.04] transition":""}`,onClick:d,role:e&&i?"button":void 0,title:e||void 0,children:[(0,Oa.jsx)(ba,{className:"w-3 h-3 text-white/40 shrink-0"}),(0,Oa.jsx)("span",{className:"flex-1 min-w-0 text-[11px] text-white/60 font-mono truncate",children:e||"file"}),t&&(0,Oa.jsxs)("span",{className:"shrink-0 flex items-center gap-1.5 text-[10px] font-mono",children:[t.added>0&&(0,Oa.jsxs)("span",{className:"text-emerald-400",children:["+",t.added]}),t.removed>0&&(0,Oa.jsxs)("span",{className:"text-red-400",children:["-",t.removed]})]}),(0,Oa.jsx)(Bf.ToolStatusIcon,{isPending:r,isError:s,isInterrupted:o,statusLabel:c})]}),[e,i,d,t,r,s,o,c]);return(0,Oa.jsx)(Bf.CardShell,{label:e||"file",status:u,defaultMode:"compact",compactHeight:90,renderHeader:f,children:l})});var t2=W($e(),1);var rt=W(le(),1),n2=(0,t2.memo)(function({action:e,input:t}){switch(e){case"set_fields":return(0,rt.jsx)(QE,{fields:t.fields});case"move":return(0,rt.jsx)(eB,{uri:nl(t,"uri")||nl(t,"id"),destination:nl(t,"destination")});case"copy":return(0,rt.jsx)(tB,{uri:nl(t,"uri"),destination:nl(t,"destination")});case"create_folder":return(0,rt.jsx)(nB,{uri:nl(t,"uri")});case"delete":return(0,rt.jsx)(rB,{});case"revert":return(0,rt.jsx)(aB,{});default:return(0,rt.jsx)(sB,{action:e,input:t})}});function QE({fields:n}){if(!n||typeof n!="object")return(0,rt.jsx)(e2,{icon:(0,rt.jsx)(ri,{className:"w-3 h-3"}),text:"Updated fields"});let e=[];for(let[t,r]of Object.entries(n))if(r!==void 0)if(t==="tags"&&r&&typeof r=="object"){let a=r,s=[];Array.isArray(a.add)&&a.add.length&&s.push(a.add.map(o=>`+${o}`).join(" ")),Array.isArray(a.remove)&&a.remove.length&&s.push(a.remove.map(o=>`-${o}`).join(" ")),Array.isArray(a.set)&&s.push(a.set.join(", ")),e.push({key:"tags",value:s.join(" ")||"(cleared)"})}else if(t==="metadata"&&r&&typeof r=="object"){let a=Object.entries(r).map(([s,o])=>o===null?`${s}: (removed)`:`${s}: ${String(o)}`).join(", ");e.push({key:"metadata",value:a||"(empty)"})}else e.push({key:t,value:r===null?"(cleared)":String(r)});return(0,rt.jsxs)("div",{className:"px-3 py-2 space-y-0.5",children:[e.map(t=>(0,rt.jsxs)("div",{className:"flex gap-2 text-[11px]",children:[(0,rt.jsxs)("span",{className:"text-white/45 shrink-0",children:[t.key,":"]}),(0,rt.jsx)("span",{className:"text-white/75 break-all",children:t.value})]},t.key)),e.length===0&&(0,rt.jsx)(e2,{icon:(0,rt.jsx)(ri,{className:"w-3 h-3"}),text:"Updated fields"})]})}function eB({uri:n,destination:e}){return(0,rt.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2 text-[11px] font-mono",children:[(0,rt.jsx)("span",{className:"text-white/50 truncate",children:n||"?"}),(0,rt.jsx)(ti,{className:"w-3 h-3 text-white/35 shrink-0"}),(0,rt.jsx)("span",{className:"text-white/75 truncate",children:e||"?"})]})}function tB({uri:n,destination:e}){return(0,rt.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2 text-[11px] font-mono",children:[(0,rt.jsx)(ra,{className:"w-3 h-3 text-sky-400/60 shrink-0"}),(0,rt.jsx)("span",{className:"text-white/50 truncate",children:n||"?"}),(0,rt.jsx)(ti,{className:"w-3 h-3 text-white/35 shrink-0"}),(0,rt.jsx)("span",{className:"text-white/75 truncate",children:e||"?"})]})}function nB({uri:n}){return(0,rt.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2 text-[11px] font-mono",children:[(0,rt.jsx)(wr,{className:"w-3 h-3 text-sky-300/70 shrink-0"}),(0,rt.jsx)("span",{className:"text-white/75 truncate",children:n||"?"})]})}function rB(){return(0,rt.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2",children:[(0,rt.jsx)(It,{className:"w-3 h-3 text-rose-400/70"}),(0,rt.jsx)("span",{className:"text-[11px] text-rose-300/80",children:"Deleted"})]})}function aB(){return(0,rt.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2",children:[(0,rt.jsx)(oo,{className:"w-3 h-3 text-amber-400/70"}),(0,rt.jsx)("span",{className:"text-[11px] text-white/70",children:"Reverted to previous version"})]})}function sB({action:n,input:e}){let t=Object.entries(e).filter(([r])=>r!=="action"&&r!=="id"&&r!=="uri").slice(0,5).map(([r,a])=>`${r}: ${typeof a=="string"?a.slice(0,60):JSON.stringify(a)?.slice(0,60)??"?"}`).join(", ");return(0,rt.jsxs)("div",{className:"px-3 py-2 text-[11px] text-white/60",children:[(0,rt.jsx)("span",{className:"text-white/45 mr-1",children:n}),t&&(0,rt.jsx)("span",{className:"text-white/50",children:t})]})}function e2({icon:n,text:e}){return(0,rt.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2 text-[11px] text-white/60",children:[n,(0,rt.jsx)("span",{children:e})]})}function nl(n,e){let t=n[e];return typeof t=="string"?t:void 0}var _a=W(le(),1),oB=200,rl=new Map;function r2(n,e){if(rl.size>=oB){let t=rl.keys().next().value;t!==void 0&&rl.delete(t)}rl.set(n,e)}var iB=8,lB=200,o2=(0,$n.memo)(function({tool:e,status:t,conversationId:r}){let a=(0,al.useChatHost)(),s=(0,s2.useWorkspaceChatStore)(A=>r?A.conversationsById?.[r]?.agentId:void 0),o=(0,al.useHasRowIdentity)(),i=(0,al.useRowDisclosureValue)("card"),u=o&&i!==!0?iB:lB,c=(0,$n.useMemo)(()=>Qi(e.input),[e.input]),d=(0,$n.useMemo)(()=>(0,_f.extractPathsFromToolCall)(e)[0]||(c?a2(c,"uri")||a2(c,"path"):void 0),[e,c]),f=String(t||"").toLowerCase(),h=f==="pending"||f.includes("pending"),p=f==="interrupted",m=!p&&(f==="error"||f.includes("error")||f.includes("fail")),g=c?.action,x=d?Ji(d):void 0,w=(0,$n.useMemo)(()=>a0(e.structuredContent),[e.structuredContent]),y=(0,$n.useMemo)(()=>{let A=e.structuredContent,G=A&&typeof A=="object"?String(A.status||"").toLowerCase():"";return G==="pending_review"||G.includes("pending")},[e.structuredContent]),C=(0,$n.useMemo)(()=>w??(c&&!h?Ku(c):null),[w,c,h]),k=(0,$n.useMemo)(()=>c?h?[]:uB(g,c):[],[g,c,h]),v=(0,$n.useCallback)(A=>{let G=s||void 0;!G||!A||a.openFilesystemWidget?.(G,A)},[s,a]),b=(0,$n.useMemo)(()=>{if(h)return(0,_f.previewInput)(e.input,!0)},[h,e.input]),P=!h&&!m&&!!g&&Zi(g),[N,M]=(0,$n.useState)(()=>P&&d&&s?rl.get(`${s}|${e.id}`)??null:null);(0,$n.useEffect)(()=>{if(!P||!d||!s){M(null);return}let A=`${s}|${e.id}`,G=rl.get(A);if(G!==void 0){M(G);return}let V=!1,K=()=>{V||(async()=>{try{let J=await Ko({agentId:s,files:[d]});if(V)return;let Q=Yo(J)[0],re=sc(Q?.version?.baseline);if(!re?.content){r2(A,null);return}let pe=Nf(re.content,Jo(Q));r2(A,pe),V||M(pe)}catch{}})()},L=globalThis,R=null,z=null;return typeof L.requestIdleCallback=="function"?R=L.requestIdleCallback(K,{timeout:1500}):z=setTimeout(K,200),()=>{V=!0,R!==null&&L.cancelIdleCallback?.(R),z!==null&&clearTimeout(z)}},[P,d,s,e.id]);let U=N??k,I=N?Rf(N):C;return h?(0,_a.jsx)(Of,{uri:d,lineCounts:null,isPending:!0,reviewPending:!1,isError:!1,isInterrupted:!1,onUriClick:d?v:void 0,children:(0,_a.jsx)(cB,{content:b})}):g&&!Zi(g)?(0,_a.jsx)(Of,{uri:d,lineCounts:null,isPending:!1,reviewPending:y,isError:m,isInterrupted:p,onUriClick:d?v:void 0,children:(0,_a.jsx)(n2,{action:g,input:c||{}})}):(0,_a.jsx)(Of,{uri:d,lineCounts:I,isPending:!1,reviewPending:y,isError:m,isInterrupted:p,onUriClick:d?v:void 0,children:U.length>0?(0,_a.jsx)(Yi,{hunks:U,language:x,maxLines:u}):(0,_a.jsx)("div",{className:"px-3 py-2 text-[11px] text-white/40 italic",children:m?"Operation failed":"Done"})})});function uB(n,e){if(!n){let t=$u(e);return t?r0(t):[]}if(n==="replace_text"){let t=e.edits;if(Array.isArray(t)&&t.length>0)return wI(t.filter(s=>!!s&&typeof s=="object"&&typeof s.find=="string"));let r=typeof e.find=="string"?e.find:"",a=typeof e.replace=="string"?e.replace:"";return bI(r,a)}if(n==="update"||n==="replace_lines"){let t=$u(e);return t?vI(t):[]}if(n==="append_text"||n==="prepend_text"||n==="insert"){let t=typeof e.text=="string"?e.text:"";return t?kI(t):[]}return[]}function cB({content:n}){return n?(0,_a.jsx)("pre",{className:"px-3 py-1.5 text-[11px] leading-[18px] whitespace-pre overflow-x-auto overflow-y-clip bg-emerald-500/8 text-white/70 font-mono",children:n}):(0,_a.jsx)("div",{className:"px-3 py-2 text-[11px] text-white/40 italic",children:"Running..."})}function a2(n,e){let t=n[e];return typeof t=="string"?t:void 0}var Ha=W($e(),1);function i2({port:n}){let e=n.useCurrentUser(),t=e?.name,r=e?.email,a=e?.role,s=e?.priority,o=(0,Ha.useMemo)(()=>t||r?{name:t,email:r}:void 0,[t,r]),i=(0,Ha.useMemo)(()=>a!==void 0||s!==void 0?{role:a,priority:s}:void 0,[a,s]),l=n.useProjectId(),u=n.useUserId(),c=n.getGrantedFeatures(l,u).join(","),d=(0,Ha.useMemo)(()=>c.split(",").filter(Boolean),[c]);return(0,Ha.useMemo)(()=>({currentUser:o,currentRole:i,grantedFeatures:d,useAgents(){let f=n.useAgentIds(),h=n.useAgentsById();return(0,Ha.useMemo)(()=>{let p={};for(let m of f){let g=h[m];g&&(p[m]={id:g.id,slug:g.slug,name:g.name,config:g.config})}return{ids:f,byId:p}},[f,h])},useFileMarks:f=>n.useFileMarks(f),clearFileMark:f=>n.clearFileMark(f),getStreamUrl(f,h,p){return n.buildEventStreamUrl({packageSlug:"brain-core",agentId:f,projectId:h,types:p})},subscribeFilesystemEvents(f,h,p,m){return n.subscribeRealtime({channel:"filesystem",projectId:h,agentId:f,onEvent:(g,x)=>p(x),...m?{onConnChange:m}:{}})},isDocker:n.isDocker,usePackageIconBySlug(){let f=n.useProjectId(),[h,p]=(0,Ha.useState)({});return(0,Ha.useEffect)(()=>{if(!f)return;let m=!1,g=`/api/packages/agent-core/packages/overview?projectId=${encodeURIComponent(f)}`;return fetch(g,{credentials:"include"}).then(x=>x.ok?x.json():null).then(x=>{if(m||!x?.packages)return;let w={};for(let y of x.packages){if(!y.id)continue;let C=(0,sr.resolveLucideIcon)(y.icon);if(!C)continue;let k=y.id.replace(/^@[^/]+\//,"");w[k]=C,w[y.id]=C}p(w)}).catch(()=>{}),()=>{m=!0}},[f]),h}}),[n,o,i,d])}var u2=W(le(),1);function l2({port:n,children:e}){let t=i2({port:n});return(0,u2.jsx)(Qb,{value:t,children:e})}var Xs=W(le(),1),dB="workspace.provider:@neuralis/brain-core",fB=(0,Xs.jsx)("div",{className:"flex h-full items-center justify-center text-xs text-white/30",children:"Loading..."}),c2=!1;function hB(n){let{registry:e,port:t}=n;!c2&&t.onClientStateReset&&(c2=!0,t.onClientStateReset(o=>{B.getState().resetClientState(o)}));function r({children:o}){return(0,Xs.jsx)(l2,{port:t,children:o})}e.register({packageSlug:"@neuralis/brain-core",componentImport:dB,Component:r});function a({agentId:o,widgetId:i,state:l}){let u=t.useProjectId(),c=t.useUserId();return(0,Xs.jsx)(Uf.WorkspaceHostPortProvider,{port:t,children:(0,Xs.jsx)(Uf.PackageApiProvider,{slug:"brain-core",projectId:u,agentId:o,userId:c,children:(0,Xs.jsx)(l0,{agentId:o,projectId:u,userId:c,widgetId:i,state:l})})})}let s=Hf.default.lazy(()=>Promise.resolve({default:a}));e.register({packageSlug:"@neuralis/brain-core",componentImport:"@neuralis/brain-core/app/filesystem",Component:o=>(0,Xs.jsx)(Hf.Suspense,{fallback:fB,children:(0,Xs.jsx)(s,{...o})})}),(0,d2.registerCardComponent)("filesystem.change",o2,{owner:{kind:"package-direct",packageId:"@neuralis/brain-core"},renderer:"direct",mountPolicy:"virtualized",estimateHeight:QI,composer:SI,matchTools:CI})}export{hB as installFilesystemHostComponents};
54
+ `)}function t0(t){let e=Ar(t);return e.length===0?[]:[{skippedBefore:0,lines:e.map(n=>({type:"add",content:n}))}]}function CL(t,e){let n=Ar(t).map(a=>({type:"remove",content:a})),r=Ar(e).map(a=>({type:"add",content:a}));return[{skippedBefore:0,lines:[...n,...r]}]}function IL(t){return t.map((e,n)=>{let r=Ar(e.find).map(s=>({type:"remove",content:s})),a=Ar(e.replace??"").map(s=>({type:"add",content:s}));return{skippedBefore:n>0?-1:0,lines:[...r,...a]}}).filter(e=>e.lines.length>0)}function LL(t){return t0(t)}function AL(t){let e=Ar(t);return e.length===0?[]:[{skippedBefore:0,lines:e.map(n=>({type:"add",content:n}))}]}function Zu(t){let e=t.action;if(!e){let n=Ju(t);return n!=null?{added:Ar(n).length,removed:0}:null}if(e==="replace_text"){let n=t.edits;if(Array.isArray(n)){let s=0,i=0;for(let o of n){if(!o||typeof o!="object")continue;let l=o;typeof l.find=="string"&&(i+=Ar(l.find).length),typeof l.replace=="string"&&(s+=Ar(l.replace).length)}return{added:s,removed:i}}let r=typeof t.find=="string"?t.find:"",a=typeof t.replace=="string"?t.replace:"";return{added:Ar(a).length,removed:Ar(r).length}}if(e==="update"||e==="replace_lines"){let n=Ju(t);return n!=null?{added:Ar(n).length,removed:0}:null}if(e==="append_text"||e==="prepend_text"||e==="insert"){let n=typeof t.text=="string"?t.text:"";return{added:Ar(n).length,removed:0}}return null}var EE={".ts":"typescript",".tsx":"tsx",".js":"javascript",".jsx":"jsx",".json":"json",".md":"markdown",".py":"python",".css":"css",".html":"html",".yaml":"yaml",".yml":"yaml",".sh":"bash",".sql":"sql",".rs":"rust",".go":"go",".java":"java",".xml":"xml",".toml":"toml",".env":"bash",".scss":"scss",".less":"less",".graphql":"graphql",".vue":"markup",".svelte":"markup",".txt":"text"};function Qo(t){let e=t.match(/(\.[a-zA-Z0-9]+)$/)?.[1]?.toLowerCase();return e?EE[e]:void 0}var OE=new Set(["update","replace_text","append_text","prepend_text","insert","replace_lines"]);function el(t){return!!t&&OE.has(t)}function Ar(t){return t?t.split(`
55
+ `):[]}function tl(t){return _E((0,Mf.parseSettledObject)(t))}function Tf(t,e){let n=e0(t),r=e0(e),a=n.length,s=r.length,i=Array.from({length:a+1},()=>new Array(s+1).fill(0));for(let c=a-1;c>=0;c--)for(let d=s-1;d>=0;d--)i[c][d]=n[c]===r[d]?i[c+1][d+1]+1:Math.max(i[c+1][d],i[c][d+1]);let o=[],l=0,u=0;for(;l<a&&u<s;)n[l]===r[u]?(o.push({type:"context",content:n[l]}),l++,u++):i[l+1][u]>=i[l][u+1]?(o.push({type:"remove",content:n[l]}),l++):(o.push({type:"add",content:r[u]}),u++);for(;l<a;)o.push({type:"remove",content:n[l++]});for(;u<s;)o.push({type:"add",content:r[u++]});return[{skippedBefore:0,lines:o}]}function Df(t){let e=0,n=0;for(let r of t)for(let a of r.lines)a.type==="add"?e++:a.type==="remove"&&n++;return{added:e,removed:n}}function Ju(t){for(let e of["content","file_content","text"]){let n=t[e];if(typeof n=="string")return n}if(typeof t.content=="object"&&t.content!==null)try{return JSON.stringify(t.content,null,2)}catch{}return null}function n0(t){if(!t||typeof t!="object"||Array.isArray(t))return null;let e=t;if(e.ok===!1)return null;let n=e.version;if(!n||typeof n!="object"||Array.isArray(n))return null;let r=n.diff;if(!r||typeof r!="object"||Array.isArray(r))return null;let a=r,s=typeof a.added=="number"?a.added:null,i=typeof a.removed=="number"?a.removed:null;return s==null||i==null?null:{added:s,removed:i}}function BE(t){let e=(0,Mf.extractPathsFromToolCall)(t);if(e.length===0){let r=tl(t.input),a=typeof r?.uri=="string"&&r.uri||typeof r?.path=="string"&&r.path||"";if(!a)return[];e=[a]}let n=n0(t.structuredContent);return e.map((r,a)=>a===0&&n?{path:r,diff:n}:{path:r})}var PL={tab:"changes",changes:BE},NL=["fs_write","fs_create","fs_modify"];function _E(t){if(!t||typeof t.action=="string"||!UE(t))return t;let e={};if(typeof t.uri=="string"&&(e.uri=t.uri),typeof t.id=="string"&&(e.id=t.id),typeof t.move=="string")return{...e,action:"move",destination:t.move};if(typeof t.copy=="string")return{...e,action:"copy",destination:t.copy};if(t.mkdir!==void 0)return{...e,action:"create_folder"};if(t.revert!==void 0)return{...e,action:"revert"};if(t.delete!==void 0)return{...e,action:"delete"};let n=Array.isArray(t.edit)?t.edit.filter(o=>!!o&&typeof o=="object").map(o=>({find:typeof o.old_string=="string"?o.old_string:"",replace:typeof o.new_string=="string"?o.new_string:""})).filter(o=>o.find.length>0):[];if(n.length>0)return{...e,action:"replace_text",edits:n};let r=Rf(t.lines);if(r&&typeof r.content=="string")return{...e,action:"replace_lines",content:r.content};let a=Rf(t.insert);if(a&&typeof a.insert_text=="string")return{...e,action:"insert",text:a.insert_text};let s=Rf(t.overwrite);if(s&&s.content!==void 0)return{...e,action:"update",content:s.content};let i=Rf(t.create);return i&&i.content!==void 0?{...e,content:i.content}:t.fields!==void 0?{...e,action:"set_fields",fields:t.fields}:t}var HE=["create","overwrite","edit","insert","lines","fields","move","copy","mkdir","revert","delete"];function UE(t){return HE.some(e=>t[e]!==void 0)}function Rf(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function ML(t){let e=new Map;for(let n of t)if(n.status)for(let[r,a]of[[!0,n.status.staged],[!1,[...n.status.unstaged,...n.status.untracked]]])for(let s of a){let i=`${n.source}://${[n.repo.rel,s.path].filter(Boolean).join("/")}`,o=e.get(i)??new Map,l=JSON.stringify([n.source,n.repo.rel,s.path]),u=o.get(l);u?(u.staged||=r,u.unstaged||=!r):o.set(l,{group:n,path:s.path,staged:r,unstaged:!r}),e.set(i,o)}return e}function Qu(t){return`${t.source}://${t.repo.rel}`}function r0(t){let e=Fs(t.source,t.repo.name);return e.prefix?`${e.prefix} ${e.name}`:e.name}function TL(t,e){return e.kind==="pending"?[]:t.filter(n=>(!e.source||n.source===e.source)&&(!e.repo||Qu(n)===e.repo)&&(!e.branch||n.status?.branch===e.branch))}function DL(t,e,n){return n.kind==="git"?[]:t.filter(r=>!(n.source&&r.sourceSlug!==n.source||n.agent&&r.agentId!==n.agent||n.origin&&r.origin!==n.origin||(n.repo||n.branch)&&!e.some(s=>r.sourceSlug===s.source&&zi(r.uri).startsWith(`${s.source}://${s.repo.rel?`${s.repo.rel}/`:""}`)&&(!n.repo||Qu(s)===n.repo)&&(!n.branch||s.status?.branch===n.branch)))).sort((r,a)=>r.createdAt<a.createdAt?-1:r.createdAt>a.createdAt?1:0)}function FL(t,e,n,r){let a=new Set(t.map(i=>zi(i.uri))),s=[];for(let i of e.keys())(n==="git"||!a.has(i))&&s.push({kind:"git",key:`git:${i}`,uri:i});return t.forEach((i,o)=>s.push({kind:r==="cards"?"pending-card":"pending-row",key:i.id,rec:i,index:o})),s}var GE=32,WE=346;function EL(t){return t==="pending-row"?GE:WE}function OL(t){return t!=="pending-row"}function BL(t,e,n=100,r){let a=[],s=[];for(let i of t)e.has(i.id)||(SL(i)||r?.(i.id)?.requiresAcknowledgement.length?s.push(i):a.length<n&&a.push(i));return{approvable:a,needsAck:s}}function a0(t){let e=t instanceof Error?t.message:String(t??"");return e.includes("PENDING_STATE_CHANGED")||e.includes("PENDING_GENERATION_CHANGED")?"changed":e.includes("CURRENT_STATE_ACKNOWLEDGEMENT_REQUIRED")?"needs-ack":"error"}var RL=new WeakMap;function Ff(t){if(t.diffState!=="readable")return null;let e=RL.get(t);return e||(e=Tf(t.baseline.state==="text"?t.baseline.text:"",t.current.state==="text"?t.current.text:""),RL.set(t,e)),e}var Hn=j($e(),1),UL=j(Za(),1);var ut=j(ie(),1),_L={originalDraftUnknown:{label:"Older change \u2014 original draft unknown",chip:"bg-amber-500/15 text-amber-200 border-amber-400/30"},externalChanged:{label:"Changed outside the review",chip:"bg-rose-500/15 text-rose-200 border-rose-400/30"},unreviewable:{label:"Diff not readable",chip:"bg-sky-500/15 text-sky-200 border-sky-400/30"},fresh:{label:"No confirmation needed now",chip:"bg-emerald-500/15 text-emerald-200 border-emerald-400/30"}},HL={ok:{label:"Done",tone:"text-emerald-300"},changed:{label:"Changed since the preview \u2014 check the fresh state and confirm again",tone:"text-amber-300"},"needs-ack":{label:"Still needs a confirmation",tone:"text-amber-300"},error:{label:"Refused",tone:"text-rose-300"}};async function Ef(t,e,n,r,a){let s={agentId:t.agentId,...t.projectId?{projectId:t.projectId}:{},id:e.id,expectedFingerprint:n.expectedFingerprint,...a?{acknowledgeCurrentState:!0}:{}};try{let i=r==="approve"?await fc({...s,uri:e.uri},t.client):r==="revert"?await Y0(s,t.client):await Z0(s,t.client);if(i&&i.ok===!1){let o="error"in i&&i.error?String(i.error):"Review refused";return{id:e.id,uri:e.uri,action:r,outcome:a0(o),detail:o}}return{id:e.id,uri:e.uri,action:r,outcome:"ok"}}catch(i){return{id:e.id,uri:e.uri,action:r,outcome:a0(i),detail:i instanceof Error?i.message:"Review refused"}}}function zE({rec:t,preview:e}){let n=(0,Hn.useMemo)(()=>Ff(e),[e]);return Qg(t,e)?(0,ut.jsx)("div",{className:"px-2.5 py-2 text-[10.5px] text-white/60 leading-relaxed",children:"The file is gone. Approving or dismissing accepts that it stays gone \u2014 nothing is recreated and the saved earlier version stays in history. Revert restores that version."}):n?(0,ut.jsx)("div",{className:"max-h-56 overflow-auto overlay-scroll",style:{scrollbarGutter:"auto"},children:(0,ut.jsx)(Zo,{hunks:n,language:Qo(t.uri),maxLines:400})}):(0,ut.jsxs)("div",{className:"px-2.5 py-2 text-[10.5px] text-white/50",children:["Diff ",e.diffState,": current ",e.current.state,", baseline ",e.baseline.state," (",e.baselineProvenance,")."]})}var ec="h-7 px-2.5 rounded-md text-[11px] font-medium transition disabled:opacity-40 inline-flex items-center gap-1.5";function GL({request:t,agentId:e,projectId:n,run:r,onClose:a,onDone:s,next:i=0,onNext:o,refetch:l,onBatchStart:u}){let c=H(R=>R.client),d=(0,Hn.useMemo)(()=>t.kind==="single"?[t.rec]:t.records,[t]),[f,h]=(0,Hn.useState)(()=>t.kind==="single"&&t.preview?{[t.rec.id]:t.preview}:{}),[p,g]=(0,Hn.useState)(!1),[m,x]=(0,Hn.useState)({}),y=(0,Hn.useRef)(!0),b=(0,Hn.useRef)(new Map);(0,Hn.useEffect)(()=>(y.current=!0,()=>{y.current=!1}),[]);let C=(0,Hn.useCallback)((R,U=!1)=>{let v=(b.current.get(R.id)??0)+1;b.current.set(R.id,v);let T=()=>y.current&&b.current.get(R.id)===v;(U&&l?l(R):r(()=>Xi({agentId:e,...n?{projectId:n}:{},id:R.id},c),T)).then(Y=>{T()&&Y&&h(N=>({...N,[R.id]:Y}))},Y=>{T()&&h(N=>({...N,[R.id]:Y instanceof Error?Y:new Error("Preview failed")}))})},[e,n,r,l]);(0,Hn.useEffect)(()=>{for(let R of d)!f[R.id]&&!b.current.has(R.id)&&C(R)},[d,C]);let L=(0,Hn.useMemo)(()=>{let R=new Map;for(let U of d){let v=f[U.id];if(!v||v instanceof Error)continue;let T=v.requiresAcknowledgement[0]??"fresh";R.set(T,[...R.get(T)??[],U])}return R},[d,f]),P=d.filter(R=>!f[R.id]).length,w=R=>m[R.id]!==void 0&&m[R.id].outcome!=="changed",k=t.kind==="group"&&P===0&&!p&&d.every(R=>w(R)||f[R.id]instanceof Error),_=(0,Hn.useCallback)(async(R,U)=>{g(!0),u?.();let v=[];for(let T of R){let V=f[T.id];if(!V||V instanceof Error||m[T.id]?.outcome==="ok")continue;let Y=await Ef({agentId:e,projectId:n,client:c},T,V,U,V.requiresAcknowledgement.length>0);v.push(Y),x(N=>({...N,[T.id]:Y})),Y.outcome==="changed"&&(h(N=>{let{[T.id]:A,...B}=N;return B}),C(T,!0))}g(!1),s(v)},[f,m,e,n,s,C,u]);if(typeof document>"u")return null;let M=t.kind==="single"?t:null;return(0,UL.createPortal)((0,ut.jsx)("div",{className:"fixed inset-0 z-[1100] flex items-center justify-center bg-black/40 backdrop-blur-[1px]",onMouseDown:p?void 0:a,children:(0,ut.jsxs)("div",{role:"dialog","aria-modal":"true","aria-label":"Review pending changes",onMouseDown:R=>R.stopPropagation(),className:"w-[min(640px,92vw)] max-h-[82vh] flex flex-col rounded-xl border border-amber-400/25 bg-[#15151d] shadow-[0_30px_80px_-24px_rgba(0,0,0,0.85)]",children:[(0,ut.jsxs)("div",{className:"flex items-start gap-2.5 p-4 pb-2 shrink-0",children:[(0,ut.jsx)(Sa,{className:"h-4 w-4 text-amber-300 shrink-0 mt-0.5"}),(0,ut.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,ut.jsx)("div",{className:"text-[12px] font-semibold text-white/90",children:M?`Review the current state \u2014 ${M.action}`:t.kind==="group"&&t.total>d.length?`${d.length} of ${t.total} changes need your confirmation`:`${d.length} changes need your confirmation`}),(0,ut.jsx)("div",{className:"mt-1 text-[10.5px] text-white/55 leading-relaxed",children:"Each change is checked against its own fresh preview. Confirming accepts the state shown here; a change that moves again before you confirm is refused and stays in the list."}),P>0?(0,ut.jsxs)("div",{className:"mt-1.5 inline-flex items-center gap-1.5 text-[10.5px] text-white/45",children:[(0,ut.jsx)(We,{className:"h-3 w-3 animate-spin"})," Loading ",P," preview",P>1?"s":"","\u2026"]}):null]})]}),(0,ut.jsxs)("div",{className:"min-h-0 flex-1 overflow-auto overlay-scroll px-4 space-y-3",children:[[...L].map(([R,U])=>(0,ut.jsxs)("section",{className:"rounded-lg border border-white/8 bg-black/20",children:[(0,ut.jsxs)("div",{className:"flex items-center gap-2 px-2.5 py-1.5 border-b border-white/5",children:[(0,ut.jsxs)("span",{className:`inline-flex items-center rounded-full border px-2 py-0.5 text-[10px] font-semibold ${_L[R].chip}`,children:[_L[R].label," \xB7 ",U.length]}),M?null:(0,ut.jsxs)("div",{className:"ml-auto flex items-center gap-1.5",children:[(0,ut.jsxs)("button",{type:"button",disabled:p||U.every(w),onClick:()=>{_(U,"dismiss")},className:`${ec} bg-white/[0.04] hover:bg-white/[0.08] text-white/70`,children:[(0,ut.jsx)(ta,{className:"h-3 w-3"})," Confirm & dismiss ",U.length]}),(0,ut.jsxs)("button",{type:"button",disabled:p||U.every(w),onClick:()=>{_(U,"approve")},className:`${ec} bg-emerald-500/20 hover:bg-emerald-500/30 border border-emerald-400/40 text-emerald-100 font-semibold`,children:[(0,ut.jsx)(gs,{className:"h-3 w-3"})," Confirm & approve ",U.length]})]})]}),U.map(v=>{let T=f[v.id],V=m[v.id];return(0,ut.jsxs)("div",{className:"border-b border-white/5 last:border-0",children:[(0,ut.jsxs)("div",{className:"flex items-center gap-2 px-2.5 py-1 text-[10.5px]",children:[(0,ut.jsx)("span",{className:"min-w-0 flex-1 truncate font-mono text-white/70",title:v.uri,children:v.uri}),V?(0,ut.jsx)("span",{className:HL[V.outcome].tone,title:V.detail,children:HL[V.outcome].label}):null]}),(0,ut.jsx)(zE,{rec:v,preview:T})]},v.id)})]},R)),d.filter(R=>f[R.id]instanceof Error).map(R=>(0,ut.jsxs)("div",{className:"rounded-md bg-rose-500/10 px-2.5 py-1.5 text-[10.5px] text-rose-200/90",children:[R.uri,": ",f[R.id].message]},R.id))]}),(0,ut.jsxs)("div",{className:"flex items-center justify-end gap-2 p-4 pt-3 shrink-0",children:[(0,ut.jsxs)("button",{type:"button",onClick:a,disabled:p,className:`${ec} bg-white/[0.04] hover:bg-white/[0.08] text-white/70`,children:[(0,ut.jsx)(Ht,{className:"h-3 w-3"})," ",Object.keys(m).length?"Close":"Cancel"]}),k&&o&&i>0?(0,ut.jsxs)("button",{type:"button",onClick:()=>o(d.map(R=>R.id)),className:`${ec} border border-amber-400/40 bg-amber-500/15 hover:bg-amber-500/25 text-amber-100 font-semibold`,children:[(0,ut.jsx)(Sa,{className:"h-3 w-3"})," Next batch (",i," left)"]}):null,M?["revert","dismiss","approve"].map(R=>{let U=R===M.action,v=R==="approve"?Dn:R==="revert"?Ca:ta,T=R==="revert"?"border border-rose-400/40 bg-rose-500/15 hover:bg-rose-500/25 text-rose-100":U?"border border-emerald-400/40 bg-emerald-500/20 hover:bg-emerald-500/30 text-emerald-100 font-semibold":"bg-white/[0.04] hover:bg-white/[0.08] text-white/70";return(0,ut.jsxs)("button",{type:"button",disabled:p||P>0||m[M.rec.id]?.outcome==="ok",onClick:()=>{_([M.rec],R)},className:`${ec} ${T}`,children:[(0,ut.jsx)(v,{className:"h-3 w-3"})," ",U?`Confirm & ${R}`:R[0].toUpperCase()+R.slice(1)]},R)}):null]})]})}),document.body)}var J=j(ie(),1),jL={create:(0,J.jsx)(Ss,{className:"w-3.5 h-3.5 text-emerald-300/80"}),modify:(0,J.jsx)(vs,{className:"w-3.5 h-3.5 text-sky-300/80"}),delete:(0,J.jsx)(Nt,{className:"w-3.5 h-3.5 text-red-300/80"}),move:(0,J.jsx)(Tl,{className:"w-3.5 h-3.5 text-violet-300/80"})},VL=t=>t==="approved"?"bg-emerald-400":t==="reverted"?"bg-white/30":"bg-amber-400";function qL({diff:t}){return!t||t.added===0&&t.removed===0?null:(0,J.jsxs)("span",{className:"font-mono text-[10px] shrink-0",children:[t.added>0?(0,J.jsxs)("span",{className:"text-emerald-300",children:["+",t.added]}):null,t.added>0&&t.removed>0?" ":null,t.removed>0?(0,J.jsxs)("span",{className:"text-red-300",children:["\u2212",t.removed]}):null]})}var $L=(0,J.jsxs)("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded bg-rose-500/15 text-rose-200/90 text-[10px] shrink-0",title:"The backing file no longer exists \u2014 this change can only be discarded.",children:[(0,J.jsx)(zl,{className:"w-3 h-3"})," Orphaned"]});function KL({orphaned:t,busy:e,onApprove:n,onRevert:r,onDiscard:a,onDismiss:s,className:i}){let o=(0,J.jsx)(Of.LiveSpinner,{className:"w-3.5 h-3.5"});return(0,J.jsx)("div",{className:i,children:t?(0,J.jsx)("button",{type:"button",onClick:a,disabled:e,title:"Discard (remove this un-actionable change)",className:"p-1 rounded hover:bg-rose-500/15 text-rose-300/80 disabled:opacity-40",children:e?o:(0,J.jsx)(Nt,{className:"w-3.5 h-3.5"})}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)("button",{type:"button",onClick:n,disabled:e,title:"Approve",className:"p-1 rounded hover:bg-emerald-500/15 text-emerald-300/80 disabled:opacity-40",children:e?o:(0,J.jsx)(Dn,{className:"w-3.5 h-3.5"})}),(0,J.jsx)("button",{type:"button",onClick:r,disabled:e,title:"Revert",className:"p-1 rounded hover:bg-red-500/15 text-red-300/80 disabled:opacity-40",children:(0,J.jsx)(Ca,{className:"w-3.5 h-3.5"})}),(0,J.jsx)("button",{type:"button",onClick:s,disabled:e,title:"Dismiss (stop reviewing \u2014 keep the change, no revert)",className:"p-1 rounded hover:bg-white/10 text-white/50 hover:text-white/80 disabled:opacity-40",children:(0,J.jsx)(ta,{className:"w-3.5 h-3.5"})})]})})}function WL({uri:t,rows:e,agentId:n,projectId:r,canWrite:a,revisions:s,queue:i}){let o=e.get(zi(t));return o?(0,J.jsx)(J.Fragment,{children:[...o.values()].map(l=>(0,J.jsx)(fe.default.Fragment,{children:[!0,!1].filter(u=>u?l.staged:l.unstaged).map(u=>(0,J.jsxs)("div",{children:[(0,J.jsxs)("div",{className:"px-3 py-1 text-[10px] text-white/40",children:[l.group.repo.name," (",l.group.repo.rel||"root",") \xB7 ",u?"Git HEAD \u2192 index (staged)":"Git index \u2192 working file (unstaged/untracked)"]}),(0,J.jsx)("div",{className:"max-h-72 overflow-auto overlay-scroll",style:{scrollbarGutter:"auto"},children:(0,J.jsx)(bi,{source:l.group.source,repo:l.group.repo.rel,path:l.path,mode:{kind:"working",staged:u},agentId:n,projectId:r,variant:"card",canWrite:a&&l.group.repo.canWrite===!0,revision:s[l.group.source]??0,runContent:i.run,peekContent:i.peek})})]},String(u)))},`${l.group.source}/${l.group.repo.rel}/${l.path}`))}):null}var XL=(t,e)=>`preview\0${t.id}\0${t.updatedAt}\0${e}`,jE=t=>2*((t.baseline.state==="text"?t.baseline.text.length:0)+(t.current.state==="text"?t.current.text.length:0))+256,VE=(0,fe.memo)(function({rec:e,agentId:n,projectId:r,focused:a,orphaned:s,onOpen:i,onApprove:o,onRevert:l,onDiscard:u,onDismiss:c,onFocus:d,busy:f,queue:h,revision:p,canWrite:g,onPreview:m,peekPreview:x,takeRefetch:y,extra:b}){let C=H(re=>re.client),[L,P]=(0,fe.useState)(!0),[w,k]=(0,fe.useState)(()=>x(e.id)??null),[_,M]=(0,fe.useState)(!1),[R,U]=(0,fe.useState)(null),[v,T]=(0,fe.useState)(""),V=(0,fe.useRef)(0),Y=h.visible.has(e.id),N=(0,fe.useRef)(!1);N.current=L&&Y;let A=XL(e,p),B=(0,fe.useRef)("");(0,fe.useEffect)(()=>{let re=++V.current;if(!L||!Y||B.current===A){M(!1);return}let he=y(e.id,A);if(he==="wait"){M(!0);return}if(he){k(he),U(null),T(A),B.current=A,M(!1);return}return M(!0),h.run(()=>Xi({agentId:n,...r?{projectId:r}:{},id:e.id},C),()=>re===V.current&&N.current,{key:A,bytes:jE}).then(Ne=>{!Ne||re!==V.current||!N.current||(m(Ne),k(Ne),U(null),T(A),B.current=A,M(!1))}).catch(Ne=>{re===V.current&&(U(Ne instanceof Error?Ne.message:"Failed to load review"),M(!1))}),()=>{V.current++}},[n,r,e.id,A,L,Y,h.run]);let K=(0,fe.useMemo)(()=>w?Ff(w):null,[w]),te=(0,fe.useMemo)(()=>K?Df(K):null,[K]),ne=v===A?w?.indexState??null:null,pe=R??(w&&w.diffState!=="readable"?`Review diff unavailable: ${w.diffState}; current ${w.current.state}, baseline ${w.baseline.state}.`:null),Se=(0,fe.useCallback)(()=>P(re=>!re),[]),le=e.diff&&(e.diff.added>0||e.diff.removed>0)?e.diff:te??void 0;return(0,J.jsxs)("div",{ref:re=>h.register(e.id,re),onMouseDown:d,className:`rounded-lg border overflow-hidden transition-colors ${s?"border-rose-400/30 bg-rose-500/[0.04]":a?"border-amber-400/40 ring-1 ring-amber-400/25 bg-amber-400/[0.03]":"border-white/8 bg-black/20"}`,children:[(0,J.jsxs)("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 px-2.5 py-1.5",children:[(0,J.jsx)("button",{type:"button",onClick:Se,"aria-expanded":L,className:"text-white/40 hover:text-white/80 shrink-0",children:L?(0,J.jsx)(Et,{className:"w-3.5 h-3.5"}):(0,J.jsx)(un,{className:"w-3.5 h-3.5"})}),jL[e.op],(0,J.jsxs)("button",{type:"button",onClick:()=>i(e.uri),className:"min-w-[6rem] flex-1 text-left truncate text-xs text-white/85 hover:text-white",title:e.uri,children:[gt(e.uri)||e.uri,(0,J.jsxs)("span",{className:"ml-1.5 text-[10px] text-white/30 font-mono",children:[et(e.uri),"/"]})]}),(0,J.jsx)(qL,{diff:le}),ne&&ne!=="stored"?(0,J.jsx)("span",{className:"text-[10px] text-amber-200/80 shrink-0",children:ne==="missing"?"Index missing":ne==="stale"?"Index stale":"Recovery only"}):null,s?$L:e.status==="approved"||e.status==="reverted"?(0,J.jsx)("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${VL(e.status)}`,title:e.status}):null,g?(0,J.jsx)(KL,{orphaned:s,busy:f,onApprove:o,onRevert:l,onDiscard:u,onDismiss:c,className:"ml-auto flex items-center gap-1 shrink-0"}):null]}),L?(0,J.jsxs)("div",{className:"border-t border-white/5",children:[(0,J.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-1 text-[10px] text-white/40",children:["Review baseline \u2192 current file",_&&w?(0,J.jsx)(Of.LiveSpinner,{className:"w-3 h-3"}):null]}),(0,J.jsx)("div",{className:"max-h-72 overflow-auto overlay-scroll",style:{scrollbarGutter:"auto"},children:_&&!w?(0,J.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-xs text-white/40",children:[(0,J.jsx)(Of.LiveSpinner,{className:"w-3.5 h-3.5"})," Loading diff\u2026"]}):pe?(0,J.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-xs text-red-300/80",children:[(0,J.jsx)(ot,{className:"w-3.5 h-3.5"})," ",pe]}):K?(0,J.jsx)(Zo,{hunks:K,language:Qo(e.uri),maxLines:600}):null})]}):null,L?b:null]})}),nl="bg-transparent border border-white/8 rounded px-1.5 py-0.5 text-white/70",rl={background:"var(--w-composer-bg-rgb, rgba(20,20,28,1))"},qE={kind:"all",source:"",repo:"",branch:"",agent:"",origin:""},tc=100;function YL({agentId:t,projectId:e}){let n=H(z=>z.client),r=hn(),a=Ja({grantedFeatures:[...r.grantedFeatures??[]]},"drive.write"),s=ti(),i=H(z=>z.sources),o=H(z=>z.sourceChangeRevision),[l,u]=(0,fe.useState)(null),c=l??o,d=(0,fe.useRef)(o);d.current=o;let f=(0,fe.useRef)(o),h=(0,fe.useCallback)(()=>u(z=>z??d.current),[]),p=H(z=>z.pendingPanelFilter),g=H(z=>z.setPendingPanelFilter),m=H(z=>z.openFile),x=H(z=>z.removeFilePath),y=H(z=>z.setActiveWorkspaceTab),b=H(z=>z.refreshPendingCount),C=p.conversationId??"",[L,P]=(0,fe.useState)(null),w=Pc(L),k=(0,fe.useRef)(new Map),_=(0,fe.useCallback)(z=>k.current.get(z),[]),M=(0,fe.useRef)(new Map),R=(0,fe.useRef)(Promise.withResolvers()),U=(0,fe.useCallback)((z,I)=>{let q=M.current.get(z);return q===null?"wait":(q&&M.current.delete(z),q?.key===I?q.preview:void 0)},[]),[v,T]=(0,fe.useState)(qE),V=z=>I=>T(q=>({...q,[z]:I.target.value})),[Y,N]=(0,fe.useState)("cards"),[A,B]=(0,fe.useState)([]),[K,te]=(0,fe.useState)(new Set),[ne,pe]=(0,fe.useState)(!1),[Se,le]=(0,fe.useState)(null),[re,he]=(0,fe.useState)(null),[Ne,Ee]=(0,fe.useState)({}),ze=(0,fe.useRef)({nonces:Ne,revisions:c});ze.current={nonces:Ne,revisions:c};let ct=(0,fe.useCallback)(async z=>{M.current.set(z.id,null);try{let I=(await R.current.promise)?.find(de=>de.id===z.id)??z,q=await Xi({agentId:t,...e?{projectId:e}:{},id:z.id},n),F=(ze.current.nonces[z.id]??0)+1+(ze.current.revisions[I.sourceSlug]??0);return M.current.set(z.id,{key:XL(I,F),preview:q}),k.current.set(z.id,q),q}catch(I){throw M.current.delete(z.id),I}finally{Ee(I=>({...I,[z.id]:(I[z.id]??0)+1}))}},[t,e]),[it,Qe]=(0,fe.useState)(0),[Ye,Lt]=(0,fe.useState)(null),[Le,at]=(0,fe.useState)([]),[ft,bt]=(0,fe.useState)(!1),[At,Tt]=(0,fe.useState)(!1),[Ue,me]=(0,fe.useState)(!1),[Ot,Jt]=(0,fe.useState)(!1),[ue,be]=(0,fe.useState)(new Set),Ge=(0,fe.useRef)(null),Re=(0,fe.useRef)(0),Te=wL({agentId:t,projectId:e,sources:i,revisions:c,resetKey:`${t}\0${e}\0${C}`}),vt=(0,fe.useCallback)(async z=>{if(!t)return;let I=++Re.current;pe(!0),le(null);try{let q=await K0({agentId:t,...e?{projectId:e}:{},...C?{conversationId:C}:{},...z?{include_orphans:!0}:{}},n);if(I!==Re.current)return;let F=new Set(q.changes.map(de=>de.id));return B(q.changes),te(de=>z?new Set(q.orphanIds):new Set([...de].filter(D=>F.has(D)))),q.changes}catch(q){I===Re.current&&le(q instanceof Error?q.message:"Failed to load changes");return}finally{I===Re.current&&pe(!1)}},[t,e,C]),mt=(0,fe.useCallback)(async()=>{await Promise.all([vt(!0),Te.refresh(!0)]),b({agentId:t,projectId:e})},[vt,Te.refresh,b,t,e]);(0,fe.useEffect)(()=>(k.current.clear(),Lt(null),B([]),te(new Set),at([]),vt(!0),()=>{Re.current++,k.current.clear()}),[vt]);let Gt=(0,fe.useRef)(vt);Gt.current=vt;let je=(0,fe.useRef)(!0);(0,fe.useEffect)(()=>{if(je.current){je.current=!1;return}c!==f.current&&Gt.current(!1)},[c]);let kt=Te.groups,on=(0,fe.useMemo)(()=>Array.from(new Set([...A.map(z=>z.sourceSlug),...kt.map(z=>z.source)])).sort(),[A,kt]),Oe=(0,fe.useMemo)(()=>Array.from(new Set(A.map(z=>z.agentId).filter(Boolean))).sort(),[A]),ee=(0,fe.useMemo)(()=>Array.from(new Set(A.map(z=>z.origin).filter(Boolean))).sort(),[A]),oe=(0,fe.useMemo)(()=>DL(A,kt,v),[A,kt,v]),He=(0,fe.useMemo)(()=>TL(kt,v),[kt,v]),Ve=(0,fe.useMemo)(()=>ML(He),[He]),Ae=(0,fe.useMemo)(()=>FL(oe,Ve,v.kind,Y),[oe,Ve,v.kind,Y]),[ce,Pt]=(0,fe.useState)(0),{approvable:Ft,needsAck:Zt}=(0,fe.useMemo)(()=>BL(oe,K,tc,_),[oe,K,_,ce]),dn=(0,fe.useRef)(new Set),rr=Zt.filter(z=>!dn.current.has(z.id)),qr=(0,fe.useCallback)(z=>{for(let q of z)dn.current.add(q);let I=Zt.filter(q=>!dn.current.has(q.id));Lt({kind:"group",records:I.slice(0,tc),total:I.length})},[Zt]),Mn=(0,fe.useRef)(Ae);Mn.current=Ae;let Yn=(0,fe.useCallback)(z=>EL(Mn.current[z]?.kind??"pending-card"),[]),$r=(0,fe.useCallback)(z=>Mn.current[z]?.key??z,[]),ar=lo({count:Ae.length,getScrollElement:()=>L,estimateSize:Yn,getItemKey:$r,overscan:4});ar.shouldAdjustScrollPositionOnItemSizeChange=$E,(0,fe.useEffect)(()=>{Qe(z=>oe.length===0?0:Math.min(z,oe.length-1))},[oe.length]);let Pr=Ae.length-oe.length;(0,fe.useEffect)(()=>{oe.length>0&&ar.scrollToIndex(Pr+it,{align:"auto"})},[it,Y]);let Kr=(0,fe.useCallback)(z=>{m({agentId:t,projectId:e,uri:z}),y("file")},[t,e,m,y]),ln=(0,fe.useCallback)(z=>{if(z.op!=="delete"||!z.uri)return;let I=s.getState().files[z.uri];(!I||I.status==="deleted")&&x(z.uri)},[x,s]),Jn=(0,fe.useCallback)(async z=>{for(let F of z){let de=A.find(D=>D.id===F.id);de&&F.outcome==="ok"&&F.action!=="revert"&&ln(de),F.outcome!=="ok"&&F.outcome!=="needs-ack"&&!M.current.has(F.id)&&k.current.delete(F.id)}let I=z.filter(F=>F.outcome!=="ok"&&F.outcome!=="needs-ack"&&!M.current.has(F.id));I.length&&Ee(F=>{let de={...F};for(let D of I)de[D.id]=(de[D.id]??0)+1;return de}),at(z);let q=await vt(!1);f.current=s.getState().sourceChangeRevision,u(null),R.current.resolve(q),R.current=Promise.withResolvers(),b({agentId:t,projectId:e})},[A,ln,vt,b,t,e,s]),Wt=(0,fe.useCallback)(async(z,I)=>{if(!a)return;let q=k.current.get(z.id);if(!q||q.requiresAcknowledgement.length){Lt({kind:"single",rec:z,action:I,...q?{preview:q}:{}});return}he(z.id);try{await Jn([await Ef({agentId:t,projectId:e,client:n},z,q,I,!1)])}finally{he(null)}},[a,t,e,Jn]),gr=(0,fe.useCallback)(async z=>{he(z.id);try{let I=await J0({agentId:t,...e?{projectId:e}:{},id:z.id},n);I.ok?ln(z):le(I.error||"Discard failed"),await vt(!1),b({agentId:t,projectId:e})}catch(I){le(I instanceof Error?I.message:"Discard failed")}finally{he(null)}},[t,e,vt,ln,b]),Un=(0,fe.useCallback)(async()=>{Ge.current&&(clearTimeout(Ge.current),Ge.current=null),Jt(!0),me(!1),le(null);try{await Q0({agentId:t,...e?{projectId:e}:{},...C?{conversationId:C}:{}},n);let z=A.filter(q=>K.has(q.id)),I=await vt(!0);if(I){let q=new Set(I.map(F=>F.id));for(let F of z)q.has(F.id)||ln(F)}b({agentId:t,projectId:e})}catch(z){le(z instanceof Error?z.message:"Repair failed")}finally{Jt(!1)}},[t,e,C,vt,A,K,ln,b]),Nr=(0,fe.useCallback)(()=>{if(Ue){Un();return}me(!0),Ge.current&&clearTimeout(Ge.current),Ge.current=setTimeout(()=>me(!1),3e3)},[Ue,Un]);(0,fe.useEffect)(()=>()=>{Ge.current&&clearTimeout(Ge.current)},[]);let pa=(0,fe.useCallback)(async()=>{bt(!0),Tt(!1),le(null),h();let z=[];try{for(let I of Ft){let q=k.current.get(I.id);if(!q){try{q=await Xi({agentId:t,...e?{projectId:e}:{},id:I.id},n)}catch(F){z.push({id:I.id,uri:I.uri,action:"approve",outcome:"error",detail:F instanceof Error?F.message:"Preview failed"});continue}k.current.set(I.id,q)}if(q.requiresAcknowledgement.length){z.push({id:I.id,uri:I.uri,action:"approve",outcome:"needs-ack"});continue}z.push(await Ef({agentId:t,projectId:e,client:n},I,q,"approve",!1))}}finally{bt(!1);let I=Ft.filter(q=>z.some(F=>F.id===q.id&&F.outcome==="needs-ack"));I.length&&Pt(q=>q+1),await Jn(z),I.length&&a&&(dn.current.clear(),Lt({kind:"group",records:I.slice(0,tc),total:I.length}))}},[Ft,t,e,Jn,a]),fn=(0,fe.useCallback)(z=>Qe(I=>oe.length===0?0:Math.max(0,Math.min(oe.length-1,I+z))),[oe.length]),Xr=(0,fe.useCallback)(z=>{if(re||ft||!a||Ye)return;let I=oe[it],q=I?K.has(I.id):!1;z.key==="ArrowDown"||z.key==="ArrowRight"?(z.preventDefault(),fn(1)):z.key==="ArrowUp"||z.key==="ArrowLeft"?(z.preventDefault(),fn(-1)):q&&I&&(z.key==="d"||z.key==="r"||z.key==="Enter")?(z.preventDefault(),gr(I)):(z.key==="a"||z.key==="Enter")&&I?(z.preventDefault(),Wt(I,"approve")):z.key==="r"&&I?(z.preventDefault(),Wt(I,"revert")):z.key==="x"&&!q&&I&&(z.preventDefault(),Wt(I,"dismiss"))},[re,ft,a,Ye,oe,it,K,fn,gr,Wt]),ma=z=>{if(z.kind==="git"){let D=!ue.has(z.uri);return(0,J.jsxs)("div",{ref:xe=>w.register(z.uri,xe),className:"rounded-lg border border-white/8 bg-black/20",children:[(0,J.jsx)("button",{type:"button","aria-expanded":D,className:"px-3 py-2 text-xs text-white/85",onClick:()=>be(xe=>{let Mt=new Set(xe);return Mt.has(z.uri)?Mt.delete(z.uri):Mt.add(z.uri),Mt}),children:z.uri}),D?(0,J.jsx)(WL,{uri:z.uri,rows:Ve,agentId:t,projectId:e,canWrite:a,revisions:c,queue:w}):null]})}let{rec:I,index:q}=z,F=K.has(I.id),de={onApprove:()=>{Wt(I,"approve")},onRevert:()=>{Wt(I,"revert")},onDiscard:()=>{gr(I)},onDismiss:()=>{Wt(I,"dismiss")}};return z.kind==="pending-card"?(0,J.jsx)(VE,{rec:I,agentId:t,projectId:e,focused:q===it,orphaned:F,onOpen:Kr,...de,onFocus:()=>Qe(q),busy:re===I.id,queue:w,revision:(Ne[I.id]??0)+(c[I.sourceSlug]??0),canWrite:a,onPreview:D=>{k.current.set(I.id,D),D.requiresAcknowledgement.length&&Pt(xe=>xe+1)},peekPreview:_,takeRefetch:U,extra:v.kind==="all"?(0,J.jsx)(WL,{uri:I.uri,rows:Ve,agentId:t,projectId:e,canWrite:a,revisions:c,queue:w}):null}):(0,J.jsxs)("div",{onMouseDown:()=>Qe(q),className:`group h-8 flex items-center gap-2 px-2 rounded-lg ${q===it?"bg-amber-400/[0.06] ring-1 ring-amber-400/20":"hover:bg-white/5"}`,children:[jL[I.op],(0,J.jsxs)("button",{type:"button",onClick:()=>Kr(I.uri),className:"min-w-0 flex-1 text-left truncate text-xs text-white/85 hover:text-white",title:I.uri,children:[gt(I.uri)||I.uri,(0,J.jsxs)("span",{className:"ml-1.5 text-[10px] text-white/30 font-mono",children:[et(I.uri),"/"]})]}),(0,J.jsx)(qL,{diff:I.diff}),F?$L:(0,J.jsx)("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${VL(I.status)}`,title:I.status}),a?(0,J.jsx)(KL,{orphaned:F,busy:re===I.id,...de,className:"hidden group-hover:flex items-center gap-0.5 shrink-0"}):null]})},xn=Le.filter(z=>z.outcome!=="ok"),Tn=ne||Te.loading;return(0,J.jsxs)("div",{className:"w-full h-full flex flex-col min-h-0 outline-none",tabIndex:0,onKeyDown:Xr,children:[a&&Ye?(0,J.jsx)(GL,{request:Ye,agentId:t,projectId:e,run:w.run,onClose:()=>Lt(null),next:Ye.kind==="group"?rr.filter(z=>!Ye.records.some(I=>I.id===z.id)).length:0,onNext:qr,refetch:ct,onBatchStart:h,onDone:z=>{for(let I of z)dn.current.add(I.id);Jn(z)}},Ye.kind==="group"?`group\0${Ye.records[0]?.id??""}`:`single\0${Ye.rec.id}`):null,(0,J.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5 px-3 py-2 border-b border-white/5 shrink-0",children:[(0,J.jsx)("span",{className:"text-xs font-semibold text-white/80",children:"Changes"}),(0,J.jsx)("span",{className:"text-[10px] text-white/35",children:oe.length>0?`${Math.min(it+1,oe.length)}/${oe.length}`:"0"}),(0,J.jsxs)("div",{className:"ml-auto flex flex-wrap items-center justify-end gap-1",children:[(0,J.jsxs)("div",{className:"flex items-center rounded-lg border border-white/8 overflow-hidden",children:[(0,J.jsx)("button",{type:"button",onClick:()=>fn(-1),disabled:oe.length===0||it===0,className:"p-1.5 text-white/45 hover:text-white/80 disabled:opacity-30",title:"Previous (\u2191)",children:(0,J.jsx)(bl,{className:"w-3.5 h-3.5"})}),(0,J.jsx)("button",{type:"button",onClick:()=>fn(1),disabled:oe.length===0||it>=oe.length-1,className:"p-1.5 text-white/45 hover:text-white/80 disabled:opacity-30",title:"Next (\u2193)",children:(0,J.jsx)(un,{className:"w-3.5 h-3.5"})})]}),a?At?(0,J.jsxs)("button",{type:"button",onClick:()=>{pa()},disabled:ft||Ft.length===0,className:"inline-flex shrink-0 whitespace-nowrap items-center gap-1 rounded-lg border border-emerald-500/30 bg-emerald-500/15 px-2 py-1 text-[10px] text-emerald-100 hover:bg-emerald-500/20 disabled:opacity-40",title:`Approve ${Ft.length} visible change(s) that need no confirmation`,children:[ft?(0,J.jsx)(We,{className:"w-3 h-3 animate-spin"}):(0,J.jsx)(gs,{className:"w-3 h-3"})," Approve ",Ft.length,"?"]}):(0,J.jsxs)("button",{type:"button",onClick:()=>Tt(!0),disabled:Ft.length===0,className:"inline-flex shrink-0 whitespace-nowrap items-center gap-1 rounded-lg border border-white/8 px-2 py-1 text-[10px] text-white/55 hover:text-white/85 hover:bg-white/5 disabled:opacity-30",title:"Approve every visible change that needs no confirmation",children:[(0,J.jsx)(gs,{className:"w-3 h-3"})," Approve ",Ft.length]}):null,a&&Zt.length>0?(0,J.jsxs)("button",{type:"button",onClick:()=>{dn.current.clear(),Lt({kind:"group",records:Zt.slice(0,tc),total:Zt.length})},className:"inline-flex shrink-0 whitespace-nowrap items-center gap-1 rounded-lg border border-amber-400/30 px-2 py-1 text-[10px] text-amber-200/90 hover:bg-amber-500/10",title:`Review the changes that need your confirmation, grouped by reason (up to ${tc} at a time)`,children:[(0,J.jsx)(Sa,{className:"w-3 h-3"})," ",Zt.length," need confirmation"]}):null,(0,J.jsxs)("div",{className:"flex items-center rounded-lg border border-white/8 overflow-hidden",children:[(0,J.jsx)("button",{type:"button",onClick:()=>N("list"),title:"Compact list",className:`p-1.5 ${Y==="list"?"bg-white/10 text-white":"text-white/45 hover:text-white/80"}`,children:(0,J.jsx)(ni,{className:"w-3.5 h-3.5"})}),(0,J.jsx)("button",{type:"button",onClick:()=>N("cards"),title:"Diff cards",className:`p-1.5 ${Y==="cards"?"bg-white/10 text-white":"text-white/45 hover:text-white/80"}`,children:(0,J.jsx)(Ka,{className:"w-3.5 h-3.5"})})]}),a&&K.size>0?(0,J.jsxs)("button",{type:"button",onClick:Nr,disabled:Ot,className:Ue?"inline-flex shrink-0 whitespace-nowrap items-center gap-1 rounded-lg border border-rose-500/40 bg-rose-500/15 px-2 py-1 text-[10px] text-rose-100 hover:bg-rose-500/25 disabled:opacity-40":"inline-flex shrink-0 whitespace-nowrap items-center gap-1 rounded-lg border border-rose-400/25 px-2 py-1 text-[10px] text-rose-200/80 hover:text-rose-100 hover:bg-rose-500/10 disabled:opacity-40",title:Ue?`Discard all ${K.size} orphaned change(s)`:"Repair \u2014 discard orphaned changes whose backing file no longer exists",children:[Ot?(0,J.jsx)(We,{className:"w-3 h-3 animate-spin"}):Ue?(0,J.jsx)(Nt,{className:"w-3 h-3"}):(0,J.jsx)(ci,{className:"w-3 h-3"}),Ue?`Discard ${K.size}?`:`Repair ${K.size}`]}):null,(0,J.jsx)("button",{type:"button",onClick:()=>{mt()},disabled:Tn,title:"Refresh",className:"p-1.5 rounded-lg text-white/45 hover:text-white/80 hover:bg-white/5 disabled:opacity-40",children:(0,J.jsx)(_t,{className:`w-3.5 h-3.5 ${Tn?"animate-spin":""}`})}),(0,J.jsx)(zL.SkillLauncher,{variant:"icon",size:"sm",skill:"manage-files",packageId:"@neuralis/brain-core",scripts:["scripts/pending.sh","scripts/approve.sh"],label:"Review or approve pending changes with the agent",icon:"FileText"})]})]}),(0,J.jsxs)("div",{className:"flex flex-wrap items-center gap-2 px-3 py-1.5 border-b border-white/5 shrink-0 text-[11px]",children:[C?(0,J.jsxs)("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded bg-violet-500/15 text-violet-200/90",title:C,children:["conversation ",(0,J.jsx)("button",{type:"button",onClick:()=>g({}),className:"rounded hover:bg-violet-400/20 -mr-0.5",title:"Clear conversation filter",children:(0,J.jsx)(Ht,{className:"w-3 h-3"})})]}):null,(0,J.jsxs)("select",{"aria-label":"Change type",value:v.kind,onChange:V("kind"),className:nl,style:rl,children:[(0,J.jsx)("option",{value:"all",children:"All changes"}),(0,J.jsx)("option",{value:"pending",children:"Pending review"}),(0,J.jsx)("option",{value:"git",children:"Git"})]}),(0,J.jsxs)("select",{"aria-label":"Source",value:v.source,onChange:V("source"),className:nl,style:rl,children:[(0,J.jsx)("option",{value:"",children:"All sources"}),on.map(z=>(0,J.jsx)("option",{value:z,children:z},z))]}),(0,J.jsxs)("select",{"aria-label":"Repository",value:v.repo,onChange:V("repo"),className:nl,style:rl,children:[(0,J.jsx)("option",{value:"",children:"All repositories"}),kt.map(z=>(0,J.jsx)("option",{value:Qu(z),children:r0(z)},Qu(z)))]}),(0,J.jsxs)("select",{"aria-label":"Checked-out branch",value:v.branch,onChange:V("branch"),className:nl,style:rl,children:[(0,J.jsx)("option",{value:"",children:"All checked-out branches"}),[...new Set(kt.map(z=>z.status?.branch).filter(Boolean))].map(z=>(0,J.jsx)("option",{value:z,children:z},z))]}),Oe.length>1?(0,J.jsxs)("select",{"aria-label":"Agent",value:v.agent,onChange:V("agent"),className:nl,style:rl,children:[(0,J.jsx)("option",{value:"",children:"All agents"}),Oe.map(z=>(0,J.jsx)("option",{value:z,children:z},z))]}):null,ee.length>1?(0,J.jsxs)("select",{"aria-label":"Origin",value:v.origin,onChange:V("origin"),className:nl,style:rl,children:[(0,J.jsx)("option",{value:"",children:"All origins"}),ee.map(z=>(0,J.jsx)("option",{value:z,children:z},z))]}):null]}),He.filter(z=>z.error).map(z=>(0,J.jsxs)("div",{className:"px-3 py-2 text-xs text-red-300 shrink-0",children:[r0(z),": ",z.error]},`${z.source}/${z.repo.rel}`)),Se?(0,J.jsxs)("div",{className:"mx-3 mt-2 flex items-center gap-2 rounded-lg border border-red-500/25 bg-red-500/10 px-2.5 py-1.5 text-[11px] text-red-200/85 shrink-0",children:[(0,J.jsx)(ot,{className:"w-3.5 h-3.5"})," ",Se]}):null,xn.length?(0,J.jsxs)("div",{className:"mx-3 mt-2 max-h-28 overflow-auto overlay-scroll rounded-lg border border-amber-500/25 bg-amber-500/[0.06] px-2.5 py-1.5 text-[10.5px] text-amber-100/85 shrink-0",children:[(0,J.jsxs)("div",{className:"flex items-center gap-2 font-semibold",children:[Le.length-xn.length," done \xB7 ",xn.length," not done",(0,J.jsx)("button",{type:"button",onClick:()=>at([]),className:"ml-auto rounded hover:bg-white/10",title:"Dismiss",children:(0,J.jsx)(Ht,{className:"w-3 h-3"})})]}),xn.map(z=>(0,J.jsxs)("div",{className:"truncate font-mono",title:z.detail,children:[z.action," ",z.uri,": ",z.outcome==="changed"?"changed since the preview (409)":z.outcome==="needs-ack"?"needs confirmation \u2014 opened in the review dialog":z.detail??"refused"]},z.id))]}):null,(0,J.jsx)("div",{ref:P,className:"flex-1 min-h-0 overflow-auto overlay-scroll px-2 py-2",style:{overflowAnchor:"none"},children:Tn&&Ae.length===0?(0,J.jsxs)("div",{className:"flex items-center gap-2 px-3 py-6 text-xs text-white/40",children:[(0,J.jsx)(We,{className:"w-3.5 h-3.5 animate-spin"})," Loading\u2026"]}):Ae.length===0?(0,J.jsx)("div",{className:"px-3 py-8 text-center text-xs text-white/35",children:"No pending review changes."}):(0,J.jsx)("div",{style:{height:ar.getTotalSize(),width:"100%",position:"relative"},children:ar.getVirtualItems().map(z=>{let I=Ae[z.index];return I?(0,J.jsx)("div",{"data-index":z.index,ref:OL(I.kind)?ar.measureElement:void 0,className:I.kind==="pending-row"?"":"pb-1.5",style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${z.start}px)`},children:ma(I)},z.key):null})})})]})}var $E=(t,e,n)=>t.end<=(n.scrollOffset??0);var X=j(ie(),1),KE=2e5,XE=2500,YE=12e3;function JL(t,e){let n=String(t||"").trim().replace(/\\/g,"/");if(!n)return e;if(n.includes("://")){let s=n.indexOf("://"),i=n.slice(0,s),o=n.slice(s+3).replace(/\/+/g,"/").replace(/^\/+/,"");return`${i}://${o}`}let r=sr(e),a=n.replace(/\/+/g,"/").replace(/^\/+/,"");return a?`${r}${a}`:e}function s0(){let t=H(F=>F.client),e=H(F=>F.openFiles),n=H(F=>F.activeFile),r=H(F=>F.files),a=H(F=>F.fileContentByPath),s=H(F=>F.fileBaseContentByPath),i=H(F=>F.fileErrorByPath),o=H(F=>F.openFile),l=H(F=>F.patchFileNode),u=H(F=>F.saveFileInPlace),c=H(F=>F.markFileDeleted),d=H(F=>F.clearFilePrev),f=H(F=>F.refresh),h=H(F=>F.activeProjectId),p=H(F=>F.workspacePanels),g=H(F=>F.setWorkspacePanelOpen),m=H(F=>F.activeWorkspaceTab),x=H(F=>F.setActiveWorkspaceTab),y=H(F=>F.gitDiffTarget),b=H(F=>F.setGitDiffTarget),C=H(F=>F.gitCommitTarget),L=H(F=>F.setGitCommitTarget),P=H(F=>F.diffViewMode),w=H(F=>F.activeAgentId),k=hn(),_=k.useAgents(),M=(0,yt.useMemo)(()=>Ms(_),[_]),R=w?M.byId.get(w)??null:null,U=k.MarkdownRenderer,v=n?r[n]:null,T=n?a[n]??"":"",V=v?.uri??"",Y=v?JE(V):!1,N=v?ZE(V):!1,A=v?QE(V):!1,B=v?eO(V):!1,K=v?nO(V):!1,te=v?rd(V):void 0,ne=v?tO(V):"Binary file",pe=Y,[Se,le]=(0,yt.useState)(!1),[re,he]=(0,yt.useState)(""),[Ne,Ee]=(0,yt.useState)(""),[ze,ct]=(0,yt.useState)(!1),[it,Qe]=(0,yt.useState)(null),[Ye,Lt]=(0,yt.useState)(!1),[Le,at]=(0,yt.useState)(!1),[ft,bt]=(0,yt.useState)(!1),[At,Tt]=(0,yt.useState)(!1),[Ue,me]=(0,yt.useState)(!0),[Ot,Jt]=(0,yt.useState)(!1),ue=H(F=>F.filePrevByPath),be=n?ue[n]:void 0,Ge=!!be&&v?.status==="pending_review",Re=!!be,Te=(0,yt.useMemo)(()=>v?v.sourceAgentId?M.byId.get(v.sourceAgentId)??null:R:null,[v,M,R]),vt=n?i[n]:void 0,mt=!!n&&!mc({fileBaseContentByPath:s,fileErrorByPath:i},n),Gt=vt?`Read failed: ${vt}`:mt?"Loading\u2026":"Empty file",je=v?.status==="deleted",kt=p.upload&&m==="upload",on=p.sources&&m==="sources",Oe=p.packages&&m==="packages",ee=p.pending&&m==="pending",oe=m==="git-diff"&&!!y,He=m==="git-commit"&&!!C,Ve=!kt&&!on&&!Oe&&!ee&&!oe&&!He,Ae=v?.sourceAgentId??w??void 0,ce=v?.sourceAgentId??w??null,Pt=(0,yt.useMemo)(()=>!v?.uri||!Ae?null:ex(Ae,v.uri,h??void 0),[v?.uri,Ae,h]),Ft=(0,yt.useRef)(null),Zt=(0,yt.useRef)(null),dn=(0,ZL.useContainerWidth)(Zt),rr=P==="auto"?dn?"split":"unified":P,[qr,Mn]=(0,yt.useState)(void 0),Yn=v?.git;(0,yt.useEffect)(()=>{let F=!1;if(!ce||!V||!Yn||N||A||B){Mn(void 0);return}let de=qe(V),D=V.indexOf("://"),xe=D>=0?V.slice(D+3):"";if(!de||!xe){Mn(void 0);return}return(async()=>{try{let Mt=await lc({agentId:ce,...h?{projectId:h}:{},source:de,path:xe,staged:!1},t);if(F)return;if(Mt&&Mt.ok===!1){Mn(void 0);return}let zt=typeof Mt?.diff=="string"?Mt.diff:"",yn=E1(zt);Mn(ld(yn)?void 0:yn)}catch{F||Mn(void 0)}})(),()=>{F=!0}},[ce,h,V,Yn,N,A,B]);let $r=fi(v?.version?.changedAt),ar=v?.version?.sync,Pr=!0,Kr=!!v&&Se&&(Ne!==T||JL(re,v.uri)!==v.uri),ln=v?.version?.diff,Jn=!!ln&&(ln.added>0||ln.removed>0),Wt=!!v&&yp(v),gr=(0,yt.useMemo)(()=>{if(!v)return"/";if(v.parentUri&&v.parentUri!==v.uri)return v.parentUri;let F=et(v.uri);return F===v.uri?sr(v.uri):F},[v]),Un=(0,yt.useMemo)(()=>rO(T),[T]),Nr=v?.readSource==="live",pa=!!v&&!Se&&!N&&!A&&(K||Un.charCount>=KE||Un.lineCount>=XE||Nr&&Un.charCount>=YE),fn=(0,yt.useCallback)(async()=>{if(!(!ce||!v||Ye)){Lt(!0),Qe(null);try{await c({agentId:ce,projectId:h??null,node:v})}catch(F){console.error("[Filesystem] delete failed",F),Qe(F instanceof Error?F.message:"Delete failed")}finally{Lt(!1)}}},[ce,v,Ye,h,c]),Xr=(0,yt.useCallback)(async()=>{if(!(!ce||!v||Le)){at(!0);try{let F=await yr({agentId:ce,...h?{projectId:h}:{},id:v.id,uri:v.uri,fields:{status:"active"}},t);if(F&&F.ok===!1){Qe(ga(F,"Restore failed"));return}f({agentId:ce,projectId:h??null}),o({agentId:ce,projectId:h??null,uri:v.uri,readAgentId:Te?.id,force:!0})}catch(F){console.error("[Filesystem] restore failed",F)}finally{at(!1)}}},[ce,v,Le,h,f,o,Te?.id]),ma=(0,yt.useCallback)(async()=>{if(!(!ce||!v||ft)){if(v.status==="pending_review"){g("pending",!0),x("pending");return}bt(!0);try{let F=await fc({agentId:ce,...h?{projectId:h}:{},id:v.id,uri:v.uri},t);if(F&&F.ok){let de=v.storeKey||n||Va(v);de&&(l(de,{status:"active"}),d(de)),o({agentId:ce,projectId:h??null,uri:v.uri,readAgentId:Te?.id,force:!0})}}catch(F){console.error("[Filesystem] approve failed",F)}finally{bt(!1)}}},[ce,v,ft,h,o,Te?.id,n,l,d]),xn=(0,yt.useCallback)(async()=>{if(!(!ce||!v||At)){if(v.status==="pending_review"){g("pending",!0),x("pending");return}Tt(!0);try{let F=await yr({agentId:ce,...h?{projectId:h}:{},id:v.id,uri:v.uri,revert:!0},t);if(F&&F.ok===!1){Qe(ga(F,"Revert failed"));return}if(F&&F.ok){let de=v.storeKey||n||Va(v);de&&(l(de,{status:be?.status||"active"}),d(de)),o({agentId:ce,projectId:h??null,uri:v.uri,readAgentId:Te?.id,force:!0})}}catch(F){console.error("[Filesystem] revert failed",F)}finally{Tt(!1)}}},[ce,v,At,h,o,Te?.id,n,be,l,d]);(0,yt.useEffect)(()=>{if(!v){Ft.current=null,le(!1),Jt(!1),he(""),Ee(""),Qe(null);return}let F=v.storeKey||n||Va(v),de=Ft.current!==F;if(Ft.current=F,de){le(!1),Jt(!1),me(!0),he(v.uri),Ee(T),Qe(null);return}Se||(he(v.uri),Ee(T),Qe(null))},[v?.storeKey,v?.uri,T,n,Se]);let Tn=(0,yt.useCallback)(()=>{Wt&&Jt(F=>!F)},[Wt]),z=(0,yt.useCallback)(()=>{!v||je||(he(v.uri),Ee(T),Qe(null),le(!0))},[v,T,je]),I=(0,yt.useCallback)(()=>{v&&(he(v.uri),Ee(T),Qe(null),le(!1))},[v,T]),q=(0,yt.useCallback)(async()=>{if(!v||!ce||ze)return;let F=v.uri,de=JL(re,F);if(!de){Qe("Invalid target URI");return}ct(!0),Qe(null);try{await u({agentId:ce,projectId:h??null,readAgentId:Te?.id,node:v,targetUri:de,content:Ne,currentContent:T}),me(!0),le(!1)}catch(D){Qe(D instanceof Error?D.message:"Save failed")}finally{ct(!1)}},[v,ce,ze,re,Ne,T,h,Te?.id,u]);return(0,X.jsxs)("div",{className:"h-full w-full flex flex-col min-w-0 min-h-0",children:[e.length>0||p.upload||Pr&&p.sources||p.packages||p.pending||y||C?(0,X.jsxs)("div",{className:"flex shrink-0 items-stretch",style:{backgroundColor:"transparent",borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[(0,X.jsxs)("div",{[ud]:"",className:"flex min-w-0 flex-1 overflow-x-auto overflow-y-hidden",children:[(0,X.jsx)(_1,{}),p.upload?(0,X.jsxs)("div",{className:"group flex shrink-0 items-center",children:[(0,X.jsxs)("button",{type:"button",className:$("flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",kt?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>x("upload"),children:[(0,X.jsx)(Ia,{className:"w-3.5 h-3.5 shrink-0"}),(0,X.jsx)("span",{className:"truncate flex-1",children:"Upload"})]}),(0,X.jsx)("button",{type:"button","aria-label":"Close Upload",className:"opacity-0 group-hover:opacity-100 focus-visible:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:F=>{F.stopPropagation(),g("upload",!1)},children:(0,X.jsx)(Ht,{className:"w-3 h-3"})})]}):null,Pr&&p.sources?(0,X.jsxs)("div",{className:"group flex shrink-0 items-center",children:[(0,X.jsxs)("button",{type:"button",className:$("flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",on?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>x("sources"),children:[(0,X.jsx)(ui,{className:"w-3.5 h-3.5 shrink-0"}),(0,X.jsx)("span",{className:"truncate flex-1",children:"Sources"})]}),(0,X.jsx)("button",{type:"button","aria-label":"Close Sources",className:"opacity-0 group-hover:opacity-100 focus-visible:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:F=>{F.stopPropagation(),g("sources",!1)},children:(0,X.jsx)(Ht,{className:"w-3 h-3"})})]}):null,p.packages?(0,X.jsxs)("div",{className:"group flex shrink-0 items-center",children:[(0,X.jsxs)("button",{type:"button",className:$("flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",Oe?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>x("packages"),children:[(0,X.jsx)(wr,{className:"w-3.5 h-3.5 shrink-0"}),(0,X.jsx)("span",{className:"truncate flex-1",children:"Packages"})]}),(0,X.jsx)("button",{type:"button","aria-label":"Close Packages",className:"opacity-0 group-hover:opacity-100 focus-visible:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:F=>{F.stopPropagation(),g("packages",!1)},children:(0,X.jsx)(Ht,{className:"w-3 h-3"})})]}):null,p.pending?(0,X.jsxs)("div",{className:"group flex shrink-0 items-center",children:[(0,X.jsxs)("button",{type:"button",className:$("flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",ee?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>x("pending"),children:[(0,X.jsx)(Ka,{className:"w-3.5 h-3.5 shrink-0"}),(0,X.jsx)("span",{className:"truncate flex-1",children:"Changes"})]}),(0,X.jsx)("button",{type:"button","aria-label":"Close Changes",className:"opacity-0 group-hover:opacity-100 focus-visible:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:F=>{F.stopPropagation(),g("pending",!1)},children:(0,X.jsx)(Ht,{className:"w-3 h-3"})})]}):null,y?(0,X.jsxs)("div",{className:"group flex shrink-0 items-center",children:[(0,X.jsxs)("button",{type:"button",className:$("flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",oe?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>x("git-diff"),title:`Diff: ${xi(y.repo,y.path)} (${e1(y)})`,children:[(0,X.jsx)(or,{className:"w-3.5 h-3.5 shrink-0 text-violet-300/80"}),(0,X.jsx)("span",{className:"truncate flex-1",children:xi(y.repo,gt(y.path)||y.path)})]}),(0,X.jsx)("button",{type:"button","aria-label":"Close Git diff",className:"opacity-0 group-hover:opacity-100 focus-visible:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:F=>{F.stopPropagation(),b(null),oe&&x("file")},children:(0,X.jsx)(Ht,{className:"w-3 h-3"})})]}):null,C?(0,X.jsxs)("div",{className:"group flex shrink-0 items-center",children:[(0,X.jsxs)("button",{type:"button",className:$("flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",He?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>x("git-commit"),title:C.kind==="commit"?xi(C.repo,`Commit ${tn(C.sha)}: ${C.subject}`):xi(C.repo,`Outgoing changes (${tn(C.base)}..${tn(C.head)})`),children:[C.kind==="commit"?(0,X.jsx)(Dr,{className:"w-3.5 h-3.5 shrink-0 text-violet-300/80"}):(0,X.jsx)(Mr,{className:"w-3.5 h-3.5 shrink-0 text-blue-300/80"}),(0,X.jsx)("span",{className:"truncate flex-1",children:C.kind==="commit"?xi(C.repo,`${tn(C.sha)} ${C.subject}`):xi(C.repo,"Outgoing changes")})]}),(0,X.jsx)("button",{type:"button","aria-label":"Close Git commit",className:"opacity-0 group-hover:opacity-100 focus-visible:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:F=>{F.stopPropagation(),L(null)},children:(0,X.jsx)(Ht,{className:"w-3 h-3"})})]}):null]}),(0,X.jsx)(H1,{})]}):null,Ve&&v?(0,X.jsxs)("div",{className:"flex items-center justify-between gap-2 px-2 py-1.5 text-[11px]",style:{backgroundColor:"transparent",borderBottom:!Ot||!Wt?"1px solid rgba(255,255,255,0.05)":"none"},children:[(0,X.jsxs)("div",{className:$("min-w-0 flex-1 flex items-center gap-2 rounded-lg px-1.5 py-1 transition",Wt?"cursor-pointer hover:bg-white/[0.04]":""),role:Wt?"button":void 0,tabIndex:Wt?0:void 0,"aria-expanded":Wt?Ot:void 0,onClick:Tn,onKeyDown:F=>{Wt&&(F.key==="Enter"||F.key===" ")&&(F.preventDefault(),Tn())},children:[Jn?(0,X.jsxs)("span",{className:$("inline-flex shrink-0 items-center gap-1 rounded-full border px-2 py-1 text-[10px]",$r.pillClassName),children:[(0,X.jsx)(or,{className:$("w-3 h-3",$r.iconClassName)}),(0,X.jsxs)("span",{className:"text-emerald-200/95",children:["+",ln.added]}),(0,X.jsx)("span",{className:"text-white/25",children:"/"}),(0,X.jsxs)("span",{className:"text-rose-200/95",children:["-",ln.removed]})]}):null,(0,X.jsxs)("div",{className:"min-w-0 flex-1",children:[Se?(0,X.jsx)("input",{value:re,onChange:F=>he(F.target.value),onClick:F=>F.stopPropagation(),onKeyDown:F=>F.stopPropagation(),className:"h-7 w-full rounded-md bg-white/[0.04] border border-white/[0.12] px-2 text-[11px] font-mono text-white/85 outline-none focus:border-white/[0.2]",disabled:ze}):(0,X.jsxs)("div",{className:"min-w-0 flex items-center gap-2",title:`${qe(v.uri)} \xB7 ${v.uri}`,children:[(0,X.jsx)("span",{className:$("shrink-0 text-white/88 font-medium",v.status==="deleted"?"line-through text-red-200/70":""),children:v.name}),(0,X.jsx)("span",{className:"truncate font-mono text-white/42",children:gr})]}),vt?(0,X.jsx)("div",{className:"text-[10px] text-red-300/80 truncate",title:vt,children:"Read failed"}):null,it?(0,X.jsx)("div",{className:"text-[10px] text-red-300/80 truncate",title:it,children:it}):null]}),Wt?(0,X.jsx)(Et,{className:$("w-3.5 h-3.5 shrink-0 text-white/35 transition-transform",Ot&&"rotate-180")}):null]}),(0,X.jsxs)("div",{className:"flex items-center gap-2",children:[Se?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)("button",{type:"button",className:"inline-flex items-center justify-center rounded-md bg-emerald-500/15 border border-emerald-500/25 p-1.5 text-emerald-100 hover:bg-emerald-500/20 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:q,disabled:ze||!ce,"aria-label":"Save changes",children:ze?(0,X.jsx)(We,{className:"w-3 h-3 animate-spin"}):(0,X.jsx)(Dn,{className:"w-3 h-3"})}),(0,X.jsx)("button",{type:"button",className:"inline-flex items-center justify-center rounded-md bg-white/5 p-1.5 text-white/70 hover:bg-white/10 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:I,disabled:ze,"aria-label":"Cancel edit",children:(0,X.jsx)(Ht,{className:"w-3 h-3"})})]}):(0,X.jsx)("button",{type:"button",className:"inline-flex items-center justify-center rounded-md bg-white/5 p-1.5 text-white/60 hover:text-white/80 hover:bg-white/10 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:z,disabled:!ce||je||B,title:B?"Binary files cannot be edited in-place":"Edit in-place","aria-label":"Edit in-place",children:(0,X.jsx)(si,{className:"w-3 h-3"})}),(0,X.jsx)("button",{type:"button",className:$("inline-flex items-center justify-center rounded-md p-1.5 transition","border border-red-500/15 bg-red-500/10 text-red-300/70 hover:text-red-200 hover:bg-red-500/15","disabled:opacity-40 disabled:cursor-not-allowed"),onClick:fn,disabled:!ce||Ye||Le,title:"Mark as deleted","aria-label":"Mark as deleted",children:Ye?(0,X.jsx)(We,{className:"w-3 h-3 animate-spin"}):(0,X.jsx)(Nt,{className:"w-3 h-3"})}),(0,X.jsx)("button",{type:"button",className:"inline-flex items-center justify-center rounded-md bg-white/5 p-1.5 text-white/60 hover:text-white/80 hover:bg-white/10 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>{!ce||!v||o({agentId:ce,projectId:h??null,uri:v.uri,readAgentId:Te?.id,force:!0})},title:"Reload file","aria-label":"Reload file",children:(0,X.jsx)(_t,{className:"w-3 h-3"})}),!Se&&Re&&v?.status!=="pending_review"?(0,X.jsx)("button",{type:"button",className:"inline-flex items-center justify-center rounded-md bg-white/5 p-1.5 text-white/60 hover:text-white/80 hover:bg-white/10 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:xn,disabled:At||ft||!ce,title:"Undo to previous version","aria-label":"Undo to previous version",children:At?(0,X.jsx)(We,{className:"w-3 h-3 animate-spin"}):(0,X.jsx)(Ca,{className:"w-3 h-3"})}):null]})]}):null,Ve&&v&&Ot&&Wt?(0,X.jsx)(xp,{node:v,hideVersionDiff:!0}):null,Ve&&v&&Kr?(0,X.jsxs)("div",{className:"flex items-center justify-between gap-3 px-2 py-2",style:{background:"linear-gradient(90deg, rgba(56,189,248,0.08) 0%, rgba(56,189,248,0.02) 100%)",borderBottom:"1px solid rgba(56,189,248,0.16)"},children:[(0,X.jsxs)("div",{className:"flex items-center gap-2 text-[11px] text-sky-100/85",children:[(0,X.jsx)(Xa,{className:"w-3.5 h-3.5 text-sky-300/75"}),(0,X.jsx)("span",{children:"Local draft in progress"})]}),(0,X.jsx)("div",{className:"text-[10px] text-sky-100/55",children:"Save or cancel to resolve the draft state"})]}):null,Ve&&v&&Ge&&!Se?(0,X.jsxs)("div",{className:"flex items-center justify-between gap-3 px-2 py-2",style:{background:"linear-gradient(90deg, rgba(251,191,36,0.08) 0%, rgba(244,63,94,0.03) 100%)",borderBottom:"1px solid rgba(251,191,36,0.18)"},children:[(0,X.jsxs)("div",{className:"flex items-center gap-2 text-[11px] text-amber-200/80",children:[(0,X.jsx)(or,{className:"w-3.5 h-3.5 text-amber-400/70"}),(0,X.jsx)("span",{children:"Pending changes \u2014 review and approve or revert"})]}),(0,X.jsxs)("div",{className:"flex items-center gap-2",children:[(0,X.jsxs)("button",{type:"button",className:$("inline-flex items-center gap-1 rounded-md px-2 py-1 text-[11px] transition",Ue?"bg-amber-500/15 border border-amber-500/25 text-amber-100":"bg-white/5 text-white/50 hover:bg-white/10 hover:text-white/70"),onClick:()=>me(!Ue),children:[(0,X.jsx)(or,{className:"w-3 h-3"}),"Diff"]}),Ue?(0,X.jsx)(sd,{}):null,(0,X.jsxs)("button",{type:"button",className:"inline-flex items-center gap-1 rounded-md bg-emerald-500/15 border border-emerald-500/25 px-2 py-1 text-[11px] text-emerald-100 hover:bg-emerald-500/20 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:ma,disabled:ft||At||!ce,title:"Accept current state",children:[ft?(0,X.jsx)(We,{className:"w-3 h-3 animate-spin"}):(0,X.jsx)(Dn,{className:"w-3 h-3"}),"Approve"]}),(0,X.jsxs)("button",{type:"button",className:"inline-flex items-center gap-1 rounded-md bg-red-500/10 border border-red-500/20 px-2 py-1 text-[11px] text-red-200/80 hover:bg-red-500/15 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:xn,disabled:ft||At||!ce,title:"Revert to previous version",children:[At?(0,X.jsx)(We,{className:"w-3 h-3 animate-spin"}):(0,X.jsx)(Ca,{className:"w-3 h-3"}),"Revert"]})]})]}):null,Ve&&v&&!Se&&v.presence==="stale_indexed"?(0,X.jsxs)("div",{className:"flex items-center justify-between gap-3 px-2 py-2",style:{background:"linear-gradient(90deg, rgba(244,114,182,0.08) 0%, rgba(251,191,36,0.03) 100%)",borderBottom:"1px solid rgba(244,114,182,0.15)"},children:[(0,X.jsxs)("div",{className:"flex items-center gap-2 text-[11px] text-rose-100/85",children:[(0,X.jsx)(Ya,{className:"w-3.5 h-3.5 text-rose-300/75"}),(0,X.jsx)("span",{children:"This indexed node is missing from the live source"})]}),(0,X.jsx)("div",{className:"text-[10px] text-rose-100/55",children:"Useful for spotting sync drift"})]}):null,Ve&&v&&!Se&&v.presence==="unindexed"?(0,X.jsx)("div",{className:"flex items-center justify-between gap-3 px-2 py-2",style:{background:"linear-gradient(90deg, rgba(251,191,36,0.07) 0%, rgba(255,255,255,0.02) 100%)",borderBottom:"1px solid rgba(251,191,36,0.15)"},children:(0,X.jsxs)("div",{className:"flex items-center gap-2 text-[11px] text-amber-100/82",children:[(0,X.jsx)(ot,{className:"w-3.5 h-3.5 text-amber-300/75"}),(0,X.jsx)("span",{children:"Unindexed \u2014 file exists on the connector but is not yet vector-indexed"})]})}):null,(0,X.jsxs)("div",{ref:Zt,className:"flex-1 min-h-0 relative",children:[kt&&w?(0,X.jsx)("div",{className:"w-full h-full overflow-y-auto",children:(0,X.jsx)(Hg,{agentId:w,projectId:h??null})}):null,Pr&&on&&w?(0,X.jsx)("div",{className:"w-full h-full overflow-y-auto",children:(0,X.jsx)(dL,{agentId:w,projectId:h??null,isDocker:k.isDocker})}):null,Oe&&h?(0,X.jsx)("div",{className:"w-full h-full overflow-y-auto",children:(0,X.jsx)(bL,{projectId:h})}):null,ee&&w?(0,X.jsx)("div",{className:"w-full h-full min-h-0",children:(0,X.jsx)(YL,{agentId:w,projectId:h??null})}):null,oe&&y?(0,X.jsx)("div",{className:"w-full h-full min-h-0",children:(0,X.jsx)(Bg,{target:y,agentId:w,projectId:h??null})}):null,He&&C?(0,X.jsx)("div",{className:"w-full h-full min-h-0",children:(0,X.jsx)(sp,{target:C,agentId:w,projectId:h??null})}):null,Ve&&je?(0,X.jsxs)("div",{className:"absolute inset-x-4 top-4 z-10 rounded-xl border border-red-500/25 bg-black/70 p-3 backdrop-blur-sm",children:[(0,X.jsx)("div",{className:"text-[11px] text-red-200/85 mb-2",children:"This file is marked as deleted."}),(0,X.jsxs)("div",{className:"flex items-center gap-2",children:[(0,X.jsxs)("button",{type:"button",className:"h-8 px-3 rounded-lg text-xs font-semibold border border-emerald-500/30 bg-emerald-500/15 text-emerald-100 hover:bg-emerald-500/20 disabled:opacity-50 disabled:cursor-not-allowed",onClick:Xr,disabled:!ce||Le||Ye,children:[Le?(0,X.jsx)(We,{className:"w-3 h-3 animate-spin inline mr-1"}):null,"Restore"]}),(0,X.jsxs)("button",{type:"button",className:"h-8 px-3 rounded-lg text-xs font-semibold border border-red-500/30 bg-red-500/15 text-red-100 hover:bg-red-500/20 disabled:opacity-50 disabled:cursor-not-allowed",onClick:fn,disabled:!ce||Ye||Le,children:[Ye?(0,X.jsx)(We,{className:"w-3 h-3 animate-spin inline mr-1"}):null,"Delete"]})]})]}):null,Ve&&v?Ge&&Ue&&be&&!Se?(0,X.jsx)(Ag,{oldContent:be.content,newContent:T,language:te,viewMode:rr,className:"w-full h-full min-h-0"}):B&&!N&&!A&&!Se?(0,X.jsx)("div",{className:$("w-full h-full min-h-0 flex items-center justify-center px-6 text-center",je&&"blur-[2px] opacity-65"),children:(0,X.jsxs)("div",{className:"max-w-md rounded-2xl border border-white/10 bg-white/[0.035] px-5 py-4 shadow-[0_18px_46px_-26px_rgba(0,0,0,0.65)]",children:[(0,X.jsx)(ot,{className:"w-6 h-6 mx-auto mb-3 text-amber-300/75"}),(0,X.jsxs)("div",{className:"text-sm font-semibold text-white/82",children:[ne," preview disabled"]}),(0,X.jsx)("div",{className:"mt-2 text-xs leading-5 text-white/45",children:"This file is treated as binary, so Neuralis will not decode it into the text editor."})]})}):N&&Pt&&!Se?(0,X.jsx)("div",{className:"w-full h-full min-h-0 overflow-auto px-2 py-1.5",children:(0,X.jsxs)("div",{className:$(je&&"blur-[2px] opacity-65"),children:[(0,X.jsx)("div",{className:"text-[11px] text-white/45 mb-3",children:"Image preview"}),(0,X.jsx)("img",{src:Pt,alt:v.name,className:"max-w-full max-h-[calc(100vh-220px)] rounded-xl bg-black/20 shadow-[0_18px_46px_-26px_rgba(0,0,0,0.65),inset_0_1px_0_rgba(255,255,255,0.06)]"})]})}):A&&Pt&&!Se?(0,X.jsx)("div",{className:"w-full h-full min-h-0 overflow-auto px-2 py-1.5",children:(0,X.jsxs)("div",{className:$(je&&"blur-[2px] opacity-65"),children:[(0,X.jsx)("div",{className:"text-[11px] text-white/45 mb-3",children:"Video preview"}),(0,X.jsx)("video",{src:Pt,controls:!0,className:"w-full max-w-[1100px] rounded-xl bg-black/20 shadow-[0_18px_46px_-26px_rgba(0,0,0,0.65),inset_0_1px_0_rgba(255,255,255,0.06)]"})]})}):Y&&U&&!pa&&!Se?(0,X.jsx)("div",{className:$("w-full h-full min-h-0 overflow-auto px-1 py-1 text-white/80",je&&"blur-[2px] opacity-65"),children:T?(0,X.jsx)("div",{className:"min-h-full min-w-0",children:(0,X.jsx)(U,{content:T})}):(0,X.jsx)("div",{className:"px-2 py-1.5 text-sm text-white/30",children:Gt})}):(0,X.jsx)(Og,{value:Se?Ne:T,language:te,readOnly:!Se||je||ze,wrap:pe,onChange:Se?Ee:void 0,className:$("w-full h-full min-h-0",je&&"opacity-65"),placeholder:Gt,ariaLabel:Se?"File content editor":"File content viewer",gitLineStatus:qr}):Ve?(0,X.jsxs)("div",{className:"absolute inset-0 flex flex-col items-center justify-center text-white/20",children:[(0,X.jsx)(Cl,{className:"w-12 h-12 mb-2 opacity-50"}),(0,X.jsx)("div",{className:"text-sm",children:kt?"Upload files using this tab":"No file open"})]}):null,Ve&&v?(0,X.jsxs)("div",{className:"pointer-events-none absolute bottom-2 right-3 z-10 text-[10px] text-white/42",children:[(0,X.jsxs)("span",{children:[Un.lineCount.toLocaleString()," lines"]}),(0,X.jsxs)("span",{className:"ml-3",children:[Un.charCount.toLocaleString()," chars"]})]}):null]})]})}function JE(t){let e=gt(t).toLowerCase();return e.endsWith(".md")||e.endsWith(".mdx")||e.endsWith(".markdown")}function ZE(t){let e=gt(String(t||"")).toLowerCase();return e.endsWith(".png")||e.endsWith(".jpg")||e.endsWith(".jpeg")||e.endsWith(".webp")||e.endsWith(".gif")}function QE(t){let e=gt(String(t||"")).toLowerCase();return e.endsWith(".mp4")||e.endsWith(".webm")||e.endsWith(".mov")||e.endsWith(".m4v")}function eO(t){let e=gt(String(t||"")).toLowerCase();return/\.(wasm|png|jpe?g|gif|webp|ico|bmp|mp4|webm|avi|mov|m4v|mkv|mp3|wav|ogg|flac|aac|zip|tar|gz|bz2|7z|rar|pdf|docx?|xlsx?|pptx?|exe|dll|so|dylib|ttf|otf|woff2?|eot)$/.test(e)}function tO(t){let e=gt(String(t||"")).toLowerCase();return e.endsWith(".wasm")?"WebAssembly binary":e.endsWith(".pdf")?"PDF":"Binary file"}function nO(t){let e=gt(String(t||"")).toLowerCase();return e.endsWith(".jsonl")||e.endsWith(".ndjson")||e.endsWith(".log")}function rO(t){if(!t)return{charCount:0,lineCount:0};let e=1;for(let n=0;n<t.length;n++)t.charCodeAt(n)===10&&(e+=1);return{charCount:t.length,lineCount:e}}var ds="brain://project-info",z$=[{kind:"docs",label:"Upload Docs",folderUri:`${ds}/docs`,accept:".md,.txt,.pdf,.doc,.docx"},{kind:"requirements",label:"Upload Requirements",folderUri:`${ds}/requirements`,accept:".md,.txt,.pdf"},{kind:"architecture",label:"Upload Architecture",folderUri:`${ds}/architecture`,accept:".md,.txt,.pdf,.drawio,.json,.yaml,.yml"},{kind:"design",label:"Upload Design",folderUri:`${ds}/design`,accept:".md,.txt,.pdf,.fig,.png,.jpg,.jpeg,.webp"},{kind:"assets",label:"Upload Assets",folderUri:`${ds}/assets`,accept:".png,.jpg,.jpeg,.webp,.svg,.gif"},{kind:"datasets",label:"Upload Datasets",folderUri:`${ds}/datasets`,accept:".csv,.json,.jsonl,.parquet,.txt,.zip"},{kind:"other",label:"Upload File",folderUri:`${ds}/misc`}];var cn=j($e(),1);var QL=250,aO=1e3,sO=2e3,iO=6e3,oO=1e3,lO=5e3,uO=["filesystem:created","filesystem:updated","filesystem:deleted","filesystem:reverted","sync:completed","pending:changed"],cO=new Set(uO),dO=["filesAdded","filesUpdated","filesRemoved","filesMoved","chunksRemoved"];function fO(t){return t.mode==="purge"?!1:dO.every(e=>t[e]===0)}function e2(t,e){let n=ti(),r=H(T=>T.refreshTree),a=H(T=>T.refresh),s=H(T=>T.ensureFolderLoaded),i=H(T=>T.reconcileSourceFolders),o=H(T=>T.reconcileFolders),l=H(T=>T.setSourceDirty),u=H(T=>T.upsertFileNodeFromEvent),c=H(T=>T.incrementFolderBadges),d=H(T=>T.replaceFilePath),f=H(T=>T.clearFilePrev),h=H(T=>T.autoExpandToFile),p=H(T=>T.loadGitStatus),g=H(T=>T.notifyGitLogChanged),m=H(T=>T.refreshPendingCount),x=(0,cn.useRef)(0),y=(0,cn.useRef)(new Map),b=(0,cn.useRef)(new Map),C=(0,cn.useRef)(new Map);(0,cn.useEffect)(()=>{let T=y.current,V=C.current;return()=>{for(let Y of T.values())clearTimeout(Y);T.clear();for(let Y of V.values())clearTimeout(Y);V.clear()}},[t,e,n]),(0,cn.useEffect)(()=>{let T=b.current;return()=>{x.current+=1;for(let V of T.values())clearTimeout(V.timer);T.clear()}},[t,e,n]);let L=(0,cn.useRef)(null),P=(0,cn.useCallback)(()=>{if(!t||!e)return;let T=Date.now(),V=L.current,Y=V?V.deadline:T+lO;V&&clearTimeout(V.timer);let N=setTimeout(()=>{L.current=null,!(typeof document<"u"&&document.visibilityState==="hidden")&&m({agentId:t,projectId:e})},Math.max(0,Math.min(oO,Y-T)));L.current={timer:N,deadline:Y}},[t,e,m]),w=(0,cn.useRef)(P);w.current=P;let k=H(T=>T.activeAgentId===t&&T.activeProjectId===e);(0,cn.useEffect)(()=>{t&&e&&k&&m({agentId:t,projectId:e})},[t,e,k,m]),(0,cn.useEffect)(()=>{if(!t||!e)return;let T=()=>{document.visibilityState!=="hidden"&&w.current()},V=()=>w.current();return document.addEventListener("visibilitychange",T),window.addEventListener("focus",V),()=>{document.removeEventListener("visibilitychange",T),window.removeEventListener("focus",V),L.current&&clearTimeout(L.current.timer),L.current=null}},[t,e,m]);let _=(0,cn.useCallback)(T=>{let{type:V,payload:Y}=T,N=le=>{if(!t||!le)return;let re=n.getState().activeSource,he=typeof re=="string"&&re?re.includes("://")?qe(re):re:"",Ne=C.current,Ee=Ne.get(le);Ee&&clearTimeout(Ee),Ne.set(le,setTimeout(()=>{Ne.delete(le),n.setState(ze=>({sourceChangeRevision:{...ze.sourceChangeRevision,[le]:(ze.sourceChangeRevision[le]??0)+1}})),he===le&&p({agentId:t,projectId:e,source:le})},QL))},A=le=>{if(!t)return;let re=b.current,he=Date.now(),Ne=re.get(le),Ee=Ne?Ne.deadline:he+iO;Ne&&clearTimeout(Ne.timer);let ze=setTimeout(()=>{re.delete(le),i({agentId:t,projectId:e,source:le})},Math.max(0,Math.min(sO,Ee-he)));re.set(le,{timer:ze,deadline:Ee})};if(V==="sync:completed"){if(!t)return;let le=typeof Y.source=="string"?Y.source:void 0;if(le&&fO(Y)){N(le);return}le?(n.getState().loadedFolders?.[`${le}://`]?A(le):l(le,!0),N(le)):r({agentId:t,projectId:e});return}if(Y.changeType==="badge"){if(!t)return;let le=n.getState().activeAgentId;if(le&&le!==t)return;let re=typeof Y.source=="string"&&Y.source?Y.source:qe(typeof Y.uri=="string"?Y.uri:"");if(!re)return;let he=y.current,Ne=he.get(re);Ne&&clearTimeout(Ne),he.set(re,setTimeout(()=>{he.delete(re),n.setState(ct=>({sourceChangeRevision:{...ct.sourceChangeRevision,[re]:(ct.sourceChangeRevision[re]??0)+1}})),s({agentId:t,projectId:e,uri:`${re}://`,force:!0}),a({agentId:t,projectId:e});let Ee=n.getState().activeSource;(typeof Ee=="string"&&Ee?Ee.includes("://")?qe(Ee):Ee:"")===re&&p({agentId:t,projectId:e,source:re}),g(re)},QL));return}if(Y.external===!0){if(!t)return;let le=n.getState().activeAgentId;if(le&&le!==t)return;let re=typeof Y.source=="string"&&Y.source?Y.source:qe(typeof Y.uri=="string"?Y.uri:"");if(!re)return;if(N(re),!n.getState().loadedFolders?.[`${re}://`]){l(re,!0);return}A(re);return}let B=Y.uri;if(!B)return;let K=Y.changeType,te=Array.isArray(Y.folder_ancestors)&&Y.folder_ancestors.length>0?Y.folder_ancestors:xa(B);te.length>0&&c(te),Array.isArray(Y.new_folder_ancestors)&&Y.new_folder_ancestors.length>0&&c(Y.new_folder_ancestors);let ne=typeof Y.action=="string"?Y.action:void 0,pe={id:Y.id,uri:B,folder_ancestors:te,sourceAgentId:T.agentId,sourceProjectId:T.projectId},Se=le=>{if(!t)return;let re=Array.from(new Set(le.filter(he=>typeof he=="string"&&!!he).map(he=>et(he))));re.length>0&&o({agentId:t,projectId:e,folders:re})};switch(V){case"filesystem:created":case"filesystem:updated":u({...pe,status:Y.status}),Y.status==="pending_review"&&h(B),Y.newUri&&(d(B,Y.newUri),u({...pe,uri:Y.newUri,folder_ancestors:Y.new_folder_ancestors,status:Y.status})),ne==="review_approved"&&Y.status==="active"&&f(B),K==="structure"&&Se([B,Y.newUri]);break;case"filesystem:deleted":u({...pe,status:"deleted"}),K==="structure"&&Se([B]);break;case"filesystem:reverted":u({...pe,status:Y.status||"active"}),f(B),Se([B]);break}N(qe(B))},[t,e,n,r,a,s,i,o,l,u,c,d,f,h,p,g]),M=(0,cn.useRef)(_);M.current=_;let R=(0,cn.useRef)(null),U=(0,cn.useCallback)(()=>{if(!t)return;let T=x.current;R.current&&clearTimeout(R.current),R.current=setTimeout(()=>{R.current=null,T===x.current&&(async()=>{try{await a({agentId:t,projectId:e})}catch{return}if(T!==x.current)return;w.current();let V=n.getState();n.setState(N=>({sourceChangeRevision:Object.fromEntries(N.sources.map(A=>[qe(A.uri_root),(N.sourceChangeRevision[qe(A.uri_root)]??0)+1]))}));let Y=new Set;for(let[N,A]of Object.entries(V.loadedFolders||{})){if(!A)continue;let B=qe(N);B&&Y.add(B)}await Promise.all(Array.from(Y).map(N=>i({agentId:t,projectId:e,source:N})))})()},aO)},[t,e,n,a,i]),v=(0,cn.useRef)(U);v.current=U,(0,cn.useEffect)(()=>{let T=R;return()=>{T.current&&clearTimeout(T.current)}},[t,e,n]),(0,cn.useEffect)(()=>{if(!t||!e)return;let T=ew();if(!T?.subscribeFilesystemEvents)return;let V=!0,Y=T.subscribeFilesystemEvents(t,e,N=>{if(!V)return;let A=N;if(!A||typeof A!="object"||!cO.has(A.type)||!A.payload||typeof A.payload!="object")return;if(A.type==="pending:changed"){w.current();return}let B=A.payload.changeType==="badge",K=A.payload.external===!0;!B&&!K&&A.agentId!==t||M.current(A)},()=>{V&&v.current()});return()=>{V=!1,Y()}},[t,e,n])}var Bf=j(Wn(),1);var kn=j(ie(),1);function i0(t){let e=H(A=>A.sidebarOpen),n=H(A=>A.sidebarWidth),r=H(A=>A.setSidebarWidth),a=H(A=>A.loadList),s=H(A=>A.refreshTree),i=H(A=>A.applyNav),o=H(A=>A.searchQuery),l=H(A=>A.setSearchQuery),u=H(A=>A.clearSearch),c=H(A=>A.sidebarView),d=H(A=>A.setSidebarView),f=(0,Rn.useRef)(null),h=(0,Rn.useRef)(null),p=(0,Rn.useRef)(null),[g,m]=(0,Rn.useState)(!1),x=hn(),y=(0,Bf.useWorkspaceHostPort)(),b=H(A=>A.activeProjectId),C=t.projectId??b,L=x.useFileMarks(t.agentId),P=x.useAgents(),w=(0,Rn.useMemo)(()=>Ms(P),[P]),k=t.agentId?w.byId.get(t.agentId):null,_=k?.name||k?.slug,M=k?.config?.appearance?.icon,R=co(k?.id,w),U=(0,Rn.useMemo)(()=>{let A=L||{},B=0;for(let K of Object.keys(A)){let te=A[K]?.ts??0;te>B&&(B=te)}return B},[L]);e2(t.agentId,C),(0,Rn.useEffect)(()=>{t.agentId&&a({agentId:t.agentId,projectId:C,userId:t.userId??null})},[t.agentId,C,t.userId]),(0,Rn.useEffect)(()=>{if(!t.agentId)return;let A=t.state?.nav;if(!A)return;let B=JSON.stringify(A);f.current!==B&&(f.current=B,y&&t.widgetId&&(0,Bf.consumeWidgetNav)(y,{agentId:t.agentId,widgetId:t.widgetId}),i({agentId:t.agentId,projectId:C,nav:A,readAgentId:t.agentId}))},[i,t.agentId,C,t.state,y,t.widgetId]);let v=(0,Rn.useRef)(!1);(0,Rn.useEffect)(()=>{if(!t.agentId||!U||v.current)return;let A=setTimeout(()=>{v.current=!0,s({agentId:t.agentId,projectId:C}).finally(()=>{v.current=!1})},1500);return()=>clearTimeout(A)},[U,C,t.agentId,s]);let T=8,V=(0,Rn.useCallback)(A=>{A.preventDefault(),p.current={startX:A.clientX,startWidth:n},m(!0),A.currentTarget.setPointerCapture(A.pointerId)},[n]),Y=(0,Rn.useCallback)(A=>{let B=p.current;if(!B)return;let K=h.current,te=K?Math.max(fl,K.clientWidth-T):B.startWidth,ne=Math.min(te,Math.max(fl,B.startWidth+(A.clientX-B.startX)));r(ne)},[r]),N=(0,Rn.useCallback)(A=>{p.current&&(p.current=null,m(!1),A.currentTarget.releasePointerCapture(A.pointerId))},[]);return(0,kn.jsxs)("div",{className:"flex flex-col w-full h-full overflow-hidden transition-colors duration-300",children:[(0,kn.jsx)(hh,{agentId:t.agentId,agentName:_,agentIcon:M,agentAccent:R,supportsSources:!0,onOpenProjectFiles:()=>{i({agentId:t.agentId,projectId:C,nav:{kind:"filesystem",action:"list",uri:ds}})}}),(0,kn.jsxs)("div",{ref:h,className:`flex-1 min-h-0 flex flex-row ${g?"select-none cursor-col-resize":""}`,children:[(0,kn.jsxs)("div",{className:"h-full flex flex-col min-h-0 shrink-0 overflow-hidden",style:{width:e?n:0,backgroundColor:"transparent",borderRight:e?"1px solid rgba(255,255,255,0.05)":"none"},children:[(0,kn.jsxs)("div",{className:"px-2 pt-2 pb-1 flex items-center justify-between",children:[(0,kn.jsx)("div",{className:"text-[10px] text-white/40 font-bold uppercase tracking-wider shrink-0",children:c==="git"?"Git Control":c==="search"?"Search":"Explorer"}),c==="search"?(0,kn.jsx)("input",{type:"text",value:o,onChange:A=>l(A.target.value),onKeyDown:A=>{A.key==="Escape"&&(u(),d("tree"))},placeholder:"Search\u2026",autoFocus:!0,"aria-label":"Search query",className:"flex-1 min-w-0 mx-2 h-6 bg-transparent border-0 text-xs text-white/85 placeholder:text-white/30 outline-none"}):null,(0,kn.jsxs)("div",{className:"flex items-center gap-0.5 shrink-0",children:[(0,kn.jsx)("button",{type:"button",onClick:()=>{c==="search"?(u(),d("tree")):d("search")},className:`h-6 w-6 rounded-md inline-flex items-center justify-center transition-colors ${c==="search"?"text-white/85":"text-white/40 hover:text-white/70"}`,title:"Search in explorer","aria-label":"Toggle explorer search","aria-pressed":c==="search",children:(0,kn.jsx)(Bl,{className:"w-3.5 h-3.5"})}),(0,kn.jsx)("button",{type:"button",onClick:()=>d(c==="git"?"tree":"git"),className:`h-6 w-6 rounded-md inline-flex items-center justify-center transition-colors ${c==="git"?"text-violet-300/90":"text-white/40 hover:text-white/70"}`,title:"Git Control","aria-label":"Toggle Git Control panel","aria-pressed":c==="git",children:(0,kn.jsx)(Cn,{className:"w-3.5 h-3.5"})})]})]}),(0,kn.jsx)(fp,{agentId:t.agentId,sidebarView:c})]}),e&&(0,kn.jsx)("div",{role:"separator","aria-orientation":"vertical",onPointerDown:V,onPointerMove:Y,onPointerUp:N,className:"w-2 shrink-0 cursor-col-resize bg-white/0 hover:bg-white/[0.06] transition relative touch-none",children:(0,kn.jsx)("div",{className:"absolute inset-y-6 left-1/2 -translate-x-1/2 w-[2px] rounded-full bg-white/[0.07]"})}),(0,kn.jsx)("div",{className:"flex-1 min-w-0 min-h-0",children:(0,kn.jsx)(s0,{})})]})]})}var Xn=j($e(),1),Uf=j(Zr(),1),il=j(Zr(),1),f2=j(r2(),1);var ji=j($e(),1);var _f=j(Zr(),1);var Ha=j(ie(),1),hO=27,u0=90,pO=17,mO=12,gO=1.4,xO=18,l0=32,a2=new WeakMap;function s2(t,e){let n=a2.get(t);if(n&&n.status===e)return n;let r={status:e};return a2.set(t,r),r}function yO(t,e){let n=s2(t,e);if(n.compact!==void 0)return n.compact;let r=String(e??"").toLowerCase(),a=r==="pending"||r.includes("pending"),s;if(a)s=l0;else{let i=tl(t.input),o=i&&typeof i.action=="string"?i.action:void 0;if(o&&!el(o))s=l0;else if(el(o))s=u0;else{let l=0;try{let u=i?Zu(i):null;l=u?u.added+u.removed:0}catch{l=0}s=l<=0?l0:Math.min(u0,l*xO)}}return n.compact=s,s}function bO(t,e){let n=s2(t,e);if(n.expanded!==void 0)return n.expanded;let r=tl(t.input)??{},a=0;try{let i=Zu(r);a=i?i.added+i.removed:0}catch{a=0}let s=Math.max(u0,mO+Math.ceil(a*gO)*pO);return n.expanded=s,s}function i2(t){let e=t.disclosure===!0?bO(t.tool,t.status):yO(t.tool,t.status);return hO+e}var Hf=(0,ji.memo)(function({uri:e,lineCounts:n,isPending:r,reviewPending:a,isError:s,isInterrupted:i,onUriClick:o,children:l}){let u=(0,ji.useMemo)(()=>r?"pending":i?"interrupted":s?"error":"committed",[r,s,i]),c=a&&u==="committed"?"pending review":u,d=(0,ji.useCallback)(()=>{e&&o&&o(e)},[e,o]),f=(0,ji.useCallback)(()=>(0,Ha.jsxs)("div",{className:`px-3 py-1 flex items-center gap-2 min-w-0 ${e&&o?"cursor-pointer hover:bg-white/[0.04] transition":""}`,onClick:d,role:e&&o?"button":void 0,title:e||void 0,children:[(0,Ha.jsx)(va,{className:"w-3 h-3 text-white/40 shrink-0"}),(0,Ha.jsx)("span",{className:"flex-1 min-w-0 text-[11px] text-white/60 font-mono truncate",children:e||"file"}),n&&(0,Ha.jsxs)("span",{className:"shrink-0 flex items-center gap-1.5 text-[10px] font-mono",children:[n.added>0&&(0,Ha.jsxs)("span",{className:"text-emerald-400",children:["+",n.added]}),n.removed>0&&(0,Ha.jsxs)("span",{className:"text-red-400",children:["-",n.removed]})]}),(0,Ha.jsx)(_f.ToolStatusIcon,{isPending:r,isError:s,isInterrupted:i,statusLabel:c})]}),[e,o,d,n,r,s,i,c]);return(0,Ha.jsx)(_f.CardShell,{label:e||"file",status:u,defaultMode:"compact",compactHeight:90,renderHeader:f,children:l})});var l2=j($e(),1);var Ze=j(ie(),1),u2=(0,l2.memo)(function({action:e,input:n}){switch(e){case"set_fields":return(0,Ze.jsx)(wO,{fields:n.fields});case"move":return(0,Ze.jsx)(vO,{uri:al(n,"uri")||al(n,"id"),destination:al(n,"destination")});case"copy":return(0,Ze.jsx)(kO,{uri:al(n,"uri"),destination:al(n,"destination")});case"create_folder":return(0,Ze.jsx)(SO,{uri:al(n,"uri")});case"delete":return(0,Ze.jsx)(CO,{});case"revert":return(0,Ze.jsx)(IO,{});default:return(0,Ze.jsx)(LO,{action:e,input:n})}});function wO({fields:t}){if(!t||typeof t!="object")return(0,Ze.jsx)(o2,{icon:(0,Ze.jsx)(ao,{className:"w-3 h-3"}),text:"Updated fields"});let e=[];for(let[n,r]of Object.entries(t))if(r!==void 0)if(n==="tags"&&r&&typeof r=="object"){let a=r,s=[];Array.isArray(a.add)&&a.add.length&&s.push(a.add.map(i=>`+${i}`).join(" ")),Array.isArray(a.remove)&&a.remove.length&&s.push(a.remove.map(i=>`-${i}`).join(" ")),Array.isArray(a.set)&&s.push(a.set.join(", ")),e.push({key:"tags",value:s.join(" ")||"(cleared)"})}else if(n==="metadata"&&r&&typeof r=="object"){let a=Object.entries(r).map(([s,i])=>i===null?`${s}: (removed)`:`${s}: ${String(i)}`).join(", ");e.push({key:"metadata",value:a||"(empty)"})}else e.push({key:n,value:r===null?"(cleared)":String(r)});return(0,Ze.jsxs)("div",{className:"px-3 py-2 space-y-0.5",children:[e.map(n=>(0,Ze.jsxs)("div",{className:"flex gap-2 text-[11px]",children:[(0,Ze.jsxs)("span",{className:"text-white/45 shrink-0",children:[n.key,":"]}),(0,Ze.jsx)("span",{className:"text-white/75 break-all",children:n.value})]},n.key)),e.length===0&&(0,Ze.jsx)(o2,{icon:(0,Ze.jsx)(ao,{className:"w-3 h-3"}),text:"Updated fields"})]})}function vO({uri:t,destination:e}){return(0,Ze.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2 text-[11px] font-mono",children:[(0,Ze.jsx)("span",{className:"text-white/50 truncate",children:t||"?"}),(0,Ze.jsx)(no,{className:"w-3 h-3 text-white/35 shrink-0"}),(0,Ze.jsx)("span",{className:"text-white/75 truncate",children:e||"?"})]})}function kO({uri:t,destination:e}){return(0,Ze.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2 text-[11px] font-mono",children:[(0,Ze.jsx)(na,{className:"w-3 h-3 text-sky-400/60 shrink-0"}),(0,Ze.jsx)("span",{className:"text-white/50 truncate",children:t||"?"}),(0,Ze.jsx)(no,{className:"w-3 h-3 text-white/35 shrink-0"}),(0,Ze.jsx)("span",{className:"text-white/75 truncate",children:e||"?"})]})}function SO({uri:t}){return(0,Ze.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2 text-[11px] font-mono",children:[(0,Ze.jsx)(br,{className:"w-3 h-3 text-sky-300/70 shrink-0"}),(0,Ze.jsx)("span",{className:"text-white/75 truncate",children:t||"?"})]})}function CO(){return(0,Ze.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2",children:[(0,Ze.jsx)(Nt,{className:"w-3 h-3 text-rose-400/70"}),(0,Ze.jsx)("span",{className:"text-[11px] text-rose-300/80",children:"Deleted"})]})}function IO(){return(0,Ze.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2",children:[(0,Ze.jsx)(oi,{className:"w-3 h-3 text-amber-400/70"}),(0,Ze.jsx)("span",{className:"text-[11px] text-white/70",children:"Reverted to previous version"})]})}function LO({action:t,input:e}){let n=Object.entries(e).filter(([r])=>r!=="action"&&r!=="id"&&r!=="uri").slice(0,5).map(([r,a])=>`${r}: ${typeof a=="string"?a.slice(0,60):JSON.stringify(a)?.slice(0,60)??"?"}`).join(", ");return(0,Ze.jsxs)("div",{className:"px-3 py-2 text-[11px] text-white/60",children:[(0,Ze.jsx)("span",{className:"text-white/45 mr-1",children:t}),n&&(0,Ze.jsx)("span",{className:"text-white/50",children:n})]})}function o2({icon:t,text:e}){return(0,Ze.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2 text-[11px] text-white/60",children:[t,(0,Ze.jsx)("span",{children:e})]})}function al(t,e){let n=t[e];return typeof n=="string"?n:void 0}var Ua=j(ie(),1),AO=200,sl=new Map;function c2(t,e){if(sl.size>=AO){let n=sl.keys().next().value;n!==void 0&&sl.delete(n)}sl.set(t,e)}var PO=8,NO=200,h2=(0,Xn.memo)(function({tool:e,status:n,conversationId:r}){let a=(0,il.useChatHost)(),s=(0,f2.useWorkspaceChatStore)(v=>r?v.conversationsById?.[r]?.agentId:void 0),i=(0,il.useHasRowIdentity)(),o=(0,il.useRowDisclosureValue)("card"),u=i&&o!==!0?PO:NO,c=(0,Xn.useMemo)(()=>tl(e.input),[e.input]),d=(0,Xn.useMemo)(()=>(0,Uf.extractPathsFromToolCall)(e)[0]||(c?d2(c,"uri")||d2(c,"path"):void 0),[e,c]),f=String(n||"").toLowerCase(),h=f==="pending"||f.includes("pending"),p=f==="interrupted",g=!p&&(f==="error"||f.includes("error")||f.includes("fail")),m=c?.action,x=d?Qo(d):void 0,y=(0,Xn.useMemo)(()=>n0(e.structuredContent),[e.structuredContent]),b=(0,Xn.useMemo)(()=>{let v=e.structuredContent,T=v&&typeof v=="object"?String(v.status||"").toLowerCase():"";return T==="pending_review"||T.includes("pending")},[e.structuredContent]),C=(0,Xn.useMemo)(()=>y??(c&&!h?Zu(c):null),[y,c,h]),L=(0,Xn.useMemo)(()=>c?h?[]:RO(m,c):[],[m,c,h]),P=(0,Xn.useCallback)(v=>{let T=s||void 0;!T||!v||a.openFilesystemWidget?.(T,v)},[s,a]),w=(0,Xn.useMemo)(()=>{if(h)return(0,Uf.previewInput)(e.input,!0)},[h,e.input]),k=!h&&!g&&!!m&&el(m),[_,M]=(0,Xn.useState)(()=>k&&d&&s?sl.get(`${s}|${e.id}`)??null:null);(0,Xn.useEffect)(()=>{if(!k||!d||!s){M(null);return}let v=`${s}|${e.id}`,T=sl.get(v);if(T!==void 0){M(T);return}let V=!1,Y=()=>{V||(async()=>{try{let K=await $i({agentId:s,files:[d]});if(V)return;let te=Yi(K)[0],ne=pc(te?.version?.baseline);if(!ne?.content){c2(v,null);return}let pe=Tf(ne.content,Ji(te));c2(v,pe),V||M(pe)}catch{}})()},N=globalThis,A=null,B=null;return typeof N.requestIdleCallback=="function"?A=N.requestIdleCallback(Y,{timeout:1500}):B=setTimeout(Y,200),()=>{V=!0,A!==null&&N.cancelIdleCallback?.(A),B!==null&&clearTimeout(B)}},[k,d,s,e.id]);let R=_??L,U=_?Df(_):C;return h?(0,Ua.jsx)(Hf,{uri:d,lineCounts:null,isPending:!0,reviewPending:!1,isError:!1,isInterrupted:!1,onUriClick:d?P:void 0,children:(0,Ua.jsx)(MO,{content:w})}):m&&!el(m)?(0,Ua.jsx)(Hf,{uri:d,lineCounts:null,isPending:!1,reviewPending:b,isError:g,isInterrupted:p,onUriClick:d?P:void 0,children:(0,Ua.jsx)(u2,{action:m,input:c||{}})}):(0,Ua.jsx)(Hf,{uri:d,lineCounts:U,isPending:!1,reviewPending:b,isError:g,isInterrupted:p,onUriClick:d?P:void 0,children:R.length>0?(0,Ua.jsx)(Zo,{hunks:R,language:x,maxLines:u}):(0,Ua.jsx)("div",{className:"px-3 py-2 text-[11px] text-white/40 italic",children:g?"Operation failed":"Done"})})});function RO(t,e){if(!t){let n=Ju(e);return n?t0(n):[]}if(t==="replace_text"){let n=e.edits;if(Array.isArray(n)&&n.length>0)return IL(n.filter(s=>!!s&&typeof s=="object"&&typeof s.find=="string"));let r=typeof e.find=="string"?e.find:"",a=typeof e.replace=="string"?e.replace:"";return CL(r,a)}if(t==="update"||t==="replace_lines"){let n=Ju(e);return n?LL(n):[]}if(t==="append_text"||t==="prepend_text"||t==="insert"){let n=typeof e.text=="string"?e.text:"";return n?AL(n):[]}return[]}function MO({content:t}){return t?(0,Ua.jsx)("pre",{className:"px-3 py-1.5 text-[11px] leading-[18px] whitespace-pre overflow-x-auto overflow-y-clip bg-emerald-500/8 text-white/70 font-mono",children:t}):(0,Ua.jsx)("div",{className:"px-3 py-2 text-[11px] text-white/40 italic",children:"Running..."})}function d2(t,e){let n=t[e];return typeof n=="string"?n:void 0}var Ga=j($e(),1);function p2({port:t}){let e=t.useCurrentUser(),n=e?.name,r=e?.email,a=e?.role,s=e?.priority,i=(0,Ga.useMemo)(()=>n||r?{name:n,email:r}:void 0,[n,r]),o=(0,Ga.useMemo)(()=>a!==void 0||s!==void 0?{role:a,priority:s}:void 0,[a,s]),l=t.useProjectId(),u=t.useUserId(),c=t.getGrantedFeatures(l,u).join(","),d=(0,Ga.useMemo)(()=>c.split(",").filter(Boolean),[c]);return(0,Ga.useMemo)(()=>({currentUser:i,currentRole:o,grantedFeatures:d,useAgents(){let f=t.useAgentIds(),h=t.useAgentsById();return(0,Ga.useMemo)(()=>{let p={};for(let g of f){let m=h[g];m&&(p[g]={id:m.id,slug:m.slug,name:m.name,config:m.config})}return{ids:f,byId:p}},[f,h])},useFileMarks:f=>t.useFileMarks(f),clearFileMark:f=>t.clearFileMark(f),getStreamUrl(f,h,p){return t.buildEventStreamUrl({packageSlug:"brain-core",agentId:f,projectId:h,types:p})},subscribeFilesystemEvents(f,h,p,g){return t.subscribeRealtime({channel:"filesystem",projectId:h,agentId:f,onEvent:(m,x)=>p(x),...g?{onConnChange:g}:{}})},isDocker:t.isDocker,usePackageIconBySlug(){let f=t.useProjectId(),[h,p]=(0,Ga.useState)({});return(0,Ga.useEffect)(()=>{if(!f)return;let g=!1,m=`/api/packages/agent-core/packages/overview?projectId=${encodeURIComponent(f)}`;return fetch(m,{credentials:"include"}).then(x=>x.ok?x.json():null).then(x=>{if(g||!x?.packages)return;let y={};for(let b of x.packages){if(!b.id)continue;let C=(0,lr.resolveLucideIcon)(b.icon);if(!C)continue;let L=b.id.replace(/^@[^/]+\//,"");y[L]=C,y[b.id]=C}p(y)}).catch(()=>{}),()=>{g=!0}},[f]),h}}),[t,i,o,d])}var g2=j(ie(),1);function m2({port:t,children:e}){let n=p2({port:t});return(0,g2.jsx)(tw,{value:n,children:e})}var fs=j(ie(),1),TO="workspace.provider:@neuralis/brain-core",x2=(0,fs.jsx)("div",{className:"flex h-full items-center justify-center text-xs text-white/30",children:"Loading..."}),y2=!1;function DO(t){let{registry:e,port:n}=t;!y2&&n.onClientStateReset&&(y2=!0,n.onClientStateReset(Tx));function r({children:i}){let o=n.useUserId();return(0,ol.useEffect)(()=>{Mx(o)},[o]),(0,fs.jsx)(m2,{port:n,children:i})}e.register({packageSlug:"@neuralis/brain-core",componentImport:TO,Component:r});function a({agentId:i,widgetId:o,state:l}){let u=n.useProjectId(),c=n.useUserId(),d=Dx(o,c,u,i);return d?(0,fs.jsx)(Gf.WorkspaceHostPortProvider,{port:n,children:(0,fs.jsx)(Gf.PackageApiProvider,{slug:"brain-core",projectId:u,agentId:i,userId:c,children:(0,fs.jsx)(Ex,{store:d,children:(0,fs.jsx)(i0,{agentId:i,projectId:u,userId:c,widgetId:o,state:l})},`${o}\0${c}\0${u}\0${i}`)})}):x2}let s=ol.default.lazy(()=>Promise.resolve({default:a}));e.register({packageSlug:"@neuralis/brain-core",componentImport:"@neuralis/brain-core/app/filesystem",Component:i=>(0,fs.jsx)(ol.Suspense,{fallback:x2,children:(0,fs.jsx)(s,{...i})})}),(0,b2.registerCardComponent)("filesystem.change",h2,{owner:{kind:"package-direct",packageId:"@neuralis/brain-core"},renderer:"direct",mountPolicy:"virtualized",estimateHeight:i2,composer:PL,matchTools:NL})}export{DO as installFilesystemHostComponents};