@vantran-se/openchamber-web 2.1.1 → 2.2.0

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 (442) hide show
  1. package/README.md +32 -24
  2. package/bin/cli.js +1 -3
  3. package/bin/cli.test.js +40 -16
  4. package/bin/lib/DOCUMENTATION.md +6 -5
  5. package/bin/lib/cli-args.js +6 -1
  6. package/bin/lib/cli-args.test.js +34 -0
  7. package/bin/lib/cli-lifecycle.js +0 -1
  8. package/bin/lib/cli-network.js +8 -2
  9. package/bin/lib/cli-process.js +1 -1
  10. package/bin/lib/cli-settings-accessors.test.js +21 -13
  11. package/bin/lib/cli-startup.js +17 -11
  12. package/bin/lib/cli-startup.test.js +92 -2
  13. package/bin/lib/commands-connect-url.js +8 -1
  14. package/bin/lib/commands-schedule.js +8 -2
  15. package/bin/lib/commands-serve.js +15 -21
  16. package/bin/lib/commands-update.js +12 -24
  17. package/bin/lib/commands-update.test.js +14 -46
  18. package/dist/assets/DiffView-Cv9MSXl1.js +4 -0
  19. package/dist/assets/FilePreviewCommentMenu-D4kLseHj.js +4 -0
  20. package/dist/assets/FilesView-BVoD8I2x.js +14 -0
  21. package/dist/assets/{GitView-DzuzhIPx.js → GitView-Bzb8p-ew.js} +4 -4
  22. package/dist/assets/GuestSurfacePane-Crdbvsxo.js +1 -0
  23. package/dist/assets/InProgressOperationBanner-CwMjNQgk.js +2 -0
  24. package/dist/assets/{JsonTreeView-B_EPRjzy.js → JsonTreeView-DRKHZfsn.js} +1 -1
  25. package/dist/assets/MarkdownImageGallery-DZtqT1Zn.js +1 -0
  26. package/dist/assets/MarkdownRendererImpl-CqG7HCNd.js +10 -0
  27. package/dist/assets/OnboardingScreen-DMIxwYK5.js +1 -0
  28. package/dist/assets/{PatchDiff-6yh1csza.js → PatchDiff-CUcCg1jk.js} +1 -1
  29. package/dist/assets/PierreDiffViewer-CnnR-dnD.js +228 -0
  30. package/dist/assets/PlanView-RCBadcY7.js +5 -0
  31. package/dist/assets/SettingsView-CjBjZFRO.js +30 -0
  32. package/dist/assets/SettingsWindow-DyM7QuhI.js +1 -0
  33. package/dist/assets/SubmoduleDiffSummary-BWIfgMED.js +1 -0
  34. package/dist/assets/ToolOutputDialog-Q0P3FuAi.js +15 -0
  35. package/dist/assets/ToolPartDiffPreview-p7qR9FpU.js +8 -0
  36. package/dist/assets/{VirtualizedFileDiff-BTJVRkyo.js → VirtualizedFileDiff-CFpjL8Ns.js} +3 -3
  37. package/dist/assets/{Virtualizer-xCEYz34p.js → Virtualizer-C0IsclZn.js} +1 -1
  38. package/dist/assets/WalkthroughView-DI31zD02.js +4 -0
  39. package/dist/assets/appThemeRegistry-B9gkFq9i.js +1 -0
  40. package/dist/assets/{computeVirtualFileMetrics-CmPe29DM.js → computeVirtualFileMetrics-C2WM6JC2.js} +2 -2
  41. package/dist/assets/de-YKfk5MmC.js +14 -0
  42. package/dist/assets/es-_gwT0kr-.js +20 -0
  43. package/dist/assets/fileTreeStatus-D438yi8M.js +1 -0
  44. package/dist/assets/fr-DqzvXmIm.js +18 -0
  45. package/dist/assets/index-BLaHKdtx.js +1 -0
  46. package/dist/assets/index-BkMXRrVQ.css +1 -0
  47. package/dist/assets/index-DxNa7xYB.js +65 -0
  48. package/dist/assets/initializeSharedPreferences-Bck5EAWP.js +1 -0
  49. package/dist/assets/{isDiffPlainText-CQmDCnEv.js → isDiffPlainText-Dgbw8VKk.js} +1 -1
  50. package/dist/assets/{isFilePlainText-CYBUzW4I.js → isFilePlainText-_ZS5UYRj.js} +1 -1
  51. package/dist/assets/ja-B-GFYhQE.js +20 -0
  52. package/dist/assets/ko-mzksfqDC.js +20 -0
  53. package/dist/assets/main-C5Xx8dn_.js +2 -0
  54. package/dist/assets/main-CfBSQM1H.js +990 -0
  55. package/dist/assets/markdownCore-BmWwW1ll.js +7 -0
  56. package/dist/assets/miniChat-mnKwy4vQ.js +2 -0
  57. package/dist/assets/mobile-DeEQd0wZ.js +2 -0
  58. package/dist/assets/nl-CWQr6NSq.js +20 -0
  59. package/dist/assets/{parseDiffFromFile-Cy0PNxun.js → parseDiffFromFile-BUgn-T9p.js} +2 -2
  60. package/dist/assets/patchFileDiff-Dt8LhgBh.js +13 -0
  61. package/dist/assets/pl-UmRcDUX2.js +20 -0
  62. package/dist/assets/pt-BR-BSLybvVF.js +20 -0
  63. package/dist/assets/relocateRestoredSession-B5E9xb3T.js +1 -0
  64. package/dist/assets/renderElectronMiniChatApp-C0a9A5_J.js +2 -0
  65. package/dist/assets/renderMobileApp-BNncg3Pk.js +25 -0
  66. package/dist/assets/runtimeEndpointReset-CZ5aafpl.js +62 -0
  67. package/dist/assets/{selectionMarkdown-TkYk5h9l.js → selectionMarkdown-CUN3wUld.js} +9 -9
  68. package/dist/assets/{sessionOwnership-Bs1xbRfB.js → sessionOwnership-BSuxCEhb.js} +1 -1
  69. package/dist/assets/shikiHighlight-DHDx-6eM.js +1 -0
  70. package/dist/assets/space-apply-DM_2pRW7.js +1 -0
  71. package/dist/assets/space-close-Bpomt8z0.js +1 -0
  72. package/dist/assets/{surface-B6n7wJtt.js → surface-C-jQaGnL.js} +1 -1
  73. package/dist/assets/{textMateThemeFromAppTheme-CDlKffWz.js → textMateThemeFromAppTheme-DlsTphbY.js} +1 -1
  74. package/dist/assets/tr-gaTrX_HK.js +11 -0
  75. package/dist/assets/uk-CnJF6ykl.js +20 -0
  76. package/dist/assets/{useAppFontEffects-DCqCVGlT.js → useAppFontEffects-DGlvOqP_.js} +194 -233
  77. package/dist/assets/useInlineCommentController-kMN4Wg_D.js +2 -0
  78. package/dist/assets/{useRootScrollLock-BowwS8kq.js → useRootScrollLock-DMPpvpNP.js} +2 -2
  79. package/dist/assets/{vendor-base-ui-DX96QhTP.js → vendor-base-ui-Det7U81h.js} +1 -1
  80. package/dist/assets/{vendor-codemirror-autocomplete-DW1FQz9_.js → vendor-codemirror-autocomplete-BSHQHbKu.js} +1 -1
  81. package/dist/assets/{vendor-codemirror-commands-DpmhalwN.js → vendor-codemirror-commands-C4G_dPWe.js} +1 -1
  82. package/dist/assets/{vendor-codemirror-lang-angular-BqExbN1M.js → vendor-codemirror-lang-angular-B6LbBGHB.js} +1 -1
  83. package/dist/assets/{vendor-codemirror-lang-cpp-DZA36HfS.js → vendor-codemirror-lang-cpp-BWWXBx7W.js} +1 -1
  84. package/dist/assets/{vendor-codemirror-lang-css-B07blnnZ.js → vendor-codemirror-lang-css-Cayfb29q.js} +1 -1
  85. package/dist/assets/{vendor-codemirror-lang-go-BM8K9D1-.js → vendor-codemirror-lang-go-BoKlCNKw.js} +1 -1
  86. package/dist/assets/{vendor-codemirror-lang-html-DaH9adfE.js → vendor-codemirror-lang-html-BQWerHsJ.js} +1 -1
  87. package/dist/assets/{vendor-codemirror-lang-java-CsdC0viz.js → vendor-codemirror-lang-java-DWX7Fq_K.js} +1 -1
  88. package/dist/assets/{vendor-codemirror-lang-javascript-CpGYXGuo.js → vendor-codemirror-lang-javascript-DbpEcZM0.js} +2 -2
  89. package/dist/assets/{vendor-codemirror-lang-jinja-BBeGzXw5.js → vendor-codemirror-lang-jinja-D1JIJRA7.js} +1 -1
  90. package/dist/assets/{vendor-codemirror-lang-json-58T70Hqs.js → vendor-codemirror-lang-json-BzgckzmB.js} +1 -1
  91. package/dist/assets/{vendor-codemirror-lang-less-BI-xCA59.js → vendor-codemirror-lang-less-B9EpDXFi.js} +1 -1
  92. package/dist/assets/{vendor-codemirror-lang-liquid-zEcMa-zy.js → vendor-codemirror-lang-liquid-9U7kRbSf.js} +1 -1
  93. package/dist/assets/{vendor-codemirror-lang-markdown-BLKnlLP4.js → vendor-codemirror-lang-markdown-D2TEBIvZ.js} +1 -1
  94. package/dist/assets/{vendor-codemirror-lang-php-9f35M83-.js → vendor-codemirror-lang-php-BT6sDVzE.js} +1 -1
  95. package/dist/assets/vendor-codemirror-lang-python-jAMtYiA9.js +3 -0
  96. package/dist/assets/{vendor-codemirror-lang-rust-MNDL_jZQ.js → vendor-codemirror-lang-rust-CVO56EiL.js} +1 -1
  97. package/dist/assets/{vendor-codemirror-lang-sass-p9epsSNm.js → vendor-codemirror-lang-sass-DZlOoUWu.js} +1 -1
  98. package/dist/assets/{vendor-codemirror-lang-sql-Bqzh0EXX.js → vendor-codemirror-lang-sql-fZ6t1DPw.js} +1 -1
  99. package/dist/assets/{vendor-codemirror-lang-vue-BnNUWV-p.js → vendor-codemirror-lang-vue-DxbqrLiE.js} +1 -1
  100. package/dist/assets/{vendor-codemirror-lang-wast-C2a-oLmk.js → vendor-codemirror-lang-wast-DyU1Gt-I.js} +1 -1
  101. package/dist/assets/vendor-codemirror-lang-xml-C9a_K5_p.js +1 -0
  102. package/dist/assets/{vendor-codemirror-lang-yaml-C0sjswB0.js → vendor-codemirror-lang-yaml-Cptq8l0e.js} +1 -1
  103. package/dist/assets/{vendor-codemirror-language-ByBn5zIW.js → vendor-codemirror-language-DufXoQvE.js} +2 -2
  104. package/dist/assets/vendor-codemirror-language-data-CtwSWKtX.js +2 -0
  105. package/dist/assets/{vendor-codemirror-search-ib-sHD5W.js → vendor-codemirror-search-CvXM_pZg.js} +1 -1
  106. package/dist/assets/{vendor-codemirror-state-G3UuR-be.js → vendor-codemirror-state-Dek9sMtw.js} +1 -1
  107. package/dist/assets/{vendor-codemirror-view-Bniqp7p5.js → vendor-codemirror-view-1e0FQ6Wn.js} +1 -1
  108. package/dist/assets/vendor-framer-motion-DxDVhOLc.js +9 -0
  109. package/dist/assets/vendor-katex-CuQvj9-L.js +257 -0
  110. package/dist/assets/vendor-katex-DdZNUVNG.css +1 -0
  111. package/dist/assets/{vendor-motion-dom-DcCgeG69.js → vendor-motion-dom-HXPOMxb7.js} +1 -1
  112. package/dist/assets/{vendor-opencode-client-DHzhmLwV.js → vendor-opencode-client-BmFcUkbQ.js} +1 -1
  113. package/dist/assets/{vendor-replit-codemirror-vim-DkzqxN2H.js → vendor-replit-codemirror-vim-BlJRn-cW.js} +2 -2
  114. package/dist/assets/{vendor-tanstack-react-virtual-H_JmXOFV.js → vendor-tanstack-react-virtual-CvuLsk7D.js} +1 -1
  115. package/dist/assets/{vendor-tanstack-virtual-core-Dxc8hSTB.js → vendor-tanstack-virtual-core-DPaNcJcT.js} +1 -1
  116. package/dist/assets/zh-CN-t2vigSB1.js +20 -0
  117. package/dist/assets/zh-TW-jAgqBokB.js +20 -0
  118. package/dist/index.html +6 -6
  119. package/dist/mini-chat.html +6 -6
  120. package/dist/mobile.html +6 -6
  121. package/package.json +8 -5
  122. package/server/index.js +80 -36
  123. package/server/lib/agent-memory/actions.js +1 -6
  124. package/server/lib/agent-memory/routes.js +1 -2
  125. package/server/lib/agent-memory/runtime.js +1 -8
  126. package/server/lib/agent-tool/DOCUMENTATION.md +7 -3
  127. package/server/lib/agent-tool/runtime.js +3 -6
  128. package/server/lib/agent-tool/runtime.test.js +0 -2
  129. package/server/lib/browser-control/DOCUMENTATION.md +6 -0
  130. package/server/lib/changelog/update-notes.js +1 -1
  131. package/server/lib/context-obligatory/runtime.js +1 -2
  132. package/server/lib/dev-tunnel/DOCUMENTATION.md +8 -0
  133. package/server/lib/dev-tunnel/client.js +21 -10
  134. package/server/lib/dev-tunnel/tunnel.test.js +34 -0
  135. package/server/lib/dispatch-results/runtime.js +1 -1
  136. package/server/lib/enterprise-mode.d.ts +1 -0
  137. package/server/lib/enterprise-mode.js +13 -2
  138. package/server/lib/enterprise-mode.test.js +21 -0
  139. package/server/lib/event-stream/DOCUMENTATION.md +2 -2
  140. package/server/lib/event-stream/index.js +1 -3
  141. package/server/lib/event-stream/translate-v2.js +1 -9
  142. package/server/lib/event-stream/translate-v2.test.js +0 -11
  143. package/server/lib/fs/DOCUMENTATION.md +5 -2
  144. package/server/lib/fs/routes.js +62 -15
  145. package/server/lib/fs/routes.test.js +278 -48
  146. package/server/lib/fs/workspace-file-names.js +104 -0
  147. package/server/lib/fs/workspace-file-names.test.js +62 -0
  148. package/server/lib/git/DOCUMENTATION.md +17 -5
  149. package/server/lib/git/contributor-provenance-storage.js +9 -6
  150. package/server/lib/git/contributor-provenance-storage.test.js +29 -0
  151. package/server/lib/git/credential-broker.js +1 -1
  152. package/server/lib/git/credential-resolver.js +1 -4
  153. package/server/lib/git/credentials.js +1 -0
  154. package/server/lib/git/discovery-endpoint.js +1 -1
  155. package/server/lib/git/identity-provisioning.js +2 -1
  156. package/server/lib/git/identity-storage.js +3 -4
  157. package/server/lib/git/lfs-discovery.js +14 -14
  158. package/server/lib/git/lfs-discovery.test.js +16 -6
  159. package/server/lib/git/network-operation-plan.js +50 -62
  160. package/server/lib/git/network-operation-plan.test.js +103 -1
  161. package/server/lib/git/network-operation-registry.js +4 -6
  162. package/server/lib/git/network-operation-storage.js +4 -6
  163. package/server/lib/git/network-operations.js +12 -4
  164. package/server/lib/git/network-operations.test.js +19 -6
  165. package/server/lib/git/redaction.js +2 -1
  166. package/server/lib/git/repository-credential-runtime.js +5 -3
  167. package/server/lib/git/repository-credential-runtime.test.js +22 -0
  168. package/server/lib/git/routes.js +31 -137
  169. package/server/lib/git/routes.test.js +2 -2
  170. package/server/lib/git/service.js +143 -27
  171. package/server/lib/git/service.test.js +215 -1
  172. package/server/lib/git/ssh-credential-storage.js +1 -4
  173. package/server/lib/git/submodule-discovery.js +1 -1
  174. package/server/lib/git/worktree-bootstrap-storage.js +3 -4
  175. package/server/lib/git/worktree-bootstrap-storage.test.js +15 -0
  176. package/server/lib/git/worktree-creation.js +194 -0
  177. package/server/lib/git/worktree-creation.test.js +155 -0
  178. package/server/lib/github/DOCUMENTATION.md +11 -6
  179. package/server/lib/github/auth.js +2 -4
  180. package/server/lib/github/device-flow.js +2 -2
  181. package/server/lib/github/gh-cli-credential.js +1 -0
  182. package/server/lib/github/octokit.js +31 -0
  183. package/server/lib/github/pr-status.js +35 -18
  184. package/server/lib/github/pr-status.test.js +271 -3
  185. package/server/lib/github/reference-search.js +102 -13
  186. package/server/lib/github/reference-search.test.js +48 -7
  187. package/server/lib/github/routes.auth.test.js +18 -0
  188. package/server/lib/github/routes.js +360 -6
  189. package/server/lib/github/routes.mutations.test.js +239 -0
  190. package/server/lib/github/routes.test.js +134 -2
  191. package/server/lib/gitlab/DOCUMENTATION.md +5 -1
  192. package/server/lib/gitlab/auth-storage.test.js +1 -0
  193. package/server/lib/gitlab/mappers.js +30 -1
  194. package/server/lib/gitlab/resources.js +230 -6
  195. package/server/lib/gitlab/resources.test.js +179 -0
  196. package/server/lib/gitlab/routes.js +200 -6
  197. package/server/lib/gitlab/routes.test.js +186 -2
  198. package/server/lib/gitlab/validation.js +1 -5
  199. package/server/lib/guests/DOCUMENTATION.md +1 -1
  200. package/server/lib/guests/oauth.js +2 -2
  201. package/server/lib/guests/service.js +1 -1
  202. package/server/lib/guests/sockets.js +1 -1
  203. package/server/lib/injected-env.d.ts +8 -0
  204. package/server/lib/injected-env.js +50 -0
  205. package/server/lib/injected-env.test.js +56 -0
  206. package/server/lib/linear/DOCUMENTATION.md +5 -6
  207. package/server/lib/linear/issues.js +62 -4
  208. package/server/lib/linear/issues.test.js +68 -0
  209. package/server/lib/linear/oauth.js +5 -5
  210. package/server/lib/linear/parse.js +2 -9
  211. package/server/lib/message-queue/DOCUMENTATION.md +23 -1
  212. package/server/lib/message-queue/runtime.js +85 -12
  213. package/server/lib/message-queue/runtime.test.js +172 -2
  214. package/server/lib/notifications/apns-runtime.js +5 -6
  215. package/server/lib/notifications/apns-runtime.test.js +20 -4
  216. package/server/lib/openchamber-control/DOCUMENTATION.md +19 -1
  217. package/server/lib/openchamber-control/actions.js +2 -1
  218. package/server/lib/openchamber-control/service.js +119 -20
  219. package/server/lib/openchamber-control/service.test.js +166 -0
  220. package/server/lib/openchamber-sessions/archive-store.js +1 -6
  221. package/server/lib/openchamber-sessions/routes.js +47 -12
  222. package/server/lib/openchamber-sessions/routes.test.js +65 -2
  223. package/server/lib/openchamber-sessions/session-metadata-store.js +1 -6
  224. package/server/lib/opencode/DOCUMENTATION.md +22 -8
  225. package/server/lib/opencode/agents.js +62 -0
  226. package/server/lib/opencode/auth-state-runtime.js +3 -1
  227. package/server/lib/opencode/auth.d.ts +1 -1
  228. package/server/lib/opencode/auth.js +8 -0
  229. package/server/lib/opencode/auth.test.js +31 -0
  230. package/server/lib/opencode/config-entity-routes.js +16 -0
  231. package/server/lib/opencode/config-entity-v2.test.js +16 -1
  232. package/server/lib/opencode/config-paths.test.js +2 -2
  233. package/server/lib/opencode/config-v2.js +2 -4
  234. package/server/lib/opencode/feature-routes-runtime.js +89 -49
  235. package/server/lib/opencode/lifecycle.js +41 -21
  236. package/server/lib/opencode/lifecycle.test.js +50 -2
  237. package/server/lib/opencode/model-discovery.js +1 -1
  238. package/server/lib/opencode/model-discovery.test.js +17 -0
  239. package/server/lib/opencode/models-metadata.js +0 -2
  240. package/server/lib/opencode/openchamber-routes.test.js +3 -3
  241. package/server/lib/opencode/plugins.js +6 -9
  242. package/server/lib/opencode/provider-source-route.test.js +101 -3
  243. package/server/lib/opencode/providers-disabled.test.js +59 -0
  244. package/server/lib/opencode/providers.js +34 -0
  245. package/server/lib/opencode/proxy.js +11 -3
  246. package/server/lib/opencode/routes.js +40 -2
  247. package/server/lib/opencode/settings-helpers.js +27 -1
  248. package/server/lib/opencode/settings-helpers.test.js +19 -7
  249. package/server/lib/opencode/settings-registry.json +27 -16
  250. package/server/lib/opencode/settings-runtime.test.js +18 -0
  251. package/server/lib/opencode/shared-service-runtime.js +23 -104
  252. package/server/lib/opencode/shared.js +77 -46
  253. package/server/lib/opencode/shared.test.js +12 -12
  254. package/server/lib/opencode/shutdown-runtime.test.js +2 -3
  255. package/server/lib/opencode/skill-routes.js +123 -38
  256. package/server/lib/opencode/skill-routes.test.js +201 -0
  257. package/server/lib/opencode/skills.js +81 -34
  258. package/server/lib/opencode/skills.test.js +176 -21
  259. package/server/lib/opencode/startup-pipeline-runtime.js +6 -3
  260. package/server/lib/opencode/startup-pipeline-runtime.test.js +2 -1
  261. package/server/lib/opencode/watcher.test.js +0 -54
  262. package/server/lib/outbound-proxy.js +52 -0
  263. package/server/lib/outbound-proxy.test.js +55 -0
  264. package/server/lib/package-manager.js +23 -17
  265. package/server/lib/package-manager.test.js +5 -18
  266. package/server/lib/permission-auto-accept/DOCUMENTATION.md +1 -1
  267. package/server/lib/permission-auto-accept/runtime.js +19 -47
  268. package/server/lib/permission-auto-accept/runtime.test.js +2 -2
  269. package/server/lib/project-context/DOCUMENTATION.md +7 -1
  270. package/server/lib/project-context/routes.js +1 -2
  271. package/server/lib/project-context/runtime.js +12 -14
  272. package/server/lib/project-context/runtime.test.js +78 -2
  273. package/server/lib/projects/project-config.js +30 -15
  274. package/server/lib/projects/project-config.test.js +30 -0
  275. package/server/lib/projects/project-setup.js +1 -2
  276. package/server/lib/projects/routes.js +1 -2
  277. package/server/lib/quota/DOCUMENTATION.md +35 -7
  278. package/server/lib/quota/index.js +1 -0
  279. package/server/lib/quota/providers/claude/index.js +1 -1
  280. package/server/lib/quota/providers/cline-pass.js +1 -1
  281. package/server/lib/quota/providers/exe-dev.js +1 -1
  282. package/server/lib/quota/providers/google/index.js +1 -1
  283. package/server/lib/quota/providers/hyper.js +1 -1
  284. package/server/lib/quota/providers/kimi.js +116 -36
  285. package/server/lib/quota/providers/kimi.test.js +128 -3
  286. package/server/lib/quota/providers/opencode-go.js +144 -21
  287. package/server/lib/quota/providers/opencode-go.test.js +229 -6
  288. package/server/lib/quota/providers/openrouter.js +1 -1
  289. package/server/lib/quota/providers/zenmux.js +1 -1
  290. package/server/lib/quota/utils/auth.js +1 -0
  291. package/server/lib/quota/utils/transformers.js +2 -6
  292. package/server/lib/relay/DOCUMENTATION.md +18 -3
  293. package/server/lib/relay/e2ee.js +7 -7
  294. package/server/lib/relay/host-client.js +84 -13
  295. package/server/lib/relay/host-client.test.js +201 -1
  296. package/server/lib/relay/identity.js +6 -29
  297. package/server/lib/relay/identity.test.js +18 -28
  298. package/server/lib/relay/key-store.js +141 -0
  299. package/server/lib/relay/key-store.test.js +138 -0
  300. package/server/lib/relay/service.js +8 -8
  301. package/server/lib/relay/service.test.js +10 -5
  302. package/server/lib/relay/signing-key.js +13 -36
  303. package/server/lib/relay/tunnel-codec.js +10 -10
  304. package/server/lib/route-module-exports.test.js +22 -0
  305. package/server/lib/routing/DOCUMENTATION.md +23 -3
  306. package/server/lib/routing/cache.js +87 -0
  307. package/server/lib/routing/defaults.js +11 -0
  308. package/server/lib/routing/history.js +12 -4
  309. package/server/lib/routing/runtime.js +39 -3
  310. package/server/lib/routing/runtime.test.js +81 -2
  311. package/server/lib/routing/store.js +12 -1
  312. package/server/lib/routing/store.test.js +13 -0
  313. package/server/lib/scheduled-tasks/DOCUMENTATION.md +59 -1
  314. package/server/lib/scheduled-tasks/existing-session.js +119 -0
  315. package/server/lib/scheduled-tasks/existing-session.test.js +350 -0
  316. package/server/lib/scheduled-tasks/loops.js +1 -8
  317. package/server/lib/scheduled-tasks/routes.js +8 -8
  318. package/server/lib/scheduled-tasks/runtime.js +103 -13
  319. package/server/lib/scheduled-tasks/runtime.test.js +48 -0
  320. package/server/lib/scheduled-tasks/service.js +33 -11
  321. package/server/lib/scheduled-tasks/service.test.js +128 -2
  322. package/server/lib/scheduled-tasks/session-defaults.js +27 -0
  323. package/server/lib/scheduled-tasks/session-defaults.test.js +19 -0
  324. package/server/lib/session-assist/context.js +1 -0
  325. package/server/lib/session-folders/routes.js +2 -2
  326. package/server/lib/session-goal/objectives.js +1 -1
  327. package/server/lib/session-knowledge/routes.js +2 -2
  328. package/server/lib/session-knowledge/runtime.js +1 -2
  329. package/server/lib/session-work/DOCUMENTATION.md +39 -14
  330. package/server/lib/session-work/questions.js +31 -2
  331. package/server/lib/session-work/runtime.js +22 -13
  332. package/server/lib/session-work/runtime.test.js +43 -26
  333. package/server/lib/session-work/state.js +10 -4
  334. package/server/lib/session-work/state.test.js +8 -1
  335. package/server/lib/shared/DOCUMENTATION.md +89 -0
  336. package/server/lib/shared/guards.js +53 -0
  337. package/server/lib/shared/guards.test.js +112 -0
  338. package/server/lib/skills-catalog/DOCUMENTATION.md +10 -8
  339. package/server/lib/skills-catalog/cache.js +3 -2
  340. package/server/lib/skills-catalog/curated-sources.js +5 -1
  341. package/server/lib/skills-catalog/git.js +107 -20
  342. package/server/lib/skills-catalog/git.test.js +78 -0
  343. package/server/lib/skills-catalog/install.js +21 -12
  344. package/server/lib/skills-catalog/scan.js +25 -15
  345. package/server/lib/skills-catalog/source.js +26 -1
  346. package/server/lib/skills-catalog/source.test.js +27 -0
  347. package/server/lib/source-control/DOCUMENTATION.md +2 -1
  348. package/server/lib/source-control/audit-storage.js +7 -6
  349. package/server/lib/source-control/audit-storage.test.js +11 -0
  350. package/server/lib/source-control/binding-service.js +2 -5
  351. package/server/lib/source-control/change-request-worktree.js +90 -0
  352. package/server/lib/source-control/change-request-worktree.test.js +121 -0
  353. package/server/lib/source-control/mutation-executor.js +1 -1
  354. package/server/lib/source-control/mutation-storage.js +11 -5
  355. package/server/lib/source-control/provider-instance.js +1 -2
  356. package/server/lib/source-control/repository-identity.js +1 -1
  357. package/server/lib/source-control/routes.js +14 -2
  358. package/server/lib/spaces/DOCUMENTATION.md +42 -17
  359. package/server/lib/spaces/command-stream.test.js +15 -0
  360. package/server/lib/spaces/dispatcher.js +7 -0
  361. package/server/lib/spaces/dispatcher.test.js +17 -0
  362. package/server/lib/spaces/hardening.js +2 -2
  363. package/server/lib/spaces/hardening.test.js +1 -1
  364. package/server/lib/spaces/host.js +2 -0
  365. package/server/lib/spaces/journey.js +66 -5
  366. package/server/lib/spaces/journey.test.js +95 -4
  367. package/server/lib/spaces/layout.js +1 -1
  368. package/server/lib/spaces/places/docker-disk.js +38 -14
  369. package/server/lib/spaces/places/docker-disk.test.js +80 -1
  370. package/server/lib/spaces/places/docker.js +35 -11
  371. package/server/lib/spaces/places/fake-docker.js +22 -3
  372. package/server/lib/spaces/places/memory-place.js +3 -0
  373. package/server/lib/spaces/places/packed.docker.live.test.js +1 -1
  374. package/server/lib/spaces/routes.js +5 -0
  375. package/server/lib/spaces/routes.test.js +4 -2
  376. package/server/lib/spaces/run-command.js +9 -2
  377. package/server/lib/spaces/tools.js +4 -5
  378. package/server/lib/spaces/tools.test.js +2 -2
  379. package/server/lib/terminal/runtime.js +18 -6
  380. package/server/lib/terminal/runtime.test.js +66 -0
  381. package/server/lib/tts/index.js +3 -0
  382. package/server/lib/tts/service.js +4 -2
  383. package/server/lib/walkthrough/DOCUMENTATION.md +3 -1
  384. package/server/lib/walkthrough/index.js +2 -3
  385. package/server/lib/walkthrough/pr-source.test.js +22 -0
  386. package/server/lib/walkthrough/sources.js +6 -1
  387. package/server/opencode-proxy.test.js +127 -0
  388. package/bin/lib/commands-startup.test.js +0 -15
  389. package/dist/assets/CodeMirrorCommentWidgets-CVDSjcrP.js +0 -1
  390. package/dist/assets/DiffView-Ct7vL3fD.js +0 -4
  391. package/dist/assets/FilesView-DT0uEYgT.js +0 -17
  392. package/dist/assets/GuestSurfacePane-DVvk1VPu.js +0 -1
  393. package/dist/assets/LinearIssuesView-C10MwA9h.js +0 -1
  394. package/dist/assets/MarkdownImageGallery-BbN_K_3d.js +0 -1
  395. package/dist/assets/MarkdownRendererImpl-BLt2Tkk9.js +0 -10
  396. package/dist/assets/OnboardingScreen-Bgp5A3WB.js +0 -1
  397. package/dist/assets/PierreDiffViewer-CWJLj-S-.js +0 -210
  398. package/dist/assets/PlanView-DsRWnsOI.js +0 -5
  399. package/dist/assets/PublishDialog-CCeKloRu.js +0 -2
  400. package/dist/assets/SettingsView-BuPPsNPp.js +0 -30
  401. package/dist/assets/SettingsWindow-CM5fL8Ot.js +0 -1
  402. package/dist/assets/SubmoduleDiffSummary-CfsMcfiQ.js +0 -1
  403. package/dist/assets/ToolOutputDialog-mZrfSofz.js +0 -15
  404. package/dist/assets/ToolPartDiffPreview-BUGCRYEL.js +0 -8
  405. package/dist/assets/WalkthroughView-ClBo7PPd.js +0 -4
  406. package/dist/assets/appThemeRegistry-CxzMxR-H.js +0 -1
  407. package/dist/assets/de-CBla4hjd.js +0 -14
  408. package/dist/assets/es-BmnZtxTD.js +0 -20
  409. package/dist/assets/fileTreeStatus-BSHFIGEg.js +0 -1
  410. package/dist/assets/fr-OVKIBUZO.js +0 -18
  411. package/dist/assets/index-CKCFKmjF.js +0 -1
  412. package/dist/assets/index-Dbx4V4GN.css +0 -1
  413. package/dist/assets/index-vQ1Pg1cr.js +0 -61
  414. package/dist/assets/ja-6v-yr-gE.js +0 -20
  415. package/dist/assets/ko-I_ZLvgQ9.js +0 -20
  416. package/dist/assets/main-CmO4dRtR.js +0 -2
  417. package/dist/assets/main-b9vqhlYM.js +0 -999
  418. package/dist/assets/markdownCore-BPEZRQfP.js +0 -7
  419. package/dist/assets/miniChat-B5Oi7B-6.js +0 -2
  420. package/dist/assets/mobile-CVtShif9.js +0 -2
  421. package/dist/assets/nl-DcvIJf46.js +0 -20
  422. package/dist/assets/patchFileDiff-CW3wCH1O.js +0 -13
  423. package/dist/assets/pl-JxCUl0sd.js +0 -20
  424. package/dist/assets/pt-BR-L89mjja2.js +0 -20
  425. package/dist/assets/relocateRestoredSession-DYh_9oBa.js +0 -1
  426. package/dist/assets/renderElectronMiniChatApp-BD-1JHSg.js +0 -2
  427. package/dist/assets/renderMobileApp-7s5InXt1.js +0 -25
  428. package/dist/assets/runtimeEndpointReset-DqLJC6L1.js +0 -53
  429. package/dist/assets/shikiHighlight-CXgZnvHh.js +0 -1
  430. package/dist/assets/space-apply-1trGVIl8.js +0 -1
  431. package/dist/assets/space-close-y7j-NuBv.js +0 -1
  432. package/dist/assets/tr-ka5J1flt.js +0 -11
  433. package/dist/assets/uk-PyGe6Q_u.js +0 -20
  434. package/dist/assets/useInlineCommentController-CrjSGCpi.js +0 -2
  435. package/dist/assets/vendor-codemirror-lang-python-B7ClrMIT.js +0 -3
  436. package/dist/assets/vendor-codemirror-lang-xml-C8tGnS64.js +0 -1
  437. package/dist/assets/vendor-codemirror-language-data-q2bKO1EM.js +0 -2
  438. package/dist/assets/vendor-framer-motion-Bq3iTZ6r.js +0 -1
  439. package/dist/assets/vendor-katex-CHD9BdDO.js +0 -257
  440. package/dist/assets/vendor-katex-Cp579UoJ.css +0 -1
  441. package/dist/assets/zh-CN-B0P2tybJ.js +0 -20
  442. package/dist/assets/zh-TW-Bs9C5cN8.js +0 -20
@@ -1,5 +1,5 @@
1
- import{c as _t,p as se,g as Ce,b as Gt,d as Wt,e as $t,f as Dt,i as Xe,h as jt,j as qt,s as Tt,k as ot,l as Kt,m as Xt,R as Yt,I as Zt,n as at,r as Jt,w as Qt,o as ei,q as ti,t as lt,u as ii,v as ni,x as si,y as dt,S as ri,z as oi,A as ai,B as ht,C as li,D as di,E as hi,F as ut,G as _e,H as ui,J as fi,K as ci,L as pi,M as gi,a as mi,N as Si}from"./parseDiffFromFile-Cy0PNxun.js";import{k as P,m as Ie,l as Ci,u as me,w as Ye,d as bt,e as ft,x as _,y as xe,z as yi,i as ve,b as Li,a as vi,A as fe,B as Mt,C as Ge}from"./computeVirtualFileMetrics-CmPe29DM.js";import{h as Ri,g as Re,d as ke,c as D,a as j,i as ye,r as ki,e as pe,f as Ei,j as Ft,k as Hi,l as ct,b as It,m as Le,n as ie}from"./isDiffPlainText-CQmDCnEv.js";import{k$ as wi,kZ as Ee,kY as re,k_ as Ze,l0 as xi,ih as ce,l1 as Ai,l2 as Di,l3 as pt,l4 as Ti,kP as bi,kQ as Mi,kR as Fi,kS as Ii}from"./useAppFontEffects-DCqCVGlT.js";import{t as ne}from"./vendor-hast-util-to-html-BKBhbTDb.js";function Pt(e){return e.map(t=>({...t,hunkContent:t.hunkContent.map(i=>({...i}))}))}function zt(e){return{...e,hunks:Pt(e.hunks),deletionLines:[...e.deletionLines],additionLines:[...e.additionLines]}}function ze(e){return e!==""?e.split(wi):[]}function Je(e,t,i){const n=e==="clone"?zt(t):t;if(!n.isPartial)throw new Error("hydratePartialDiff: fileDiff must be partial");switch(n.type){case"change":case"rename-changed":return Pi(n,Ni(n,i),gt(n,i));case"rename-pure":{const s=gt(n,i);Oi(n,i);const r=ze(s.contents);return n.isPartial=!1,n.deletionLines=r,n.additionLines=r,Nt(n,null,s),n}}throw new Error(`hydratePartialDiff: ${n.type} diffs cannot be hydrated from loaded files`)}function Pi(e,t,i){const n=ze(t.contents),s=ze(i.contents),{hunks:r,splitLineCount:o,unifiedLineCount:a}=zi(e.hunks,s.length);return e.hunks=r,e.splitLineCount=o,e.unifiedLineCount=a,e.isPartial=!1,e.deletionLines=n,e.additionLines=s,Nt(e,t,i),e}function zi(e,t){let i=0,n=0,s=0;const r=[];for(const o of e){const a=Math.max(o.additionStart-1,0),l=Math.max(o.deletionStart-1,0);let h=a,d=l,u=0,c=0,f=0,p=0;const g=[];for(const C of o.hunkContent){if(C.type==="context"){g.push({...C,additionLineIndex:h,deletionLineIndex:d}),h+=C.lines,d+=C.lines,f+=C.lines,p+=C.lines;continue}g.push({...C,additionLineIndex:h,deletionLineIndex:d}),h+=C.additions,d+=C.deletions,u+=C.additions,c+=C.deletions,f+=Math.max(C.additions,C.deletions),p+=C.additions+C.deletions}const S=Math.max(Ee(o.additionStart,o.additionCount)-s,0);r.push({...o,collapsedBefore:S,additionLineIndex:a,deletionLineIndex:l,additionLines:u,deletionLines:c,hunkContent:g,splitLineStart:i+S,unifiedLineStart:n+S,splitLineCount:f,unifiedLineCount:p}),i+=S+f,n+=S+p,s=re(o.additionStart,o.additionCount)}if(r.length>0){const o=r[r.length-1],a=re(o.additionStart,o.additionCount),l=Math.max(t-a,0);i+=l,n+=l}return{hunks:r,splitLineCount:i,unifiedLineCount:n}}function Ni(e,t){if(t.oldFile==null)throw new Error(`hydratePartialDiff: ${e.type} diff for ${e.name} requires oldFile`);return t.oldFile}function gt(e,t){if(t.newFile==null)throw new Error(`hydratePartialDiff: ${e.type} diff for ${e.name} requires newFile`);return t.newFile}function Oi(e,t){if(t.oldFile!==null)throw new Error(`hydratePartialDiff: ${e.type} diff for ${e.name} requires oldFile to be null`)}function Ui(e,t,i){return e.cacheKey!=null?`${e.cacheKey}:hydrated`:Bi(t,i)}function Nt(e,t,i){const n=Ui(e,t,i);if(n==null){delete e.cacheKey;return}e.cacheKey=n}function Bi(e,t){return e!=null&&t!=null?e.cacheKey!=null&&t.cacheKey!=null?_t("hydrated-files",e.cacheKey,t.cacheKey):void 0:e?.cacheKey??t?.cacheKey}var Vi=class{isDeletionsScrolling=!1;isAdditionsScrolling=!1;timeoutId=-1;codeDeletions;codeAdditions;enabled=!1;cleanUp(){this.enabled&&(this.codeDeletions?.removeEventListener("scroll",this.handleDeletionsScroll),this.codeAdditions?.removeEventListener("scroll",this.handleAdditionsScroll),clearTimeout(this.timeoutId),this.codeDeletions=void 0,this.codeAdditions=void 0,this.enabled=!1)}setup(e,t,i){if(t==null||i==null)for(const n of e.children??[])n instanceof HTMLElement&&("deletions"in n.dataset?t=n:"additions"in n.dataset&&(i=n));if(i==null||t==null){this.cleanUp();return}this.codeDeletions!==t&&(this.codeDeletions?.removeEventListener("scroll",this.handleDeletionsScroll),this.codeDeletions=t,t.addEventListener("scroll",this.handleDeletionsScroll,{passive:!0})),this.codeAdditions!==i&&(this.codeAdditions?.removeEventListener("scroll",this.handleAdditionsScroll),this.codeAdditions=i,i.addEventListener("scroll",this.handleAdditionsScroll,{passive:!0})),this.enabled=!0}handleDeletionsScroll=()=>{this.isAdditionsScrolling||(this.isDeletionsScrolling=!0,clearTimeout(this.timeoutId),this.timeoutId=setTimeout(()=>{this.isDeletionsScrolling=!1},300),this.codeAdditions?.scrollTo({left:this.codeDeletions?.scrollLeft}))};handleAdditionsScroll=()=>{this.isDeletionsScrolling||(this.isAdditionsScrolling=!0,clearTimeout(this.timeoutId),this.timeoutId=setTimeout(()=>{this.isAdditionsScrolling=!1},300),this.codeDeletions?.scrollTo({left:this.codeAdditions?.scrollLeft}))}};function Ae(e){return P({tagName:"div",properties:{"data-content-buffer":"","data-buffer-size":e,style:`grid-row: span ${e};min-height:calc(${e} * 1lh)`}})}function De(e){return P({tagName:"div",children:[P({tagName:"span",children:[Ie("No newline at end of file")]})],properties:{"data-no-newline":"","data-line-type":e,"data-column-content":""}})}function We(e){return P({tagName:"div",children:[Ci({name:e==="both"?"diffs-icon-expand-all":"diffs-icon-expand",properties:{"data-icon":""}})],properties:{role:"button","data-expand-button":"","data-expand-both":e==="both"?"":void 0,"data-expand-up":e==="up"?"":void 0,"data-expand-down":e==="down"?"":void 0}})}function ue({type:e,content:t,expandIndex:i,chunked:n=!1,slotName:s,isFirstHunk:r,isLastHunk:o}){let a=0;const l=[];if(e==="metadata"&&t!=null&&l.push(P({tagName:"div",children:[Ie(t)],properties:{"data-separator-wrapper":""}})),(e==="line-info"||e==="line-info-basic")&&t!=null){const h=[];i!=null&&(n?(r||(h.push(We("up")),a++),o||(h.push(We("down")),a++)):(h.push(We(!r&&!o?"both":r?"down":"up")),a++)),h.push(P({tagName:"div",children:[P({tagName:"span",children:[Ie(t)],properties:{"data-unmodified-lines":""}})],properties:{"data-separator-content":""}})),n&&i!=null&&h.push(P({tagName:"div",children:[Ie("Expand all")],properties:{role:"button","data-expand-button":"","data-expand-all-button":""}})),l.push(P({tagName:"div",children:h,properties:{"data-separator-wrapper":"","data-separator-multi-button":a>1?"":void 0}}))}return e==="custom"&&s!=null&&l.push(P({tagName:"slot",properties:{name:s}})),P({tagName:"div",children:l,properties:{"data-separator":l.length===0?"simple":e,"data-expand-index":i,"data-separator-first":r?"":void 0,"data-separator-last":o?"":void 0}})}function _i(e,t){return`hunk-separator-${e}-${t}`}function Gi(e){const t=e.at(-1);return t==null?0:Math.max(re(t.additionStart,t.additionCount),re(t.deletionStart,t.deletionCount))}function K(e,t){const i=se({name:e.prevName??e.name,contents:e.deletionLines.join("")},{name:e.name,contents:e.additionLines.join(""),lang:e.lang},t);return{hunks:i.hunks,splitLineCount:i.splitLineCount,unifiedLineCount:i.unifiedLineCount,additionLines:i.additionLines,deletionLines:i.deletionLines,type:i.type}}function Wi(e,t){const i=Math.max(e,1);let n=Array.from({length:i},(s,r)=>`${" ".repeat(r+1)}
1
+ import{c as _t,p as se,g as Ce,b as Gt,d as Wt,e as $t,f as Dt,i as Xe,h as jt,j as Kt,s as Tt,k as ot,l as qt,m as Xt,R as Yt,I as Jt,n as at,r as Zt,w as Qt,o as ei,q as ti,t as lt,u as ii,v as ni,x as si,y as dt,S as ri,z as oi,A as ai,B as ht,C as li,D as di,E as hi,F as ut,G as _e,H as ui,J as fi,K as ci,L as pi,M as gi,a as mi,N as Si}from"./parseDiffFromFile-BUgn-T9p.js";import{k as P,m as Ie,l as Ci,u as me,w as Ye,d as bt,e as ft,x as _,y as we,z as yi,i as ve,b as Li,a as vi,A as fe,B as Mt,C as Ge}from"./computeVirtualFileMetrics-C2WM6JC2.js";import{h as Ri,g as Re,d as ke,c as D,a as j,i as ye,r as ki,e as pe,f as Ei,j as Ft,k as Hi,l as ct,b as It,m as Le,n as ie}from"./isDiffPlainText-Dgbw8VKk.js";import{lJ as xi,lH as Ee,lG as re,lI as Je,lK as wi,j2 as ce,lL as Ai,lM as Di,lN as pt,lO as Ti,lx as bi,ly as Mi,lz as Fi,lA as Ii}from"./useAppFontEffects-DGlvOqP_.js";import{t as ne}from"./vendor-hast-util-to-html-BKBhbTDb.js";function Pt(e){return e.map(t=>({...t,hunkContent:t.hunkContent.map(i=>({...i}))}))}function zt(e){return{...e,hunks:Pt(e.hunks),deletionLines:[...e.deletionLines],additionLines:[...e.additionLines]}}function ze(e){return e!==""?e.split(xi):[]}function Ze(e,t,i){const n=e==="clone"?zt(t):t;if(!n.isPartial)throw new Error("hydratePartialDiff: fileDiff must be partial");switch(n.type){case"change":case"rename-changed":return Pi(n,Ni(n,i),gt(n,i));case"rename-pure":{const s=gt(n,i);Oi(n,i);const r=ze(s.contents);return n.isPartial=!1,n.deletionLines=r,n.additionLines=r,Nt(n,null,s),n}}throw new Error(`hydratePartialDiff: ${n.type} diffs cannot be hydrated from loaded files`)}function Pi(e,t,i){const n=ze(t.contents),s=ze(i.contents),{hunks:r,splitLineCount:o,unifiedLineCount:a}=zi(e.hunks,s.length);return e.hunks=r,e.splitLineCount=o,e.unifiedLineCount=a,e.isPartial=!1,e.deletionLines=n,e.additionLines=s,Nt(e,t,i),e}function zi(e,t){let i=0,n=0,s=0;const r=[];for(const o of e){const a=Math.max(o.additionStart-1,0),l=Math.max(o.deletionStart-1,0);let h=a,d=l,u=0,c=0,f=0,p=0;const g=[];for(const C of o.hunkContent){if(C.type==="context"){g.push({...C,additionLineIndex:h,deletionLineIndex:d}),h+=C.lines,d+=C.lines,f+=C.lines,p+=C.lines;continue}g.push({...C,additionLineIndex:h,deletionLineIndex:d}),h+=C.additions,d+=C.deletions,u+=C.additions,c+=C.deletions,f+=Math.max(C.additions,C.deletions),p+=C.additions+C.deletions}const S=Math.max(Ee(o.additionStart,o.additionCount)-s,0);r.push({...o,collapsedBefore:S,additionLineIndex:a,deletionLineIndex:l,additionLines:u,deletionLines:c,hunkContent:g,splitLineStart:i+S,unifiedLineStart:n+S,splitLineCount:f,unifiedLineCount:p}),i+=S+f,n+=S+p,s=re(o.additionStart,o.additionCount)}if(r.length>0){const o=r[r.length-1],a=re(o.additionStart,o.additionCount),l=Math.max(t-a,0);i+=l,n+=l}return{hunks:r,splitLineCount:i,unifiedLineCount:n}}function Ni(e,t){if(t.oldFile==null)throw new Error(`hydratePartialDiff: ${e.type} diff for ${e.name} requires oldFile`);return t.oldFile}function gt(e,t){if(t.newFile==null)throw new Error(`hydratePartialDiff: ${e.type} diff for ${e.name} requires newFile`);return t.newFile}function Oi(e,t){if(t.oldFile!==null)throw new Error(`hydratePartialDiff: ${e.type} diff for ${e.name} requires oldFile to be null`)}function Ui(e,t,i){return e.cacheKey!=null?`${e.cacheKey}:hydrated`:Bi(t,i)}function Nt(e,t,i){const n=Ui(e,t,i);if(n==null){delete e.cacheKey;return}e.cacheKey=n}function Bi(e,t){return e!=null&&t!=null?e.cacheKey!=null&&t.cacheKey!=null?_t("hydrated-files",e.cacheKey,t.cacheKey):void 0:e?.cacheKey??t?.cacheKey}var Vi=class{isDeletionsScrolling=!1;isAdditionsScrolling=!1;timeoutId=-1;codeDeletions;codeAdditions;enabled=!1;cleanUp(){this.enabled&&(this.codeDeletions?.removeEventListener("scroll",this.handleDeletionsScroll),this.codeAdditions?.removeEventListener("scroll",this.handleAdditionsScroll),clearTimeout(this.timeoutId),this.codeDeletions=void 0,this.codeAdditions=void 0,this.enabled=!1)}setup(e,t,i){if(t==null||i==null)for(const n of e.children??[])n instanceof HTMLElement&&("deletions"in n.dataset?t=n:"additions"in n.dataset&&(i=n));if(i==null||t==null){this.cleanUp();return}this.codeDeletions!==t&&(this.codeDeletions?.removeEventListener("scroll",this.handleDeletionsScroll),this.codeDeletions=t,t.addEventListener("scroll",this.handleDeletionsScroll,{passive:!0})),this.codeAdditions!==i&&(this.codeAdditions?.removeEventListener("scroll",this.handleAdditionsScroll),this.codeAdditions=i,i.addEventListener("scroll",this.handleAdditionsScroll,{passive:!0})),this.enabled=!0}handleDeletionsScroll=()=>{this.isAdditionsScrolling||(this.isDeletionsScrolling=!0,clearTimeout(this.timeoutId),this.timeoutId=setTimeout(()=>{this.isDeletionsScrolling=!1},300),this.codeAdditions?.scrollTo({left:this.codeDeletions?.scrollLeft}))};handleAdditionsScroll=()=>{this.isDeletionsScrolling||(this.isAdditionsScrolling=!0,clearTimeout(this.timeoutId),this.timeoutId=setTimeout(()=>{this.isAdditionsScrolling=!1},300),this.codeDeletions?.scrollTo({left:this.codeAdditions?.scrollLeft}))}};function Ae(e){return P({tagName:"div",properties:{"data-content-buffer":"","data-buffer-size":e,style:`grid-row: span ${e};min-height:calc(${e} * 1lh)`}})}function De(e){return P({tagName:"div",children:[P({tagName:"span",children:[Ie("No newline at end of file")]})],properties:{"data-no-newline":"","data-line-type":e,"data-column-content":""}})}function We(e){return P({tagName:"div",children:[Ci({name:e==="both"?"diffs-icon-expand-all":"diffs-icon-expand",properties:{"data-icon":""}})],properties:{role:"button","data-expand-button":"","data-expand-both":e==="both"?"":void 0,"data-expand-up":e==="up"?"":void 0,"data-expand-down":e==="down"?"":void 0}})}function ue({type:e,content:t,expandIndex:i,chunked:n=!1,slotName:s,isFirstHunk:r,isLastHunk:o}){let a=0;const l=[];if(e==="metadata"&&t!=null&&l.push(P({tagName:"div",children:[Ie(t)],properties:{"data-separator-wrapper":""}})),(e==="line-info"||e==="line-info-basic")&&t!=null){const h=[];i!=null&&(n?(r||(h.push(We("up")),a++),o||(h.push(We("down")),a++)):(h.push(We(!r&&!o?"both":r?"down":"up")),a++)),h.push(P({tagName:"div",children:[P({tagName:"span",children:[Ie(t)],properties:{"data-unmodified-lines":""}})],properties:{"data-separator-content":""}})),n&&i!=null&&h.push(P({tagName:"div",children:[Ie("Expand all")],properties:{role:"button","data-expand-button":"","data-expand-all-button":""}})),l.push(P({tagName:"div",children:h,properties:{"data-separator-wrapper":"","data-separator-multi-button":a>1?"":void 0}}))}return e==="custom"&&s!=null&&l.push(P({tagName:"slot",properties:{name:s}})),P({tagName:"div",children:l,properties:{"data-separator":l.length===0?"simple":e,"data-expand-index":i,"data-separator-first":r?"":void 0,"data-separator-last":o?"":void 0}})}function _i(e,t){return`hunk-separator-${e}-${t}`}function Gi(e){const t=e.at(-1);return t==null?0:Math.max(re(t.additionStart,t.additionCount),re(t.deletionStart,t.deletionCount))}function q(e,t){const i=se({name:e.prevName??e.name,contents:e.deletionLines.join("")},{name:e.name,contents:e.additionLines.join(""),lang:e.lang},t);return{hunks:i.hunks,splitLineCount:i.splitLineCount,unifiedLineCount:i.unifiedLineCount,additionLines:i.additionLines,deletionLines:i.deletionLines,type:i.type}}function Wi(e,t){const i=Math.max(e,1);let n=Array.from({length:i},(s,r)=>`${" ".repeat(r+1)}
2
2
  `).join("");return n===t&&(n=Array.from({length:i},(s,r)=>`\0${" ".repeat(r)}
3
- `).join("")),n}function $i(e){for(const t of e)if(t.trim().length>0)return!1;return!0}function Qe(e,t){return t.length>0&&t.length<e.deletionLines.length&&$i(t)}function Ne(e,t,i){const n=e.deletionLines.join(""),s=Wi(t.length,n),r=se({name:e.prevName??e.name,contents:n},{name:e.name,contents:s,lang:e.lang},i);return{hunks:r.hunks,splitLineCount:r.splitLineCount,unifiedLineCount:r.unifiedLineCount,additionLines:t,deletionLines:r.deletionLines,type:r.type}}function Pe(e,t){return Ne(e,[""],t)}function Ot(e,t){if(e.additionLines.length===0)return Pe(e,t);if(Qe(e,e.additionLines))return Ne(e,e.additionLines,t);const i=e.additionLines,n=K(e,t);return Ut(n,i),n}function ji(e){return e.length>1&&e.at(-1)===""}function Ut(e,t){if(!ji(t))return;const i=t.length-e.additionLines.length;if(i<=0)return;const n=e.additionLines.length,s=e.hunks.at(-1);if(s!=null&&re(s.additionStart,s.additionCount)===n){for(const r of s.hunkContent)if(r.type==="change"&&r.additions<r.deletions&&r.additionLineIndex+r.additions===n){e.additionLines=t,r.additions+=i,s.additionCount+=i,s.additionLines+=i,Ue(e);return}}}function qi(e,t,i){if(e.isPartial||e.deletionLines.length!==e.additionLines.length)return q(e,K(e,i));const n=Array.from(t);if(n.length===0)return q(e,{hunks:e.hunks,splitLineCount:e.splitLineCount,unifiedLineCount:e.unifiedLineCount,type:e.type});for(const r of n){const o=e.additionLines[r],a=e.deletionLines[r];if(o==null||a==null||Ze(o)===Ze(a))return q(e,K(e,i))}const s=Ki(e,n);if(s.size===0)return q(e,K(e,i));for(const r of s)if(!Yi(e,r,i))return q(e,K(e,i));return Ue(e),Ri(e)?q(e,K(e,i)):q(e,{hunks:e.hunks,splitLineCount:e.splitLineCount,unifiedLineCount:e.unifiedLineCount,type:e.type})}function q(e,t){return Object.assign(e,t),t}function Ki(e,t){const i=new Set;for(const n of t){const s=Xi(e,n);if(s==null)return new Set;i.add(s)}return i}function Xi(e,t){for(const[i,n]of e.hunks.entries()){const s=n.additionLineIndex+n.additionCount;if(t>=n.additionLineIndex&&t<s)return i}}function Yi(e,t,i){const n=e.hunks[t];if(n==null)return!1;const s=e.deletionLines.slice(n.deletionLineIndex,n.deletionLineIndex+n.deletionCount),r=e.additionLines.slice(n.additionLineIndex,n.additionLineIndex+n.additionCount),o=se({name:e.prevName??e.name,contents:s.join("")},{name:e.name,contents:r.join(""),lang:e.lang},{...i,context:0}),a=o.hunks[0];return a==null||o.hunks.length!==1?!1:(Zi(n,a),Bt(e,t),!0)}function Bt(e,t){const i=e.hunks[t];if(i==null)return;if(t!==e.hunks.length-1){i.noEOFCRAdditions=!1,i.noEOFCRDeletions=!1;return}const n=e.additionLines.at(-1),s=e.deletionLines.at(-1);i.noEOFCRAdditions=n!=null&&n!==""&&!n.endsWith(`
3
+ `).join("")),n}function $i(e){for(const t of e)if(t.trim().length>0)return!1;return!0}function Qe(e,t){return t.length>0&&t.length<e.deletionLines.length&&$i(t)}function Ne(e,t,i){const n=e.deletionLines.join(""),s=Wi(t.length,n),r=se({name:e.prevName??e.name,contents:n},{name:e.name,contents:s,lang:e.lang},i);return{hunks:r.hunks,splitLineCount:r.splitLineCount,unifiedLineCount:r.unifiedLineCount,additionLines:t,deletionLines:r.deletionLines,type:r.type}}function Pe(e,t){return Ne(e,[""],t)}function Ot(e,t){if(e.additionLines.length===0)return Pe(e,t);if(Qe(e,e.additionLines))return Ne(e,e.additionLines,t);const i=e.additionLines,n=q(e,t);return Ut(n,i),n}function ji(e){return e.length>1&&e.at(-1)===""}function Ut(e,t){if(!ji(t))return;const i=t.length-e.additionLines.length;if(i<=0)return;const n=e.additionLines.length,s=e.hunks.at(-1);if(s!=null&&re(s.additionStart,s.additionCount)===n){for(const r of s.hunkContent)if(r.type==="change"&&r.additions<r.deletions&&r.additionLineIndex+r.additions===n){e.additionLines=t,r.additions+=i,s.additionCount+=i,s.additionLines+=i,Ue(e);return}}}function Ki(e,t,i){if(e.isPartial||e.deletionLines.length!==e.additionLines.length)return K(e,q(e,i));const n=Array.from(t);if(n.length===0)return K(e,{hunks:e.hunks,splitLineCount:e.splitLineCount,unifiedLineCount:e.unifiedLineCount,type:e.type});for(const r of n){const o=e.additionLines[r],a=e.deletionLines[r];if(o==null||a==null||Je(o)===Je(a))return K(e,q(e,i))}const s=qi(e,n);if(s.size===0)return K(e,q(e,i));for(const r of s)if(!Yi(e,r,i))return K(e,q(e,i));return Ue(e),Ri(e)?K(e,q(e,i)):K(e,{hunks:e.hunks,splitLineCount:e.splitLineCount,unifiedLineCount:e.unifiedLineCount,type:e.type})}function K(e,t){return Object.assign(e,t),t}function qi(e,t){const i=new Set;for(const n of t){const s=Xi(e,n);if(s==null)return new Set;i.add(s)}return i}function Xi(e,t){for(const[i,n]of e.hunks.entries()){const s=n.additionLineIndex+n.additionCount;if(t>=n.additionLineIndex&&t<s)return i}}function Yi(e,t,i){const n=e.hunks[t];if(n==null)return!1;const s=e.deletionLines.slice(n.deletionLineIndex,n.deletionLineIndex+n.deletionCount),r=e.additionLines.slice(n.additionLineIndex,n.additionLineIndex+n.additionCount),o=se({name:e.prevName??e.name,contents:s.join("")},{name:e.name,contents:r.join(""),lang:e.lang},{...i,context:0}),a=o.hunks[0];return a==null||o.hunks.length!==1?!1:(Ji(n,a),Bt(e,t),!0)}function Bt(e,t){const i=e.hunks[t];if(i==null)return;if(t!==e.hunks.length-1){i.noEOFCRAdditions=!1,i.noEOFCRDeletions=!1;return}const n=e.additionLines.at(-1),s=e.deletionLines.at(-1);i.noEOFCRAdditions=n!=null&&n!==""&&!n.endsWith(`
4
4
  `),i.noEOFCRDeletions=s!=null&&s!==""&&!s.endsWith(`
5
- `)}function Zi(e,t){const i=e.additionLineIndex,n=e.deletionLineIndex;e.hunkContent=t.hunkContent.map(s=>Vt(s,i,n)),e.additionLineIndex=i+t.additionLineIndex,e.additionStart=e.additionStart+t.additionLineIndex,e.additionCount=t.additionCount,e.additionLines=t.additionLines,t.deletionLineIndex>=0&&(e.deletionLineIndex=n+t.deletionLineIndex,e.deletionStart=e.deletionStart+t.deletionLineIndex),e.deletionCount=t.deletionCount,e.deletionLines=t.deletionLines,e.noEOFCRAdditions=t.noEOFCRAdditions,e.noEOFCRDeletions=t.noEOFCRDeletions,rt(e)}function Vt(e,t,i){return{...e,additionLineIndex:e.additionLineIndex+t,deletionLineIndex:e.deletionLineIndex+i}}function rt(e){let t=0,i=0;for(const n of e.hunkContent)n.type==="context"?(t+=n.lines,i+=n.lines):(t+=Math.max(n.additions,n.deletions),i+=n.additions+n.deletions);e.splitLineCount=t,e.unifiedLineCount=i}function Ue(e){let t=0,i=0,n=0;for(const s of e.hunks)s.collapsedBefore=Math.max(Ee(s.additionStart,s.additionCount)-n,0),s.splitLineStart=t+s.collapsedBefore,s.unifiedLineStart=i+s.collapsedBefore,rt(s),t+=s.collapsedBefore+s.splitLineCount,i+=s.collapsedBefore+s.unifiedLineCount,n=re(s.additionStart,s.additionCount);if(e.hunks.length>0){const s=e.hunks[e.hunks.length-1],r=Math.max(e.additionLines.length-re(s.additionStart,s.additionCount),0);t+=r,i+=r}e.splitLineCount=t,e.unifiedLineCount=i}const mt=new WeakMap;function Ji(e){return e.length>1&&e[e.length-1]===""?e.slice(0,-1):e}function Qi(e,t){const i=Math.min(e.length,t.length);let n=0;for(;n<i&&e[n]===t[n];)n++;let s=e.length,r=t.length;for(;s>n&&r>n&&e[s-1]===t[r-1];)s--,r--;if(!(n===s&&n===r))return{start:n,deletionEnd:s,additionEnd:r}}function et(e,t,i){const n=e.hunks,s=e.additionLines,r=Ji(s),o=r===s?e:{...e,additionLines:r},a=hn(n,ln(o,t,i),e.deletionLines.length),l=cn(o,a);if(e.additionLines=r,e.hunks=l,e.editSessionDirty=!0,Sn(e),Ut(e,s),!!gn(n,e.hunks))return{regions:a.map(h=>h.previousSpan)}}function en(e,t,i,n){const s=new Set(t),r=Array.from(s).filter(d=>d>=0&&d<e.additionLines.length).sort((d,u)=>d-u);if(r.length===0)return;const o=d=>s.has(d)?n?.get(d):e.additionLines[d],{hunks:a}=e;let l,h=0;for(const d of r){for(;h<a.length;){const f=a[h];if(d<Oe(f)+f.additionCount)break;h++}const u=a[h],c=u==null?void 0:Oe(u);if(c==null||d<c||l!=null&&l!==h)return et(e,i,o);l=h}if(l!=null){if(tn(e,r,l,n,i)){e.editSessionDirty=!0;return}return et(e,i,o)}}function tn(e,t,i,n,s){if(n==null||s?.ignoreWhitespace===!0||s?.stripTrailingCr===!0)return!1;const r=nn(e),o=e.hunks[i];if(o.hunkContent.some(sn))return!1;for(const a of t){const l=n.get(a),h=e.additionLines[a];if(l==null||h==null||r.has(l)||r.has(h))return!1;let d=!1;for(const u of o.hunkContent)if(u.type==="change"&&u.additions===u.deletions&&a>=u.additionLineIndex&&a<u.additionLineIndex+u.additions){d=!0;break}if(!d)return!1}return!0}function nn(e){const t=mt.get(e);if(t?.lines===e.deletionLines)return t.set;const i=new Set(e.deletionLines);return mt.set(e,{lines:e.deletionLines,set:i}),i}function sn(e){return e?.type==="change"&&(e.additions===0||e.deletions===0)}function rn(e,t){const i=new Map,{regions:n}=t;for(let s=0;s<=n.length;s++){const r=n[s-1],o=n[s],a=s===0?e.get(0):r==null?void 0:e.get(r.lastIndex+1),l=o==null?void 0:e.get(o.firstIndex),h=a?.fromStart??0,d=l?.fromEnd??0;(h>0||d>0)&&i.set(s,{fromStart:h,fromEnd:d})}return i}function on(e,t,i){const n=[];if(e.isPartial)return n;for(const[r,o]of e.hunks.entries()){const a=Re({isPartial:e.isPartial,rangeSize:o.collapsedBefore,expandedHunks:t,hunkIndex:r,collapsedContextThreshold:i});if(a.rangeSize<=i)continue;const l=oe(o),h=l-a.rangeSize;a.fromStart>0&&n.push([h,h+a.fromStart]),a.fromEnd>0&&n.push([l-a.fromEnd,l])}const s=ke({fileDiff:e,hunkIndex:e.hunks.length-1,expandedHunks:t,collapsedContextThreshold:i,errorPrefix:"captureExpansionAnchors"});if(s!=null&&s.fromStart>0&&s.rangeSize>i){const r=e.hunks[e.hunks.length-1],o=oe(r)+r.deletionCount;n.push([o,o+s.fromStart])}return n}function an(e,t){const i=new Map;if(t.length===0)return i;const n=(r,o,a)=>{if(a<=o)return;let l=0,h=0;for(const[d,u]of t)u<=o||d>=a||(d<=o&&(l=Math.max(l,Math.min(u,a)-o)),u>=a&&(h=Math.max(h,a-Math.max(d,o))));(l>0||h>0)&&i.set(r,{fromStart:l,fromEnd:h})};for(const[r,o]of e.hunks.entries()){const a=oe(o);n(r,a-Math.max(o.collapsedBefore,0),a)}const s=e.hunks[e.hunks.length-1];return s!=null&&!e.isPartial&&e.deletionLines.length>0&&n(e.hunks.length,oe(s)+s.deletionCount,e.deletionLines.length),i}function St(e,t){return e.editSessionDirty!==!0?!1:(delete e.editSessionDirty,Object.assign(e,e.additionLines.length<=1&&e.additionLines.join("")===""?K(e,t):Ot(e,t)),!0)}function ln(e,t,i){if(Qi(e.deletionLines,e.additionLines)==null)return[];const n=se({name:e.prevName??e.name,contents:e.deletionLines.join("")},{name:e.name,contents:e.additionLines.join(""),lang:e.lang},t);let s;const r=(h,d)=>{s??=dn(e.hunks);for(let u=0;u<=d;u++){const c=s.get(h.deletionLineIndex-u);if(!(c==null||c.additions!==h.additions||c.deletions!==h.deletions)){if(h.additions>0&&i!=null){for(let f=0;f<h.additions;f++)if(i(c.additionLineIndex+f)!==n.additionLines[h.additionLineIndex+f])return d}return u}}return d},o=[];let a=0,l=0;for(const h of n.hunks){xi(h,n,r);const d=h.additionCount>0?h.additionLineIndex-a:h.deletionLineIndex-l;a+=d,l+=d;for(const u of h.hunkContent){if(u.type==="context"){a+=u.lines,l+=u.lines;continue}const c=Vt(u,0,0);c.additions===0&&(c.additionLineIndex=a),c.deletions===0&&(c.deletionLineIndex=l),o.push(c),a+=c.additions,l+=c.deletions}}return o}function dn(e){const t=new Map;for(const i of e)for(const n of i.hunkContent)n.type==="change"&&(n.additions===0||n.deletions===0)&&t.set(n.deletionLineIndex,n);return t}function hn(e,t,i){const n=e.map((o,a)=>{const l=oe(o);return{deletionStart:l,deletionEnd:l+o.deletionCount,blocks:[],previousSpan:{firstIndex:a,lastIndex:a}}}),s=[];let r=0;for(const o of t){const a=o.deletionLineIndex,l=a+o.deletions;for(;r<n.length&&n[r].deletionEnd<a;)s.push(n[r]),r++;let h=s.length>0&&un(a,l,s[s.length-1])?s.pop():void 0;for(;r<n.length&&n[r].deletionStart<=l;)h=fn(h,n[r]),r++;if(h==null){let d=a,u=l;if((o.deletions===0||o.additions===0)&&i>o.deletions){const c=s[s.length-1]?.deletionEnd??0,f=n[r]?.deletionStart??i;a>c?d--:l<f&&u++}h={deletionStart:d,deletionEnd:u,blocks:[],previousSpan:void 0}}h.deletionStart=Math.min(h.deletionStart,a),h.deletionEnd=Math.max(h.deletionEnd,l),h.blocks.push(o),s.push(h)}for(;r<n.length;)s.push(n[r]),r++;return s}function un(e,t,i){return e<=i.deletionEnd&&t>=i.deletionStart}function fn(e,t){return e==null?t:(e.deletionStart=Math.min(e.deletionStart,t.deletionStart),e.deletionEnd=Math.max(e.deletionEnd,t.deletionEnd),e.blocks.push(...t.blocks),t.previousSpan!=null&&(e.previousSpan??={...t.previousSpan},e.previousSpan.firstIndex=Math.min(e.previousSpan.firstIndex,t.previousSpan.firstIndex),e.previousSpan.lastIndex=Math.max(e.previousSpan.lastIndex,t.previousSpan.lastIndex)),e)}function cn(e,t){const i=[];let n=0,s=0;for(const r of t){const o=r.deletionStart-n;if(o<0)throw new Error("buildRegionHunks: overlapping old-side regions");n+=o,s+=o;const a=s,l=[];for(const d of r.blocks){const u=d.deletionLineIndex-n,c=d.additionLineIndex-s;if(u<0||u!==c)throw new Error("buildRegionHunks: canonical block context mismatch");Ct(l,u,s,n),n+=u,s+=c,l.push({...d}),n+=d.deletions,s+=d.additions}const h=r.deletionEnd-n;if(h<0)throw new Error("buildRegionHunks: block exceeds its old-side region");Ct(l,h,s,n),n+=h,s+=h,i.push(pn(e,{additionStart:a,additionEnd:s,deletionStart:r.deletionStart,deletionEnd:r.deletionEnd},l))}if(e.deletionLines.length-n!==e.additionLines.length-s)throw new Error("buildRegionHunks: trailing context mismatch");return i}function pn(e,t,i){const n=t.additionEnd-t.additionStart,s=t.deletionEnd-t.deletionStart;let r=0,o=0;for(const l of i)l.type==="change"&&(r+=l.additions,o+=l.deletions);const a={collapsedBefore:0,additionStart:Te(t.additionStart,n),additionCount:n,additionLines:r,additionLineIndex:Lt(t.additionStart,n),deletionStart:Te(t.deletionStart,s),deletionCount:s,deletionLines:o,deletionLineIndex:Lt(t.deletionStart,s),hunkContent:i,hunkSpecs:`@@ -${Te(t.deletionStart,s)},${s} +${Te(t.additionStart,n)},${n} @@`,splitLineStart:0,splitLineCount:0,unifiedLineStart:0,unifiedLineCount:0,noEOFCRAdditions:!1,noEOFCRDeletions:!1};return rt(a),a}function Ct(e,t,i,n){t>0&&e.push({type:"context",lines:t,additionLineIndex:i,deletionLineIndex:n})}function gn(e,t){if(e.length!==t.length)return!0;for(let i=0;i<e.length;i++){const n=e[i],s=t[i];if(oe(n)!==oe(s)||n.deletionCount!==s.deletionCount||Oe(n)!==Oe(s)||n.additionCount!==s.additionCount||n.splitLineCount!==s.splitLineCount||!mn(n,s))return!0}return!1}function mn(e,t){const i=yt(e),n=yt(t);for(;;){const s=i.next(),r=n.next();if(s.done===!0||r.done===!0)return s.done===r.done;if(s.value[0]!==r.value[0]||s.value[1]!==r.value[1])return!1}}function*yt(e){for(const t of e.hunkContent){if(t.type==="context"){for(let n=0;n<t.lines;n++)yield[t.deletionLineIndex+n,t.additionLineIndex+n];continue}const i=Math.max(t.deletions,t.additions);for(let n=0;n<i;n++)yield[n<t.deletions?t.deletionLineIndex+n:void 0,n<t.additions?t.additionLineIndex+n:void 0]}}function Oe(e){return Ee(e.additionStart,e.additionCount)}function oe(e){return Ee(e.deletionStart,e.deletionCount)}function Te(e,t){return t===0?e:e+1}function Lt(e,t){return t===0?e-1:e}function Sn(e){Ue(e);for(let t=0;t<e.hunks.length;t++)Bt(e,t)}let Cn=-1;var yn=class{options;annotationSlotName;onRenderUpdate;workerManager;__id=`diff-hunks-renderer:${++Cn}`;highlighter;diff;expandedHunks=new Map;deletionAnnotations={};additionAnnotations={};computedLangs=["text"];renderCache;pendingHighlightResult;pendingStructuralRows;editSessionActive=!1;constructor(e={theme:ce},t=Ce,i,n){this.options=e,this.annotationSlotName=t,this.onRenderUpdate=i,this.workerManager=n,n?.isWorkingPool()!==!0&&(this.highlighter=me(e.theme??ce)?Ye():void 0)}cleanUp(){this.endEditSession(),this.recycle(),this.expandedHunks.clear(),this.workerManager=void 0,this.onRenderUpdate=void 0}recycle(){this.highlighter=void 0,this.diff=void 0,this.editSessionActive?(this.renderCache!=null&&(this.renderCache.renderRange=void 0),this.pendingHighlightResult=void 0,this.pendingStructuralRows=void 0):this.clearRenderCache(),this.additionAnnotations={},this.deletionAnnotations={},this.workerManager?.cleanUpTasks(this)}beginEditSession(e,t){const{editSessionActive:i}=this;this.editSessionActive=!0,i||(this.pendingHighlightResult=void 0),this.diff=e,i&&this.renderCache!=null&&this.renderCache.diff!==e&&this.clearRenderCache();const{renderCache:n}=this;if(!e.isPartial&&e.additionLines.length===0){Object.assign(e,Pe(e,this.options.parseDiffOptions)),this.markEditSessionPass(e),this.clearRenderCache();return}if(n==null||i&&n.diff===e)return;const{options:s}=this.getRenderOptions(e),r=n.diff===e,o=t!=null&&D(n.diff,t),{result:a}=n;if(!n.highlighted||a==null||!j(n.options,s)||!r&&!o){this.clearRenderCache();return}r||(this.renderCache={diff:e,options:s,highlighted:!0,result:{...a,code:{...a.code,additionLines:[...a.code.additionLines]}},renderRange:n.renderRange})}endEditSession(){this.editSessionActive=!1,this.pendingHighlightResult=void 0,this.diff==null&&this.clearRenderCache()}editorRenderReady(){return this.renderCache?.options.useTokenTransformer===!0&&this.renderCache.highlighted&&this.renderCache.result!=null}refreshHighlightedResult(){const{diff:e,renderCache:t,workerManager:i}=this;return e==null||t==null||!D(t.diff,e)||ye(e)||Se(e,this.getTokenizeMaxLength())?Promise.resolve():!this.editSessionActive&&i?.isWorkingPool()===!0&&e.cacheKey!=null?(i.evictDiffFromCache(e.cacheKey),i.primeDiffHighlightCache(e).then(()=>{this.applyRefreshedResult(e,i.getDiffResultCache(e))}).catch(n=>this.onHighlightError(n))):this.asyncHighlight(e).then(n=>this.applyRefreshedResult(e,n)).catch(n=>this.onHighlightError(n))}applyRefreshedResult(e,t){const{diff:i,renderCache:n}=this;if(t==null||i==null||n==null||!D(i,e)||!D(n.diff,e)||this.editSessionActive)return;const{options:s}=this.getRenderOptions(i);j(s,t.options)&&(this.pendingHighlightResult={diff:i,options:t.options,highlighted:!0,result:t.result},this.onRenderUpdate?.())}get diffCache(){return this.renderCache?.diff??this.diff}clearRenderCache(){this.renderCache=void 0,this.pendingHighlightResult=void 0,this.pendingStructuralRows=void 0}setOptions(e){this.options=e}mergeOptions(e){this.options={...this.options,...e}}expandHunk(e,t,i=this.getOptionsWithDefaults().expansionLineCount){const n={...this.expandedHunks.get(e)??{fromStart:0,fromEnd:0}};(t==="up"||t==="both")&&(n.fromStart+=i),(t==="down"||t==="both")&&(n.fromEnd+=i),this.renderCache?.highlighted!==!0&&this.clearRenderCache(),this.expandedHunks.set(e,n)}getExpandedHunk(e){return this.expandedHunks.get(e)??Ai}getExpandedHunksMap(){return this.expandedHunks}setExpandedHunksMap(e){this.expandedHunks=e}setLineAnnotations(e){this.additionAnnotations={},this.deletionAnnotations={};for(const t of e){const i=(()=>{switch(t.side){case"deletions":return this.deletionAnnotations;case"additions":return this.additionAnnotations}})(),n=i[t.lineNumber]??[];i[t.lineNumber]=n,n.push(t)}}updateRenderCache(e,t,i=!1){this.pendingStructuralRows=void 0;const{renderCache:n}=this;if(n==null)return!1;const{result:s,diff:r}=n;if(s==null)return!1;if(r.isPartial)throw new Error("Could not update render cache for partial diff");const o=s.code.additionLines,a=this.pendingStructuralRows=i?new Map:void 0,l=[],h=new Map;for(const[u,c]of e){const f=o[u]?.properties??{},p=c.map(v=>v[2]).join(""),g=u<r.additionLines.length,S=g?r.additionLines[u]??"":"",C=Ze(S);a==null&&g&&(r.additionLines[u]=Gt(S,p),C!==p&&(l.push(u),h.set(u,S)));const y={type:"element",tagName:"div",properties:{"data-line":f["data-line"]??u+1,"data-line-index":f["data-line-index"]??u,"data-line-type":f["data-line-type"]??"context"},children:c.map(([v,R,m])=>v===0&&R===""?m===""?{type:"element",tagName:"br",properties:{},children:[]}:{type:"text",value:m}:{type:"element",tagName:"span",properties:{"data-char":v,style:`color:${R};`},children:[{type:"text",value:m}]})};a!=null?a.set(u,y):o[u]=y}let d=!1;if(l.length>0)if(this.editSessionActive)if(r.additionLines.length<=1&&r.additionLines.join("")==="")this.applyRecomputePreservingSessionType(r,Pe(r,this.options.parseDiffOptions)),d=!0;else if(Qe(r,r.additionLines))this.applyRecomputePreservingSessionType(r,Ne(r,r.additionLines,this.options.parseDiffOptions)),d=!0;else{const u=en(r,l,this.options.parseDiffOptions,h);this.applyExpansionRemap(u),d=u!=null}else Object.assign(r,qi(r,l,this.options.parseDiffOptions));return s.baseThemeType=t,n.isDirty=!0,d}applyExpansionRemap(e){e!=null&&(this.expandedHunks=rn(this.expandedHunks,e))}applyDocumentChange(e){const{pendingStructuralRows:t,renderCache:i}=this;this.pendingStructuralRows=void 0;const n=this.diff??i?.diff;if(n==null)return;const s=i?.result;if(n.isPartial)throw new Error("Could not apply document change for partial diff");const{additionLines:r}=n;if(n.additionLines=kn(e),s!=null&&(s.code.additionLines=Rn(r,n.additionLines,s.code.additionLines,e)),n.additionLines.length<=1&&n.additionLines.join("")===""?(this.applyRecomputePreservingSessionType(n,Pe(n,this.options.parseDiffOptions)),s!=null&&(s.code.additionLines[0]=tt(0,e.getLineText(0)))):this.editSessionActive?this.applySessionDocumentChange(n,r):Object.assign(n,Ot(n,this.options.parseDiffOptions)),t!=null&&s!=null)for(const[o,a]of t)o<s.code.additionLines.length&&(s.code.additionLines[o]=a);i!=null&&(i.isDirty=!0)}applySessionDocumentChange(e,t){const{parseDiffOptions:i}=this.options,n=e.additionLines;if(Qe(e,n)){this.applyRecomputePreservingSessionType(e,Ne(e,n,i));return}this.applyExpansionRemap(et(e,i,s=>t[s]))}applyRecomputePreservingSessionType(e,t){const i=this.editSessionActive?e.type:void 0;Object.assign(e,t),i!=null&&(e.type=i),this.markEditSessionPass(e)}markEditSessionPass(e){this.editSessionActive&&(e.editSessionDirty=!0)}getUnifiedLineDecoration({lineType:e}){return{gutterLineType:e,contentProperties:{"data-line-type":e}}}getSplitLineDecoration({side:e,type:t}){const i=t==="change"?e==="deletions"?"change-deletion":"change-addition":t;return{gutterLineType:i,contentProperties:{"data-line-type":i}}}createAnnotationElement=e=>Wt(e);getOptionsWithDefaults(){const{diffIndicators:e="bars",diffStyle:t="split",disableBackground:i=!1,disableFileHeader:n=!1,disableLineNumbers:s=!1,disableVirtualizationBuffers:r=!1,collapsed:o=!1,expandUnchanged:a=!1,collapsedContextThreshold:l=1,expansionLineCount:h=100,hunkSeparators:d="line-info",lineDiffType:u="word-alt",maxLineDiffLength:c=1e3,overflow:f="scroll",stickyHeader:p=!1,theme:g=ce,headerRenderMode:S="default",tokenizeMaxLineLength:C=1e3,tokenizeMaxLength:y=Di,useTokenTransformer:v=!1,useCSSClasses:R=!1}=this.options;return{diffIndicators:e,diffStyle:t,disableBackground:i,disableFileHeader:n,disableLineNumbers:s,disableVirtualizationBuffers:r,collapsed:o,expandUnchanged:a,collapsedContextThreshold:l,expansionLineCount:h,hunkSeparators:d,lineDiffType:u,maxLineDiffLength:c,overflow:f,stickyHeader:p,theme:this.workerManager?.getDiffRenderOptions().theme??g,headerRenderMode:S,tokenizeMaxLineLength:C,tokenizeMaxLength:y,useTokenTransformer:v,useCSSClasses:R}}async initializeHighlighter(){return this.highlighter=await bt($t(this.computedLangs,{theme:this.getLocalHighlightTheme(),preferredHighlighter:this.workerManager?.getPreferredHighlighter()??this.options.preferredHighlighter})),this.highlighter}hydrate(e){if(e==null)return;this.diff=e;const{options:t}=this.getRenderOptions(e),i=Se(e,this.getTokenizeMaxLength());let n=this.workerManager?.getDiffResultCache(e);n!=null&&!j(t,n.options)&&(n=void 0),this.renderCache??={diff:e,hydrated:!0,highlighted:!i&&!ye(e),options:t,result:i?void 0:n?.result,renderRange:void 0},!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0?this.renderCache.result==null&&!i&&this.workerManager.highlightDiffAST(this,this.diff):this.highlighter==null&&(this.computedLangs=je(e),this.initializeHighlighter())}getLocalHighlightTheme(){return this.workerManager?.getDiffRenderOptions().theme??this.options.theme??ce}getEffectiveCodeOptions(){const e=this.workerManager?.isWorkingPool()===!0?this.workerManager.getDiffRenderOptions():void 0;return{theme:this.getLocalHighlightTheme(),tokenizeMaxLineLength:e?.tokenizeMaxLineLength??this.options.tokenizeMaxLineLength}}getRenderOptions(e){const t=(()=>{if(this.workerManager?.isWorkingPool()===!0){const a=this.workerManager.getDiffRenderOptions();return this.editSessionActive&&a.useTokenTransformer!==!0?{...a,useTokenTransformer:!0}:a}const{theme:n,tokenizeMaxLineLength:s,lineDiffType:r,maxLineDiffLength:o}=this.getOptionsWithDefaults();return{theme:n,useTokenTransformer:this.editSessionActive||this.options.useTokenTransformer===!0,tokenizeMaxLineLength:s,lineDiffType:r,maxLineDiffLength:o}})();this.getOptionsWithDefaults();const{renderCache:i}=this;return i?.result==null?{options:t,forceHighlight:!0}:!D(e,i.diff)||!j(t,i.options)?{options:t,forceHighlight:!0}:{options:t,forceHighlight:!1}}getDiffForNextRender(e){const{options:t}=this.getRenderOptions(e);if(this.getReadyRenderResult(e,t)!=null||this.renderCache==null)return e;if(D(this.renderCache.diff,e))return this.renderCache.diff;const i=!(e.additionLines.length>0||e.deletionLines.length>0)||ye(e)||Se(e,this.getTokenizeMaxLength());return this.canRenderDiff(e,t,i)?e:this.renderCache.diff}canRenderDiff(e,t,i){const{renderCache:n}=this;return n==null||D(n.diff,e)?!0:i?n.result==null&&n.hydrated!==!0||this.workerManager?.isWorkingPool()===!0||this.highlighter!=null&&me(t.theme):n.result==null&&n.hydrated!==!0?!0:!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0?!n.highlighted:this.highlighter!=null&&me(t.theme)}renderDiff(e=this.diff,t=pt){if(this.diff=e,e==null){this.pendingHighlightResult=void 0;return}const{expandUnchanged:i,collapsedContextThreshold:n}=this.getOptionsWithDefaults();let{options:s,forceHighlight:r}=this.getRenderOptions(e);const o=this.getReadyRenderResult(e,s);this.pendingHighlightResult=void 0,o!=null&&(this.renderCache={...o,diff:e,renderRange:void 0},r=!1),this.renderCache??={diff:e,highlighted:!1,options:s,result:void 0,renderRange:void 0};const a=e.additionLines.length>0||e.deletionLines.length>0,l=!a||ye(e)||Se(e,this.getTokenizeMaxLength()),h=this.canRenderDiff(e,s,l),d=!D(e,this.renderCache.diff),u=!Dt(this.renderCache.renderRange,t);if(!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0){const c=this.renderCache.result==null&&this.renderCache.highlighted&&!l&&!d&&Xe(t);h&&!c&&(l||this.renderCache.result==null||!this.renderCache.highlighted&&(d||u))&&(this.renderCache.diff=e,this.renderCache.options=s,this.renderCache.highlighted=!1,(this.renderCache.result==null||d||u||r)&&(this.renderCache.result=this.workerManager.getPlainDiffAST(e,t.startingLine,t.totalLines,Xe(t)||i?!0:this.expandedHunks,n)),this.renderCache.renderRange=t),!l&&a&&(!this.renderCache.highlighted||r)&&this.workerManager.highlightDiffAST(this,e)}else{this.computedLangs=je(e),this.highlighter??=Ye();const c=this.highlighter!=null&&me(s.theme),f=this.highlighter!=null&&ft(this.computedLangs),p=!l&&f;if(h&&this.highlighter!=null&&c&&(r||l||!this.renderCache.highlighted&&p||this.renderCache.result==null)){const{result:g,options:S}=this.renderDiffWithHighlighter(e,this.highlighter,l||!f);this.renderCache={diff:e,options:S,highlighted:p,result:g,renderRange:void 0}}(!c||!l&&!f)&&this.asyncHighlight(e).then(({result:g,options:S})=>{this.applyHighlightResult(e,g,S,!l)})}return this.renderCache.result!=null?this.processDiffResult(this.renderCache.diff,t,this.renderCache.result):void 0}async asyncRender(e,t=pt){this.diff=e;const{result:i}=await this.asyncHighlight(e);return this.processDiffResult(e,t,i)}createPreElement(e,t,i){const{diffIndicators:n,disableBackground:s,disableLineNumbers:r,overflow:o}=this.getOptionsWithDefaults();return jt({type:"diff",diffIndicators:n,disableBackground:s,disableLineNumbers:r,overflow:o,split:e,totalLines:t,customProperties:i})}async asyncHighlight(e){const t=Se(e,this.getTokenizeMaxLength());this.computedLangs=t?["text"]:je(e);const i=this.highlighter!=null&&me(this.getLocalHighlightTheme()),n=t||this.highlighter!=null&&ft(this.computedLangs);return(this.highlighter==null||!i||!n)&&(this.highlighter=await this.initializeHighlighter()),this.renderDiffWithHighlighter(e,this.highlighter,t)}renderDiffWithHighlighter(e,t,i=!1){const{options:n}=this.getRenderOptions(e),{collapsedContextThreshold:s}=this.getOptionsWithDefaults(),r=ki(e,t,n,{forcePlainText:i,expandedHunks:i?!0:void 0,collapsedContextThreshold:s});if(this.editSessionActive&&e.additionLines.length===1&&e.additionLines[0]===""&&r.code.additionLines[0]==null){let o;if(pe({diff:e,diffStyle:"both",expandedHunks:i?!0:void 0,collapsedContextThreshold:s,callback:({additionLine:a})=>{if(a?.lineIndex===0)return o=a,!0}}),o==null)throw new Error("DiffHunksRenderer: missing empty addition line");r.code.additionLines[0]=tt(0,"",o.unifiedLineIndex,o.splitLineIndex)}return{result:r,options:n}}onHighlightSuccess(e,t,i,n=!0){this.editSessionActive||this.applyHighlightResult(e,t,i,n)}applyHighlightResult(e,t,i,n=!0){const{diff:s,renderCache:r}=this;s==null||r==null||!D(s,e)||!j(i,this.getRenderOptions(s).options)||(r.result==null||!r.highlighted||!j(r.options,i)||!D(r.diff,s))&&(this.pendingHighlightResult={diff:s,options:i,highlighted:n,result:t},this.onRenderUpdate?.())}getMatchingWorkerResultCache(e,t){if(this.editSessionActive)return;const i=this.workerManager?.getDiffResultCache(e);if(!(i==null||!j(t,i.options)))return i}getReadyRenderResult(e,t){const{pendingHighlightResult:i}=this;if(i!=null&&D(i.diff,e)&&j(i.options,t))return i;const n=this.getMatchingWorkerResultCache(e,t);if(!(n==null||this.hasHighlightedRenderCache(e,t)))return{diff:e,highlighted:!0,...n}}hasHighlightedRenderCache(e,t){const{renderCache:i}=this;return i?.result!=null&&i.highlighted&&D(e,i.diff)&&j(t,i.options)}onHighlightError(e){console.error(e)}getTokenizeMaxLength(){return this.options.tokenizeMaxLength??1e5}processDiffResult(e,t,{code:i,themeStyles:n,baseThemeType:s}){const{diffStyle:r,disableFileHeader:o,expandUnchanged:a,expansionLineCount:l,collapsedContextThreshold:h,hunkSeparators:d}=this.getOptionsWithDefaults(),u=this.renderCache?.isDirty??!1,c=r==="unified",f=En(e,this.options.loadDiffFiles!=null),p=!e.isPartial||f;let g=[],S=[],C=[];const y=[],{additionLines:v,deletionLines:R}=i,m={rowCount:0,hunkSeparators:d,additionsContentAST:g,deletionsContentAST:S,unifiedContentAST:C,unifiedGutterAST:xe(),deletionsGutterAST:xe(),additionsGutterAST:xe(),expansionLineCount:l,hunkData:y,incrementRowCount(H=1){m.rowCount+=H},pushToGutter(H,w){switch(H){case"unified":m.unifiedGutterAST.children.push(w);break;case"deletions":m.deletionsGutterAST.children.push(w);break;case"additions":m.additionsGutterAST.children.push(w)}}},b=Ei({fileDiff:e,errorPrefix:"DiffHunksRenderer.processDiffResult"}),L={size:0,side:void 0,increment(){this.size+=1},flush(){if(r!=="unified"){if(this.size<=0||this.side==null){this.side=void 0,this.size=0;return}this.side==="additions"?(m.pushToGutter("additions",_(void 0,"buffer",this.size)),g?.push(Ae(this.size))):(m.pushToGutter("deletions",_(void 0,"buffer",this.size)),S?.push(Ae(this.size))),this.size=0,this.side=void 0}}},F=(H,w,X,de,E)=>{m.pushToGutter(H,yi(w,X,de,E))};function ae(H){L.flush(),r==="unified"?$e("unified",H,m):($e("deletions",H,m),$e("additions",H,m))}this.pushFileLevelAnnotations(e,r,t,m),pe({diff:e,diffStyle:r,startingLine:t.startingLine,totalLines:t.totalLines,expandedHunks:a?!0:this.expandedHunks,collapsedContextThreshold:h,callback:({hunkIndex:H,hunk:w,collapsedBefore:X,collapsedAfter:de,additionLine:E,deletionLine:x,type:T})=>{const O=x!=null?x.splitLineIndex:E.splitLineIndex,Y=E!=null?E.unifiedLineIndex:x.unifiedLineIndex;r==="split"&&T!=="change"&&L.flush(),X>0&&ae({hunkIndex:H,collapsedLines:X,rangeSize:Math.max(w?.collapsedBefore??0,0),hunkSpecs:w?.hunkSpecs,isFirstHunk:H===0,isLastHunk:!1,isExpandable:p});const he=r==="unified"?Y:O,He={type:T,hunkIndex:H,lineIndex:he,unifiedLineIndex:Y,splitLineIndex:O,deletionLine:x,additionLine:E};if(r==="unified"){const A=this.getUnifiedInjectedRowsForLine?.(He);A?.before!=null&&vt(A.before,m);let z=x!=null?R[x.lineIndex]:void 0,U=E!=null?v[E.lineIndex]:void 0;if(z==null&&U==null){const V="DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong";throw console.error(V,{file:e.name}),new Error(V)}const te=T==="change"?E!=null?"change-addition":"change-deletion":T,B=this.getUnifiedLineDecoration({type:T,lineType:te,additionLineIndex:E?.lineIndex,deletionLineIndex:x?.lineIndex});F("unified",B.gutterLineType,E!=null?E.lineNumber:x.lineNumber,`${Y},${O}`,B.gutterProperties),U!=null?U=Me(U,B.contentProperties,u&&E!=null?{"data-line":E.lineNumber,"data-line-index":`${Y},${O}`}:void 0):z!=null&&(z=Me(z,B.contentProperties,u&&x!=null?{"data-line":x.lineNumber,"data-line-index":`${Y},${O}`}:void 0)),be({diffStyle:"unified",type:T,deletionLine:z,additionLine:U,unifiedSpan:this.getAnnotations("unified",x?.lineNumber,E?.lineNumber,H,he),createAnnotationElement:V=>this.createAnnotationElement(V),context:m}),A?.after!=null&&vt(A.after,m)}else{const A=this.getSplitInjectedRowsForLine?.(He);A?.before!=null&&Rt(A.before,m,L);let z=x!=null?R[x.lineIndex]:void 0,U=E!=null?v[E.lineIndex]:void 0;const te=this.getSplitLineDecoration({side:"deletions",type:T,lineIndex:x?.lineIndex}),B=this.getSplitLineDecoration({side:"additions",type:T,lineIndex:E?.lineIndex});if(z==null&&U==null){const N="DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong";throw console.error(N,{file:e.name}),new Error(N)}const V=(()=>{if(T==="change"){if(U==null)return"additions";if(z==null)return"deletions"}})();V!=null?(L.side!=null&&L.side!==V&&L.flush(),L.side=V,L.increment()):T==="change"&&L.flush();const Z=this.getAnnotations("split",x?.lineNumber,E?.lineNumber,H,he);if(Z!=null&&L.size>0&&L.flush(),x!=null){const N=Me(z,te.contentProperties,u?{"data-line":x.lineNumber,"data-line-index":`${x.unifiedLineIndex},${O}`}:void 0);F("deletions",te.gutterLineType,x.lineNumber,`${x.unifiedLineIndex},${O}`,te.gutterProperties),N!=null&&(z=N)}if(E!=null){const N=Me(U,B.contentProperties,u?{"data-line":E.lineNumber,"data-line-index":`${E.unifiedLineIndex},${O}`}:void 0);F("additions",B.gutterLineType,E.lineNumber,`${E.unifiedLineIndex},${O}`,B.gutterProperties),N!=null&&(U=N)}be({diffStyle:"split",type:T,additionLine:U,deletionLine:z,...Z,createAnnotationElement:N=>this.createAnnotationElement(N),context:m}),A?.after!=null&&Rt(A.after,m,L)}const ge=r==="split"&&w!=null&&O===w.splitLineStart+w.splitLineCount-1,W=H===e.hunks.length-1&&w!=null&&(r==="split"?O===w.splitLineStart+w.splitLineCount-1:Y===w.unifiedLineStart+w.unifiedLineCount-1),Be=ge?w.noEOFCRDeletions:!1,Ve=ge?w.noEOFCRAdditions:!1,ee=(x?.noEOFCR??!1)||Be,$=(E?.noEOFCR??!1)||Ve;if($||ee){if(r==="split"&&L.flush(),ee){const A=T==="context"||T==="context-expanded"?T:"change-deletion";r==="unified"?(m.unifiedContentAST.push(De(A)),m.pushToGutter("unified",_(A,"metadata",1))):(m.deletionsContentAST.push(De(A)),m.pushToGutter("deletions",_(A,"metadata",1)),$||(m.pushToGutter("additions",_(void 0,"buffer",1)),m.additionsContentAST.push(Ae(1))))}if($){const A=T==="context"||T==="context-expanded"?T:"change-addition";r==="unified"?(m.unifiedContentAST.push(De(A)),m.pushToGutter("unified",_(A,"metadata",1))):(m.additionsContentAST.push(De(A)),m.pushToGutter("additions",_(A,"metadata",1)),ee||(m.pushToGutter("deletions",_(void 0,"buffer",1)),m.deletionsContentAST.push(Ae(1))))}m.incrementRowCount(1)}d!=="simple"&&d!=="metadata"&&(de>0||W&&f)&&ae({hunkIndex:T==="context-expanded"?H:H+1,collapsedLines:W&&f?"unknown":de,rangeSize:b,hunkSpecs:void 0,isFirstHunk:!1,isLastHunk:!0,isExpandable:p}),m.incrementRowCount(1)}}),r==="split"&&L.flush();const k=Math.max(Gi(e.hunks),e.additionLines.length??0,e.deletionLines.length??0),M=t.bufferBefore>0||t.bufferAfter>0,le=!c&&e.type!=="deleted",I=!c&&e.type!=="new",G=m.rowCount>0||M;g=le&&G?g:void 0,S=I&&G?S:void 0,C=c&&G?C:void 0;const Q=this.createPreElement(S!=null&&g!=null,k);return{fileDiff:e,unifiedGutterAST:c&&G?m.unifiedGutterAST.children:void 0,unifiedContentAST:C,deletionsGutterAST:I&&G?m.deletionsGutterAST.children:void 0,deletionsContentAST:S,additionsGutterAST:le&&G?m.additionsGutterAST.children:void 0,additionsContentAST:g,hunkData:y,preNode:Q,themeStyles:n,baseThemeType:s,headerElement:o?void 0:this.renderHeader(e),totalLines:k,rowCount:m.rowCount,bufferBefore:t.bufferBefore,bufferAfter:t.bufferAfter,css:""}}renderCodeAST(e,t){const i=e==="unified"?t.unifiedGutterAST:e==="deletions"?t.deletionsGutterAST:t.additionsGutterAST,n=e==="unified"?t.unifiedContentAST:e==="deletions"?t.deletionsContentAST:t.additionsContentAST;if(i==null||n==null)return;const s=xe(i);return s.properties.style=`grid-row: span ${t.rowCount}`,[s,qt(n,t.rowCount)]}renderFullAST(e,t=[]){const i=this.getOptionsWithDefaults().hunkSeparators==="line-info",n=this.renderCodeAST("unified",e);if(n!=null)return t.push(P({tagName:"code",children:n,properties:{"data-code":"","data-container-size":i?"":void 0,"data-unified":""}})),{...e.preNode,children:t};const s=this.renderCodeAST("deletions",e);s!=null&&t.push(P({tagName:"code",children:s,properties:{"data-code":"","data-container-size":i?"":void 0,"data-deletions":""}}));const r=this.renderCodeAST("additions",e);return r!=null&&t.push(P({tagName:"code",children:r,properties:{"data-code":"","data-container-size":i?"":void 0,"data-additions":""}})),{...e.preNode,children:t}}renderFullHTML(e,t=[]){return ne(this.renderFullAST(e,t))}renderPartialHTML(e,t){return t==null?ne(e):ne(P({tagName:"code",children:e,properties:{"data-code":"","data-container-size":this.getOptionsWithDefaults().hunkSeparators==="line-info"?"":void 0,[`data-${t}`]:""}}))}pushFileLevelAnnotations(e,t,i,n){if(!Tt(i))return;const s=e.type!=="new"?this.getAnnotationNames(ot(this.deletionAnnotations)):[],r=e.type!=="deleted"?this.getAnnotationNames(ot(this.additionAnnotations)):[];if(s.length===0&&r.length===0)return;const o=-1,a=-1,{createAnnotationElement:l}=this;if(t==="unified"){be({diffStyle:t,type:"context",unifiedSpan:{type:"annotation",hunkIndex:o,lineIndex:a,annotations:s.concat(r)},createAnnotationElement:l,context:n});return}be({diffStyle:t,type:"context",deletionSpan:{type:"annotation",hunkIndex:o,lineIndex:a,annotations:s},additionSpan:{type:"annotation",hunkIndex:o,lineIndex:a,annotations:r},createAnnotationElement:l,context:n})}getAnnotations(e,t,i,n,s){const r={type:"annotation",hunkIndex:n,lineIndex:s,annotations:[]};if(t!=null)for(const a of this.deletionAnnotations[t]??[])r.annotations.push(this.annotationSlotName(a));const o={type:"annotation",hunkIndex:n,lineIndex:s,annotations:[]};if(i!=null)for(const a of this.additionAnnotations[i]??[])(e==="unified"?r:o).annotations.push(this.annotationSlotName(a));if(e==="unified")return r.annotations.length>0?r:void 0;if(!(o.annotations.length===0&&r.annotations.length===0))return{deletionSpan:r,additionSpan:o}}getAnnotationNames(e){return e?.map(t=>this.annotationSlotName(t))??[]}renderHeader(e){const{headerRenderMode:t,stickyHeader:i}=this.getOptionsWithDefaults();return Kt({fileOrDiff:e,mode:t,stickyHeader:i})}};const Ln=new Intl.PluralRules("en-US");function vn(e){return`${e} unmodified line${Ln.select(e)==="one"?"":"s"}`}function vt(e,t){for(const i of e)t.unifiedContentAST.push(i.content),t.pushToGutter("unified",i.gutter),t.incrementRowCount(1)}function Rt(e,t,i){for(const{deletion:n,addition:s}of e){if(n==null&&s==null)continue;const r=n!=null&&s!=null?void 0:n==null?"deletions":"additions";(r==null||i.side!==r)&&i.flush(),n!=null&&(t.deletionsContentAST.push(n.content),t.pushToGutter("deletions",n.gutter)),s!=null&&(t.additionsContentAST.push(s.content),t.pushToGutter("additions",s.gutter)),r!=null&&(i.side=r,i.increment()),t.incrementRowCount(1)}}function be({diffStyle:e,type:t,deletionLine:i,additionLine:n,unifiedSpan:s,deletionSpan:r,additionSpan:o,createAnnotationElement:a,context:l}){let h=!1;if(e==="unified"){if(n!=null?l.unifiedContentAST.push(n):i!=null&&l.unifiedContentAST.push(i),s!=null){const d=t==="change"?i!=null?"change-deletion":"change-addition":t;l.unifiedContentAST.push(a(s)),l.pushToGutter("unified",_(d,"annotation",1)),h=!0}}else if(e==="split"){if(i!=null&&l.deletionsContentAST.push(i),n!=null&&l.additionsContentAST.push(n),r!=null){const d=t==="change"?i!=null?"change-deletion":"context":t;l.deletionsContentAST.push(a(r)),l.pushToGutter("deletions",_(d,"annotation",1)),h=!0}if(o!=null){const d=t==="change"?n!=null?"change-addition":"context":t;l.additionsContentAST.push(a(o)),l.pushToGutter("additions",_(d,"annotation",1)),h=!0}}h&&l.incrementRowCount(1)}function $e(e,{hunkIndex:t,collapsedLines:i,rangeSize:n,hunkSpecs:s,isFirstHunk:r,isLastHunk:o,isExpandable:a},l){if(typeof i=="number"&&i<=0)return;const h=e==="unified"?l.unifiedContentAST:e==="deletions"?l.deletionsContentAST:l.additionsContentAST;if(l.hunkSeparators==="metadata"){s!=null&&(l.pushToGutter(e,ue({type:"metadata",content:s,isFirstHunk:r,isLastHunk:o})),h.push(ue({type:"metadata",content:s,isFirstHunk:r,isLastHunk:o})),e!=="additions"&&l.incrementRowCount(1));return}if(l.hunkSeparators==="simple"){t>0&&(l.pushToGutter(e,ue({type:"simple",isFirstHunk:r,isLastHunk:!1})),h.push(ue({type:"simple",isFirstHunk:r,isLastHunk:!1})),e!=="additions"&&l.incrementRowCount(1));return}const d=_i(e,t),u=n>l.expansionLineCount,c=a?t:void 0,f=typeof i=="number"?vn(i):"More unchanged context may be available";l.pushToGutter(e,ue({type:l.hunkSeparators,content:f,expandIndex:c,chunked:u,slotName:d,isFirstHunk:r,isLastHunk:o})),h.push(ue({type:l.hunkSeparators,content:f,expandIndex:c,chunked:u,slotName:d,isFirstHunk:r,isLastHunk:o})),e!=="additions"&&l.incrementRowCount(1),l.hunkData.push({slotName:d,hunkIndex:t,lines:typeof i=="number"?i:0,lineCountKnown:typeof i=="number",type:e,expandable:a?{up:!r,down:!o,chunked:u}:void 0})}function Me(e,t,i){return e==null||e.type!=="element"||t==null&&i==null?e:{...e,properties:{...e.properties,...t,...i}}}function kt(e){return e.length>0&&e[e.length-1]===""?e.length-1:e.length}function Rn(e,t,i,n){const s=kt(e),r=kt(t),o=Math.min(s,r);let a=0;for(;a<o&&e[a]===t[a];)a++;let l=0;for(;l<o-a&&e[s-1-l]===t[r-1-l];)l++;const h=new Array(t.length);for(let d=0;d<a;d++)h[d]=i[d];for(let d=0;d<l;d++)h[r-1-d]=i[s-1-d];s<e.length&&r<t.length&&(h[t.length-1]=i[e.length-1]);for(let d=a;d<t.length;d++)h[d]??=tt(d,n.getLineText(d));return h}function tt(e,t,i=e,n=e){return{type:"element",tagName:"div",properties:{"data-line":e+1,"data-line-index":`${i},${n}`,"data-line-type":"context"},children:[{type:"element",tagName:"span",properties:{"data-char":0},children:[{type:"text",value:t}]}]}}function kn(e){const t=[];for(let i=0;i<e.lineCount;i++)t.push(e.getLineText(i,!0));return t}function je(e){if(e.lang!=null)return[e.lang];const t=ve(e.prevName??e.name),i=ve(e.name);return t===i?[i]:[t,i]}function Se(e,t){return Math.max(e.additionLines.length,e.deletionLines.length)>t}function En(e,t){return e.isPartial&&t&&(e.type==="change"||e.type==="rename-changed")}function Hn(e,t){return e.lineNumber===t.lineNumber&&e.side===t.side&&e.metadata===t.metadata}function wn(e,t){return e.slotName===t.slotName&&e.hunkIndex===t.hunkIndex&&e.lines===t.lines&&e.lineCountKnown===t.lineCountKnown&&e.type===t.type&&e.expandable?.chunked===t.expandable?.chunked&&e.expandable?.up===t.expandable?.up&&e.expandable?.down===t.expandable?.down}async function it(e,t=300){let i;try{await Promise.race([e(),new Promise(n=>{i=setTimeout(n,t)})])}finally{i!=null&&clearTimeout(i)}}function nt({oldFile:e,newFile:t},i){if(!(e===void 0&&t===void 0)){if(e===void 0||t===void 0)throw new Error(`${i}: Pass null for an intentionally missing oldFile or newFile side`);if(e===null){if(t===null)throw new Error(`${i}: You must pass oldFile, newFile, or both`);return{oldFile:e,newFile:t}}return t===null?{oldFile:e,newFile:t}:{oldFile:e,newFile:t}}}function xn(e){return{theme:e?.theme,disableLineNumbers:e?.disableLineNumbers,overflow:e?.overflow,collapsed:e?.collapsed,disableFileHeader:e?.disableFileHeader,disableVirtualizationBuffers:e?.disableVirtualizationBuffers,stickyHeader:e?.stickyHeader,preferredHighlighter:e?.preferredHighlighter,useCSSClasses:e?.useCSSClasses,useTokenTransformer:Xt(e),tokenizeMaxLineLength:e?.tokenizeMaxLineLength,tokenizeMaxLength:e?.tokenizeMaxLength,diffStyle:e?.diffStyle,diffIndicators:e?.diffIndicators,disableBackground:e?.disableBackground,hunkSeparators:typeof e?.hunkSeparators=="function"?"custom":e?.hunkSeparators,expandUnchanged:e?.expandUnchanged,loadDiffFiles:e?.loadDiffFiles,collapsedContextThreshold:e?.collapsedContextThreshold,lineDiffType:e?.lineDiffType,maxLineDiffLength:e?.maxLineDiffLength,expansionLineCount:e?.expansionLineCount,headerRenderMode:e?.renderCustomHeader!=null?"custom":"default"}}function qe(e){return e.isPartial&&(e.type==="change"||e.type==="rename-changed"||e.type==="rename-pure")}function An(e){const t={...e};return delete t.cacheKey,t}function Et(e,t){if(e.isPartial||t.isPartial)throw new Error("FileDiff.shouldResetEditorForExternalDiff: diffs must be fully hydrated");const i=e.lang??ve(e.name),n=t.lang??ve(t.name),s=e.type!=="new",r=t.type!=="new";return e.name!==t.name||i!==n||s!==r||e.deletionLines.length!==t.deletionLines.length?!0:e.deletionLines.some((o,a)=>o!==t.deletionLines[a])}function Dn(e,t){return e.length===t.length&&e.every((i,n)=>i===t[n])}function Tn(e,t){const{oldFile:i}=e;return i==null?t.type==="new":t.type!=="new"&&i.name===(t.prevName??t.name)&&Dn(i.lines,t.deletionLines)}let bn=-1;var Mn=class{options;workerManager;isContainerManaged;static LoadedCustomComponent=!0;__id=`file-diff:${++bn}`;type="file-diff";fileContainer;spriteSVG;pre;codeUnified;codeDeletions;codeAdditions;bufferBefore;bufferAfter;themeCSSStyle;appliedThemeCSS;hasAdoptedThemeCSS=!1;unsafeCSSStyle;appliedUnsafeCSS;gutterUtilityContent;headerElement;headerPrefix;headerFilenameSuffix;headerMetadata;headerCustom;separatorCache=new Map;errorWrapper;placeHolder;hunksRenderer;resizeManager;scrollSyncManager;interactionManager;annotationCache=new Map;lineAnnotations=[];managersDirty=!1;deletionFile;additionFile;fileDiff;editSession;renderedDiff;renderRange;pendingFiles;appliedPreAttributes;headerCache={lastRenderedHTML:void 0,html:void 0,fileDiff:void 0};lastRowCount;mounted=!1;enabled=!0;editor;refreshViewTimeout;lineStateRefreshPending=!1;deferredSelectedLines;deferredEditorActiveLine;constructor(e={theme:ce},t,i=!1){this.options=e,this.workerManager=t,this.isContainerManaged=i,this.hunksRenderer=this.createHunksRenderer(e),this.resizeManager=new Yt,this.scrollSyncManager=new Vi,this.interactionManager=new Zt("diff",at(e,typeof e.hunkSeparators=="function"||(e.hunkSeparators??"line-info")==="line-info"||e.hunkSeparators==="line-info-basic"?this.handleExpandHunk:void 0,this.getLineIndex)),this.workerManager?.subscribeToThemeChanges(this),this.enabled=!0}handleHighlightRender=()=>{this.rerender()};getTheme(){return this.workerManager?.getDiffRenderOptions().theme??this.options.theme??ce}getHunksRendererOptions(e){return xn(e)}createHunksRenderer(e){return new yn(this.getHunksRendererOptions(e),this.getAnnotationSlotName,this.handleHighlightRender,this.workerManager)}getLineIndex=(e,t="additions")=>this.getLineIndexForDiff(this.getDiffForLineIndex(),e,t);getDiffForLineIndex(){return this.getRenderedDiff()}getLineIndexForDiff(e,t,i){if(e==null)return;const n=e.hunks.at(-1);let s,r;e:for(const o of e.hunks){const a=i==="deletions"?o.deletionStart:o.additionStart,l=i==="deletions"?o.deletionCount:o.additionCount;let h=Ee(a,l)+1,d=o.splitLineStart,u=o.unifiedLineStart;if(t<h){const c=h-t;s=Math.max(u-c,0),r=Math.max(d-c,0);break e}if(t>=h+l){if(o===n){const c=t-(h+l);s=u+o.unifiedLineCount+c,r=d+o.splitLineCount+c;break e}continue}for(const c of o.hunkContent)if(c.type==="context")if(t<h+c.lines){const f=t-h;r=d+f,s=u+f;break e}else h+=c.lines,d+=c.lines,u+=c.lines;else{const f=i==="deletions"?c.deletions:c.additions;if(t<h+f){const p=t-h;s=u+(i==="additions"?c.deletions:0)+p,r=d+p;break e}else h+=f,d+=Math.max(c.deletions,c.additions),u+=c.deletions+c.additions}break e}if(!(s==null||r==null))return[s,r]}setOptions(e){e!=null&&(this.options=e,this.clearReusableHeader(),this.hunksRenderer.setOptions(this.getHunksRendererOptions(e)),this.syncInteractionOptions())}syncInteractionOptions(){this.interactionManager.setOptions(at(this.options,typeof this.options.hunkSeparators=="function"||(this.options.hunkSeparators??"line-info")==="line-info"||this.options.hunkSeparators==="line-info-basic"?this.handleExpandHunk:void 0,this.getLineIndex))}mergeOptions(e){this.options={...this.options,...e}}setThemeType(e){(this.options.themeType??"system")!==e&&(this.mergeOptions({themeType:e}),this.applyCachedThemeState(e))}applyCachedThemeState(e){if(typeof this.options.theme=="string"||this.fileContainer==null||this.appliedThemeCSS==null)return!1;const t=this.appliedThemeCSS.baseThemeType??e;return this.appliedThemeCSS.themeType===t?!1:(this.applyThemeState(this.fileContainer,this.appliedThemeCSS.themeStyles,e,this.appliedThemeCSS.baseThemeType),!0)}hasThemeChanged(){return this.appliedThemeCSS!=null&&!Li(this.appliedThemeCSS.theme,this.getTheme())}getHoveredLine=()=>this.interactionManager.getHoveredLine();getAnnotationSlotName=e=>Jt(this.editSession?.annotations,e,Ce);getLatestAnnotations(){return this.editSession?.annotations?.current??this.lineAnnotations}isNewAnnotations(e){const t=this.editSession?.annotations;return e===this.lineAnnotations?!1:t==null||e!==t.provided&&e!==t.current}setLineAnnotations(e){const t=this.editSession?.annotations;if(t==null){this.lineAnnotations=e;return}this.isNewAnnotations(e)&&(this.lineAnnotations=e,Qt(t,e,Ce))}syncEditSessionAnnotationsFromEditor(e){const t=this.editSession?.annotations;return t==null||e===t.current?!1:(t.current=e,this.hunksRenderer.setLineAnnotations(e),this.renderAnnotations(),!0)}canPartiallyRender(e,t,i){return!(e||t||i||typeof this.options.hunkSeparators=="function")}setSelectedLines(e,t){this.lineStateRefreshPending?this.deferredSelectedLines=[e,t]:this.interactionManager.setSelection(e,t)}setEditorActiveLine(e,t){this.lineStateRefreshPending?this.deferredEditorActiveLine=[e,t]:this.interactionManager.setEditorActiveLine(e,{lineNumberOnly:t?.lineNumberOnly,side:t?.side??"additions"})}flushDeferredLineState(){const{deferredEditorActiveLine:e,deferredSelectedLines:t}=this;this.lineStateRefreshPending=!1,this.deferredEditorActiveLine=void 0,this.deferredSelectedLines=void 0,e!=null&&this.setEditorActiveLine(...e),t!=null&&this.interactionManager.setSelection(...t)}flushManagers(){if(!this.managersDirty||this.pre==null){this.managersDirty=!1;return}const{diffStyle:e="split",overflow:t="scroll"}=this.options;this.interactionManager.setup(this.pre),this.resizeManager.setup(this.pre,{disableAnnotations:t==="wrap",columnVariables:this.shouldApplyColumnVariables(t)?"apply":"measure"}),t==="scroll"&&e==="split"?this.scrollSyncManager.setup(this.pre,this.codeDeletions,this.codeAdditions):this.scrollSyncManager.cleanUp(),this.managersDirty=!1}shouldApplyColumnVariables(e){return typeof this.options.hunkSeparators=="function"?!0:e==="scroll"&&(this.getLatestAnnotations().length>0||this.pre?.hasAttribute("data-has-merge-conflict")===!0)}getCodeScrollLeft(){return Math.max(this.codeUnified?.scrollLeft??0,this.codeDeletions?.scrollLeft??0,this.codeAdditions?.scrollLeft??0)}setCodeScrollLeft(e){this.codeUnified!=null&&(this.codeUnified.scrollLeft=e),this.codeAdditions!=null&&(this.codeAdditions.scrollLeft=e),this.codeDeletions!=null&&(this.codeDeletions.scrollLeft=e)}__getEffectiveCodeOptions(){return{...this.options,...this.hunksRenderer.getEffectiveCodeOptions()}}cleanUp(e=!1){const{editor:t}=this;ei(this.handleEditSessionRender),this.emitPostRender(!0),t?.cleanUp(e?"recycle":"discard"),e||(this.editor=void 0),this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.managersDirty=!1,this.workerManager?.unsubscribeToThemeChanges(this),this.renderRange=void 0,e||(this.pendingFiles=void 0),this.isContainerManaged||this.fileContainer?.remove(),this.fileContainer=void 0,this.mounted=!1,e||(this.lineAnnotations=[]),this.clearAuxiliaryNodes(),this.annotationCache.clear(),this.pre=void 0,this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0,this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.appliedPreAttributes=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.placeHolder?.remove(),this.placeHolder=void 0,this.headerCache.lastRenderedHTML=void 0,e||this.clearReusableHeader(),this.errorWrapper?.remove(),this.errorWrapper=void 0,this.spriteSVG=void 0,this.lastRowCount=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,e?this.hunksRenderer.recycle():(this.hunksRenderer.cleanUp(),this.workerManager=void 0,this.fileDiff=void 0,this.editSession=void 0,this.renderedDiff=void 0,this.deletionFile=void 0,this.additionFile=void 0),this.refreshViewTimeout!=null&&(clearTimeout(this.refreshViewTimeout),this.refreshViewTimeout=void 0),this.lineStateRefreshPending=!1,this.deferredEditorActiveLine=void 0,this.deferredSelectedLines=void 0,this.enabled=!1}virtualizedSetup(){this.enabled=!0,this.workerManager?.subscribeToThemeChanges(this)}hydrate({fileContainer:e,prerenderedHTML:t,preventEmit:i=!1,lineAnnotations:n,fileDiff:s,...r}){if(!this.enabled)throw new Error("FileDiff.hydrate: attempting to call hydrate after cleaned up");if(this.fileContainer!=null)throw new Error("FileDiff.hydrate: hydrate can only be called before the instance has rendered or hydrated");const o=nt(r,"FileDiff.hydrate"),a=o?.oldFile,l=o?.newFile;this.hydrateElements(e,t);const h=this.editor!=null;h||zn(this.pre,In({fileDiff:s,oldFile:a,newFile:l}),this.options.collapsed)||Nn(this.headerElement,Pn({fileDiff:s,oldFile:a,newFile:l}),this.options.disableFileHeader)?this.render({...r,fileContainer:e,lineAnnotations:n,fileDiff:s,forceRender:h||r.forceRender,preventEmit:!0}):this.hydrationSetup({fileDiff:s,lineAnnotations:n,...o}),i||this.emitPostRender()}hydrateElements(e,t){this.fileContainer!==e&&this.emitPostRender(!0),ti(e,t);for(const i of e.shadowRoot?.children??[]){if(i instanceof SVGElement){this.spriteSVG=i;continue}if(i instanceof HTMLElement){if(i instanceof HTMLPreElement){this.pre=i;for(const n of i.children)!(n instanceof HTMLElement)||n.tagName.toLowerCase()!=="code"||("deletions"in n.dataset&&(this.codeDeletions=n),"additions"in n.dataset&&(this.codeAdditions=n),"unified"in n.dataset&&(this.codeUnified=n));continue}if("diffsHeader"in i.dataset){this.headerElement=i;continue}if(i instanceof HTMLStyleElement&&i.hasAttribute("data-theme-css")){this.themeCSSStyle=i;continue}if(i instanceof HTMLStyleElement&&i.hasAttribute("data-unsafe-css")){this.unsafeCSSStyle=i,this.appliedUnsafeCSS=i.textContent;continue}}}this.pre!=null&&(this.syncCodeNodesFromPre(this.pre),this.pre.removeAttribute("data-dehydrated")),this.fileContainer=e,this.hydrateMeasuredScrollbar()}hydrationSetup({fileDiff:e,oldFile:t,newFile:i,lineAnnotations:n}){this.lineAnnotations=n??this.lineAnnotations,this.additionFile=i,this.deletionFile=t,this.fileDiff=e??(t!==void 0&&i!==void 0?se(t,i,this.options.parseDiffOptions):void 0),this.pre!=null&&(this.syncInteractionOptions(),this.hunksRenderer.hydrate(this.fileDiff),this.renderedDiff=this.fileDiff,this.renderAnnotations(),this.renderGutterUtility(),this.injectUnsafeCSS(),this.managersDirty=!0,this.flushManagers())}rerender(){!this.enabled||this.fileDiff==null&&this.additionFile==null&&this.deletionFile==null||this.render({forceRender:!0,renderRange:this.renderRange})}onThemeChange(){this.hunksRenderer.clearRenderCache(),this.rerender()}handleExpandHunk=(e,t,i)=>{this.expandHunk(e,t,i)};expandHunk=(e,t,i)=>{this.loadFilesIfNecessary(),this.hunksRenderer.expandHunk(e,t,i),this.rerender()};loadFilesIfNecessary(){const{fileDiff:e,options:{loadDiffFiles:t}}=this;if(e==null||!qe(e)||this.pendingFiles?.fileDiff===e)return;if(t==null)throw new Error("FileDiff: loadDiffFiles is required to load full files for a partial diff");const i=this.loadFilesForDiff(e,t),n=this.pendingFiles={fileDiff:e,promise:i},s=()=>{this.pendingFiles===n&&(this.pendingFiles=void 0)};n.promise=i.finally(s)}__canAttachEditor(){return this.fileDiff!=null&&!this.fileDiff.isPartial}async prepareForEditing(){if(this.__canAttachEditor())return;const e=this.__prepareForEditing();if(e==null)throw this.fileDiff?.isPartial===!0&&!qe(this.fileDiff)?new Error("FileDiff.prepareForEditing: this partial diff cannot be hydrated; provide a complete diff"):new Error("FileDiff.prepareForEditing: a partial diff requires loadDiffFiles");if(await e,!this.__canAttachEditor())throw new Error("FileDiff.prepareForEditing: the diff did not finish loading")}__prepareForEditing(){if(!this.__canAttachEditor()){if(this.fileDiff?.isPartial===!0&&!qe(this.fileDiff))throw new Error("FileDiff: this partial diff cannot be hydrated; provide a complete diff to edit");return this.loadFilesIfNecessary(),this.pendingFiles?.promise}}async loadFilesForDiff(e,t){try{const i=await t(e);if(this.fileDiff!==e)return;await this.handleFilesLoaded(e,i)}catch(i){if(this.options.disableErrorHandling===!0)throw i;console.error(i)}}async handleFilesLoaded(e,t){if(!(this.fileDiff!==e||!e.isPartial)){if(Je("merge",e,t),this.setHydratedState(t),this.installHydratedSessionDiff(e)){this.rerender();return}await it(()=>this.primeHighlightCache(e)),!(!this.enabled||this.fileDiff!==e)&&this.rerender()}}installHydratedSessionDiff(e){if(e.isPartial)throw new Error("FileDiff.installHydratedSessionDiff: diffs cannot be partial for editing");return this.fileDiff!==e?!1:this.editSession?.outgoingDiff!=null?(this.installEditSession(e),!0):!1}updateExternalDiff(e,t){if(D(this.fileDiff,e))return!1;const i=this.editSession?.outgoingDiff??this.editSession?.diff;return this.fileDiff=e,i!=null&&(e.isPartial?this.loadFilesIfNecessary():this.installEditSession(e),this.editSession!=null&&(this.editSession.outgoingDiff=i)),this.editSession?.annotations!=null&&t!=null&&(this.lineAnnotations=t,this.editSession.annotations=lt(t,Ce,this.editSession.annotations)),!0}installEditSession(e,t,i){const n=e.additionLines.join(""),s=t!=null?ze(t.contents):void 0,r=i!=null&&Tn(i,e);if(i!=null&&!r)throw new Error("FileDiff: retained session cannot resume against a different old file");if(t!=null&&t.contents!==n&&!r)throw new Error("FileDiff: retained edits are missing their diff session state");const o=t==null||t.name===e.name&&t.lang===e.lang&&t.contents===n,a=An(e);t!=null&&s!=null&&!o&&(a.name=t.name,a.lang=t.lang),r&&i!=null&&s!=null&&(a.additionLines=s,a.type=i.type,a.hunks=i.hunks,a.editSessionDirty=!0,Ue(a)),this.editSession={diff:a,annotations:this.editSession?.annotations??lt(this.lineAnnotations,Ce),outgoingDiff:this.editSession?.outgoingDiff},this.hunksRenderer.beginEditSession(a,o&&!r?e:void 0)}setHydratedState(e){this.deletionFile=e.oldFile,this.additionFile=e.newFile,this.workerManager?.cleanUpTasks(this.hunksRenderer),this.hunksRenderer.clearRenderCache()}render({fileDiff:e,deferManagers:t=!1,forceRender:i=!1,preventEmit:n=!1,lineAnnotations:s,fileContainer:r,containerWrapper:o,renderRange:a,...l}){if(!this.enabled)throw new Error("FileDiff.render: attempting to call render after cleaned up");const h=nt(l,"FileDiff.render"),d=h?.oldFile,u=h?.newFile;this.editor?.__postponeBgTokenizeToNextFrame();const{collapsed:c=!1,themeType:f="system",expandUnchanged:p=!1}=this.options,g=c?void 0:a,S=this.hasThemeChanged(),C=h!=null,y=C&&(!Ht(d,this.deletionFile)||!Ht(u,this.additionFile));let v=e!=null&&!D(e,this.fileDiff);const R=s!=null&&(s.length>0||this.getLatestAnnotations().length>0)?this.isNewAnnotations(s):!1;if(!c&&Dt(g,this.renderRange)&&!i&&!R&&!S&&(e!=null&&!v||e==null&&!y)){const k=this.applyCachedThemeState(f);return k&&this.finalizeRender(),k}let m;e==null&&C&&(y||this.fileDiff==null)&&(m=se(h.oldFile,h.newFile,this.options.parseDiffOptions));const{renderRange:b}=this;this.renderRange=g,C?(this.deletionFile=d,this.additionFile=u):e!=null&&(this.deletionFile=void 0,this.additionFile=void 0),e!=null&&v?this.updateExternalDiff(e,s):m!=null&&(v=!0,this.updateExternalDiff(m,s)),v&&this.clearReusableHeader(),s!=null&&this.setLineAnnotations(s);const L=this.getLatestDiff();if(L==null)return!1;L.editSessionDirty===!0&&this.shouldSelfHealEditSession()&&(St(L,this.options.parseDiffOptions),this.hunksRenderer.refreshHighlightedResult()),p&&this.loadFilesIfNecessary(),this.hunksRenderer.setOptions(this.getHunksRendererOptions(this.options)),this.syncInteractionOptions(),this.hunksRenderer.setLineAnnotations(this.getLatestAnnotations());const{disableErrorHandling:F=!1,disableFileHeader:ae=!1}=this.options;if(ae&&(this.headerElement!=null&&(this.headerElement.remove(),this.headerElement=void 0,this.headerCache.lastRenderedHTML=void 0),this.clearHeaderSlots()),r=this.getOrCreateFileContainer(r,o),this.applyCachedThemeState(f),c){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{const k=this.hunksRenderer.renderDiff(L,Ti);k!=null&&this.applyThemeState(r,k.themeStyles,f,k.baseThemeType),k?.headerElement!=null&&this.applyHeaderToDOM(k.headerElement,r,k.fileDiff),this.renderSeparators([]),this.renderedDiff=k?.fileDiff??L,this.injectUnsafeCSS()}catch(k){if(F)throw k;console.error(k),k instanceof Error&&this.applyErrorToDOM(k,r)}return this.finalizeRender(),n||this.emitPostRender(),!0}try{const k=this.getOrCreatePreNode(r);if(!(this.canPartiallyRender(i,R,y||v||S||!D(this.renderedDiff,L))&&this.applyPartialRender({fileDiff:L,previousRenderRange:b,renderRange:g}))){const M=this.hunksRenderer.renderDiff(L,g);if(M==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.isWorkingPool()&&this.workerManager.initialize().catch(()=>{}).then(()=>this.rerender()),!1;this.applyThemeState(r,M.themeStyles,f,M.baseThemeType),M.headerElement!=null&&this.applyHeaderToDOM(M.headerElement,r,M.fileDiff),M.additionsContentAST!=null||M.deletionsContentAST!=null||M.unifiedContentAST!=null?this.applyHunksToDOM(k,M):this.pre!=null&&(this.pre.remove(),this.pre=void 0),this.renderSeparators(M.hunkData),this.renderedDiff=M.fileDiff}this.applyBuffers(k,g),this.injectUnsafeCSS(),this.renderAnnotations(),this.renderGutterUtility(),this.managersDirty=!0,t||this.flushManagers(),this.finalizeRender(),this.editor!=null&&this.syncRenderViewToEditor()}catch(k){if(F)throw k;console.error(k),k instanceof Error&&this.applyErrorToDOM(k,r)}return n||this.emitPostRender(),!0}finalizeRender(){}emitPostRender(e=!1){const{fileContainer:t,options:{onPostRender:i}}=this;if(e){if(!this.mounted||(this.mounted=!1,t==null))return;this.options.onPostRender?.(t,this,"unmount");return}if(t==null)return;const n=this.mounted?"update":"mount";this.mounted=!0,i?.(t,this,n)}getLatestDiff(e=this.fileDiff){return this.editSession?.diff??e}getRenderedDiff(){return this.renderedDiff}syncRenderViewToEditor(){const{editor:e,fileContainer:t}=this,i=this.getLatestAnnotations(),n=this.computeEditorRenderRange(this.renderRange),s=this.getLatestDiff();if(e==null||t==null||s==null||s.isPartial)return;const r=h=>{if(!this.enabled||this.editor!==e||this.fileContainer!==t||this.getLatestDiff()!==s)return;const d=this.editSession?.outgoingDiff,{fileDiff:u}=this,c=d!=null&&u!=null&&d!==s,f=c&&d!=null&&u!=null?Et(d,u):!1;e.__syncRenderView({highlighter:h,fileContainer:t,fileDiff:s,lineAnnotations:i,renderRange:n,externalDocument:c,resetHistory:f})},o=this.getTheme(),a=s.lang??ve(s.name),l=Ye({theme:o,lang:a});l!=null?r(l):bt({themes:vi(o),langs:["text",a],preferredHighlighter:this.workerManager?.getPreferredHighlighter()??this.options.preferredHighlighter}).then(r)}computeEditorRenderRange(e){const t=this.getLatestDiff();if(e==null||t==null||Xe(e))return e;const{diffStyle:i="split",expandUnchanged:n=!1,collapsedContextThreshold:s=1}=this.options;let r,o;return pe({diff:t,diffStyle:i,startingLine:e.startingLine,totalLines:e.totalLines,expandedHunks:n?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:s,callback:({additionLine:a})=>{a!=null&&(r??=a.lineNumber,o=a.lineNumber)}}),r==null||o==null?{...e,startingLine:0,totalLines:0}:{...e,startingLine:r-1,totalLines:o-r+1}}__acknowledgeDocumentUpdate(){this.editSession!=null&&(this.editSession.outgoingDiff=void 0)}__acceptEditorChange(e){const{lineAnnotations:t}=e;t!=null&&this.syncEditSessionAnnotationsFromEditor(t)}emitEditChange(e){const{onEditChange:t}=this.options;t?.(e)}__captureDocumentSessionState(e=!0){let{fileDiff:t,editSession:{diff:i,outgoingDiff:n}={}}=this;if(n!=null&&t!=null){if(!t.isPartial&&Et(n,t))return;i=n}if(!(i==null||i.isPartial))return{diffSession:{oldFile:i.type!=="new"?{name:i.prevName??i.name,lines:e?[...i.deletionLines]:i.deletionLines}:null,type:i.type,hunks:e?Pt(i.hunks):i.hunks},hasChanges:i.editSessionDirty===!0}}__attachEditor(e){if(this.type!=="file-diff")throw new Error(`FileDiff.__attachEditor: cannot attach an editor to a "${this.type}" diff`);if(this.editor!=null)throw new Error("FileDiff.__attachEditor: an editor is already attached");if(!this.__canAttachEditor())throw new Error("FileDiff.__attachEditor: a complete diff is required before editing");const t=()=>{this.editor=void 0,this.finishEditSession()};try{return this.resumeEditorRendering(e),t}catch(i){throw t(),i}}__resumeEditor(e){if(this.editor!==e)throw new Error("FileDiff.__resumeEditor: editor association changed");this.resumeEditorRendering(e)}resumeEditorRendering(e){const{fileDiff:t}=this,i=this.editSession?.outgoingDiff;i!=null&&t!=null&&!t.isPartial&&this.editSession?.diff===i&&this.installEditSession(t);const n=this.editSession==null&&t!=null&&!t.isPartial?t:void 0;n!=null?this.installEditSession(n,e.__getDocumentContents(Fn(n)),e.__getDocumentSessionState()):this.editSession!=null&&this.hunksRenderer.beginEditSession(this.editSession.diff),this.editor=e,this.fileDiff?.isPartial===!0&&this.loadFilesIfNecessary();const s=this.editSession?.diff;this.hunksRenderer.editorRenderReady()?(s!=null&&this.hunksRenderer.diffCache===s&&(this.renderedDiff=s),this.syncRenderViewToEditor()):this.rerender()}finishEditSession(){this.hunksRenderer.endEditSession(),this.finalizeEditSessionHunks()}__completeEditSession(e,t){this.settleEditSession(t==="install",e)}settleEditSession(e,t){const{editSession:i,fileDiff:n,lineAnnotations:s}=this;if(i==null||n==null)return;const{diff:r,annotations:o}=i;if(this.editor!=null)throw new Error("FileDiff.__completeEditSession: detach the editor before completing the session");this.hunksRenderer.endEditSession(),this.finalizeEditSessionHunks();const a=o?.current;let l,h=null,d=null,u=!1,c;if(t==null)throw new Error("FileDiff.__completeEditSession: editor is required for completion");const f=zt(r),p={name:f.name,contents:f.additionLines.join("")};f.lang!=null&&(p.lang=f.lang);const g={fileDiff:f,editor:t,originalFileDiff:n,oldFile:f.type==="new"?null:{name:f.prevName??f.name,contents:f.deletionLines.join("")},newFile:p,lineAnnotations:a,originalLineAnnotations:s};Object.freeze(g);try{if(t.__emitEditComplete(g),this.options.onEditComplete?.(g)==="accept"){if(f.cacheKey!=null&&f.cacheKey===n.cacheKey)throw new Error("FileDiff.__completeEditSession: an accepted diff must not reuse the replaced diff cacheKey");l=f,h=g.oldFile,d=g.newFile}}catch(S){u=!0,c=S}if(e&&l!=null&&(this.fileDiff=l,this.additionFile!=null&&(this.deletionFile=h,this.additionFile=d),a!=null&&(this.lineAnnotations=a)),this.editSession=void 0,e&&this.fileContainer!=null&&this.rerender(),u)throw c}finalizeEditSessionHunks(){const e=this.getLatestDiff();if(e==null||e.editSessionDirty!==!0)return!1;const{collapsedContextThreshold:t=1}=this.options,i=on(e,this.hunksRenderer.getExpandedHunksMap(),t);return St(e,this.options.parseDiffOptions),this.hunksRenderer.setExpandedHunksMap(an(e,i)),this.hunksRenderer.refreshHighlightedResult(),this.escalateEditSessionRender(),!0}applyDocumentChange(e,t){const i=this.editSession?.diff;if(i==null)throw new Error("FileDiff.applyDocumentChange: requires an active edit session");this.detachAdditionLines(),this.hunksRenderer.beginEditSession(i),this.hunksRenderer.applyDocumentChange(e),t!=null&&this.syncEditSessionAnnotationsFromEditor(t),this.rerender(),this.interactionManager.setSelectionDirty()}applySuspendedDocumentChange(e,t){this.applyDocumentChange(e,t),this.hunksRenderer.clearRenderCache()}updateRenderCache(e,t,i={}){const n=this.editSession?.diff;if(n==null)throw new Error("FileDiff.updateRenderCache: requires an active edit session");this.detachAdditionLines(),this.hunksRenderer.beginEditSession(n);const{shouldRefreshDiffsView:s,lineCountChangeInFlight:r}=i;if(this.hunksRenderer.updateRenderCache(e,t,r)){this.refreshViewTimeout!=null&&(clearTimeout(this.refreshViewTimeout),this.refreshViewTimeout=void 0),this.lineStateRefreshPending=!0,this.escalateEditSessionRender();return}s===!0&&(this.refreshViewTimeout!=null&&clearTimeout(this.refreshViewTimeout),this.lineStateRefreshPending=!0,this.refreshViewTimeout=setTimeout(()=>{this.refreshViewTimeout=void 0,this.options.diffStyle==="split"?this.refreshSplitDiffView():this.refreshUnifiedDiffView(),this.flushDeferredLineState()},150))}detachAdditionLines(){const e=this.editSession?.diff,{fileDiff:t}=this;e!=null&&(e.additionLines===t?.additionLines||e.additionLines===e.deletionLines)&&(e.additionLines=[...e.additionLines])}isLineRenderable(e){const t=this.getRenderedDiff();if(t==null)return!0;const{expandUnchanged:i=!1,collapsedContextThreshold:n=1}=this.options;return Ft({fileDiff:t,lineNumber:e,expandedHunks:i?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:n})}getNearestRenderableLine(e,t){const i=this.getRenderedDiff();if(i==null)return e;const{expandUnchanged:n=!1,collapsedContextThreshold:s=1}=this.options;return Hi({fileDiff:i,lineNumber:e,direction:t,expandedHunks:n?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:s})}revealLine(e){const t=this.getRenderedDiff(),{expandUnchanged:i=!1,collapsedContextThreshold:n=1,expansionLineCount:s=100}=this.options;if(t==null||t.isPartial||i)return!1;const r=this.hunksRenderer.getExpandedHunksMap();for(const[h,d]of t.hunks.entries()){const[u,c]=ct(d);if(e<u){const f=Re({isPartial:t.isPartial,rangeSize:d.collapsedBefore,expandedHunks:r,hunkIndex:h,collapsedContextThreshold:n}),p=u-f.rangeSize;if(f.renderAll||e<p+f.fromStart||e>=u-f.fromEnd)return!1;const g=e-(p+f.fromStart)+1,S=u-f.fromEnd-e;return g<=S?this.expandHunk(h,"up",g+s):this.expandHunk(h,"down",S+s),!0}if(e<c)return!1}const o=ke({fileDiff:t,hunkIndex:t.hunks.length-1,expandedHunks:r,collapsedContextThreshold:n,errorPrefix:"FileDiff.revealLine"});if(o==null||o.renderAll)return!1;const a=t.hunks[t.hunks.length-1],[,l]=ct(a);return e<l+o.fromStart||e>=l+o.rangeSize?!1:(this.expandHunk(t.hunks.length,"up",e-(l+o.fromStart)+1+s),!0)}shouldSelfHealEditSession(){return this.editor==null}escalateEditSessionRender(){ii(this.handleEditSessionRender)}handleEditSessionRender=()=>{this.rerender(),this.flushDeferredLineState()};removeRenderedCode(){this.resizeManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0,this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0}clearAuxiliaryNodes(){for(const{element:e}of this.separatorCache.values())e.remove();this.separatorCache.clear();for(const{element:e}of this.annotationCache.values())e.remove();this.annotationCache.clear(),this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0}renderPlaceholder(e){if(this.fileContainer==null)return!1;if(this.emitPostRender(!0),this.cleanChildNodes(),this.placeHolder==null){const t=this.fileContainer.shadowRoot??this.fileContainer.attachShadow({mode:"open"});this.placeHolder=document.createElement("div"),this.placeHolder.dataset.placeholder="",t.appendChild(this.placeHolder)}return this.setPlaceholderHeight(e)}setPlaceholderHeight(e){return this.placeHolder==null?!1:(this.placeHolder.style.setProperty("height",`${e}px`),!0)}async primeHighlightCache(e=this.fileDiff){const{workerManager:t}=this;if(e==null||t==null||!t.isWorkingPool()||e.cacheKey==null||ye(e))return;const i=this.options.tokenizeMaxLength??1e5;Math.max(e.additionLines.length,e.deletionLines.length)>i||await t.primeDiffHighlightCache(e).catch(n=>{console.error(n)})}cleanChildNodes(){this.resizeManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.interactionManager.cleanUp(),this.clearAuxiliaryNodes(),this.bufferAfter?.remove(),this.bufferBefore?.remove(),this.codeAdditions?.remove(),this.codeDeletions?.remove(),this.codeUnified?.remove(),this.errorWrapper?.remove(),this.headerElement?.remove(),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.pre?.remove(),this.spriteSVG?.remove(),this.themeCSSStyle?.remove(),this.unsafeCSSStyle?.remove(),this.bufferAfter=void 0,this.bufferBefore=void 0,this.codeAdditions=void 0,this.codeDeletions=void 0,this.codeUnified=void 0,this.errorWrapper=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.pre=void 0,this.spriteSVG=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,this.headerCache.lastRenderedHTML=void 0,this.lastRowCount=void 0,this.mounted=!1}renderSeparators(e){const{hunkSeparators:t}=this.options;if(this.isContainerManaged||this.fileContainer==null||typeof t!="function"){for(const{element:n}of this.separatorCache.values())n.remove();this.separatorCache.clear();return}const i=new Map(this.separatorCache);for(const n of e){const s=n.slotName;let r=this.separatorCache.get(s);if(r==null||!wn(n,r.hunkData)){r?.element.remove();const o=document.createElement("div");o.style.display="contents",o.slot=n.slotName;const a=t(n,this);a!=null&&o.appendChild(a),this.fileContainer.appendChild(o),r={element:o,hunkData:n},this.separatorCache.set(s,r)}i.delete(s)}for(const[n,{element:s}]of i.entries())this.separatorCache.delete(n),s.remove()}renderAnnotations(){if(this.isContainerManaged||this.fileContainer==null){for(const{element:n}of this.annotationCache.values())n.remove();this.annotationCache.clear();return}const e=new Map(this.annotationCache),{renderAnnotation:t}=this.options,i=this.getLatestAnnotations();if(t!=null&&i.length>0)for(const[n,s]of i.entries()){const r=this.getAnnotationSlotName(s),o=`${n}-${r}`;let a=this.annotationCache.get(o);if(a==null||!Hn(s,a.annotation)){a?.element.remove();const l=t(s);if(l==null)continue;a={element:ni(r),annotation:s},a.element.appendChild(l),this.fileContainer.appendChild(a.element),this.annotationCache.set(o,a)}e.delete(o)}for(const[n,{element:s}]of e.entries())this.annotationCache.delete(n),s.remove()}renderGutterUtility(){const{renderGutterUtility:e}=this.options;if(this.fileContainer==null||e==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}const t=e(this.interactionManager.getHoveredLine);if(t!=null&&this.gutterUtilityContent!=null)return;if(t==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}const i=si();i.appendChild(t),this.fileContainer.appendChild(i),this.gutterUtilityContent=i}getOrCreateFileContainer(e,t){const{fileContainer:i}=this,n=e??i??document.createElement("diffs-container"),s=i!==n;return i!=null&&s&&this.editor?.__captureFocusForDOMReplacement(),s&&this.emitPostRender(!0),this.fileContainer=n,i!=null&&s&&(this.headerCache.lastRenderedHTML=void 0,this.headerElement=void 0),t!=null&&this.fileContainer.parentNode!==t&&t.appendChild(this.fileContainer),s&&this.adoptReusableShellElements(this.fileContainer),this.ensureSpriteSVG(this.fileContainer),this.fileContainer}adoptReusableShellElements(e){const{shadowRoot:t}=e;if(t!=null)for(const i of t.children)i instanceof SVGElement?this.spriteSVG??=i:dt(i)&&i.hasAttribute("data-theme-css")?(this.themeCSSStyle??=i,this.hasAdoptedThemeCSS=!0):dt(i)&&i.hasAttribute("data-unsafe-css")&&(this.unsafeCSSStyle??=i,this.appliedUnsafeCSS??=this.options.unsafeCSS??void 0)}ensureSpriteSVG(e){const t=e.shadowRoot??e.attachShadow({mode:"open"});if(this.spriteSVG==null){const i=document.createElement("div");i.innerHTML=ri;const n=i.firstChild;n instanceof SVGElement&&(this.spriteSVG=n)}this.spriteSVG!=null&&this.spriteSVG.parentNode!==t&&t.appendChild(this.spriteSVG)}getOrCreatePreNode(e){const t=e.shadowRoot??e.attachShadow({mode:"open"});return this.pre==null?(this.pre=document.createElement("pre"),this.appliedPreAttributes=void 0,this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0,t.appendChild(this.pre)):this.pre.parentNode!==t&&(this.editor?.__captureFocusForDOMReplacement(),t.appendChild(this.pre),this.appliedPreAttributes=void 0),this.placeHolder?.remove(),this.placeHolder=void 0,this.pre}syncCodeNodesFromPre(e){this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0;for(const t of Array.from(e.children))t instanceof HTMLElement&&(t.hasAttribute("data-unified")?this.codeUnified=t:t.hasAttribute("data-deletions")?this.codeDeletions=t:t.hasAttribute("data-additions")&&(this.codeAdditions=t))}applyHeaderToDOM(e,t,i){this.cleanupErrorWrapper(),this.placeHolder?.remove(),this.placeHolder=void 0;const{headerCache:{fileDiff:n,html:s,lastRenderedHTML:r}}=this,o=(i!==this.editSession?.diff&&D(n,i)?s:void 0)??ne(e);if(this.headerCache.html=o,this.headerCache.fileDiff=i,o!==r){const p=document.createElement("div");p.innerHTML=o;const g=p.firstElementChild;if(!(g instanceof HTMLElement))return;this.headerElement!=null?t.shadowRoot?.replaceChild(g,this.headerElement):t.shadowRoot?.prepend(g),this.headerElement=g,this.headerCache.lastRenderedHTML=o}if(this.isContainerManaged)return;const{renderCustomHeader:a,renderHeaderPrefix:l,renderHeaderFilenameSuffix:h,renderHeaderMetadata:d}=this.options;if(a!=null){const p=a(i)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,bi,p),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0;return}const u=l?.(i)??void 0,c=h?.(i)??void 0,f=d?.(i)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,Mi,u),this.headerFilenameSuffix=this.upsertHeaderSlotElement(t,this.headerFilenameSuffix,Fi,c),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,Ii,f),this.headerCustom?.remove(),this.headerCustom=void 0}clearReusableHeader(){this.headerCache.html=void 0,this.headerCache.fileDiff=void 0}clearHeaderSlots(){this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0}upsertHeaderSlotElement(e,t,i,n){if(n==null){t?.remove();return}const s=t??this.createHeaderSlotElement(i);return t==null&&e.appendChild(s),this.replaceHeaderSlotContent(s,n),s}replaceHeaderSlotContent(e,t){e.replaceChildren(),t instanceof Element?e.appendChild(t):e.innerText=`${t}`}createHeaderSlotElement(e){const t=document.createElement("div");return t.slot=e,t}injectUnsafeCSS(){const{unsafeCSS:e}=this.options,t=this.fileContainer?.shadowRoot;if(t!=null){if(e==null||e===""){this.unsafeCSSStyle!=null&&(this.unsafeCSSStyle.remove(),this.unsafeCSSStyle=void 0),this.appliedUnsafeCSS=void 0;return}this.unsafeCSSStyle?.parentNode===t&&this.appliedUnsafeCSS===e||(this.unsafeCSSStyle??=oi(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=ai(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,i,n){const s=e.shadowRoot??e.attachShadow({mode:"open"}),r=n??i,o=this.getTheme(),a=typeof o=="string"?o:{...o},l=ht(s);if(this.themeCSSStyle?.parentNode===s&&this.appliedThemeCSS?.themeStyles===t&&this.appliedThemeCSS.themeType===r&&this.appliedThemeCSS.scrollbarGutter===l){this.appliedThemeCSS.theme=a;return}if(this.hasAdoptedThemeCSS&&this.themeCSSStyle?.parentNode===s){this.hasAdoptedThemeCSS=!1,this.appliedThemeCSS={theme:a,themeStyles:t,themeType:r,baseThemeType:n,scrollbarGutter:l};return}this.themeCSSStyle=li({shadowRoot:s,currentNode:this.themeCSSStyle,themeCSS:ci(t,r,l)}),this.appliedThemeCSS=this.themeCSSStyle!=null?{theme:a,themeStyles:t,themeType:r,baseThemeType:n,scrollbarGutter:l}:void 0}hydrateMeasuredScrollbar(){const e=this.fileContainer?.shadowRoot;e==null||this.themeCSSStyle==null||(this.themeCSSStyle.textContent=di(this.themeCSSStyle.textContent??"",ht(e)))}shouldGuardRebuildScroll(){return this.editor!=null&&hi()}applyHunksToDOM(e,t){this.shouldGuardRebuildScroll()?ut(e,()=>this.replaceCodeColumns(e,t)):this.replaceCodeColumns(e,t)}applyCodeColumnsInPlace(e,t,i){const n=this.getColumnPair(e);if(n==null)return!1;const s=J(t[0]),r=J(t[1]);return s==null||r==null?!1:(n.gutter.innerHTML=ne(s),n.content.innerHTML=ne(r),i!==this.lastRowCount&&(n.gutter.style.setProperty("grid-row",`span ${i}`),n.content.style.setProperty("grid-row",`span ${i}`)),!0)}replaceCodeColumns(e,t){const{overflow:i="scroll"}=this.options,n=(this.options.hunkSeparators??"line-info")==="line-info",s=i==="wrap"?t.rowCount:void 0;this.cleanupErrorWrapper(),this.applyPreNodeAttributes(e,t);let r=!1;const o=[],a=this.hunksRenderer.renderCodeAST("unified",t),l=this.hunksRenderer.renderCodeAST("deletions",t),h=this.hunksRenderer.renderCodeAST("additions",t);this.editor?.__captureFocusForDOMReplacement(),a!=null?(r=this.codeUnified==null||this.codeAdditions!=null||this.codeDeletions!=null,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0,this.codeUnified=_e({code:this.codeUnified,columnType:"unified",rowSpan:s,containerSize:n}),this.applyCodeColumnsInPlace(this.codeUnified,a,t.rowCount)||(this.codeUnified.innerHTML=this.hunksRenderer.renderPartialHTML(a)),o.push(this.codeUnified)):l!=null||h!=null?(l!=null?(r=this.codeDeletions==null||this.codeUnified!=null,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions=_e({code:this.codeDeletions,columnType:"deletions",rowSpan:s,containerSize:n}),this.applyCodeColumnsInPlace(this.codeDeletions,l,t.rowCount)||(this.codeDeletions.innerHTML=this.hunksRenderer.renderPartialHTML(l)),o.push(this.codeDeletions)):(this.codeDeletions?.remove(),this.codeDeletions=void 0),h!=null?(r=r||this.codeAdditions==null||this.codeUnified!=null,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeAdditions=_e({code:this.codeAdditions,columnType:"additions",rowSpan:s,containerSize:n}),this.applyCodeColumnsInPlace(this.codeAdditions,h,t.rowCount)||(this.codeAdditions.innerHTML=this.hunksRenderer.renderPartialHTML(h)),o.push(this.codeAdditions)):(this.codeAdditions?.remove(),this.codeAdditions=void 0)):(this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0),o.length===0?e.textContent="":r&&e.replaceChildren(...o),this.lastRowCount=t.rowCount}applyPartialRender({fileDiff:e,previousRenderRange:t,renderRange:i}){const{pre:n,codeUnified:s,codeAdditions:r,codeDeletions:o,options:{diffStyle:a="split"}}=this;if(n==null||t==null||i==null||!Number.isFinite(t.totalLines)||!Number.isFinite(i.totalLines)||this.lastRowCount==null)return!1;const l=this.getCodeColumns(a,s,o,r);if(l==null)return!1;const h=t.startingLine,d=i.startingLine,u=h+t.totalLines,c=d+i.totalLines,f=Math.max(h,d),p=Math.min(u,c);if(p<=f)return!1;const g=Math.max(0,f-h),S=Math.max(0,u-p),C=this.trimColumns({columns:l,trimStart:g,trimEnd:S,previousStart:h,overlapStart:f,overlapEnd:p,diffStyle:a});if(C<0)throw new Error("FileDiff.applyPartialRender: failed to trim to overlap");if(this.lastRowCount<C)throw new Error("FileDiff.applyPartialRender: trimmed beyond DOM row count");let y=this.lastRowCount-C;const v=(L,F)=>{if(!(F<=0))return this.hunksRenderer.renderDiff(e,{startingLine:L,totalLines:F,bufferBefore:0,bufferAfter:0})},R=v(d,Math.max(f-d,0));if(R==null&&d<f)return!1;const m=v(p,Math.max(c-p,0));if(m==null&&c>p)return!1;const b=(L,F)=>{if(L!=null){if(a==="unified"&&!Array.isArray(l))this.insertPartialHTML(a,l,L,F);else if(a==="split"&&Array.isArray(l))this.insertPartialHTML(a,l,L,F);else throw new Error("FileDiff.applyPartialRender.applyChunk: invalid chunk application");y+=L.rowCount,this.renderedDiff=L.fileDiff}};return this.cleanupErrorWrapper(),b(R,"afterbegin"),b(m,"beforeend"),this.lastRowCount!==y&&(this.applyRowSpan(a,l,y),this.lastRowCount=y),!0}insertPartialHTML(e,t,i,n){if(e==="unified"&&!Array.isArray(t)){const s=this.hunksRenderer.renderCodeAST("unified",i);this.renderPartialColumn(t,s,n)}else if(e==="split"&&Array.isArray(t)){const s=this.hunksRenderer.renderCodeAST("deletions",i),r=this.hunksRenderer.renderCodeAST("additions",i);this.renderPartialColumn(t[0],s,n),this.renderPartialColumn(t[1],r,n)}else throw new Error("FileDiff.insertPartialHTML: Invalid argument composition")}refreshSplitDiffView(){const e=this.getLatestDiff();if(this.options.diffStyle!=="split"||e==null)return;const t=this.hunksRenderer.renderDiff(e,this.renderRange);if(t==null)return;const i=this.getCodeColumns("split",this.codeUnified,this.codeDeletions,this.codeAdditions);if(!Array.isArray(i))return;const n=(s,r)=>{if(r==null)return;const o=this.hunksRenderer.renderCodeAST(s,t),a=J(o?.[0]),l=J(o?.[1]);for(const[h,d]of[[r.gutter,a],[r.content,l]])if(d!=null&&h.childElementCount===d.length)for(let u=0;u<d.length;u++){const c=h.children[u],f=d[u].properties["data-line-type"];f!=null&&c.dataset.lineType!==f&&(c.dataset.lineType=f)}};n("deletions",i[0]),n("additions",i[1]),this.renderedDiff=t.fileDiff}refreshUnifiedDiffView(){const e=this.getLatestDiff();if(this.options.diffStyle!=="unified"||e==null)return;const t=this.hunksRenderer.renderDiff(e,this.renderRange);if(t==null)return;const i=this.getCodeColumns("unified",this.codeUnified,this.codeDeletions,this.codeAdditions);if(i==null||Array.isArray(i))return;const n=this.hunksRenderer.renderCodeAST("unified",t),s=J(n?.[0]),r=J(n?.[1]),o=()=>{for(const[a,l]of[[i.gutter,s],[i.content,r]])l!=null&&(a.innerHTML=ne(l));t.rowCount!==this.lastRowCount&&(this.applyRowSpan("unified",i,t.rowCount),this.lastRowCount=t.rowCount),this.renderedDiff=t.fileDiff};this.shouldGuardRebuildScroll()?ut(this.pre,o):o(),this.renderSeparators(t.hunkData),this.managersDirty=!0,this.flushManagers(),this.syncRenderViewToEditor()}renderPartialColumn(e,t,i){if(e==null||t==null)return;const n=J(t[0]),s=J(t[1]);if(n==null||s==null)throw new Error("FileDiff.insertPartialHTML: Unexpected AST structure");const r=s.at(0);i==="beforeend"&&r?.type==="element"&&typeof r.properties["data-buffer-size"]=="number"&&this.mergeBuffersIfNecessary(r.properties["data-buffer-size"],e.content.children[e.content.children.length-1],e.gutter.children[e.gutter.children.length-1],n,s,!0);const o=s.at(-1);i==="afterbegin"&&o?.type==="element"&&typeof o.properties["data-buffer-size"]=="number"&&this.mergeBuffersIfNecessary(o.properties["data-buffer-size"],e.content.children[0],e.gutter.children[0],n,s,!1),e.gutter.insertAdjacentHTML(i,this.hunksRenderer.renderPartialHTML(n)),e.content.insertAdjacentHTML(i,this.hunksRenderer.renderPartialHTML(s))}mergeBuffersIfNecessary(e,t,i,n,s,r){if(!(t instanceof HTMLElement)||!(i instanceof HTMLElement))return;const o=this.getBufferSize(t.dataset);o!=null&&(r?(n.shift(),s.shift()):(n.pop(),s.pop()),this.updateBufferSize(t,o+e),this.updateBufferSize(i,o+e))}applyRowSpan(e,t,i){const n=s=>{s!=null&&(s.gutter.style.setProperty("grid-row",`span ${i}`),s.content.style.setProperty("grid-row",`span ${i}`))};if(e==="unified"&&!Array.isArray(t))n(t);else if(e==="split"&&Array.isArray(t))n(t[0]),n(t[1]);else throw new Error("dun fuuuuked up")}trimColumnRows(e,t,i){let n=0,s=0,r=0,o=!1;const a=i>=0;if(e==null)return 0;const l=Array.from(e.content.children),h=Array.from(e.gutter.children);if(l.length!==h.length)throw new Error("FileDiff.trimColumnRows: columns do not match");for(;r<l.length&&!(t<=0&&!a&&!o);){const d=h[r],u=l[r];if(r++,!(d instanceof HTMLElement)||!(u instanceof HTMLElement))throw console.error({gutterElement:d,contentElement:u}),new Error("FileDiff.trimColumnRows: invalid row elements");if(o&&(o=!1,d.dataset.gutterBuffer==="annotation"&&"lineAnnotation"in u.dataset||d.dataset.gutterBuffer==="metadata"&&"noNewline"in u.dataset)){d.remove(),u.remove(),s++;continue}if("lineIndex"in d.dataset&&"lineIndex"in u.dataset){(t>0||a&&n>=i)&&(d.remove(),u.remove(),t>0&&(t--,t===0&&(o=!0)),s++),n++;continue}if("separator"in d.dataset&&"separator"in u.dataset){(t>0||a&&n>=i)&&(d.remove(),u.remove(),s++);continue}if(d.dataset.gutterBuffer==="annotation"&&"lineAnnotation"in u.dataset){(t>0||a&&n>=i)&&(d.remove(),u.remove(),s++);continue}if(d.dataset.gutterBuffer==="metadata"&&"noNewline"in u.dataset){(t>0||a&&n>=i)&&(d.remove(),u.remove(),s++);continue}if(d.dataset.gutterBuffer==="buffer"&&"contentBuffer"in u.dataset){const c=this.getBufferSize(u.dataset);if(c==null)throw new Error("FileDiff.trimColumnRows: invalid element");if(t>0){const f=Math.min(t,c),p=c-f;p>0?(this.updateBufferSize(d,p),this.updateBufferSize(u,p),s+=f):(d.remove(),u.remove(),s+=c),t-=f,t===0&&p===0&&(o=!0)}else if(a){const f=n,p=n+c-1;if(i<=f)d.remove(),u.remove(),s+=c;else if(i<=p){const g=p-i+1,S=c-g;this.updateBufferSize(d,S),this.updateBufferSize(u,S),s+=g}}n+=c;continue}throw console.error({gutterElement:d,contentElement:u}),new Error("FileDiff.trimColumnRows: unknown row elements")}return s}trimColumns({columns:e,diffStyle:t,overlapEnd:i,overlapStart:n,previousStart:s,trimEnd:r,trimStart:o}){const a=Math.max(0,n-s),l=i-s;if(l<0)throw new Error("FileDiff.trimColumns: overlap ends before previous");const h=o>0,d=r>0;if(!h&&!d)return 0;const u=h?a:0,c=d?l:-1;if(t==="unified"&&!Array.isArray(e))return this.trimColumnRows(e,u,c);if(t==="split"&&Array.isArray(e)){const f=this.trimColumnRows(e[0],u,c),p=this.trimColumnRows(e[1],u,c);if(e[0]!=null&&e[1]!=null&&f!==p)throw new Error("FileDiff.trimColumns: split columns out of sync");return e[0]!=null?f:p}else throw console.error({diffStyle:t,columns:e}),new Error("FileDiff.trimColumns: Invalid columns for diffType")}getBufferSize(e){const t=Number.parseInt(e?.bufferSize??"",10);return Number.isNaN(t)?void 0:t}updateBufferSize(e,t){e.dataset.bufferSize=`${t}`,e.style.setProperty("grid-row",`span ${t}`),e.style.setProperty("min-height",`calc(${t} * 1lh)`)}getColumnPair(e){if(e==null)return;const t=e.children[0],i=e.children[1];if(!(!(t instanceof HTMLElement)||!(i instanceof HTMLElement)||t.dataset.gutter==null||i.dataset.content==null))return{gutter:t,content:i}}getCodeColumns(e,t,i,n){if(e==="unified")return this.getColumnPair(t);{const s=this.getColumnPair(i),r=this.getColumnPair(n);return s!=null||r!=null?[s,r]:void 0}}updateBuffers(e){this.pre!=null&&this.applyBuffers(this.pre,e)}applyBuffers(e,t){if(t==null||this.shouldDisableVirtualizationBuffers()){this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0);return}t.bufferBefore>0?(this.bufferBefore==null&&(this.bufferBefore=document.createElement("div"),this.bufferBefore.dataset.virtualizerBuffer="before",e.before(this.bufferBefore)),this.bufferBefore.style.setProperty("height",`${t.bufferBefore}px`),this.bufferBefore.style.setProperty("contain","strict")):this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),t.bufferAfter>0?(this.bufferAfter==null&&(this.bufferAfter=document.createElement("div"),this.bufferAfter.dataset.virtualizerBuffer="after",e.after(this.bufferAfter)),this.bufferAfter.style.setProperty("height",`${t.bufferAfter}px`),this.bufferAfter.style.setProperty("contain","strict")):this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0)}shouldDisableVirtualizationBuffers(){return this.options.disableVirtualizationBuffers??!1}applyPreNodeAttributes(e,{additionsContentAST:t,deletionsContentAST:i,totalLines:n},s){const{diffIndicators:r="bars",disableBackground:o=!1,disableLineNumbers:a=!1,overflow:l="scroll",diffStyle:h="split"}=this.options,d={type:"diff",diffIndicators:r,disableBackground:o,disableLineNumbers:a,overflow:l,split:h==="unified"?!1:t!=null&&i!=null,totalLines:n,customProperties:s};ui(d,this.appliedPreAttributes)||(fi(e,d),this.appliedPreAttributes=d)}applyErrorToDOM(e,t){this.cleanupErrorWrapper(),this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0;const i=t.shadowRoot??t.attachShadow({mode:"open"});this.errorWrapper??=document.createElement("div"),this.errorWrapper.dataset.errorWrapper="",this.errorWrapper.textContent="",i.appendChild(this.errorWrapper);const n=document.createElement("div");n.dataset.errorMessage="",n.innerText=e.message,this.errorWrapper.appendChild(n);const s=document.createElement("pre");s.dataset.errorStack="",s.innerText=e.stack??"No Error Stack",this.errorWrapper.appendChild(s)}cleanupErrorWrapper(){this.errorWrapper?.remove(),this.errorWrapper=void 0}};function Fn(e){return{name:e.name,lang:e.lang,contents:e.additionLines.join("")}}function Ht(e,t){return e==null||t==null?e==null&&t==null:It(e,t)}function In({fileDiff:e,oldFile:t,newFile:i}){return e!=null&&e.hunks.length>0||t!=null||i!=null}function Pn({fileDiff:e,oldFile:t,newFile:i}){return e!=null||t!=null||i!=null}function zn(e,t,i=!1){return!i&&e==null&&t}function Nn(e,t,i=!1){return e==null&&t&&!i}function J(e){if(!(e==null||e.type!=="element"))return e.children??[]}function On({fileDiff:e,metrics:t,disableFileHeader:i,hunkSeparators:n,expandUnchanged:s,expandedHunks:r,collapsedContextThreshold:o,canHydratePartialDiff:a}){let l=fe(t,i),h=l;const d=s?!0:r,u=e.hunks.length-1;for(let c=0;c<e.hunks.length;c++){const f=e.hunks[c];if(f==null)throw new Error("computeEstimatedDiffHeights: invalid hunk index");const p=Re({isPartial:e.isPartial,rangeSize:f.collapsedBefore,expandedHunks:d,hunkIndex:c,collapsedContextThreshold:o}),g=(p.fromStart+p.fromEnd)*t.lineHeight;if(l+=g,h+=g,p.collapsedLines>0){const y=Le({type:n,metrics:t,hunkIndex:c,hunkSpecs:f.hunkSpecs})?.totalHeight??0;l+=y,h+=y}l+=f.splitLineCount*t.lineHeight,h+=f.unifiedLineCount*t.lineHeight;const S=Un(f);l+=S.split*t.lineHeight,h+=S.unified*t.lineHeight;const C=c===u?ke({fileDiff:e,hunkIndex:c,expandedHunks:d,collapsedContextThreshold:o,errorPrefix:"computeEstimatedDiffHeights"}):void 0;if(C!=null){const y=(C.fromStart+C.fromEnd)*t.lineHeight;if(l+=y,h+=y,C.collapsedLines>0){const v=ie({type:n,metrics:t})?.totalHeight??0;l+=v,h+=v}}else if(c===u&&e.isPartial&&a){const y=ie({type:n,metrics:t})?.totalHeight??0;l+=y,h+=y}}if(e.hunks.length>0){const c=Mt(t);l+=c,h+=c}return{splitHeight:l,unifiedHeight:h}}function Un(e){if(!e.noEOFCRAdditions&&!e.noEOFCRDeletions)return{split:0,unified:0};const t=e.hunkContent.at(-1);if(t==null)return{split:0,unified:0};if(t.type==="context"){const i=t.lines>0?1:0;return{split:i,unified:i}}return Bn(e,t)}function Bn(e,t){const i=(t.deletions>0&&e.noEOFCRDeletions?1:0)+(t.additions>0&&e.noEOFCRAdditions?1:0),n=t.deletions>0&&e.noEOFCRDeletions,s=t.additions>0&&e.noEOFCRAdditions;return{split:n||s?1:0,unified:i}}const st=3e3,Fe=new Map;let Vn=-1;var is=class extends Mn{__id=`little-virtualized-file-diff:${++Vn}`;renderType="virtualized";top;height=0;metrics;cache={heightDeltas:new Map,measuredHeightDeltaTotal:0,estimatedSplitHeight:void 0,estimatedUnifiedHeight:void 0,checkpoints:[],totalLines:0,fileAnnotationHeight:0,ghostTextRows:Fe,ghostTextRowsByIndex:new Map};isVisible=!1;isSetup=!1;virtualizer;layoutDirty=!0;forceRenderOverride;currentCollapsed;pendingHydratedDiff;pendingExpansions;pendingRender;constructor(e,t,i,n,s=!1){super(e,n,s),this.virtualizer=t,this.metrics=Ge(i)}setMetrics(e,t=!1){const i=Ge(e);!t&&pi(this.metrics,i)||(this.metrics=i,this.resetLayoutCache({includeEstimatedHeights:!0}))}setLineAnnotations(e){this.syncLineAnnotations(e)&&(this.forceRenderOverride=!0)}syncLineAnnotations(e){return e==null||!this.isNewAnnotations(e)||e.length===0&&this.getLatestAnnotations().length===0?!1:(super.setLineAnnotations(e),!0)}syncEditSessionAnnotationsFromEditor(e){return super.syncEditSessionAnnotationsFromEditor(e)?(this.forceRenderOverride=!0,!0):!1}setFileAnnotationHeight(e){const t=this.cache.fileAnnotationHeight;return e===t?!1:(this.cache.fileAnnotationHeight=e,this.cache.measuredHeightDeltaTotal+=e-t,!0)}hasFileAnnotations(e){const t=this.getLatestAnnotations();return gi(t)?t.some(i=>i.lineNumber!==0?!1:e.type==="new"?i.side==="additions":e.type==="deleted"?i.side==="deletions":!0):!1}getLineHeight(e,t=!1){return this.getEstimatedLineHeight(t)+(this.cache.heightDeltas.get(e)??0)}getEstimatedLineHeight(e=!1){const t=e?2:1;return this.metrics.lineHeight*t}setOptions(e){if(this.isAdvancedMode())throw new Error("VirtualizedFileDiff.setOptions cannot be used inside CodeView. Update CodeView options instead.");if(e==null)return;const{options:t}=this,i=!mi(t,e),n=i&&qn(t,e);super.setOptions(e),n&&this.resetLayoutCache({forceSimpleRecompute:!0,includeEstimatedHeights:Kn(t,e)}),i&&(this.forceRenderOverride=!0),i&&this.isSimpleMode()&&this.virtualizer.instanceChanged(this,n)}setThemeType(e){if(this.isAdvancedMode())throw new Error("VirtualizedFileDiff.setThemeType cannot be used inside CodeView. Update CodeView options instead.");super.setThemeType(e)}resetLayoutCache({forceSimpleRecompute:e=!1,includeEstimatedHeights:t=!1,resetRenderRange:i=!0}={}){this.layoutDirty=!0,this.cache.fileAnnotationHeight=0,this.cache.heightDeltas.clear(),this.cache.measuredHeightDeltaTotal=0,this.cache.ghostTextRows=Fe,this.cache.ghostTextRowsByIndex.size>0&&this.cache.ghostTextRowsByIndex.clear(),this.invalidateDerivedLayoutCache(t,i),e&&this.isSimpleMode()&&this.computeApproximateSize()}invalidateDerivedLayoutCache(e,t=!0){this.layoutDirty=!0,this.cache.checkpoints.length>0&&(this.cache.checkpoints.length=0),this.cache.totalLines!==0&&(this.cache.totalLines=0),e&&(this.cache.estimatedSplitHeight=void 0,this.cache.estimatedUnifiedHeight=void 0),this.renderRange!=null&&t&&(this.renderRange=void 0)}applyGhostTextRows(e,t){const{cache:{heightDeltas:i,ghostTextRows:n,ghostTextRowsByIndex:s},metrics:{lineHeight:r}}=this;if(n===t)return!1;const o=this.getDiffStyle(),a=new Map;for(const[h,d]of t){const u=this.getLineIndexForDiff(e,h+1,"additions");u!=null&&a.set(o==="split"?u[1]:u[0],d)}let l=!1;for(const h of new Set([...s.keys(),...a.keys()])){const d=((a.get(h)??0)-(s.get(h)??0))*r;if(d===0)continue;const u=(i.get(h)??0)+d;u===0?i.delete(h):i.set(h,u),this.cache.measuredHeightDeltaTotal+=d,l=!0}return this.cache.ghostTextRows=t,this.cache.ghostTextRowsByIndex=a,l}reconcileHeights(){let e=!1;const{options:{overflow:t="scroll"},metrics:{lineHeight:i}}=this,n=this.placeHolder!=null?this.getLayoutDiff():this.getRenderedDiff();if(this.fileContainer==null||n==null)return this.height!==0&&(e=!0),this.height=0,e;this.top=this.getVirtualizedTop(),e=this.applyGhostTextRows(n,this.editor?.__getGhostTextRows()??Fe);const{ghostTextRowsByIndex:s}=this.cache,r=t!=="scroll"||this.getLatestAnnotations().length>0||this.isResizeDebuggingEnabled();if(this.placeHolder!=null||!r&&this.cache.heightDeltas.size===0&&this.cache.fileAnnotationHeight===0)return e&&(this.computeApproximateSize(!0),this.setPlaceholderHeight(this.height)),e;const o=this.getDiffStyle(),a=o==="split"?[this.codeDeletions,this.codeAdditions]:[this.codeUnified];if(this.renderRange!=null&&Tt(this.renderRange)){const l=_n(a)??0;this.setFileAnnotationHeight(l)&&(e=!0)}for(const l of a){if(l==null)continue;const h=l.children[1];if(!(h instanceof HTMLElement))continue;const d=o==="split"&&l===this.codeDeletions;for(const u of h.children){if(!(u instanceof HTMLElement))continue;const c=u.dataset.lineIndex;if(c==null)continue;const f=Yn(c,o),p=s.get(f)??0;if(d&&p>0)continue;const g=this.cache.heightDeltas.get(f)??0;if(!r&&g===p*i)continue;let S=u.getBoundingClientRect().height+p*i,C=!1;u.nextElementSibling instanceof HTMLElement&&("lineAnnotation"in u.nextElementSibling.dataset||"noNewline"in u.nextElementSibling.dataset)&&("noNewline"in u.nextElementSibling.dataset&&(C=!0),S+=u.nextElementSibling.getBoundingClientRect().height);const y=this.getEstimatedLineHeight(C),v=S-y;v!==g&&(e=!0,this.cache.measuredHeightDeltaTotal+=v-g,v===0?this.cache.heightDeltas.delete(f):this.cache.heightDeltas.set(f,v))}}return(e||this.isResizeDebuggingEnabled())&&this.computeApproximateSize(!0),e}onRender=e=>this.fileContainer==null?!1:(e&&(this.top=this.getVirtualizedTop()),this.render());flushManagers(){super.flushManagers(),this.lineStateRefreshPending&&this.flushDeferredLineState()}updateCodeViewLayout(e,t,i,n){let s=!1,r=!1;const{pendingExpansions:o,pendingHydratedDiff:a,options:{collapsed:l=!1}}=this;if(a!=null&&(this.pendingHydratedDiff=void 0,a.expectedDiff===e&&(Object.assign(e,a.nextDiff),this.setHydratedState(a.files),this.installHydratedSessionDiff(e),this.forceRenderOverride=!0,s=!0,r=!0)),o!=null){this.pendingExpansions=void 0;for(const{hunkIndex:p,direction:g,expansionLineCountOverride:S}of o)this.hunksRenderer.expandHunk(p,g,S),this.forceRenderOverride=!0,r=!0}const h=this.updateExternalDiff(e,n),{pendingRenderDiff:d,layoutDiffChanged:u,renderedDiffChanged:c,annotationsChanged:f}=this.updatePendingRender(e,n);return!this.forceRenderOverride&&(h||c||f)&&(this.forceRenderOverride=!0),(i?.resetDiffLayoutCache===!0||u)&&(s=!0),(u||i?.resetDiffLayoutCache===!0&&i.includeEstimatedDiffHeights)&&(r=!0),i?.metrics!=null&&(this.metrics=Ge(i.metrics),s=!0,r=!0),this.currentCollapsed!==l&&(this.currentCollapsed=l,s=!0),s?this.resetLayoutCache({includeEstimatedHeights:r}):r&&this.invalidateDerivedLayoutCache(!0),this.top=t,this.computeApproximateSize(!1,d),this.height}getLinePosition(e,t="additions"){const i=this.getLayoutDiff();if(i==null||e<1)return;const n=this.getLineIndexForDiff(i,e,t);if(n==null)return;const{disableFileHeader:s=!1,expandUnchanged:r=!1,collapsed:o=!1,collapsedContextThreshold:a=1}=this.options,l=this.getDiffStyle(),h=this.getHunkSeparatorType(),d=l==="split"?n[1]:n[0];this.approximateLayoutCheckpoints(i);const u=fe(this.metrics,s),c=this.getLayoutCheckpointBeforeLineIndex(d);let f=c?.top??u+this.cache.fileAnnotationHeight;if(o)return{top:u,height:0};let p;return pe({diff:i,diffStyle:l,startingLine:c?.renderedLineIndex??0,expandedHunks:r?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:a,callback:({hunkIndex:g,hunk:S,collapsedBefore:C,collapsedAfter:y,deletionLine:v,additionLine:R})=>{const m=l==="split"?R?.splitLineIndex??v?.splitLineIndex:R?.unifiedLineIndex??v?.unifiedLineIndex;if(m==null)throw new Error("VirtualizedFileDiff.getLinePosition: missing line index data");if(C>0){const L=Le({type:h,metrics:this.metrics,hunkIndex:g,hunkSpecs:S?.hunkSpecs});if(L!=null){if(f+=L.gapBefore,d>=m-C&&d<m)return p={top:f,height:L.height},!0;f+=L.height+L.gapAfter}}const b=this.getLineHeight(m,(R?.noEOFCR??!1)||(v?.noEOFCR??!1));if(m===d)return p={top:f,height:b},!0;if(f+=b,y>0){const L=ie({type:h,metrics:this.metrics});if(L!=null){if(d>m&&d<=m+y)return p={top:f+L.gapBefore,height:L.height},!0;f+=L.totalHeight}}return!1}}),p}getEditorViewport(){return this.virtualizer.type==="simple"?this.virtualizer.getRoot():this.virtualizer.getContainerElement()}getNumericScrollAnchor(e){const t=this.getLayoutDiff();if(t==null)return;const{disableFileHeader:i=!1,expandUnchanged:n=!1,collapsed:s=!1,collapsedContextThreshold:r=1}=this.options;if(s)return;const o=this.getDiffStyle(),a=this.getHunkSeparatorType();this.approximateLayoutCheckpoints(t);const l=this.getLayoutCheckpointBeforeTop(e);let h=l?.top??fe(this.metrics,i)+this.cache.fileAnnotationHeight,d;return pe({diff:t,diffStyle:o,startingLine:l?.renderedLineIndex??0,expandedHunks:n?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:r,callback:({hunkIndex:u,hunk:c,collapsedBefore:f,collapsedAfter:p,deletionLine:g,additionLine:S})=>{const C=o==="split"?S?.splitLineIndex??g?.splitLineIndex:S?.unifiedLineIndex??g?.unifiedLineIndex;if(C==null)throw new Error("VirtualizedFileDiff.getNumericScrollAnchor: missing line index data");if(f>0){const v=Le({type:a,metrics:this.metrics,hunkIndex:u,hunkSpecs:c?.hunkSpecs});v!=null&&(h+=v.totalHeight)}if(h>=e&&(g!=null?d={lineNumber:g.lineNumber,side:"deletions",top:h}:S!=null&&(d={lineNumber:S.lineNumber,side:"additions",top:h}),d!=null))return!0;const y=this.getLineHeight(C,(S?.noEOFCR??!1)||(g?.noEOFCR??!1));if(h+=y,p>0){const v=ie({type:a,metrics:this.metrics});v!=null&&(h+=v.totalHeight)}return!1}}),d}getVirtualizedHeight(){return this.height}getAdvancedStickySpecs(e){const t=this.getLayoutDiff();if(this.top==null||t==null)return;if(this.options.collapsed===!0)return{topOffset:this.top,height:this.height};const i=e!=null?this.computeRenderRangeFromWindow(t,this.top,e):this.renderRange;if(i==null)return;const{bufferBefore:n,bufferAfter:s,totalLines:r}=i;let o=0;if(r===0){const a=e??this.virtualizer.getWindowSpecs();this.top<a.top&&(o=s)}return{topOffset:this.top+n+o,height:this.height-(n+s)}}cleanUp(e=!1){const t=this.cache.ghostTextRows.size>0;t&&(this.layoutDirty=!0);const i=e&&this.isAdvancedMode()&&this.fileContainer!=null&&(t||!D(this.getRenderedDiff(),this.getLatestDiff()));this.fileContainer!=null&&this.isSimpleMode()&&this.getSimpleVirtualizer()?.disconnect(this.fileContainer),e||(this.resetLayoutCache({includeEstimatedHeights:!0}),this.pendingExpansions=void 0,this.pendingHydratedDiff=void 0),this.pendingRender=void 0,this.isSetup=!1,super.cleanUp(e),i&&this.virtualizer.instanceChanged(this,!0)}expandHunk=(e,t,i)=>{this.fileDiff!=null&&(this.loadFilesIfNecessary(),this.isAdvancedMode()?(this.pendingExpansions??=[],this.pendingExpansions.push({hunkIndex:e,direction:t,expansionLineCountOverride:i})):(this.hunksRenderer.expandHunk(e,t,i),this.resetLayoutCache({includeEstimatedHeights:!0}),this.computeApproximateSize()),this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0))};async handleFilesLoaded(e,t){if(!(this.fileDiff!==e||!e.isPartial)){if(this.isAdvancedMode()){const i=Je("clone",e,t);if(await it(()=>this.primeHighlightCache(i)),this.fileDiff!==e)return;this.pendingHydratedDiff={expectedDiff:e,nextDiff:i,files:t}}else{if(Je("merge",e,t),this.setHydratedState(t),!this.installHydratedSessionDiff(e)&&(await it(()=>this.primeHighlightCache(e)),this.fileDiff!==e))return;this.resetLayoutCache({includeEstimatedHeights:!0}),this.computeApproximateSize()}this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0)}}loadFilesIfNecessary(){if(this.pendingHydratedDiff!=null){if(this.pendingHydratedDiff.expectedDiff===this.fileDiff)return;this.pendingHydratedDiff=void 0}super.loadFilesIfNecessary()}isLineRenderable(e){if(super.isLineRenderable(e))return!0;const{pendingExpansions:t}=this,i=this.getRenderedDiff();if(t==null||t.length===0||i==null)return!1;const{expansionLineCount:n=100,collapsedContextThreshold:s=1}=this.options,r=new Map(this.hunksRenderer.getExpandedHunksMap());for(const o of t){const a={...r.get(o.hunkIndex)??{fromStart:0,fromEnd:0}},l=o.expansionLineCountOverride??n;(o.direction==="up"||o.direction==="both")&&(a.fromStart+=l),(o.direction==="down"||o.direction==="both")&&(a.fromEnd+=l),r.set(o.hunkIndex,a)}return Ft({fileDiff:i,lineNumber:e,expandedHunks:r,collapsedContextThreshold:s})}invalidateEditSessionLayout(){this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache({forceSimpleRecompute:this.isSimpleMode(),includeEstimatedHeights:!0,resetRenderRange:!1}),this.isSimpleMode()||this.computeApproximateSize(!0),this.getSimpleVirtualizer()?.requestHeightReconcile(this)}escalateEditSessionRender(){this.invalidateEditSessionLayout(),!(!this.enabled||this.fileDiff==null)&&(this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0))}shouldSelfHealEditSession(){return!this.isAdvancedMode()&&super.shouldSelfHealEditSession()}setVisibility(e){this.isAdvancedMode()||this.fileContainer==null||(this.renderRange=void 0,e&&!this.isVisible?(this.top=this.getVirtualizedTop(),this.isVisible=!0):!e&&this.isVisible&&(this.isVisible=!1,this.rerender()))}rerender(){if(!this.enabled||this.fileDiff==null&&this.additionFile==null&&this.deletionFile==null)return;const e=this.getLatestDiff(),t=e==null?void 0:this.hunksRenderer.getDiffForNextRender(e);this.isSimpleMode()&&(this.pendingRender=void 0),this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!D(this.getRenderedDiff(),t))}syncGhostTextRows(){const e=this.getAdvancedVirtualizer();e!=null?(e.capturePendingLayoutAnchor(),this.layoutDirty=!0,e.instanceChanged(this,!0)):this.getSimpleVirtualizer()?.requestHeightReconcile(this)}applyDocumentChange(e,t,i=!1){const{renderRange:n}=this;this.getAdvancedVirtualizer()?.capturePendingLayoutAnchor(),super.applyDocumentChange(e,t),this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache({forceSimpleRecompute:this.isSimpleMode(),includeEstimatedHeights:!0,resetRenderRange:!1});const s=this.getRenderedDiff();if(!this.isSimpleMode())this.computeApproximateSize(!0);else if(i&&n!=null&&s!=null){const r=this.virtualizer.getWindowSpecs(),o=this.computeRenderRangeFromWindow(s,this.top??0,r);o.bufferAfter!==n.bufferAfter&&this.updateBuffers(o)}this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0)}computeApproximateSize(e=!1,t=this.getLayoutDiff()){const i=this.isResizeDebuggingEnabled();if(!e&&!this.layoutDirty&&!i)return;const n=this.height===0;if(this.height=0,this.cache.checkpoints=[],this.cache.totalLines=0,t==null){this.layoutDirty=!1;return}this.applyGhostTextRows(t,this.editor?.__getGhostTextRows()??Fe);const{disableFileHeader:s=!1,collapsed:r=!1}=this.options,o=fe(this.metrics,s);if(this.height+=o,r){this.layoutDirty=!1;return}this.height=this.getActiveEstimatedHeight(t)+this.cache.measuredHeightDeltaTotal,i&&!n&&this.validateComputedHeight(t),this.layoutDirty=!1}getLayoutDiff(){return this.pendingRender?.diff??this.getRenderedDiff()}getActiveEstimatedHeight(e=this.getLayoutDiff()){this.ensureEstimatedDiffHeights(e);const t=this.getDiffStyle()==="split"?this.cache.estimatedSplitHeight:this.cache.estimatedUnifiedHeight;if(t==null)throw new Error("VirtualizedFileDiff.getActiveEstimatedHeight: missing estimated height");return t}ensureEstimatedDiffHeights(e=this.getLayoutDiff()){if(e==null){this.cache.estimatedSplitHeight=void 0,this.cache.estimatedUnifiedHeight=void 0;return}if(this.cache.estimatedSplitHeight!=null&&this.cache.estimatedUnifiedHeight!=null)return;const{disableFileHeader:t=!1,expandUnchanged:i=!1,collapsedContextThreshold:n=1}=this.options,{splitHeight:s,unifiedHeight:r}=On({fileDiff:e,metrics:this.metrics,disableFileHeader:t,hunkSeparators:this.getHunkSeparatorType(),expandUnchanged:i,expandedHunks:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:n,canHydratePartialDiff:Ke(e,this.options.loadDiffFiles!=null)});this.cache.estimatedSplitHeight=s,this.cache.estimatedUnifiedHeight=r}validateComputedHeight(e=this.getLayoutDiff()){if(this.fileContainer==null||e==null)return;const t=this.fileContainer.getBoundingClientRect();t.height!==this.height?console.log("VirtualizedFileDiff.computeApproximateSize: computed height doesnt match",{name:e.name,elementHeight:t.height,computedHeight:this.height}):console.log("VirtualizedFileDiff.computeApproximateSize: computed height IS CORRECT")}render({fileContainer:e,fileDiff:t,forceRender:i=!1,lineAnnotations:n,...s}={}){const r=nt(s,"VirtualizedFileDiff.render"),o=r!=null,a=r?.oldFile,l=r?.newFile,h=o&&(!At(a,this.deletionFile)||!At(l,this.additionFile));let d=t??this.fileDiff;t==null&&o&&(h||this.fileDiff==null)&&(d=se(r.oldFile,r.newFile,this.options.parseDiffOptions));const{forceRenderOverride:u,isSetup:c}=this;this.forceRenderOverride=void 0;const f=d!=null&&!D(this.fileDiff,d),p=f||h;if(e=this.getOrCreateFileContainer(e),d==null)return console.error("VirtualizedFileDiff.render: attempting to virtually render when we dont have the correct data"),!1;f&&this.updateExternalDiff(d,n);const{pendingRenderDiff:g,layoutDiffChanged:S,renderedDiffChanged:C,annotationsChanged:y}=this.pendingRender!=null&&this.pendingRender.latestDiff===(this.getLatestDiff(d)??d)?{pendingRenderDiff:this.pendingRender.diff,layoutDiffChanged:!1,renderedDiffChanged:!1,annotationsChanged:this.syncLineAnnotations(n)}:this.updatePendingRender(d,n);if(S&&this.resetLayoutCache({includeEstimatedHeights:!0}),c)this.top??=this.getVirtualizedTop(),this.layoutDirty&&this.isSimpleMode()&&(this.getSimpleVirtualizer()?.markDOMDirty(),this.computeApproximateSize(!1,g));else{this.computeApproximateSize(!1,g);const b=this.getSimpleVirtualizer();if(this.top??=this.getVirtualizedTop(),this.isAdvancedMode())this.isVisible=!0;else{if(b==null)throw new Error("VirtualizedFileDiff.render: simple virtualizer is not available");b.connect(e,this),this.isVisible=b.isInstanceVisible(this.top??0,this.height)}this.isSetup=!0}if(!this.isVisible&&this.isSimpleMode()&&(!p||!c))return r!=null&&(this.deletionFile=a,this.additionFile=l),f&&this.clearReusableHeader(),this.renderPlaceholder(this.height);const v=this.virtualizer.getWindowSpecs(),R=this.top??0,m=this.computeRenderRangeFromWindow(g,R,v);return super.render({fileDiff:d,fileContainer:e,renderRange:m,lineAnnotations:n,forceRender:(u??i)||y||C||f,...r,...s})}finalizeRender(){if(!D(this.getRenderedDiff(),this.pendingRender?.diff))throw new Error("VirtualizedFileDiff.render: rendered a different diff than its prepared layout");this.pendingRender=void 0,this.isSimpleMode()&&this.getSimpleVirtualizer()?.requestHeightReconcile(this)}updatePendingRender(e,t){const i=this.getLatestDiff(e)??e,n=this.getRenderedDiff(),{pendingRender:s}=this,r=s?.diff??n,o=this.hunksRenderer.getDiffForNextRender(i);return this.pendingRender={latestDiff:i,diff:o},{pendingRenderDiff:o,annotationsChanged:this.syncLineAnnotations(t),layoutDiffChanged:!D(r,o),renderedDiffChanged:!D(n,o)}}syncVirtualizedTop(){this.top=this.getVirtualizedTop()}shouldDisableVirtualizationBuffers(){return this.isAdvancedMode()||super.shouldDisableVirtualizationBuffers()}shouldGuardRebuildScroll(){return!1}isSimpleMode(){return this.virtualizer.type==="simple"}isAdvancedMode(){return this.virtualizer.type==="advanced"}getVirtualizedTop(){return this.virtualizer.type==="advanced"?this.virtualizer.getLocalTopForInstance(this):this.fileContainer!=null?this.virtualizer.getOffsetInScrollContainer(this.fileContainer):0}getSimpleVirtualizer(){return this.virtualizer.type==="simple"?this.virtualizer:void 0}getAdvancedVirtualizer(){return this.virtualizer.type==="advanced"?this.virtualizer:void 0}isResizeDebuggingEnabled(){return this.getSimpleVirtualizer()?.config.resizeDebugging??!1}getDiffStyle(){return this.options.diffStyle??"split"}getHunkSeparatorType(){return Xn(this.options.hunkSeparators)}approximateLayoutCheckpoints(e){if(!this.layoutDirty&&this.cache.checkpoints.length>0||e.hunks.length===0||this.options.collapsed===!0)return;const{disableFileHeader:t=!1,expandUnchanged:i=!1,collapsedContextThreshold:n=1}=this.options,s=e.hunks.length-1,r=Ke(e,this.options.loadDiffFiles!=null),o=this.getDiffStyle(),a=this.getHunkSeparatorType(),l=i?!0:this.hunksRenderer.getExpandedHunksMap(),h=Gn(this.cache.heightDeltas);let d=fe(this.metrics,t)+this.cache.fileAnnotationHeight,u=0;const c=({rowCount:f,startLineIndex:p,preSeparatorHeight:g=0,postSeparatorHeight:S=0,metadataOffsets:C=[]})=>{if(f<=0)return;const y=u,v=u+f;let R=Wn(y);for(;R<v;){const m=R-y,b=d+(m>0?g:0)+m*this.metrics.lineHeight+$n(C,m)*this.metrics.lineHeight+wt(h,p,p+m);this.cache.checkpoints.push({renderedLineIndex:R,lineIndex:p+m,top:b}),R+=st}d+=g+f*this.metrics.lineHeight+C.length*this.metrics.lineHeight+wt(h,p,p+f)+S,u=v};for(let f=0;f<e.hunks.length;f++){const p=e.hunks[f];if(p==null)throw new Error("VirtualizedFileDiff.approximateLayoutCheckpoints: invalid hunk index");const g=Re({isPartial:e.isPartial,rangeSize:p.collapsedBefore,expandedHunks:l,hunkIndex:f,collapsedContextThreshold:n}),S=g.collapsedLines>0?Le({type:a,metrics:this.metrics,hunkIndex:f,hunkSpecs:p.hunkSpecs})?.totalHeight??0:0;c({rowCount:g.fromStart,startLineIndex:(o==="split"?p.splitLineStart:p.unifiedLineStart)-g.rangeSize});let C=S;c({rowCount:g.fromEnd,startLineIndex:(o==="split"?p.splitLineStart:p.unifiedLineStart)-g.fromEnd,preSeparatorHeight:C}),g.fromEnd>0&&(C=0);const y=f===s?ke({fileDiff:e,hunkIndex:f,expandedHunks:l,collapsedContextThreshold:n,errorPrefix:"VirtualizedFileDiff"}):void 0,v=y!=null&&y.collapsedLines>0?ie({type:a,metrics:this.metrics})?.totalHeight??0:f===s&&r?ie({type:a,metrics:this.metrics})?.totalHeight??0:0,R=y!=null?y.fromStart+y.fromEnd:0,m=o==="split"?p.splitLineCount:p.unifiedLineCount,b=o==="split"?p.splitLineStart:p.unifiedLineStart;c({rowCount:m,startLineIndex:b,preSeparatorHeight:C,postSeparatorHeight:R===0?v:0,metadataOffsets:jn({diffStyle:o,hunk:p,rowCount:m})}),y!=null&&R>0&&c({rowCount:R,startLineIndex:b+m,postSeparatorHeight:v})}this.cache.totalLines=u}getLayoutCheckpointBeforeLineIndex(e){if(e<=0||this.cache.checkpoints.length===0)return;let t=0,i=this.cache.checkpoints.length-1,n;for(;t<=i;){const s=t+i>>1,r=this.cache.checkpoints[s];if(r==null)throw new Error("VirtualizedFileDiff: invalid checkpoint index");r.lineIndex<=e?(n=r,t=s+1):i=s-1}return n}getLayoutCheckpointBeforeTop(e,t){let i=0,n=this.cache.checkpoints.length-1,s=-1;for(;i<=n;){const r=i+n>>1,o=this.cache.checkpoints[r];if(o==null)throw new Error("VirtualizedFileDiff: invalid checkpoint index");o.top<=e?(s=r,i=r+1):n=r-1}if(t==null)return s>=0?this.cache.checkpoints[s]:void 0;for(let r=s;r>=0;r--){const o=this.cache.checkpoints[r];if(o==null)throw new Error("VirtualizedFileDiff: invalid checkpoint index");if(o.renderedLineIndex%t===0)return o}}getExpandedLineCount(e,t){let i=0;if(e.isPartial){for(const a of e.hunks)i+=t==="split"?a.splitLineCount:a.unifiedLineCount;return i}const{expandUnchanged:n=!1,collapsedContextThreshold:s=1}=this.options,r=n?!0:this.hunksRenderer.getExpandedHunksMap();for(const[a,l]of e.hunks.entries()){const h=t==="split"?l.splitLineCount:l.unifiedLineCount;i+=h;const d=Math.max(l.collapsedBefore,0),{fromStart:u,fromEnd:c,renderAll:f}=Re({isPartial:e.isPartial,rangeSize:d,expandedHunks:r,hunkIndex:a,collapsedContextThreshold:s});d>0&&(i+=f?d:u+c)}const o=ke({fileDiff:e,hunkIndex:e.hunks.length-1,expandedHunks:r,collapsedContextThreshold:s,errorPrefix:"VirtualizedFileDiff"});return o!=null&&(i+=o.fromStart+o.fromEnd),i}getLayoutLineCount(e,t){const i=this.getExpandedLineCount(e,t),n=t==="split"?e.splitLineCount:e.unifiedLineCount;return Math.max(i,n,e.additionLines.length,e.deletionLines.length,this.cache.totalLines)}computeRenderRangeFromWindow(e,t,{top:i,bottom:n}){const{disableFileHeader:s=!1,expandUnchanged:r=!1,collapsedContextThreshold:o=1}=this.options,{hunkLineCount:a,lineHeight:l}=this.metrics,h=this.getDiffStyle(),d=this.getHunkSeparatorType(),u=Ke(e,this.options.loadDiffFiles!=null),c=this.height;let f=this.getLayoutLineCount(e,h);const p=fe(this.metrics,s),g=e.hunks.length>0?Mt(this.metrics):0,{fileAnnotationHeight:S}=this.cache,C=p+S,y=Math.max(0,c-p-S-g),v=this.hasFileAnnotations(e),R=t+p,m=S>0&&v&&R<n&&R+S>i;if(t<i-c||t>n)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:c-p-g};if(f<=a||e.hunks.length===0)return{startingLine:0,totalLines:a,bufferBefore:0,bufferAfter:0};this.approximateLayoutCheckpoints(e),f=this.getLayoutLineCount(e,h);const b=Math.ceil(Math.max(n-i,0)/l),L=Math.ceil(b/a)*a+a,F=L/a,ae=F,k=[],M=(i+n)/2,le=this.getLayoutCheckpointBeforeTop(Math.max(0,i-t-L*l*2),a);let I=t+(le?.top??C),G=le?.renderedLineIndex??0,Q,H,w;if(pe({diff:e,diffStyle:h,startingLine:le?.renderedLineIndex??0,expandedHunks:r?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:o,callback:({hunkIndex:ge,hunk:W,collapsedBefore:Be,collapsedAfter:Ve,deletionLine:ee,additionLine:$})=>{const A=$!=null?$.splitLineIndex:ee.splitLineIndex,z=$!=null?$.unifiedLineIndex:ee.unifiedLineIndex,U=($?.noEOFCR??!1)||(ee?.noEOFCR??!1),te=ge===e.hunks.length-1&&W!=null&&(h==="split"?A===W.splitLineStart+W.splitLineCount-1:z===W.unifiedLineStart+W.unifiedLineCount-1),B=(Be>0?Le({type:d,metrics:this.metrics,hunkIndex:ge,hunkSpecs:W?.hunkSpecs}):void 0)?.totalHeight??0;I+=B;const V=G%a===0,Z=Math.floor(G/a);if(V&&(k[Z]=I-(t+C+B),w!=null)){if(w<=0)return!0;w--}const N=this.getLineHeight(h==="split"?A:z,U);if(I>i-N&&I<n&&(Q??=Z),H==null&&I+N>M&&(H=Z),w==null&&I>=n&&V&&(w=ae),G++,I+=N,Ve>0||te&&u){const we=ie({type:d,metrics:this.metrics});we!=null&&(I<n&&I+we.totalHeight>i&&(Q??=Z),H==null&&I+we.totalHeight>M&&(H=Z),I+=we.totalHeight)}return!1}}),Q==null)if(m)Q=0,H=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:c-p-g};H??=Q;const X=Math.round(H-F/2),de=Math.max(0,Math.ceil(f/a)-F),E=Math.max(0,Math.min(X,de)),x=E*a,T=X<0?L+X*a:L,O=k[E]??0,Y=x===0?0:S+O,he=E+T/a,He=he<k.length?y-k[he]:y-(I-t-C);return{startingLine:x,totalLines:T,bufferBefore:Y,bufferAfter:Math.max(0,He)}}};function _n(e){let t;for(const i of e){if(i==null)continue;const n=i.children[1];if(n instanceof HTMLElement)for(const s of n.children)s instanceof HTMLElement&&s.dataset.lineAnnotation===Si&&(t=Math.max(t??0,s.getBoundingClientRect().height))}return t}function Gn(e){const t=Array.from(e).sort((r,o)=>r[0]-o[0]),i=[],n=[0];let s=0;for(const[r,o]of t)i.push(r),s+=o,n.push(s);return{lineIndexes:i,prefixTotals:n}}function wt({lineIndexes:e,prefixTotals:t},i,n){if(i>=n||e.length===0)return 0;const s=xt(e,i);return(t[xt(e,n)]??0)-(t[s]??0)}function xt(e,t){let i=0,n=e.length;for(;i<n;){const s=i+n>>1,r=e[s];if(r==null)throw new Error("VirtualizedFileDiff: invalid prefix index");r<t?i=s+1:n=s}return i}function Wn(e){return Math.ceil(e/st)*st}function $n(e,t){let i=0;for(const n of e)n<t&&i++;return i}function jn({diffStyle:e,hunk:t,rowCount:i}){if(i<=0||!t.noEOFCRAdditions&&!t.noEOFCRDeletions)return[];const n=t.hunkContent.at(-1);if(n==null)return[];if(n.type==="context")return[i-1];const s=Math.max(n.deletions,n.additions),r=n.deletions+n.additions;if(e==="split")return s>0&&(t.noEOFCRAdditions||t.noEOFCRDeletions)?[i-1]:[];const o=[],a=i-r;return n.deletions>0&&t.noEOFCRDeletions&&o.push(a+n.deletions-1),n.additions>0&&t.noEOFCRAdditions&&o.push(i-1),o}function qn(e,t){return(e.diffStyle??"split")!==(t.diffStyle??"split")||(e.overflow??"scroll")!==(t.overflow??"scroll")||(e.collapsed??!1)!==(t.collapsed??!1)||(e.disableLineNumbers??!1)!==(t.disableLineNumbers??!1)||(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||(e.diffIndicators??"bars")!==(t.diffIndicators??"bars")||(e.hunkSeparators??"line-info")!==(t.hunkSeparators??"line-info")||!!e.loadDiffFiles!=!!t.loadDiffFiles||(e.expandUnchanged??!1)!==(t.expandUnchanged??!1)||(e.collapsedContextThreshold??1)!==(t.collapsedContextThreshold??1)||e.unsafeCSS!==t.unsafeCSS}function Kn(e,t){return(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||(e.hunkSeparators??"line-info")!==(t.hunkSeparators??"line-info")||!!e.loadDiffFiles!=!!t.loadDiffFiles||(e.expandUnchanged??!1)!==(t.expandUnchanged??!1)||(e.collapsedContextThreshold??1)!==(t.collapsedContextThreshold??1)}function Ke(e,t){return e.isPartial&&t&&(e.type==="change"||e.type==="rename-changed")}function Xn(e){return typeof e=="function"?"custom":e??"line-info"}function At(e,t){return e==null||t==null?e==null&&t==null:It(e,t)}function Yn(e,t){const[i,n]=e.split(",").map(Number);return t==="split"?n:i}export{Mn as F,is as V};
5
+ `)}function Ji(e,t){const i=e.additionLineIndex,n=e.deletionLineIndex;e.hunkContent=t.hunkContent.map(s=>Vt(s,i,n)),e.additionLineIndex=i+t.additionLineIndex,e.additionStart=e.additionStart+t.additionLineIndex,e.additionCount=t.additionCount,e.additionLines=t.additionLines,t.deletionLineIndex>=0&&(e.deletionLineIndex=n+t.deletionLineIndex,e.deletionStart=e.deletionStart+t.deletionLineIndex),e.deletionCount=t.deletionCount,e.deletionLines=t.deletionLines,e.noEOFCRAdditions=t.noEOFCRAdditions,e.noEOFCRDeletions=t.noEOFCRDeletions,rt(e)}function Vt(e,t,i){return{...e,additionLineIndex:e.additionLineIndex+t,deletionLineIndex:e.deletionLineIndex+i}}function rt(e){let t=0,i=0;for(const n of e.hunkContent)n.type==="context"?(t+=n.lines,i+=n.lines):(t+=Math.max(n.additions,n.deletions),i+=n.additions+n.deletions);e.splitLineCount=t,e.unifiedLineCount=i}function Ue(e){let t=0,i=0,n=0;for(const s of e.hunks)s.collapsedBefore=Math.max(Ee(s.additionStart,s.additionCount)-n,0),s.splitLineStart=t+s.collapsedBefore,s.unifiedLineStart=i+s.collapsedBefore,rt(s),t+=s.collapsedBefore+s.splitLineCount,i+=s.collapsedBefore+s.unifiedLineCount,n=re(s.additionStart,s.additionCount);if(e.hunks.length>0){const s=e.hunks[e.hunks.length-1],r=Math.max(e.additionLines.length-re(s.additionStart,s.additionCount),0);t+=r,i+=r}e.splitLineCount=t,e.unifiedLineCount=i}const mt=new WeakMap;function Zi(e){return e.length>1&&e[e.length-1]===""?e.slice(0,-1):e}function Qi(e,t){const i=Math.min(e.length,t.length);let n=0;for(;n<i&&e[n]===t[n];)n++;let s=e.length,r=t.length;for(;s>n&&r>n&&e[s-1]===t[r-1];)s--,r--;if(!(n===s&&n===r))return{start:n,deletionEnd:s,additionEnd:r}}function et(e,t,i){const n=e.hunks,s=e.additionLines,r=Zi(s),o=r===s?e:{...e,additionLines:r},a=hn(n,ln(o,t,i),e.deletionLines.length),l=cn(o,a);if(e.additionLines=r,e.hunks=l,e.editSessionDirty=!0,Sn(e),Ut(e,s),!!gn(n,e.hunks))return{regions:a.map(h=>h.previousSpan)}}function en(e,t,i,n){const s=new Set(t),r=Array.from(s).filter(d=>d>=0&&d<e.additionLines.length).sort((d,u)=>d-u);if(r.length===0)return;const o=d=>s.has(d)?n?.get(d):e.additionLines[d],{hunks:a}=e;let l,h=0;for(const d of r){for(;h<a.length;){const f=a[h];if(d<Oe(f)+f.additionCount)break;h++}const u=a[h],c=u==null?void 0:Oe(u);if(c==null||d<c||l!=null&&l!==h)return et(e,i,o);l=h}if(l!=null){if(tn(e,r,l,n,i)){e.editSessionDirty=!0;return}return et(e,i,o)}}function tn(e,t,i,n,s){if(n==null||s?.ignoreWhitespace===!0||s?.stripTrailingCr===!0)return!1;const r=nn(e),o=e.hunks[i];if(o.hunkContent.some(sn))return!1;for(const a of t){const l=n.get(a),h=e.additionLines[a];if(l==null||h==null||r.has(l)||r.has(h))return!1;let d=!1;for(const u of o.hunkContent)if(u.type==="change"&&u.additions===u.deletions&&a>=u.additionLineIndex&&a<u.additionLineIndex+u.additions){d=!0;break}if(!d)return!1}return!0}function nn(e){const t=mt.get(e);if(t?.lines===e.deletionLines)return t.set;const i=new Set(e.deletionLines);return mt.set(e,{lines:e.deletionLines,set:i}),i}function sn(e){return e?.type==="change"&&(e.additions===0||e.deletions===0)}function rn(e,t){const i=new Map,{regions:n}=t;for(let s=0;s<=n.length;s++){const r=n[s-1],o=n[s],a=s===0?e.get(0):r==null?void 0:e.get(r.lastIndex+1),l=o==null?void 0:e.get(o.firstIndex),h=a?.fromStart??0,d=l?.fromEnd??0;(h>0||d>0)&&i.set(s,{fromStart:h,fromEnd:d})}return i}function on(e,t,i){const n=[];if(e.isPartial)return n;for(const[r,o]of e.hunks.entries()){const a=Re({isPartial:e.isPartial,rangeSize:o.collapsedBefore,expandedHunks:t,hunkIndex:r,collapsedContextThreshold:i});if(a.rangeSize<=i)continue;const l=oe(o),h=l-a.rangeSize;a.fromStart>0&&n.push([h,h+a.fromStart]),a.fromEnd>0&&n.push([l-a.fromEnd,l])}const s=ke({fileDiff:e,hunkIndex:e.hunks.length-1,expandedHunks:t,collapsedContextThreshold:i,errorPrefix:"captureExpansionAnchors"});if(s!=null&&s.fromStart>0&&s.rangeSize>i){const r=e.hunks[e.hunks.length-1],o=oe(r)+r.deletionCount;n.push([o,o+s.fromStart])}return n}function an(e,t){const i=new Map;if(t.length===0)return i;const n=(r,o,a)=>{if(a<=o)return;let l=0,h=0;for(const[d,u]of t)u<=o||d>=a||(d<=o&&(l=Math.max(l,Math.min(u,a)-o)),u>=a&&(h=Math.max(h,a-Math.max(d,o))));(l>0||h>0)&&i.set(r,{fromStart:l,fromEnd:h})};for(const[r,o]of e.hunks.entries()){const a=oe(o);n(r,a-Math.max(o.collapsedBefore,0),a)}const s=e.hunks[e.hunks.length-1];return s!=null&&!e.isPartial&&e.deletionLines.length>0&&n(e.hunks.length,oe(s)+s.deletionCount,e.deletionLines.length),i}function St(e,t){return e.editSessionDirty!==!0?!1:(delete e.editSessionDirty,Object.assign(e,e.additionLines.length<=1&&e.additionLines.join("")===""?q(e,t):Ot(e,t)),!0)}function ln(e,t,i){if(Qi(e.deletionLines,e.additionLines)==null)return[];const n=se({name:e.prevName??e.name,contents:e.deletionLines.join("")},{name:e.name,contents:e.additionLines.join(""),lang:e.lang},t);let s;const r=(h,d)=>{s??=dn(e.hunks);for(let u=0;u<=d;u++){const c=s.get(h.deletionLineIndex-u);if(!(c==null||c.additions!==h.additions||c.deletions!==h.deletions)){if(h.additions>0&&i!=null){for(let f=0;f<h.additions;f++)if(i(c.additionLineIndex+f)!==n.additionLines[h.additionLineIndex+f])return d}return u}}return d},o=[];let a=0,l=0;for(const h of n.hunks){wi(h,n,r);const d=h.additionCount>0?h.additionLineIndex-a:h.deletionLineIndex-l;a+=d,l+=d;for(const u of h.hunkContent){if(u.type==="context"){a+=u.lines,l+=u.lines;continue}const c=Vt(u,0,0);c.additions===0&&(c.additionLineIndex=a),c.deletions===0&&(c.deletionLineIndex=l),o.push(c),a+=c.additions,l+=c.deletions}}return o}function dn(e){const t=new Map;for(const i of e)for(const n of i.hunkContent)n.type==="change"&&(n.additions===0||n.deletions===0)&&t.set(n.deletionLineIndex,n);return t}function hn(e,t,i){const n=e.map((o,a)=>{const l=oe(o);return{deletionStart:l,deletionEnd:l+o.deletionCount,blocks:[],previousSpan:{firstIndex:a,lastIndex:a}}}),s=[];let r=0;for(const o of t){const a=o.deletionLineIndex,l=a+o.deletions;for(;r<n.length&&n[r].deletionEnd<a;)s.push(n[r]),r++;let h=s.length>0&&un(a,l,s[s.length-1])?s.pop():void 0;for(;r<n.length&&n[r].deletionStart<=l;)h=fn(h,n[r]),r++;if(h==null){let d=a,u=l;if((o.deletions===0||o.additions===0)&&i>o.deletions){const c=s[s.length-1]?.deletionEnd??0,f=n[r]?.deletionStart??i;a>c?d--:l<f&&u++}h={deletionStart:d,deletionEnd:u,blocks:[],previousSpan:void 0}}h.deletionStart=Math.min(h.deletionStart,a),h.deletionEnd=Math.max(h.deletionEnd,l),h.blocks.push(o),s.push(h)}for(;r<n.length;)s.push(n[r]),r++;return s}function un(e,t,i){return e<=i.deletionEnd&&t>=i.deletionStart}function fn(e,t){return e==null?t:(e.deletionStart=Math.min(e.deletionStart,t.deletionStart),e.deletionEnd=Math.max(e.deletionEnd,t.deletionEnd),e.blocks.push(...t.blocks),t.previousSpan!=null&&(e.previousSpan??={...t.previousSpan},e.previousSpan.firstIndex=Math.min(e.previousSpan.firstIndex,t.previousSpan.firstIndex),e.previousSpan.lastIndex=Math.max(e.previousSpan.lastIndex,t.previousSpan.lastIndex)),e)}function cn(e,t){const i=[];let n=0,s=0;for(const r of t){const o=r.deletionStart-n;if(o<0)throw new Error("buildRegionHunks: overlapping old-side regions");n+=o,s+=o;const a=s,l=[];for(const d of r.blocks){const u=d.deletionLineIndex-n,c=d.additionLineIndex-s;if(u<0||u!==c)throw new Error("buildRegionHunks: canonical block context mismatch");Ct(l,u,s,n),n+=u,s+=c,l.push({...d}),n+=d.deletions,s+=d.additions}const h=r.deletionEnd-n;if(h<0)throw new Error("buildRegionHunks: block exceeds its old-side region");Ct(l,h,s,n),n+=h,s+=h,i.push(pn(e,{additionStart:a,additionEnd:s,deletionStart:r.deletionStart,deletionEnd:r.deletionEnd},l))}if(e.deletionLines.length-n!==e.additionLines.length-s)throw new Error("buildRegionHunks: trailing context mismatch");return i}function pn(e,t,i){const n=t.additionEnd-t.additionStart,s=t.deletionEnd-t.deletionStart;let r=0,o=0;for(const l of i)l.type==="change"&&(r+=l.additions,o+=l.deletions);const a={collapsedBefore:0,additionStart:Te(t.additionStart,n),additionCount:n,additionLines:r,additionLineIndex:Lt(t.additionStart,n),deletionStart:Te(t.deletionStart,s),deletionCount:s,deletionLines:o,deletionLineIndex:Lt(t.deletionStart,s),hunkContent:i,hunkSpecs:`@@ -${Te(t.deletionStart,s)},${s} +${Te(t.additionStart,n)},${n} @@`,splitLineStart:0,splitLineCount:0,unifiedLineStart:0,unifiedLineCount:0,noEOFCRAdditions:!1,noEOFCRDeletions:!1};return rt(a),a}function Ct(e,t,i,n){t>0&&e.push({type:"context",lines:t,additionLineIndex:i,deletionLineIndex:n})}function gn(e,t){if(e.length!==t.length)return!0;for(let i=0;i<e.length;i++){const n=e[i],s=t[i];if(oe(n)!==oe(s)||n.deletionCount!==s.deletionCount||Oe(n)!==Oe(s)||n.additionCount!==s.additionCount||n.splitLineCount!==s.splitLineCount||!mn(n,s))return!0}return!1}function mn(e,t){const i=yt(e),n=yt(t);for(;;){const s=i.next(),r=n.next();if(s.done===!0||r.done===!0)return s.done===r.done;if(s.value[0]!==r.value[0]||s.value[1]!==r.value[1])return!1}}function*yt(e){for(const t of e.hunkContent){if(t.type==="context"){for(let n=0;n<t.lines;n++)yield[t.deletionLineIndex+n,t.additionLineIndex+n];continue}const i=Math.max(t.deletions,t.additions);for(let n=0;n<i;n++)yield[n<t.deletions?t.deletionLineIndex+n:void 0,n<t.additions?t.additionLineIndex+n:void 0]}}function Oe(e){return Ee(e.additionStart,e.additionCount)}function oe(e){return Ee(e.deletionStart,e.deletionCount)}function Te(e,t){return t===0?e:e+1}function Lt(e,t){return t===0?e-1:e}function Sn(e){Ue(e);for(let t=0;t<e.hunks.length;t++)Bt(e,t)}let Cn=-1;var yn=class{options;annotationSlotName;onRenderUpdate;workerManager;__id=`diff-hunks-renderer:${++Cn}`;highlighter;diff;expandedHunks=new Map;deletionAnnotations={};additionAnnotations={};computedLangs=["text"];renderCache;pendingHighlightResult;pendingStructuralRows;editSessionActive=!1;constructor(e={theme:ce},t=Ce,i,n){this.options=e,this.annotationSlotName=t,this.onRenderUpdate=i,this.workerManager=n,n?.isWorkingPool()!==!0&&(this.highlighter=me(e.theme??ce)?Ye():void 0)}cleanUp(){this.endEditSession(),this.recycle(),this.expandedHunks.clear(),this.workerManager=void 0,this.onRenderUpdate=void 0}recycle(){this.highlighter=void 0,this.diff=void 0,this.editSessionActive?(this.renderCache!=null&&(this.renderCache.renderRange=void 0),this.pendingHighlightResult=void 0,this.pendingStructuralRows=void 0):this.clearRenderCache(),this.additionAnnotations={},this.deletionAnnotations={},this.workerManager?.cleanUpTasks(this)}beginEditSession(e,t){const{editSessionActive:i}=this;this.editSessionActive=!0,i||(this.pendingHighlightResult=void 0),this.diff=e,i&&this.renderCache!=null&&this.renderCache.diff!==e&&this.clearRenderCache();const{renderCache:n}=this;if(!e.isPartial&&e.additionLines.length===0){Object.assign(e,Pe(e,this.options.parseDiffOptions)),this.markEditSessionPass(e),this.clearRenderCache();return}if(n==null||i&&n.diff===e)return;const{options:s}=this.getRenderOptions(e),r=n.diff===e,o=t!=null&&D(n.diff,t),{result:a}=n;if(!n.highlighted||a==null||!j(n.options,s)||!r&&!o){this.clearRenderCache();return}r||(this.renderCache={diff:e,options:s,highlighted:!0,result:{...a,code:{...a.code,additionLines:[...a.code.additionLines]}},renderRange:n.renderRange})}endEditSession(){this.editSessionActive=!1,this.pendingHighlightResult=void 0,this.diff==null&&this.clearRenderCache()}editorRenderReady(){return this.renderCache?.options.useTokenTransformer===!0&&this.renderCache.highlighted&&this.renderCache.result!=null}refreshHighlightedResult(){const{diff:e,renderCache:t,workerManager:i}=this;return e==null||t==null||!D(t.diff,e)||ye(e)||Se(e,this.getTokenizeMaxLength())?Promise.resolve():!this.editSessionActive&&i?.isWorkingPool()===!0&&e.cacheKey!=null?(i.evictDiffFromCache(e.cacheKey),i.primeDiffHighlightCache(e).then(()=>{this.applyRefreshedResult(e,i.getDiffResultCache(e))}).catch(n=>this.onHighlightError(n))):this.asyncHighlight(e).then(n=>this.applyRefreshedResult(e,n)).catch(n=>this.onHighlightError(n))}applyRefreshedResult(e,t){const{diff:i,renderCache:n}=this;if(t==null||i==null||n==null||!D(i,e)||!D(n.diff,e)||this.editSessionActive)return;const{options:s}=this.getRenderOptions(i);j(s,t.options)&&(this.pendingHighlightResult={diff:i,options:t.options,highlighted:!0,result:t.result},this.onRenderUpdate?.())}get diffCache(){return this.renderCache?.diff??this.diff}clearRenderCache(){this.renderCache=void 0,this.pendingHighlightResult=void 0,this.pendingStructuralRows=void 0}setOptions(e){this.options=e}mergeOptions(e){this.options={...this.options,...e}}expandHunk(e,t,i=this.getOptionsWithDefaults().expansionLineCount){const n={...this.expandedHunks.get(e)??{fromStart:0,fromEnd:0}};(t==="up"||t==="both")&&(n.fromStart+=i),(t==="down"||t==="both")&&(n.fromEnd+=i),this.renderCache?.highlighted!==!0&&this.clearRenderCache(),this.expandedHunks.set(e,n)}getExpandedHunk(e){return this.expandedHunks.get(e)??Ai}getExpandedHunksMap(){return this.expandedHunks}setExpandedHunksMap(e){this.expandedHunks=e}setLineAnnotations(e){this.additionAnnotations={},this.deletionAnnotations={};for(const t of e){const i=(()=>{switch(t.side){case"deletions":return this.deletionAnnotations;case"additions":return this.additionAnnotations}})(),n=i[t.lineNumber]??[];i[t.lineNumber]=n,n.push(t)}}updateRenderCache(e,t,i=!1){this.pendingStructuralRows=void 0;const{renderCache:n}=this;if(n==null)return!1;const{result:s,diff:r}=n;if(s==null)return!1;if(r.isPartial)throw new Error("Could not update render cache for partial diff");const o=s.code.additionLines,a=this.pendingStructuralRows=i?new Map:void 0,l=[],h=new Map;for(const[u,c]of e){const f=o[u]?.properties??{},p=c.map(v=>v[2]).join(""),g=u<r.additionLines.length,S=g?r.additionLines[u]??"":"",C=Je(S);a==null&&g&&(r.additionLines[u]=Gt(S,p),C!==p&&(l.push(u),h.set(u,S)));const y={type:"element",tagName:"div",properties:{"data-line":f["data-line"]??u+1,"data-line-index":f["data-line-index"]??u,"data-line-type":f["data-line-type"]??"context"},children:c.map(([v,R,m])=>v===0&&R===""?m===""?{type:"element",tagName:"br",properties:{},children:[]}:{type:"text",value:m}:{type:"element",tagName:"span",properties:{"data-char":v,style:`color:${R};`},children:[{type:"text",value:m}]})};a!=null?a.set(u,y):o[u]=y}let d=!1;if(l.length>0)if(this.editSessionActive)if(r.additionLines.length<=1&&r.additionLines.join("")==="")this.applyRecomputePreservingSessionType(r,Pe(r,this.options.parseDiffOptions)),d=!0;else if(Qe(r,r.additionLines))this.applyRecomputePreservingSessionType(r,Ne(r,r.additionLines,this.options.parseDiffOptions)),d=!0;else{const u=en(r,l,this.options.parseDiffOptions,h);this.applyExpansionRemap(u),d=u!=null}else Object.assign(r,Ki(r,l,this.options.parseDiffOptions));return s.baseThemeType=t,n.isDirty=!0,d}applyExpansionRemap(e){e!=null&&(this.expandedHunks=rn(this.expandedHunks,e))}applyDocumentChange(e){const{pendingStructuralRows:t,renderCache:i}=this;this.pendingStructuralRows=void 0;const n=this.diff??i?.diff;if(n==null)return;const s=i?.result;if(n.isPartial)throw new Error("Could not apply document change for partial diff");const{additionLines:r}=n;if(n.additionLines=kn(e),s!=null&&(s.code.additionLines=Rn(r,n.additionLines,s.code.additionLines,e)),n.additionLines.length<=1&&n.additionLines.join("")===""?(this.applyRecomputePreservingSessionType(n,Pe(n,this.options.parseDiffOptions)),s!=null&&(s.code.additionLines[0]=tt(0,e.getLineText(0)))):this.editSessionActive?this.applySessionDocumentChange(n,r):Object.assign(n,Ot(n,this.options.parseDiffOptions)),t!=null&&s!=null)for(const[o,a]of t)o<s.code.additionLines.length&&(s.code.additionLines[o]=a);i!=null&&(i.isDirty=!0)}applySessionDocumentChange(e,t){const{parseDiffOptions:i}=this.options,n=e.additionLines;if(Qe(e,n)){this.applyRecomputePreservingSessionType(e,Ne(e,n,i));return}this.applyExpansionRemap(et(e,i,s=>t[s]))}applyRecomputePreservingSessionType(e,t){const i=this.editSessionActive?e.type:void 0;Object.assign(e,t),i!=null&&(e.type=i),this.markEditSessionPass(e)}markEditSessionPass(e){this.editSessionActive&&(e.editSessionDirty=!0)}getUnifiedLineDecoration({lineType:e}){return{gutterLineType:e,contentProperties:{"data-line-type":e}}}getSplitLineDecoration({side:e,type:t}){const i=t==="change"?e==="deletions"?"change-deletion":"change-addition":t;return{gutterLineType:i,contentProperties:{"data-line-type":i}}}createAnnotationElement=e=>Wt(e);getOptionsWithDefaults(){const{diffIndicators:e="bars",diffStyle:t="split",disableBackground:i=!1,disableFileHeader:n=!1,disableLineNumbers:s=!1,disableVirtualizationBuffers:r=!1,collapsed:o=!1,expandUnchanged:a=!1,collapsedContextThreshold:l=1,expansionLineCount:h=100,hunkSeparators:d="line-info",lineDiffType:u="word-alt",maxLineDiffLength:c=1e3,overflow:f="scroll",stickyHeader:p=!1,theme:g=ce,headerRenderMode:S="default",tokenizeMaxLineLength:C=1e3,tokenizeMaxLength:y=Di,useTokenTransformer:v=!1,useCSSClasses:R=!1}=this.options;return{diffIndicators:e,diffStyle:t,disableBackground:i,disableFileHeader:n,disableLineNumbers:s,disableVirtualizationBuffers:r,collapsed:o,expandUnchanged:a,collapsedContextThreshold:l,expansionLineCount:h,hunkSeparators:d,lineDiffType:u,maxLineDiffLength:c,overflow:f,stickyHeader:p,theme:this.workerManager?.getDiffRenderOptions().theme??g,headerRenderMode:S,tokenizeMaxLineLength:C,tokenizeMaxLength:y,useTokenTransformer:v,useCSSClasses:R}}async initializeHighlighter(){return this.highlighter=await bt($t(this.computedLangs,{theme:this.getLocalHighlightTheme(),preferredHighlighter:this.workerManager?.getPreferredHighlighter()??this.options.preferredHighlighter})),this.highlighter}hydrate(e){if(e==null)return;this.diff=e;const{options:t}=this.getRenderOptions(e),i=Se(e,this.getTokenizeMaxLength());let n=this.workerManager?.getDiffResultCache(e);n!=null&&!j(t,n.options)&&(n=void 0),this.renderCache??={diff:e,hydrated:!0,highlighted:!i&&!ye(e),options:t,result:i?void 0:n?.result,renderRange:void 0},!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0?this.renderCache.result==null&&!i&&this.workerManager.highlightDiffAST(this,this.diff):this.highlighter==null&&(this.computedLangs=je(e),this.initializeHighlighter())}getLocalHighlightTheme(){return this.workerManager?.getDiffRenderOptions().theme??this.options.theme??ce}getEffectiveCodeOptions(){const e=this.workerManager?.isWorkingPool()===!0?this.workerManager.getDiffRenderOptions():void 0;return{theme:this.getLocalHighlightTheme(),tokenizeMaxLineLength:e?.tokenizeMaxLineLength??this.options.tokenizeMaxLineLength}}getRenderOptions(e){const t=(()=>{if(this.workerManager?.isWorkingPool()===!0){const a=this.workerManager.getDiffRenderOptions();return this.editSessionActive&&a.useTokenTransformer!==!0?{...a,useTokenTransformer:!0}:a}const{theme:n,tokenizeMaxLineLength:s,lineDiffType:r,maxLineDiffLength:o}=this.getOptionsWithDefaults();return{theme:n,useTokenTransformer:this.editSessionActive||this.options.useTokenTransformer===!0,tokenizeMaxLineLength:s,lineDiffType:r,maxLineDiffLength:o}})();this.getOptionsWithDefaults();const{renderCache:i}=this;return i?.result==null?{options:t,forceHighlight:!0}:!D(e,i.diff)||!j(t,i.options)?{options:t,forceHighlight:!0}:{options:t,forceHighlight:!1}}getDiffForNextRender(e){const{options:t}=this.getRenderOptions(e);if(this.getReadyRenderResult(e,t)!=null||this.renderCache==null)return e;if(D(this.renderCache.diff,e))return this.renderCache.diff;const i=!(e.additionLines.length>0||e.deletionLines.length>0)||ye(e)||Se(e,this.getTokenizeMaxLength());return this.canRenderDiff(e,t,i)?e:this.renderCache.diff}canRenderDiff(e,t,i){const{renderCache:n}=this;return n==null||D(n.diff,e)?!0:i?n.result==null&&n.hydrated!==!0||this.workerManager?.isWorkingPool()===!0||this.highlighter!=null&&me(t.theme):n.result==null&&n.hydrated!==!0?!0:!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0?!n.highlighted:this.highlighter!=null&&me(t.theme)}renderDiff(e=this.diff,t=pt){if(this.diff=e,e==null){this.pendingHighlightResult=void 0;return}const{expandUnchanged:i,collapsedContextThreshold:n}=this.getOptionsWithDefaults();let{options:s,forceHighlight:r}=this.getRenderOptions(e);const o=this.getReadyRenderResult(e,s);this.pendingHighlightResult=void 0,o!=null&&(this.renderCache={...o,diff:e,renderRange:void 0},r=!1),this.renderCache??={diff:e,highlighted:!1,options:s,result:void 0,renderRange:void 0};const a=e.additionLines.length>0||e.deletionLines.length>0,l=!a||ye(e)||Se(e,this.getTokenizeMaxLength()),h=this.canRenderDiff(e,s,l),d=!D(e,this.renderCache.diff),u=!Dt(this.renderCache.renderRange,t);if(!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0){const c=this.renderCache.result==null&&this.renderCache.highlighted&&!l&&!d&&Xe(t);h&&!c&&(l||this.renderCache.result==null||!this.renderCache.highlighted&&(d||u))&&(this.renderCache.diff=e,this.renderCache.options=s,this.renderCache.highlighted=!1,(this.renderCache.result==null||d||u||r)&&(this.renderCache.result=this.workerManager.getPlainDiffAST(e,t.startingLine,t.totalLines,Xe(t)||i?!0:this.expandedHunks,n)),this.renderCache.renderRange=t),!l&&a&&(!this.renderCache.highlighted||r)&&this.workerManager.highlightDiffAST(this,e)}else{this.computedLangs=je(e),this.highlighter??=Ye();const c=this.highlighter!=null&&me(s.theme),f=this.highlighter!=null&&ft(this.computedLangs),p=!l&&f;if(h&&this.highlighter!=null&&c&&(r||l||!this.renderCache.highlighted&&p||this.renderCache.result==null)){const{result:g,options:S}=this.renderDiffWithHighlighter(e,this.highlighter,l||!f);this.renderCache={diff:e,options:S,highlighted:p,result:g,renderRange:void 0}}(!c||!l&&!f)&&this.asyncHighlight(e).then(({result:g,options:S})=>{this.applyHighlightResult(e,g,S,!l)})}return this.renderCache.result!=null?this.processDiffResult(this.renderCache.diff,t,this.renderCache.result):void 0}async asyncRender(e,t=pt){this.diff=e;const{result:i}=await this.asyncHighlight(e);return this.processDiffResult(e,t,i)}createPreElement(e,t,i){const{diffIndicators:n,disableBackground:s,disableLineNumbers:r,overflow:o}=this.getOptionsWithDefaults();return jt({type:"diff",diffIndicators:n,disableBackground:s,disableLineNumbers:r,overflow:o,split:e,totalLines:t,customProperties:i})}async asyncHighlight(e){const t=Se(e,this.getTokenizeMaxLength());this.computedLangs=t?["text"]:je(e);const i=this.highlighter!=null&&me(this.getLocalHighlightTheme()),n=t||this.highlighter!=null&&ft(this.computedLangs);return(this.highlighter==null||!i||!n)&&(this.highlighter=await this.initializeHighlighter()),this.renderDiffWithHighlighter(e,this.highlighter,t)}renderDiffWithHighlighter(e,t,i=!1){const{options:n}=this.getRenderOptions(e),{collapsedContextThreshold:s}=this.getOptionsWithDefaults(),r=ki(e,t,n,{forcePlainText:i,expandedHunks:i?!0:void 0,collapsedContextThreshold:s});if(this.editSessionActive&&e.additionLines.length===1&&e.additionLines[0]===""&&r.code.additionLines[0]==null){let o;if(pe({diff:e,diffStyle:"both",expandedHunks:i?!0:void 0,collapsedContextThreshold:s,callback:({additionLine:a})=>{if(a?.lineIndex===0)return o=a,!0}}),o==null)throw new Error("DiffHunksRenderer: missing empty addition line");r.code.additionLines[0]=tt(0,"",o.unifiedLineIndex,o.splitLineIndex)}return{result:r,options:n}}onHighlightSuccess(e,t,i,n=!0){this.editSessionActive||this.applyHighlightResult(e,t,i,n)}applyHighlightResult(e,t,i,n=!0){const{diff:s,renderCache:r}=this;s==null||r==null||!D(s,e)||!j(i,this.getRenderOptions(s).options)||(r.result==null||!r.highlighted||!j(r.options,i)||!D(r.diff,s))&&(this.pendingHighlightResult={diff:s,options:i,highlighted:n,result:t},this.onRenderUpdate?.())}getMatchingWorkerResultCache(e,t){if(this.editSessionActive)return;const i=this.workerManager?.getDiffResultCache(e);if(!(i==null||!j(t,i.options)))return i}getReadyRenderResult(e,t){const{pendingHighlightResult:i}=this;if(i!=null&&D(i.diff,e)&&j(i.options,t))return i;const n=this.getMatchingWorkerResultCache(e,t);if(!(n==null||this.hasHighlightedRenderCache(e,t)))return{diff:e,highlighted:!0,...n}}hasHighlightedRenderCache(e,t){const{renderCache:i}=this;return i?.result!=null&&i.highlighted&&D(e,i.diff)&&j(t,i.options)}onHighlightError(e){console.error(e)}getTokenizeMaxLength(){return this.options.tokenizeMaxLength??1e5}processDiffResult(e,t,{code:i,themeStyles:n,baseThemeType:s}){const{diffStyle:r,disableFileHeader:o,expandUnchanged:a,expansionLineCount:l,collapsedContextThreshold:h,hunkSeparators:d}=this.getOptionsWithDefaults(),u=this.renderCache?.isDirty??!1,c=r==="unified",f=En(e,this.options.loadDiffFiles!=null),p=!e.isPartial||f;let g=[],S=[],C=[];const y=[],{additionLines:v,deletionLines:R}=i,m={rowCount:0,hunkSeparators:d,additionsContentAST:g,deletionsContentAST:S,unifiedContentAST:C,unifiedGutterAST:we(),deletionsGutterAST:we(),additionsGutterAST:we(),expansionLineCount:l,hunkData:y,incrementRowCount(H=1){m.rowCount+=H},pushToGutter(H,x){switch(H){case"unified":m.unifiedGutterAST.children.push(x);break;case"deletions":m.deletionsGutterAST.children.push(x);break;case"additions":m.additionsGutterAST.children.push(x)}}},b=Ei({fileDiff:e,errorPrefix:"DiffHunksRenderer.processDiffResult"}),L={size:0,side:void 0,increment(){this.size+=1},flush(){if(r!=="unified"){if(this.size<=0||this.side==null){this.side=void 0,this.size=0;return}this.side==="additions"?(m.pushToGutter("additions",_(void 0,"buffer",this.size)),g?.push(Ae(this.size))):(m.pushToGutter("deletions",_(void 0,"buffer",this.size)),S?.push(Ae(this.size))),this.size=0,this.side=void 0}}},F=(H,x,X,de,E)=>{m.pushToGutter(H,yi(x,X,de,E))};function ae(H){L.flush(),r==="unified"?$e("unified",H,m):($e("deletions",H,m),$e("additions",H,m))}this.pushFileLevelAnnotations(e,r,t,m),pe({diff:e,diffStyle:r,startingLine:t.startingLine,totalLines:t.totalLines,expandedHunks:a?!0:this.expandedHunks,collapsedContextThreshold:h,callback:({hunkIndex:H,hunk:x,collapsedBefore:X,collapsedAfter:de,additionLine:E,deletionLine:w,type:T})=>{const O=w!=null?w.splitLineIndex:E.splitLineIndex,Y=E!=null?E.unifiedLineIndex:w.unifiedLineIndex;r==="split"&&T!=="change"&&L.flush(),X>0&&ae({hunkIndex:H,collapsedLines:X,rangeSize:Math.max(x?.collapsedBefore??0,0),hunkSpecs:x?.hunkSpecs,isFirstHunk:H===0,isLastHunk:!1,isExpandable:p});const he=r==="unified"?Y:O,He={type:T,hunkIndex:H,lineIndex:he,unifiedLineIndex:Y,splitLineIndex:O,deletionLine:w,additionLine:E};if(r==="unified"){const A=this.getUnifiedInjectedRowsForLine?.(He);A?.before!=null&&vt(A.before,m);let z=w!=null?R[w.lineIndex]:void 0,U=E!=null?v[E.lineIndex]:void 0;if(z==null&&U==null){const V="DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong";throw console.error(V,{file:e.name}),new Error(V)}const te=T==="change"?E!=null?"change-addition":"change-deletion":T,B=this.getUnifiedLineDecoration({type:T,lineType:te,additionLineIndex:E?.lineIndex,deletionLineIndex:w?.lineIndex});F("unified",B.gutterLineType,E!=null?E.lineNumber:w.lineNumber,`${Y},${O}`,B.gutterProperties),U!=null?U=Me(U,B.contentProperties,u&&E!=null?{"data-line":E.lineNumber,"data-line-index":`${Y},${O}`}:void 0):z!=null&&(z=Me(z,B.contentProperties,u&&w!=null?{"data-line":w.lineNumber,"data-line-index":`${Y},${O}`}:void 0)),be({diffStyle:"unified",type:T,deletionLine:z,additionLine:U,unifiedSpan:this.getAnnotations("unified",w?.lineNumber,E?.lineNumber,H,he),createAnnotationElement:V=>this.createAnnotationElement(V),context:m}),A?.after!=null&&vt(A.after,m)}else{const A=this.getSplitInjectedRowsForLine?.(He);A?.before!=null&&Rt(A.before,m,L);let z=w!=null?R[w.lineIndex]:void 0,U=E!=null?v[E.lineIndex]:void 0;const te=this.getSplitLineDecoration({side:"deletions",type:T,lineIndex:w?.lineIndex}),B=this.getSplitLineDecoration({side:"additions",type:T,lineIndex:E?.lineIndex});if(z==null&&U==null){const N="DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong";throw console.error(N,{file:e.name}),new Error(N)}const V=(()=>{if(T==="change"){if(U==null)return"additions";if(z==null)return"deletions"}})();V!=null?(L.side!=null&&L.side!==V&&L.flush(),L.side=V,L.increment()):T==="change"&&L.flush();const J=this.getAnnotations("split",w?.lineNumber,E?.lineNumber,H,he);if(J!=null&&L.size>0&&L.flush(),w!=null){const N=Me(z,te.contentProperties,u?{"data-line":w.lineNumber,"data-line-index":`${w.unifiedLineIndex},${O}`}:void 0);F("deletions",te.gutterLineType,w.lineNumber,`${w.unifiedLineIndex},${O}`,te.gutterProperties),N!=null&&(z=N)}if(E!=null){const N=Me(U,B.contentProperties,u?{"data-line":E.lineNumber,"data-line-index":`${E.unifiedLineIndex},${O}`}:void 0);F("additions",B.gutterLineType,E.lineNumber,`${E.unifiedLineIndex},${O}`,B.gutterProperties),N!=null&&(U=N)}be({diffStyle:"split",type:T,additionLine:U,deletionLine:z,...J,createAnnotationElement:N=>this.createAnnotationElement(N),context:m}),A?.after!=null&&Rt(A.after,m,L)}const ge=r==="split"&&x!=null&&O===x.splitLineStart+x.splitLineCount-1,W=H===e.hunks.length-1&&x!=null&&(r==="split"?O===x.splitLineStart+x.splitLineCount-1:Y===x.unifiedLineStart+x.unifiedLineCount-1),Be=ge?x.noEOFCRDeletions:!1,Ve=ge?x.noEOFCRAdditions:!1,ee=(w?.noEOFCR??!1)||Be,$=(E?.noEOFCR??!1)||Ve;if($||ee){if(r==="split"&&L.flush(),ee){const A=T==="context"||T==="context-expanded"?T:"change-deletion";r==="unified"?(m.unifiedContentAST.push(De(A)),m.pushToGutter("unified",_(A,"metadata",1))):(m.deletionsContentAST.push(De(A)),m.pushToGutter("deletions",_(A,"metadata",1)),$||(m.pushToGutter("additions",_(void 0,"buffer",1)),m.additionsContentAST.push(Ae(1))))}if($){const A=T==="context"||T==="context-expanded"?T:"change-addition";r==="unified"?(m.unifiedContentAST.push(De(A)),m.pushToGutter("unified",_(A,"metadata",1))):(m.additionsContentAST.push(De(A)),m.pushToGutter("additions",_(A,"metadata",1)),ee||(m.pushToGutter("deletions",_(void 0,"buffer",1)),m.deletionsContentAST.push(Ae(1))))}m.incrementRowCount(1)}d!=="simple"&&d!=="metadata"&&(de>0||W&&f)&&ae({hunkIndex:T==="context-expanded"?H:H+1,collapsedLines:W&&f?"unknown":de,rangeSize:b,hunkSpecs:void 0,isFirstHunk:!1,isLastHunk:!0,isExpandable:p}),m.incrementRowCount(1)}}),r==="split"&&L.flush();const k=Math.max(Gi(e.hunks),e.additionLines.length??0,e.deletionLines.length??0),M=t.bufferBefore>0||t.bufferAfter>0,le=!c&&e.type!=="deleted",I=!c&&e.type!=="new",G=m.rowCount>0||M;g=le&&G?g:void 0,S=I&&G?S:void 0,C=c&&G?C:void 0;const Q=this.createPreElement(S!=null&&g!=null,k);return{fileDiff:e,unifiedGutterAST:c&&G?m.unifiedGutterAST.children:void 0,unifiedContentAST:C,deletionsGutterAST:I&&G?m.deletionsGutterAST.children:void 0,deletionsContentAST:S,additionsGutterAST:le&&G?m.additionsGutterAST.children:void 0,additionsContentAST:g,hunkData:y,preNode:Q,themeStyles:n,baseThemeType:s,headerElement:o?void 0:this.renderHeader(e),totalLines:k,rowCount:m.rowCount,bufferBefore:t.bufferBefore,bufferAfter:t.bufferAfter,css:""}}renderCodeAST(e,t){const i=e==="unified"?t.unifiedGutterAST:e==="deletions"?t.deletionsGutterAST:t.additionsGutterAST,n=e==="unified"?t.unifiedContentAST:e==="deletions"?t.deletionsContentAST:t.additionsContentAST;if(i==null||n==null)return;const s=we(i);return s.properties.style=`grid-row: span ${t.rowCount}`,[s,Kt(n,t.rowCount)]}renderFullAST(e,t=[]){const i=this.getOptionsWithDefaults().hunkSeparators==="line-info",n=this.renderCodeAST("unified",e);if(n!=null)return t.push(P({tagName:"code",children:n,properties:{"data-code":"","data-container-size":i?"":void 0,"data-unified":""}})),{...e.preNode,children:t};const s=this.renderCodeAST("deletions",e);s!=null&&t.push(P({tagName:"code",children:s,properties:{"data-code":"","data-container-size":i?"":void 0,"data-deletions":""}}));const r=this.renderCodeAST("additions",e);return r!=null&&t.push(P({tagName:"code",children:r,properties:{"data-code":"","data-container-size":i?"":void 0,"data-additions":""}})),{...e.preNode,children:t}}renderFullHTML(e,t=[]){return ne(this.renderFullAST(e,t))}renderPartialHTML(e,t){return t==null?ne(e):ne(P({tagName:"code",children:e,properties:{"data-code":"","data-container-size":this.getOptionsWithDefaults().hunkSeparators==="line-info"?"":void 0,[`data-${t}`]:""}}))}pushFileLevelAnnotations(e,t,i,n){if(!Tt(i))return;const s=e.type!=="new"?this.getAnnotationNames(ot(this.deletionAnnotations)):[],r=e.type!=="deleted"?this.getAnnotationNames(ot(this.additionAnnotations)):[];if(s.length===0&&r.length===0)return;const o=-1,a=-1,{createAnnotationElement:l}=this;if(t==="unified"){be({diffStyle:t,type:"context",unifiedSpan:{type:"annotation",hunkIndex:o,lineIndex:a,annotations:s.concat(r)},createAnnotationElement:l,context:n});return}be({diffStyle:t,type:"context",deletionSpan:{type:"annotation",hunkIndex:o,lineIndex:a,annotations:s},additionSpan:{type:"annotation",hunkIndex:o,lineIndex:a,annotations:r},createAnnotationElement:l,context:n})}getAnnotations(e,t,i,n,s){const r={type:"annotation",hunkIndex:n,lineIndex:s,annotations:[]};if(t!=null)for(const a of this.deletionAnnotations[t]??[])r.annotations.push(this.annotationSlotName(a));const o={type:"annotation",hunkIndex:n,lineIndex:s,annotations:[]};if(i!=null)for(const a of this.additionAnnotations[i]??[])(e==="unified"?r:o).annotations.push(this.annotationSlotName(a));if(e==="unified")return r.annotations.length>0?r:void 0;if(!(o.annotations.length===0&&r.annotations.length===0))return{deletionSpan:r,additionSpan:o}}getAnnotationNames(e){return e?.map(t=>this.annotationSlotName(t))??[]}renderHeader(e){const{headerRenderMode:t,stickyHeader:i}=this.getOptionsWithDefaults();return qt({fileOrDiff:e,mode:t,stickyHeader:i})}};const Ln=new Intl.PluralRules("en-US");function vn(e){return`${e} unmodified line${Ln.select(e)==="one"?"":"s"}`}function vt(e,t){for(const i of e)t.unifiedContentAST.push(i.content),t.pushToGutter("unified",i.gutter),t.incrementRowCount(1)}function Rt(e,t,i){for(const{deletion:n,addition:s}of e){if(n==null&&s==null)continue;const r=n!=null&&s!=null?void 0:n==null?"deletions":"additions";(r==null||i.side!==r)&&i.flush(),n!=null&&(t.deletionsContentAST.push(n.content),t.pushToGutter("deletions",n.gutter)),s!=null&&(t.additionsContentAST.push(s.content),t.pushToGutter("additions",s.gutter)),r!=null&&(i.side=r,i.increment()),t.incrementRowCount(1)}}function be({diffStyle:e,type:t,deletionLine:i,additionLine:n,unifiedSpan:s,deletionSpan:r,additionSpan:o,createAnnotationElement:a,context:l}){let h=!1;if(e==="unified"){if(n!=null?l.unifiedContentAST.push(n):i!=null&&l.unifiedContentAST.push(i),s!=null){const d=t==="change"?i!=null?"change-deletion":"change-addition":t;l.unifiedContentAST.push(a(s)),l.pushToGutter("unified",_(d,"annotation",1)),h=!0}}else if(e==="split"){if(i!=null&&l.deletionsContentAST.push(i),n!=null&&l.additionsContentAST.push(n),r!=null){const d=t==="change"?i!=null?"change-deletion":"context":t;l.deletionsContentAST.push(a(r)),l.pushToGutter("deletions",_(d,"annotation",1)),h=!0}if(o!=null){const d=t==="change"?n!=null?"change-addition":"context":t;l.additionsContentAST.push(a(o)),l.pushToGutter("additions",_(d,"annotation",1)),h=!0}}h&&l.incrementRowCount(1)}function $e(e,{hunkIndex:t,collapsedLines:i,rangeSize:n,hunkSpecs:s,isFirstHunk:r,isLastHunk:o,isExpandable:a},l){if(typeof i=="number"&&i<=0)return;const h=e==="unified"?l.unifiedContentAST:e==="deletions"?l.deletionsContentAST:l.additionsContentAST;if(l.hunkSeparators==="metadata"){s!=null&&(l.pushToGutter(e,ue({type:"metadata",content:s,isFirstHunk:r,isLastHunk:o})),h.push(ue({type:"metadata",content:s,isFirstHunk:r,isLastHunk:o})),e!=="additions"&&l.incrementRowCount(1));return}if(l.hunkSeparators==="simple"){t>0&&(l.pushToGutter(e,ue({type:"simple",isFirstHunk:r,isLastHunk:!1})),h.push(ue({type:"simple",isFirstHunk:r,isLastHunk:!1})),e!=="additions"&&l.incrementRowCount(1));return}const d=_i(e,t),u=n>l.expansionLineCount,c=a?t:void 0,f=typeof i=="number"?vn(i):"More unchanged context may be available";l.pushToGutter(e,ue({type:l.hunkSeparators,content:f,expandIndex:c,chunked:u,slotName:d,isFirstHunk:r,isLastHunk:o})),h.push(ue({type:l.hunkSeparators,content:f,expandIndex:c,chunked:u,slotName:d,isFirstHunk:r,isLastHunk:o})),e!=="additions"&&l.incrementRowCount(1),l.hunkData.push({slotName:d,hunkIndex:t,lines:typeof i=="number"?i:0,lineCountKnown:typeof i=="number",type:e,expandable:a?{up:!r,down:!o,chunked:u}:void 0})}function Me(e,t,i){return e==null||e.type!=="element"||t==null&&i==null?e:{...e,properties:{...e.properties,...t,...i}}}function kt(e){return e.length>0&&e[e.length-1]===""?e.length-1:e.length}function Rn(e,t,i,n){const s=kt(e),r=kt(t),o=Math.min(s,r);let a=0;for(;a<o&&e[a]===t[a];)a++;let l=0;for(;l<o-a&&e[s-1-l]===t[r-1-l];)l++;const h=new Array(t.length);for(let d=0;d<a;d++)h[d]=i[d];for(let d=0;d<l;d++)h[r-1-d]=i[s-1-d];s<e.length&&r<t.length&&(h[t.length-1]=i[e.length-1]);for(let d=a;d<t.length;d++)h[d]??=tt(d,n.getLineText(d));return h}function tt(e,t,i=e,n=e){return{type:"element",tagName:"div",properties:{"data-line":e+1,"data-line-index":`${i},${n}`,"data-line-type":"context"},children:[{type:"element",tagName:"span",properties:{"data-char":0},children:[{type:"text",value:t}]}]}}function kn(e){const t=[];for(let i=0;i<e.lineCount;i++)t.push(e.getLineText(i,!0));return t}function je(e){if(e.lang!=null)return[e.lang];const t=ve(e.prevName??e.name),i=ve(e.name);return t===i?[i]:[t,i]}function Se(e,t){return Math.max(e.additionLines.length,e.deletionLines.length)>t}function En(e,t){return e.isPartial&&t&&(e.type==="change"||e.type==="rename-changed")}function Hn(e,t){return e.lineNumber===t.lineNumber&&e.side===t.side&&e.metadata===t.metadata}function xn(e,t){return e.slotName===t.slotName&&e.hunkIndex===t.hunkIndex&&e.lines===t.lines&&e.lineCountKnown===t.lineCountKnown&&e.type===t.type&&e.expandable?.chunked===t.expandable?.chunked&&e.expandable?.up===t.expandable?.up&&e.expandable?.down===t.expandable?.down}async function it(e,t=300){let i;try{await Promise.race([e(),new Promise(n=>{i=setTimeout(n,t)})])}finally{i!=null&&clearTimeout(i)}}function nt({oldFile:e,newFile:t},i){if(!(e===void 0&&t===void 0)){if(e===void 0||t===void 0)throw new Error(`${i}: Pass null for an intentionally missing oldFile or newFile side`);if(e===null){if(t===null)throw new Error(`${i}: You must pass oldFile, newFile, or both`);return{oldFile:e,newFile:t}}return t===null?{oldFile:e,newFile:t}:{oldFile:e,newFile:t}}}function wn(e){return{theme:e?.theme,disableLineNumbers:e?.disableLineNumbers,overflow:e?.overflow,collapsed:e?.collapsed,disableFileHeader:e?.disableFileHeader,disableVirtualizationBuffers:e?.disableVirtualizationBuffers,stickyHeader:e?.stickyHeader,preferredHighlighter:e?.preferredHighlighter,useCSSClasses:e?.useCSSClasses,useTokenTransformer:Xt(e),tokenizeMaxLineLength:e?.tokenizeMaxLineLength,tokenizeMaxLength:e?.tokenizeMaxLength,diffStyle:e?.diffStyle,diffIndicators:e?.diffIndicators,disableBackground:e?.disableBackground,hunkSeparators:typeof e?.hunkSeparators=="function"?"custom":e?.hunkSeparators,expandUnchanged:e?.expandUnchanged,loadDiffFiles:e?.loadDiffFiles,collapsedContextThreshold:e?.collapsedContextThreshold,lineDiffType:e?.lineDiffType,maxLineDiffLength:e?.maxLineDiffLength,expansionLineCount:e?.expansionLineCount,headerRenderMode:e?.renderCustomHeader!=null?"custom":"default"}}function Ke(e){return e.isPartial&&(e.type==="change"||e.type==="rename-changed"||e.type==="rename-pure")}function An(e){const t={...e};return delete t.cacheKey,t}function Et(e,t){if(e.isPartial||t.isPartial)throw new Error("FileDiff.shouldResetEditorForExternalDiff: diffs must be fully hydrated");const i=e.lang??ve(e.name),n=t.lang??ve(t.name),s=e.type!=="new",r=t.type!=="new";return e.name!==t.name||i!==n||s!==r||e.deletionLines.length!==t.deletionLines.length?!0:e.deletionLines.some((o,a)=>o!==t.deletionLines[a])}function Dn(e,t){return e.length===t.length&&e.every((i,n)=>i===t[n])}function Tn(e,t){const{oldFile:i}=e;return i==null?t.type==="new":t.type!=="new"&&i.name===(t.prevName??t.name)&&Dn(i.lines,t.deletionLines)}let bn=-1;var Mn=class{options;workerManager;isContainerManaged;static LoadedCustomComponent=!0;__id=`file-diff:${++bn}`;type="file-diff";fileContainer;spriteSVG;pre;codeUnified;codeDeletions;codeAdditions;bufferBefore;bufferAfter;themeCSSStyle;appliedThemeCSS;hasAdoptedThemeCSS=!1;unsafeCSSStyle;appliedUnsafeCSS;gutterUtilityContent;headerElement;headerPrefix;headerFilenameSuffix;headerMetadata;headerCustom;separatorCache=new Map;errorWrapper;placeHolder;hunksRenderer;resizeManager;scrollSyncManager;interactionManager;annotationCache=new Map;lineAnnotations=[];managersDirty=!1;deletionFile;additionFile;fileDiff;editSession;renderedDiff;renderRange;pendingFiles;appliedPreAttributes;headerCache={lastRenderedHTML:void 0,html:void 0,fileDiff:void 0};lastRowCount;mounted=!1;enabled=!0;editor;refreshViewTimeout;lineStateRefreshPending=!1;deferredSelectedLines;deferredEditorActiveLine;constructor(e={theme:ce},t,i=!1){this.options=e,this.workerManager=t,this.isContainerManaged=i,this.hunksRenderer=this.createHunksRenderer(e),this.resizeManager=new Yt,this.scrollSyncManager=new Vi,this.interactionManager=new Jt("diff",at(e,typeof e.hunkSeparators=="function"||(e.hunkSeparators??"line-info")==="line-info"||e.hunkSeparators==="line-info-basic"?this.handleExpandHunk:void 0,this.getLineIndex)),this.workerManager?.subscribeToThemeChanges(this),this.enabled=!0}handleHighlightRender=()=>{this.rerender()};getTheme(){return this.workerManager?.getDiffRenderOptions().theme??this.options.theme??ce}getHunksRendererOptions(e){return wn(e)}createHunksRenderer(e){return new yn(this.getHunksRendererOptions(e),this.getAnnotationSlotName,this.handleHighlightRender,this.workerManager)}getLineIndex=(e,t="additions")=>this.getLineIndexForDiff(this.getDiffForLineIndex(),e,t);getDiffForLineIndex(){return this.getRenderedDiff()}getLineIndexForDiff(e,t,i){if(e==null)return;const n=e.hunks.at(-1);let s,r;e:for(const o of e.hunks){const a=i==="deletions"?o.deletionStart:o.additionStart,l=i==="deletions"?o.deletionCount:o.additionCount;let h=Ee(a,l)+1,d=o.splitLineStart,u=o.unifiedLineStart;if(t<h){const c=h-t;s=Math.max(u-c,0),r=Math.max(d-c,0);break e}if(t>=h+l){if(o===n){const c=t-(h+l);s=u+o.unifiedLineCount+c,r=d+o.splitLineCount+c;break e}continue}for(const c of o.hunkContent)if(c.type==="context")if(t<h+c.lines){const f=t-h;r=d+f,s=u+f;break e}else h+=c.lines,d+=c.lines,u+=c.lines;else{const f=i==="deletions"?c.deletions:c.additions;if(t<h+f){const p=t-h;s=u+(i==="additions"?c.deletions:0)+p,r=d+p;break e}else h+=f,d+=Math.max(c.deletions,c.additions),u+=c.deletions+c.additions}break e}if(!(s==null||r==null))return[s,r]}setOptions(e){e!=null&&(this.options=e,this.clearReusableHeader(),this.hunksRenderer.setOptions(this.getHunksRendererOptions(e)),this.syncInteractionOptions())}syncInteractionOptions(){this.interactionManager.setOptions(at(this.options,typeof this.options.hunkSeparators=="function"||(this.options.hunkSeparators??"line-info")==="line-info"||this.options.hunkSeparators==="line-info-basic"?this.handleExpandHunk:void 0,this.getLineIndex))}mergeOptions(e){this.options={...this.options,...e}}setThemeType(e){(this.options.themeType??"system")!==e&&(this.mergeOptions({themeType:e}),this.applyCachedThemeState(e))}applyCachedThemeState(e){if(typeof this.options.theme=="string"||this.fileContainer==null||this.appliedThemeCSS==null)return!1;const t=this.appliedThemeCSS.baseThemeType??e;return this.appliedThemeCSS.themeType===t?!1:(this.applyThemeState(this.fileContainer,this.appliedThemeCSS.themeStyles,e,this.appliedThemeCSS.baseThemeType),!0)}hasThemeChanged(){return this.appliedThemeCSS!=null&&!Li(this.appliedThemeCSS.theme,this.getTheme())}getHoveredLine=()=>this.interactionManager.getHoveredLine();getAnnotationSlotName=e=>Zt(this.editSession?.annotations,e,Ce);getLatestAnnotations(){return this.editSession?.annotations?.current??this.lineAnnotations}isNewAnnotations(e){const t=this.editSession?.annotations;return e===this.lineAnnotations?!1:t==null||e!==t.provided&&e!==t.current}setLineAnnotations(e){const t=this.editSession?.annotations;if(t==null){this.lineAnnotations=e;return}this.isNewAnnotations(e)&&(this.lineAnnotations=e,Qt(t,e,Ce))}syncEditSessionAnnotationsFromEditor(e){const t=this.editSession?.annotations;return t==null||e===t.current?!1:(t.current=e,this.hunksRenderer.setLineAnnotations(e),this.renderAnnotations(),!0)}canPartiallyRender(e,t,i){return!(e||t||i||typeof this.options.hunkSeparators=="function")}setSelectedLines(e,t){this.lineStateRefreshPending?this.deferredSelectedLines=[e,t]:this.interactionManager.setSelection(e,t)}setEditorActiveLine(e,t){this.lineStateRefreshPending?this.deferredEditorActiveLine=[e,t]:this.interactionManager.setEditorActiveLine(e,{lineNumberOnly:t?.lineNumberOnly,side:t?.side??"additions"})}flushDeferredLineState(){const{deferredEditorActiveLine:e,deferredSelectedLines:t}=this;this.lineStateRefreshPending=!1,this.deferredEditorActiveLine=void 0,this.deferredSelectedLines=void 0,e!=null&&this.setEditorActiveLine(...e),t!=null&&this.interactionManager.setSelection(...t)}flushManagers(){if(!this.managersDirty||this.pre==null){this.managersDirty=!1;return}const{diffStyle:e="split",overflow:t="scroll"}=this.options;this.interactionManager.setup(this.pre),this.resizeManager.setup(this.pre,{disableAnnotations:t==="wrap",columnVariables:this.shouldApplyColumnVariables(t)?"apply":"measure"}),t==="scroll"&&e==="split"?this.scrollSyncManager.setup(this.pre,this.codeDeletions,this.codeAdditions):this.scrollSyncManager.cleanUp(),this.managersDirty=!1}shouldApplyColumnVariables(e){return typeof this.options.hunkSeparators=="function"?!0:e==="scroll"&&(this.getLatestAnnotations().length>0||this.pre?.hasAttribute("data-has-merge-conflict")===!0)}getCodeScrollLeft(){return Math.max(this.codeUnified?.scrollLeft??0,this.codeDeletions?.scrollLeft??0,this.codeAdditions?.scrollLeft??0)}setCodeScrollLeft(e){this.codeUnified!=null&&(this.codeUnified.scrollLeft=e),this.codeAdditions!=null&&(this.codeAdditions.scrollLeft=e),this.codeDeletions!=null&&(this.codeDeletions.scrollLeft=e)}__getEffectiveCodeOptions(){return{...this.options,...this.hunksRenderer.getEffectiveCodeOptions()}}cleanUp(e=!1){const{editor:t}=this;ei(this.handleEditSessionRender),this.emitPostRender(!0),t?.cleanUp(e?"recycle":"discard"),e||(this.editor=void 0),this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.managersDirty=!1,this.workerManager?.unsubscribeToThemeChanges(this),this.renderRange=void 0,e||(this.pendingFiles=void 0),this.isContainerManaged||this.fileContainer?.remove(),this.fileContainer=void 0,this.mounted=!1,e||(this.lineAnnotations=[]),this.clearAuxiliaryNodes(),this.annotationCache.clear(),this.pre=void 0,this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0,this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.appliedPreAttributes=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.placeHolder?.remove(),this.placeHolder=void 0,this.headerCache.lastRenderedHTML=void 0,e||this.clearReusableHeader(),this.errorWrapper?.remove(),this.errorWrapper=void 0,this.spriteSVG=void 0,this.lastRowCount=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,e?this.hunksRenderer.recycle():(this.hunksRenderer.cleanUp(),this.workerManager=void 0,this.fileDiff=void 0,this.editSession=void 0,this.renderedDiff=void 0,this.deletionFile=void 0,this.additionFile=void 0),this.refreshViewTimeout!=null&&(clearTimeout(this.refreshViewTimeout),this.refreshViewTimeout=void 0),this.lineStateRefreshPending=!1,this.deferredEditorActiveLine=void 0,this.deferredSelectedLines=void 0,this.enabled=!1}virtualizedSetup(){this.enabled=!0,this.workerManager?.subscribeToThemeChanges(this)}hydrate({fileContainer:e,prerenderedHTML:t,preventEmit:i=!1,lineAnnotations:n,fileDiff:s,...r}){if(!this.enabled)throw new Error("FileDiff.hydrate: attempting to call hydrate after cleaned up");if(this.fileContainer!=null)throw new Error("FileDiff.hydrate: hydrate can only be called before the instance has rendered or hydrated");const o=nt(r,"FileDiff.hydrate"),a=o?.oldFile,l=o?.newFile;this.hydrateElements(e,t);const h=this.editor!=null;h||zn(this.pre,In({fileDiff:s,oldFile:a,newFile:l}),this.options.collapsed)||Nn(this.headerElement,Pn({fileDiff:s,oldFile:a,newFile:l}),this.options.disableFileHeader)?this.render({...r,fileContainer:e,lineAnnotations:n,fileDiff:s,forceRender:h||r.forceRender,preventEmit:!0}):this.hydrationSetup({fileDiff:s,lineAnnotations:n,...o}),i||this.emitPostRender()}hydrateElements(e,t){this.fileContainer!==e&&this.emitPostRender(!0),ti(e,t);for(const i of e.shadowRoot?.children??[]){if(i instanceof SVGElement){this.spriteSVG=i;continue}if(i instanceof HTMLElement){if(i instanceof HTMLPreElement){this.pre=i;for(const n of i.children)!(n instanceof HTMLElement)||n.tagName.toLowerCase()!=="code"||("deletions"in n.dataset&&(this.codeDeletions=n),"additions"in n.dataset&&(this.codeAdditions=n),"unified"in n.dataset&&(this.codeUnified=n));continue}if("diffsHeader"in i.dataset){this.headerElement=i;continue}if(i instanceof HTMLStyleElement&&i.hasAttribute("data-theme-css")){this.themeCSSStyle=i;continue}if(i instanceof HTMLStyleElement&&i.hasAttribute("data-unsafe-css")){this.unsafeCSSStyle=i,this.appliedUnsafeCSS=i.textContent;continue}}}this.pre!=null&&(this.syncCodeNodesFromPre(this.pre),this.pre.removeAttribute("data-dehydrated")),this.fileContainer=e,this.hydrateMeasuredScrollbar()}hydrationSetup({fileDiff:e,oldFile:t,newFile:i,lineAnnotations:n}){this.lineAnnotations=n??this.lineAnnotations,this.additionFile=i,this.deletionFile=t,this.fileDiff=e??(t!==void 0&&i!==void 0?se(t,i,this.options.parseDiffOptions):void 0),this.pre!=null&&(this.syncInteractionOptions(),this.hunksRenderer.hydrate(this.fileDiff),this.renderedDiff=this.fileDiff,this.renderAnnotations(),this.renderGutterUtility(),this.injectUnsafeCSS(),this.managersDirty=!0,this.flushManagers())}rerender(){!this.enabled||this.fileDiff==null&&this.additionFile==null&&this.deletionFile==null||this.render({forceRender:!0,renderRange:this.renderRange})}onThemeChange(){this.hunksRenderer.clearRenderCache(),this.rerender()}handleExpandHunk=(e,t,i)=>{this.expandHunk(e,t,i)};expandHunk=(e,t,i)=>{this.loadFilesIfNecessary(),this.hunksRenderer.expandHunk(e,t,i),this.rerender()};loadFilesIfNecessary(){const{fileDiff:e,options:{loadDiffFiles:t}}=this;if(e==null||!Ke(e)||this.pendingFiles?.fileDiff===e)return;if(t==null)throw new Error("FileDiff: loadDiffFiles is required to load full files for a partial diff");const i=this.loadFilesForDiff(e,t),n=this.pendingFiles={fileDiff:e,promise:i},s=()=>{this.pendingFiles===n&&(this.pendingFiles=void 0)};n.promise=i.finally(s)}__canAttachEditor(){return this.fileDiff!=null&&!this.fileDiff.isPartial}async prepareForEditing(){if(this.__canAttachEditor())return;const e=this.__prepareForEditing();if(e==null)throw this.fileDiff?.isPartial===!0&&!Ke(this.fileDiff)?new Error("FileDiff.prepareForEditing: this partial diff cannot be hydrated; provide a complete diff"):new Error("FileDiff.prepareForEditing: a partial diff requires loadDiffFiles");if(await e,!this.__canAttachEditor())throw new Error("FileDiff.prepareForEditing: the diff did not finish loading")}__prepareForEditing(){if(!this.__canAttachEditor()){if(this.fileDiff?.isPartial===!0&&!Ke(this.fileDiff))throw new Error("FileDiff: this partial diff cannot be hydrated; provide a complete diff to edit");return this.loadFilesIfNecessary(),this.pendingFiles?.promise}}async loadFilesForDiff(e,t){try{const i=await t(e);if(this.fileDiff!==e)return;await this.handleFilesLoaded(e,i)}catch(i){if(this.options.disableErrorHandling===!0)throw i;console.error(i)}}async handleFilesLoaded(e,t){if(!(this.fileDiff!==e||!e.isPartial)){if(Ze("merge",e,t),this.setHydratedState(t),this.installHydratedSessionDiff(e)){this.rerender();return}await it(()=>this.primeHighlightCache(e)),!(!this.enabled||this.fileDiff!==e)&&this.rerender()}}installHydratedSessionDiff(e){if(e.isPartial)throw new Error("FileDiff.installHydratedSessionDiff: diffs cannot be partial for editing");return this.fileDiff!==e?!1:this.editSession?.outgoingDiff!=null?(this.installEditSession(e),!0):!1}updateExternalDiff(e,t){if(D(this.fileDiff,e))return!1;const i=this.editSession?.outgoingDiff??this.editSession?.diff;return this.fileDiff=e,i!=null&&(e.isPartial?this.loadFilesIfNecessary():this.installEditSession(e),this.editSession!=null&&(this.editSession.outgoingDiff=i)),this.editSession?.annotations!=null&&t!=null&&(this.lineAnnotations=t,this.editSession.annotations=lt(t,Ce,this.editSession.annotations)),!0}installEditSession(e,t,i){const n=e.additionLines.join(""),s=t!=null?ze(t.contents):void 0,r=i!=null&&Tn(i,e);if(i!=null&&!r)throw new Error("FileDiff: retained session cannot resume against a different old file");if(t!=null&&t.contents!==n&&!r)throw new Error("FileDiff: retained edits are missing their diff session state");const o=t==null||t.name===e.name&&t.lang===e.lang&&t.contents===n,a=An(e);t!=null&&s!=null&&!o&&(a.name=t.name,a.lang=t.lang),r&&i!=null&&s!=null&&(a.additionLines=s,a.type=i.type,a.hunks=i.hunks,a.editSessionDirty=!0,Ue(a)),this.editSession={diff:a,annotations:this.editSession?.annotations??lt(this.lineAnnotations,Ce),outgoingDiff:this.editSession?.outgoingDiff},this.hunksRenderer.beginEditSession(a,o&&!r?e:void 0)}setHydratedState(e){this.deletionFile=e.oldFile,this.additionFile=e.newFile,this.workerManager?.cleanUpTasks(this.hunksRenderer),this.hunksRenderer.clearRenderCache()}render({fileDiff:e,deferManagers:t=!1,forceRender:i=!1,preventEmit:n=!1,lineAnnotations:s,fileContainer:r,containerWrapper:o,renderRange:a,...l}){if(!this.enabled)throw new Error("FileDiff.render: attempting to call render after cleaned up");const h=nt(l,"FileDiff.render"),d=h?.oldFile,u=h?.newFile;this.editor?.__postponeBgTokenizeToNextFrame();const{collapsed:c=!1,themeType:f="system",expandUnchanged:p=!1}=this.options,g=c?void 0:a,S=this.hasThemeChanged(),C=h!=null,y=C&&(!Ht(d,this.deletionFile)||!Ht(u,this.additionFile));let v=e!=null&&!D(e,this.fileDiff);const R=s!=null&&(s.length>0||this.getLatestAnnotations().length>0)?this.isNewAnnotations(s):!1;if(!c&&Dt(g,this.renderRange)&&!i&&!R&&!S&&(e!=null&&!v||e==null&&!y)){const k=this.applyCachedThemeState(f);return k&&this.finalizeRender(),k}let m;e==null&&C&&(y||this.fileDiff==null)&&(m=se(h.oldFile,h.newFile,this.options.parseDiffOptions));const{renderRange:b}=this;this.renderRange=g,C?(this.deletionFile=d,this.additionFile=u):e!=null&&(this.deletionFile=void 0,this.additionFile=void 0),e!=null&&v?this.updateExternalDiff(e,s):m!=null&&(v=!0,this.updateExternalDiff(m,s)),v&&this.clearReusableHeader(),s!=null&&this.setLineAnnotations(s);const L=this.getLatestDiff();if(L==null)return!1;L.editSessionDirty===!0&&this.shouldSelfHealEditSession()&&(St(L,this.options.parseDiffOptions),this.hunksRenderer.refreshHighlightedResult()),p&&this.loadFilesIfNecessary(),this.hunksRenderer.setOptions(this.getHunksRendererOptions(this.options)),this.syncInteractionOptions(),this.hunksRenderer.setLineAnnotations(this.getLatestAnnotations());const{disableErrorHandling:F=!1,disableFileHeader:ae=!1}=this.options;if(ae&&(this.headerElement!=null&&(this.headerElement.remove(),this.headerElement=void 0,this.headerCache.lastRenderedHTML=void 0),this.clearHeaderSlots()),r=this.getOrCreateFileContainer(r,o),this.applyCachedThemeState(f),c){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{const k=this.hunksRenderer.renderDiff(L,Ti);k!=null&&this.applyThemeState(r,k.themeStyles,f,k.baseThemeType),k?.headerElement!=null&&this.applyHeaderToDOM(k.headerElement,r,k.fileDiff),this.renderSeparators([]),this.renderedDiff=k?.fileDiff??L,this.injectUnsafeCSS()}catch(k){if(F)throw k;console.error(k),k instanceof Error&&this.applyErrorToDOM(k,r)}return this.finalizeRender(),n||this.emitPostRender(),!0}try{const k=this.getOrCreatePreNode(r);if(!(this.canPartiallyRender(i,R,y||v||S||!D(this.renderedDiff,L))&&this.applyPartialRender({fileDiff:L,previousRenderRange:b,renderRange:g}))){const M=this.hunksRenderer.renderDiff(L,g);if(M==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.isWorkingPool()&&this.workerManager.initialize().catch(()=>{}).then(()=>this.rerender()),!1;this.applyThemeState(r,M.themeStyles,f,M.baseThemeType),M.headerElement!=null&&this.applyHeaderToDOM(M.headerElement,r,M.fileDiff),M.additionsContentAST!=null||M.deletionsContentAST!=null||M.unifiedContentAST!=null?this.applyHunksToDOM(k,M):this.pre!=null&&(this.pre.remove(),this.pre=void 0),this.renderSeparators(M.hunkData),this.renderedDiff=M.fileDiff}this.applyBuffers(k,g),this.injectUnsafeCSS(),this.renderAnnotations(),this.renderGutterUtility(),this.managersDirty=!0,t||this.flushManagers(),this.finalizeRender(),this.editor!=null&&this.syncRenderViewToEditor()}catch(k){if(F)throw k;console.error(k),k instanceof Error&&this.applyErrorToDOM(k,r)}return n||this.emitPostRender(),!0}finalizeRender(){}emitPostRender(e=!1){const{fileContainer:t,options:{onPostRender:i}}=this;if(e){if(!this.mounted||(this.mounted=!1,t==null))return;this.options.onPostRender?.(t,this,"unmount");return}if(t==null)return;const n=this.mounted?"update":"mount";this.mounted=!0,i?.(t,this,n)}getLatestDiff(e=this.fileDiff){return this.editSession?.diff??e}getRenderedDiff(){return this.renderedDiff}syncRenderViewToEditor(){const{editor:e,fileContainer:t}=this,i=this.getLatestAnnotations(),n=this.computeEditorRenderRange(this.renderRange),s=this.getLatestDiff();if(e==null||t==null||s==null||s.isPartial)return;const r=h=>{if(!this.enabled||this.editor!==e||this.fileContainer!==t||this.getLatestDiff()!==s)return;const d=this.editSession?.outgoingDiff,{fileDiff:u}=this,c=d!=null&&u!=null&&d!==s,f=c&&d!=null&&u!=null?Et(d,u):!1;e.__syncRenderView({highlighter:h,fileContainer:t,fileDiff:s,lineAnnotations:i,renderRange:n,externalDocument:c,resetHistory:f})},o=this.getTheme(),a=s.lang??ve(s.name),l=Ye({theme:o,lang:a});l!=null?r(l):bt({themes:vi(o),langs:["text",a],preferredHighlighter:this.workerManager?.getPreferredHighlighter()??this.options.preferredHighlighter}).then(r)}computeEditorRenderRange(e){const t=this.getLatestDiff();if(e==null||t==null||Xe(e))return e;const{diffStyle:i="split",expandUnchanged:n=!1,collapsedContextThreshold:s=1}=this.options;let r,o;return pe({diff:t,diffStyle:i,startingLine:e.startingLine,totalLines:e.totalLines,expandedHunks:n?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:s,callback:({additionLine:a})=>{a!=null&&(r??=a.lineNumber,o=a.lineNumber)}}),r==null||o==null?{...e,startingLine:0,totalLines:0}:{...e,startingLine:r-1,totalLines:o-r+1}}__acknowledgeDocumentUpdate(){this.editSession!=null&&(this.editSession.outgoingDiff=void 0)}__acceptEditorChange(e){const{lineAnnotations:t}=e;t!=null&&this.syncEditSessionAnnotationsFromEditor(t)}emitEditChange(e){const{onEditChange:t}=this.options;t?.(e)}__captureDocumentSessionState(e=!0){let{fileDiff:t,editSession:{diff:i,outgoingDiff:n}={}}=this;if(n!=null&&t!=null){if(!t.isPartial&&Et(n,t))return;i=n}if(!(i==null||i.isPartial))return{diffSession:{oldFile:i.type!=="new"?{name:i.prevName??i.name,lines:e?[...i.deletionLines]:i.deletionLines}:null,type:i.type,hunks:e?Pt(i.hunks):i.hunks},hasChanges:i.editSessionDirty===!0}}__attachEditor(e){if(this.type!=="file-diff")throw new Error(`FileDiff.__attachEditor: cannot attach an editor to a "${this.type}" diff`);if(this.editor!=null)throw new Error("FileDiff.__attachEditor: an editor is already attached");if(!this.__canAttachEditor())throw new Error("FileDiff.__attachEditor: a complete diff is required before editing");const t=()=>{this.editor=void 0,this.finishEditSession()};try{return this.resumeEditorRendering(e),t}catch(i){throw t(),i}}__resumeEditor(e){if(this.editor!==e)throw new Error("FileDiff.__resumeEditor: editor association changed");this.resumeEditorRendering(e)}resumeEditorRendering(e){const{fileDiff:t}=this,i=this.editSession?.outgoingDiff;i!=null&&t!=null&&!t.isPartial&&this.editSession?.diff===i&&this.installEditSession(t);const n=this.editSession==null&&t!=null&&!t.isPartial?t:void 0;n!=null?this.installEditSession(n,e.__getDocumentContents(Fn(n)),e.__getDocumentSessionState()):this.editSession!=null&&this.hunksRenderer.beginEditSession(this.editSession.diff),this.editor=e,this.fileDiff?.isPartial===!0&&this.loadFilesIfNecessary();const s=this.editSession?.diff;this.hunksRenderer.editorRenderReady()?(s!=null&&this.hunksRenderer.diffCache===s&&(this.renderedDiff=s),this.syncRenderViewToEditor()):this.rerender()}finishEditSession(){this.hunksRenderer.endEditSession(),this.finalizeEditSessionHunks()}__completeEditSession(e,t){this.settleEditSession(t==="install",e)}settleEditSession(e,t){const{editSession:i,fileDiff:n,lineAnnotations:s}=this;if(i==null||n==null)return;const{diff:r,annotations:o}=i;if(this.editor!=null)throw new Error("FileDiff.__completeEditSession: detach the editor before completing the session");this.hunksRenderer.endEditSession(),this.finalizeEditSessionHunks();const a=o?.current;let l,h=null,d=null,u=!1,c;if(t==null)throw new Error("FileDiff.__completeEditSession: editor is required for completion");const f=zt(r),p={name:f.name,contents:f.additionLines.join("")};f.lang!=null&&(p.lang=f.lang);const g={fileDiff:f,editor:t,originalFileDiff:n,oldFile:f.type==="new"?null:{name:f.prevName??f.name,contents:f.deletionLines.join("")},newFile:p,lineAnnotations:a,originalLineAnnotations:s};Object.freeze(g);try{if(t.__emitEditComplete(g),this.options.onEditComplete?.(g)==="accept"){if(f.cacheKey!=null&&f.cacheKey===n.cacheKey)throw new Error("FileDiff.__completeEditSession: an accepted diff must not reuse the replaced diff cacheKey");l=f,h=g.oldFile,d=g.newFile}}catch(S){u=!0,c=S}if(e&&l!=null&&(this.fileDiff=l,this.additionFile!=null&&(this.deletionFile=h,this.additionFile=d),a!=null&&(this.lineAnnotations=a)),this.editSession=void 0,e&&this.fileContainer!=null&&this.rerender(),u)throw c}finalizeEditSessionHunks(){const e=this.getLatestDiff();if(e==null||e.editSessionDirty!==!0)return!1;const{collapsedContextThreshold:t=1}=this.options,i=on(e,this.hunksRenderer.getExpandedHunksMap(),t);return St(e,this.options.parseDiffOptions),this.hunksRenderer.setExpandedHunksMap(an(e,i)),this.hunksRenderer.refreshHighlightedResult(),this.escalateEditSessionRender(),!0}applyDocumentChange(e,t){const i=this.editSession?.diff;if(i==null)throw new Error("FileDiff.applyDocumentChange: requires an active edit session");this.detachAdditionLines(),this.hunksRenderer.beginEditSession(i),this.hunksRenderer.applyDocumentChange(e),t!=null&&this.syncEditSessionAnnotationsFromEditor(t),this.rerender(),this.interactionManager.setSelectionDirty()}applySuspendedDocumentChange(e,t){this.applyDocumentChange(e,t),this.hunksRenderer.clearRenderCache()}updateRenderCache(e,t,i={}){const n=this.editSession?.diff;if(n==null)throw new Error("FileDiff.updateRenderCache: requires an active edit session");this.detachAdditionLines(),this.hunksRenderer.beginEditSession(n);const{shouldRefreshDiffsView:s,lineCountChangeInFlight:r}=i;if(this.hunksRenderer.updateRenderCache(e,t,r)){this.refreshViewTimeout!=null&&(clearTimeout(this.refreshViewTimeout),this.refreshViewTimeout=void 0),this.lineStateRefreshPending=!0,this.escalateEditSessionRender();return}s===!0&&(this.refreshViewTimeout!=null&&clearTimeout(this.refreshViewTimeout),this.lineStateRefreshPending=!0,this.refreshViewTimeout=setTimeout(()=>{this.refreshViewTimeout=void 0,this.options.diffStyle==="split"?this.refreshSplitDiffView():this.refreshUnifiedDiffView(),this.flushDeferredLineState()},150))}detachAdditionLines(){const e=this.editSession?.diff,{fileDiff:t}=this;e!=null&&(e.additionLines===t?.additionLines||e.additionLines===e.deletionLines)&&(e.additionLines=[...e.additionLines])}isLineRenderable(e){const t=this.getRenderedDiff();if(t==null)return!0;const{expandUnchanged:i=!1,collapsedContextThreshold:n=1}=this.options;return Ft({fileDiff:t,lineNumber:e,expandedHunks:i?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:n})}getNearestRenderableLine(e,t){const i=this.getRenderedDiff();if(i==null)return e;const{expandUnchanged:n=!1,collapsedContextThreshold:s=1}=this.options;return Hi({fileDiff:i,lineNumber:e,direction:t,expandedHunks:n?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:s})}revealLine(e){const t=this.getRenderedDiff(),{expandUnchanged:i=!1,collapsedContextThreshold:n=1,expansionLineCount:s=100}=this.options;if(t==null||t.isPartial||i)return!1;const r=this.hunksRenderer.getExpandedHunksMap();for(const[h,d]of t.hunks.entries()){const[u,c]=ct(d);if(e<u){const f=Re({isPartial:t.isPartial,rangeSize:d.collapsedBefore,expandedHunks:r,hunkIndex:h,collapsedContextThreshold:n}),p=u-f.rangeSize;if(f.renderAll||e<p+f.fromStart||e>=u-f.fromEnd)return!1;const g=e-(p+f.fromStart)+1,S=u-f.fromEnd-e;return g<=S?this.expandHunk(h,"up",g+s):this.expandHunk(h,"down",S+s),!0}if(e<c)return!1}const o=ke({fileDiff:t,hunkIndex:t.hunks.length-1,expandedHunks:r,collapsedContextThreshold:n,errorPrefix:"FileDiff.revealLine"});if(o==null||o.renderAll)return!1;const a=t.hunks[t.hunks.length-1],[,l]=ct(a);return e<l+o.fromStart||e>=l+o.rangeSize?!1:(this.expandHunk(t.hunks.length,"up",e-(l+o.fromStart)+1+s),!0)}shouldSelfHealEditSession(){return this.editor==null}escalateEditSessionRender(){ii(this.handleEditSessionRender)}handleEditSessionRender=()=>{this.rerender(),this.flushDeferredLineState()};removeRenderedCode(){this.resizeManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0,this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0}clearAuxiliaryNodes(){for(const{element:e}of this.separatorCache.values())e.remove();this.separatorCache.clear();for(const{element:e}of this.annotationCache.values())e.remove();this.annotationCache.clear(),this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0}renderPlaceholder(e){if(this.fileContainer==null)return!1;if(this.emitPostRender(!0),this.cleanChildNodes(),this.placeHolder==null){const t=this.fileContainer.shadowRoot??this.fileContainer.attachShadow({mode:"open"});this.placeHolder=document.createElement("div"),this.placeHolder.dataset.placeholder="",t.appendChild(this.placeHolder)}return this.setPlaceholderHeight(e)}setPlaceholderHeight(e){return this.placeHolder==null?!1:(this.placeHolder.style.setProperty("height",`${e}px`),!0)}async primeHighlightCache(e=this.fileDiff){const{workerManager:t}=this;if(e==null||t==null||!t.isWorkingPool()||e.cacheKey==null||ye(e))return;const i=this.options.tokenizeMaxLength??1e5;Math.max(e.additionLines.length,e.deletionLines.length)>i||await t.primeDiffHighlightCache(e).catch(n=>{console.error(n)})}cleanChildNodes(){this.resizeManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.interactionManager.cleanUp(),this.clearAuxiliaryNodes(),this.bufferAfter?.remove(),this.bufferBefore?.remove(),this.codeAdditions?.remove(),this.codeDeletions?.remove(),this.codeUnified?.remove(),this.errorWrapper?.remove(),this.headerElement?.remove(),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.pre?.remove(),this.spriteSVG?.remove(),this.themeCSSStyle?.remove(),this.unsafeCSSStyle?.remove(),this.bufferAfter=void 0,this.bufferBefore=void 0,this.codeAdditions=void 0,this.codeDeletions=void 0,this.codeUnified=void 0,this.errorWrapper=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.pre=void 0,this.spriteSVG=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,this.headerCache.lastRenderedHTML=void 0,this.lastRowCount=void 0,this.mounted=!1}renderSeparators(e){const{hunkSeparators:t}=this.options;if(this.isContainerManaged||this.fileContainer==null||typeof t!="function"){for(const{element:n}of this.separatorCache.values())n.remove();this.separatorCache.clear();return}const i=new Map(this.separatorCache);for(const n of e){const s=n.slotName;let r=this.separatorCache.get(s);if(r==null||!xn(n,r.hunkData)){r?.element.remove();const o=document.createElement("div");o.style.display="contents",o.slot=n.slotName;const a=t(n,this);a!=null&&o.appendChild(a),this.fileContainer.appendChild(o),r={element:o,hunkData:n},this.separatorCache.set(s,r)}i.delete(s)}for(const[n,{element:s}]of i.entries())this.separatorCache.delete(n),s.remove()}renderAnnotations(){if(this.isContainerManaged||this.fileContainer==null){for(const{element:n}of this.annotationCache.values())n.remove();this.annotationCache.clear();return}const e=new Map(this.annotationCache),{renderAnnotation:t}=this.options,i=this.getLatestAnnotations();if(t!=null&&i.length>0)for(const[n,s]of i.entries()){const r=this.getAnnotationSlotName(s),o=`${n}-${r}`;let a=this.annotationCache.get(o);if(a==null||!Hn(s,a.annotation)){a?.element.remove();const l=t(s);if(l==null)continue;a={element:ni(r),annotation:s},a.element.appendChild(l),this.fileContainer.appendChild(a.element),this.annotationCache.set(o,a)}e.delete(o)}for(const[n,{element:s}]of e.entries())this.annotationCache.delete(n),s.remove()}renderGutterUtility(){const{renderGutterUtility:e}=this.options;if(this.fileContainer==null||e==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}const t=e(this.interactionManager.getHoveredLine);if(t!=null&&this.gutterUtilityContent!=null)return;if(t==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}const i=si();i.appendChild(t),this.fileContainer.appendChild(i),this.gutterUtilityContent=i}getOrCreateFileContainer(e,t){const{fileContainer:i}=this,n=e??i??document.createElement("diffs-container"),s=i!==n;return i!=null&&s&&this.editor?.__captureFocusForDOMReplacement(),s&&this.emitPostRender(!0),this.fileContainer=n,i!=null&&s&&(this.headerCache.lastRenderedHTML=void 0,this.headerElement=void 0),t!=null&&this.fileContainer.parentNode!==t&&t.appendChild(this.fileContainer),s&&this.adoptReusableShellElements(this.fileContainer),this.ensureSpriteSVG(this.fileContainer),this.fileContainer}adoptReusableShellElements(e){const{shadowRoot:t}=e;if(t!=null)for(const i of t.children)i instanceof SVGElement?this.spriteSVG??=i:dt(i)&&i.hasAttribute("data-theme-css")?(this.themeCSSStyle??=i,this.hasAdoptedThemeCSS=!0):dt(i)&&i.hasAttribute("data-unsafe-css")&&(this.unsafeCSSStyle??=i,this.appliedUnsafeCSS??=this.options.unsafeCSS??void 0)}ensureSpriteSVG(e){const t=e.shadowRoot??e.attachShadow({mode:"open"});if(this.spriteSVG==null){const i=document.createElement("div");i.innerHTML=ri;const n=i.firstChild;n instanceof SVGElement&&(this.spriteSVG=n)}this.spriteSVG!=null&&this.spriteSVG.parentNode!==t&&t.appendChild(this.spriteSVG)}getOrCreatePreNode(e){const t=e.shadowRoot??e.attachShadow({mode:"open"});return this.pre==null?(this.pre=document.createElement("pre"),this.appliedPreAttributes=void 0,this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0,t.appendChild(this.pre)):this.pre.parentNode!==t&&(this.editor?.__captureFocusForDOMReplacement(),t.appendChild(this.pre),this.appliedPreAttributes=void 0),this.placeHolder?.remove(),this.placeHolder=void 0,this.pre}syncCodeNodesFromPre(e){this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0;for(const t of Array.from(e.children))t instanceof HTMLElement&&(t.hasAttribute("data-unified")?this.codeUnified=t:t.hasAttribute("data-deletions")?this.codeDeletions=t:t.hasAttribute("data-additions")&&(this.codeAdditions=t))}applyHeaderToDOM(e,t,i){this.cleanupErrorWrapper(),this.placeHolder?.remove(),this.placeHolder=void 0;const{headerCache:{fileDiff:n,html:s,lastRenderedHTML:r}}=this,o=(i!==this.editSession?.diff&&D(n,i)?s:void 0)??ne(e);if(this.headerCache.html=o,this.headerCache.fileDiff=i,o!==r){const p=document.createElement("div");p.innerHTML=o;const g=p.firstElementChild;if(!(g instanceof HTMLElement))return;this.headerElement!=null?t.shadowRoot?.replaceChild(g,this.headerElement):t.shadowRoot?.prepend(g),this.headerElement=g,this.headerCache.lastRenderedHTML=o}if(this.isContainerManaged)return;const{renderCustomHeader:a,renderHeaderPrefix:l,renderHeaderFilenameSuffix:h,renderHeaderMetadata:d}=this.options;if(a!=null){const p=a(i)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,bi,p),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0;return}const u=l?.(i)??void 0,c=h?.(i)??void 0,f=d?.(i)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,Mi,u),this.headerFilenameSuffix=this.upsertHeaderSlotElement(t,this.headerFilenameSuffix,Fi,c),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,Ii,f),this.headerCustom?.remove(),this.headerCustom=void 0}clearReusableHeader(){this.headerCache.html=void 0,this.headerCache.fileDiff=void 0}clearHeaderSlots(){this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0}upsertHeaderSlotElement(e,t,i,n){if(n==null){t?.remove();return}const s=t??this.createHeaderSlotElement(i);return t==null&&e.appendChild(s),this.replaceHeaderSlotContent(s,n),s}replaceHeaderSlotContent(e,t){e.replaceChildren(),t instanceof Element?e.appendChild(t):e.innerText=`${t}`}createHeaderSlotElement(e){const t=document.createElement("div");return t.slot=e,t}injectUnsafeCSS(){const{unsafeCSS:e}=this.options,t=this.fileContainer?.shadowRoot;if(t!=null){if(e==null||e===""){this.unsafeCSSStyle!=null&&(this.unsafeCSSStyle.remove(),this.unsafeCSSStyle=void 0),this.appliedUnsafeCSS=void 0;return}this.unsafeCSSStyle?.parentNode===t&&this.appliedUnsafeCSS===e||(this.unsafeCSSStyle??=oi(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=ai(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,i,n){const s=e.shadowRoot??e.attachShadow({mode:"open"}),r=n??i,o=this.getTheme(),a=typeof o=="string"?o:{...o},l=ht(s);if(this.themeCSSStyle?.parentNode===s&&this.appliedThemeCSS?.themeStyles===t&&this.appliedThemeCSS.themeType===r&&this.appliedThemeCSS.scrollbarGutter===l){this.appliedThemeCSS.theme=a;return}if(this.hasAdoptedThemeCSS&&this.themeCSSStyle?.parentNode===s){this.hasAdoptedThemeCSS=!1,this.appliedThemeCSS={theme:a,themeStyles:t,themeType:r,baseThemeType:n,scrollbarGutter:l};return}this.themeCSSStyle=li({shadowRoot:s,currentNode:this.themeCSSStyle,themeCSS:ci(t,r,l)}),this.appliedThemeCSS=this.themeCSSStyle!=null?{theme:a,themeStyles:t,themeType:r,baseThemeType:n,scrollbarGutter:l}:void 0}hydrateMeasuredScrollbar(){const e=this.fileContainer?.shadowRoot;e==null||this.themeCSSStyle==null||(this.themeCSSStyle.textContent=di(this.themeCSSStyle.textContent??"",ht(e)))}shouldGuardRebuildScroll(){return this.editor!=null&&hi()}applyHunksToDOM(e,t){this.shouldGuardRebuildScroll()?ut(e,()=>this.replaceCodeColumns(e,t)):this.replaceCodeColumns(e,t)}applyCodeColumnsInPlace(e,t,i){const n=this.getColumnPair(e);if(n==null)return!1;const s=Z(t[0]),r=Z(t[1]);return s==null||r==null?!1:(n.gutter.innerHTML=ne(s),n.content.innerHTML=ne(r),i!==this.lastRowCount&&(n.gutter.style.setProperty("grid-row",`span ${i}`),n.content.style.setProperty("grid-row",`span ${i}`)),!0)}replaceCodeColumns(e,t){const{overflow:i="scroll"}=this.options,n=(this.options.hunkSeparators??"line-info")==="line-info",s=i==="wrap"?t.rowCount:void 0;this.cleanupErrorWrapper(),this.applyPreNodeAttributes(e,t);let r=!1;const o=[],a=this.hunksRenderer.renderCodeAST("unified",t),l=this.hunksRenderer.renderCodeAST("deletions",t),h=this.hunksRenderer.renderCodeAST("additions",t);this.editor?.__captureFocusForDOMReplacement(),a!=null?(r=this.codeUnified==null||this.codeAdditions!=null||this.codeDeletions!=null,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0,this.codeUnified=_e({code:this.codeUnified,columnType:"unified",rowSpan:s,containerSize:n}),this.applyCodeColumnsInPlace(this.codeUnified,a,t.rowCount)||(this.codeUnified.innerHTML=this.hunksRenderer.renderPartialHTML(a)),o.push(this.codeUnified)):l!=null||h!=null?(l!=null?(r=this.codeDeletions==null||this.codeUnified!=null,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions=_e({code:this.codeDeletions,columnType:"deletions",rowSpan:s,containerSize:n}),this.applyCodeColumnsInPlace(this.codeDeletions,l,t.rowCount)||(this.codeDeletions.innerHTML=this.hunksRenderer.renderPartialHTML(l)),o.push(this.codeDeletions)):(this.codeDeletions?.remove(),this.codeDeletions=void 0),h!=null?(r=r||this.codeAdditions==null||this.codeUnified!=null,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeAdditions=_e({code:this.codeAdditions,columnType:"additions",rowSpan:s,containerSize:n}),this.applyCodeColumnsInPlace(this.codeAdditions,h,t.rowCount)||(this.codeAdditions.innerHTML=this.hunksRenderer.renderPartialHTML(h)),o.push(this.codeAdditions)):(this.codeAdditions?.remove(),this.codeAdditions=void 0)):(this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0),o.length===0?e.textContent="":r&&e.replaceChildren(...o),this.lastRowCount=t.rowCount}applyPartialRender({fileDiff:e,previousRenderRange:t,renderRange:i}){const{pre:n,codeUnified:s,codeAdditions:r,codeDeletions:o,options:{diffStyle:a="split"}}=this;if(n==null||t==null||i==null||!Number.isFinite(t.totalLines)||!Number.isFinite(i.totalLines)||this.lastRowCount==null)return!1;const l=this.getCodeColumns(a,s,o,r);if(l==null)return!1;const h=t.startingLine,d=i.startingLine,u=h+t.totalLines,c=d+i.totalLines,f=Math.max(h,d),p=Math.min(u,c);if(p<=f)return!1;const g=Math.max(0,f-h),S=Math.max(0,u-p),C=this.trimColumns({columns:l,trimStart:g,trimEnd:S,previousStart:h,overlapStart:f,overlapEnd:p,diffStyle:a});if(C<0)throw new Error("FileDiff.applyPartialRender: failed to trim to overlap");if(this.lastRowCount<C)throw new Error("FileDiff.applyPartialRender: trimmed beyond DOM row count");let y=this.lastRowCount-C;const v=(L,F)=>{if(!(F<=0))return this.hunksRenderer.renderDiff(e,{startingLine:L,totalLines:F,bufferBefore:0,bufferAfter:0})},R=v(d,Math.max(f-d,0));if(R==null&&d<f)return!1;const m=v(p,Math.max(c-p,0));if(m==null&&c>p)return!1;const b=(L,F)=>{if(L!=null){if(a==="unified"&&!Array.isArray(l))this.insertPartialHTML(a,l,L,F);else if(a==="split"&&Array.isArray(l))this.insertPartialHTML(a,l,L,F);else throw new Error("FileDiff.applyPartialRender.applyChunk: invalid chunk application");y+=L.rowCount,this.renderedDiff=L.fileDiff}};return this.cleanupErrorWrapper(),b(R,"afterbegin"),b(m,"beforeend"),this.lastRowCount!==y&&(this.applyRowSpan(a,l,y),this.lastRowCount=y),!0}insertPartialHTML(e,t,i,n){if(e==="unified"&&!Array.isArray(t)){const s=this.hunksRenderer.renderCodeAST("unified",i);this.renderPartialColumn(t,s,n)}else if(e==="split"&&Array.isArray(t)){const s=this.hunksRenderer.renderCodeAST("deletions",i),r=this.hunksRenderer.renderCodeAST("additions",i);this.renderPartialColumn(t[0],s,n),this.renderPartialColumn(t[1],r,n)}else throw new Error("FileDiff.insertPartialHTML: Invalid argument composition")}refreshSplitDiffView(){const e=this.getLatestDiff();if(this.options.diffStyle!=="split"||e==null)return;const t=this.hunksRenderer.renderDiff(e,this.renderRange);if(t==null)return;const i=this.getCodeColumns("split",this.codeUnified,this.codeDeletions,this.codeAdditions);if(!Array.isArray(i))return;const n=(s,r)=>{if(r==null)return;const o=this.hunksRenderer.renderCodeAST(s,t),a=Z(o?.[0]),l=Z(o?.[1]);for(const[h,d]of[[r.gutter,a],[r.content,l]])if(d!=null&&h.childElementCount===d.length)for(let u=0;u<d.length;u++){const c=h.children[u],f=d[u].properties["data-line-type"];f!=null&&c.dataset.lineType!==f&&(c.dataset.lineType=f)}};n("deletions",i[0]),n("additions",i[1]),this.renderedDiff=t.fileDiff}refreshUnifiedDiffView(){const e=this.getLatestDiff();if(this.options.diffStyle!=="unified"||e==null)return;const t=this.hunksRenderer.renderDiff(e,this.renderRange);if(t==null)return;const i=this.getCodeColumns("unified",this.codeUnified,this.codeDeletions,this.codeAdditions);if(i==null||Array.isArray(i))return;const n=this.hunksRenderer.renderCodeAST("unified",t),s=Z(n?.[0]),r=Z(n?.[1]),o=()=>{for(const[a,l]of[[i.gutter,s],[i.content,r]])l!=null&&(a.innerHTML=ne(l));t.rowCount!==this.lastRowCount&&(this.applyRowSpan("unified",i,t.rowCount),this.lastRowCount=t.rowCount),this.renderedDiff=t.fileDiff};this.shouldGuardRebuildScroll()?ut(this.pre,o):o(),this.renderSeparators(t.hunkData),this.managersDirty=!0,this.flushManagers(),this.syncRenderViewToEditor()}renderPartialColumn(e,t,i){if(e==null||t==null)return;const n=Z(t[0]),s=Z(t[1]);if(n==null||s==null)throw new Error("FileDiff.insertPartialHTML: Unexpected AST structure");const r=s.at(0);i==="beforeend"&&r?.type==="element"&&typeof r.properties["data-buffer-size"]=="number"&&this.mergeBuffersIfNecessary(r.properties["data-buffer-size"],e.content.children[e.content.children.length-1],e.gutter.children[e.gutter.children.length-1],n,s,!0);const o=s.at(-1);i==="afterbegin"&&o?.type==="element"&&typeof o.properties["data-buffer-size"]=="number"&&this.mergeBuffersIfNecessary(o.properties["data-buffer-size"],e.content.children[0],e.gutter.children[0],n,s,!1),e.gutter.insertAdjacentHTML(i,this.hunksRenderer.renderPartialHTML(n)),e.content.insertAdjacentHTML(i,this.hunksRenderer.renderPartialHTML(s))}mergeBuffersIfNecessary(e,t,i,n,s,r){if(!(t instanceof HTMLElement)||!(i instanceof HTMLElement))return;const o=this.getBufferSize(t.dataset);o!=null&&(r?(n.shift(),s.shift()):(n.pop(),s.pop()),this.updateBufferSize(t,o+e),this.updateBufferSize(i,o+e))}applyRowSpan(e,t,i){const n=s=>{s!=null&&(s.gutter.style.setProperty("grid-row",`span ${i}`),s.content.style.setProperty("grid-row",`span ${i}`))};if(e==="unified"&&!Array.isArray(t))n(t);else if(e==="split"&&Array.isArray(t))n(t[0]),n(t[1]);else throw new Error("dun fuuuuked up")}trimColumnRows(e,t,i){let n=0,s=0,r=0,o=!1;const a=i>=0;if(e==null)return 0;const l=Array.from(e.content.children),h=Array.from(e.gutter.children);if(l.length!==h.length)throw new Error("FileDiff.trimColumnRows: columns do not match");for(;r<l.length&&!(t<=0&&!a&&!o);){const d=h[r],u=l[r];if(r++,!(d instanceof HTMLElement)||!(u instanceof HTMLElement))throw console.error({gutterElement:d,contentElement:u}),new Error("FileDiff.trimColumnRows: invalid row elements");if(o&&(o=!1,d.dataset.gutterBuffer==="annotation"&&"lineAnnotation"in u.dataset||d.dataset.gutterBuffer==="metadata"&&"noNewline"in u.dataset)){d.remove(),u.remove(),s++;continue}if("lineIndex"in d.dataset&&"lineIndex"in u.dataset){(t>0||a&&n>=i)&&(d.remove(),u.remove(),t>0&&(t--,t===0&&(o=!0)),s++),n++;continue}if("separator"in d.dataset&&"separator"in u.dataset){(t>0||a&&n>=i)&&(d.remove(),u.remove(),s++);continue}if(d.dataset.gutterBuffer==="annotation"&&"lineAnnotation"in u.dataset){(t>0||a&&n>=i)&&(d.remove(),u.remove(),s++);continue}if(d.dataset.gutterBuffer==="metadata"&&"noNewline"in u.dataset){(t>0||a&&n>=i)&&(d.remove(),u.remove(),s++);continue}if(d.dataset.gutterBuffer==="buffer"&&"contentBuffer"in u.dataset){const c=this.getBufferSize(u.dataset);if(c==null)throw new Error("FileDiff.trimColumnRows: invalid element");if(t>0){const f=Math.min(t,c),p=c-f;p>0?(this.updateBufferSize(d,p),this.updateBufferSize(u,p),s+=f):(d.remove(),u.remove(),s+=c),t-=f,t===0&&p===0&&(o=!0)}else if(a){const f=n,p=n+c-1;if(i<=f)d.remove(),u.remove(),s+=c;else if(i<=p){const g=p-i+1,S=c-g;this.updateBufferSize(d,S),this.updateBufferSize(u,S),s+=g}}n+=c;continue}throw console.error({gutterElement:d,contentElement:u}),new Error("FileDiff.trimColumnRows: unknown row elements")}return s}trimColumns({columns:e,diffStyle:t,overlapEnd:i,overlapStart:n,previousStart:s,trimEnd:r,trimStart:o}){const a=Math.max(0,n-s),l=i-s;if(l<0)throw new Error("FileDiff.trimColumns: overlap ends before previous");const h=o>0,d=r>0;if(!h&&!d)return 0;const u=h?a:0,c=d?l:-1;if(t==="unified"&&!Array.isArray(e))return this.trimColumnRows(e,u,c);if(t==="split"&&Array.isArray(e)){const f=this.trimColumnRows(e[0],u,c),p=this.trimColumnRows(e[1],u,c);if(e[0]!=null&&e[1]!=null&&f!==p)throw new Error("FileDiff.trimColumns: split columns out of sync");return e[0]!=null?f:p}else throw console.error({diffStyle:t,columns:e}),new Error("FileDiff.trimColumns: Invalid columns for diffType")}getBufferSize(e){const t=Number.parseInt(e?.bufferSize??"",10);return Number.isNaN(t)?void 0:t}updateBufferSize(e,t){e.dataset.bufferSize=`${t}`,e.style.setProperty("grid-row",`span ${t}`),e.style.setProperty("min-height",`calc(${t} * 1lh)`)}getColumnPair(e){if(e==null)return;const t=e.children[0],i=e.children[1];if(!(!(t instanceof HTMLElement)||!(i instanceof HTMLElement)||t.dataset.gutter==null||i.dataset.content==null))return{gutter:t,content:i}}getCodeColumns(e,t,i,n){if(e==="unified")return this.getColumnPair(t);{const s=this.getColumnPair(i),r=this.getColumnPair(n);return s!=null||r!=null?[s,r]:void 0}}updateBuffers(e){this.pre!=null&&this.applyBuffers(this.pre,e)}applyBuffers(e,t){if(t==null||this.shouldDisableVirtualizationBuffers()){this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0);return}t.bufferBefore>0?(this.bufferBefore==null&&(this.bufferBefore=document.createElement("div"),this.bufferBefore.dataset.virtualizerBuffer="before",e.before(this.bufferBefore)),this.bufferBefore.style.setProperty("height",`${t.bufferBefore}px`),this.bufferBefore.style.setProperty("contain","strict")):this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),t.bufferAfter>0?(this.bufferAfter==null&&(this.bufferAfter=document.createElement("div"),this.bufferAfter.dataset.virtualizerBuffer="after",e.after(this.bufferAfter)),this.bufferAfter.style.setProperty("height",`${t.bufferAfter}px`),this.bufferAfter.style.setProperty("contain","strict")):this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0)}shouldDisableVirtualizationBuffers(){return this.options.disableVirtualizationBuffers??!1}applyPreNodeAttributes(e,{additionsContentAST:t,deletionsContentAST:i,totalLines:n},s){const{diffIndicators:r="bars",disableBackground:o=!1,disableLineNumbers:a=!1,overflow:l="scroll",diffStyle:h="split"}=this.options,d={type:"diff",diffIndicators:r,disableBackground:o,disableLineNumbers:a,overflow:l,split:h==="unified"?!1:t!=null&&i!=null,totalLines:n,customProperties:s};ui(d,this.appliedPreAttributes)||(fi(e,d),this.appliedPreAttributes=d)}applyErrorToDOM(e,t){this.cleanupErrorWrapper(),this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0;const i=t.shadowRoot??t.attachShadow({mode:"open"});this.errorWrapper??=document.createElement("div"),this.errorWrapper.dataset.errorWrapper="",this.errorWrapper.textContent="",i.appendChild(this.errorWrapper);const n=document.createElement("div");n.dataset.errorMessage="",n.innerText=e.message,this.errorWrapper.appendChild(n);const s=document.createElement("pre");s.dataset.errorStack="",s.innerText=e.stack??"No Error Stack",this.errorWrapper.appendChild(s)}cleanupErrorWrapper(){this.errorWrapper?.remove(),this.errorWrapper=void 0}};function Fn(e){return{name:e.name,lang:e.lang,contents:e.additionLines.join("")}}function Ht(e,t){return e==null||t==null?e==null&&t==null:It(e,t)}function In({fileDiff:e,oldFile:t,newFile:i}){return e!=null&&e.hunks.length>0||t!=null||i!=null}function Pn({fileDiff:e,oldFile:t,newFile:i}){return e!=null||t!=null||i!=null}function zn(e,t,i=!1){return!i&&e==null&&t}function Nn(e,t,i=!1){return e==null&&t&&!i}function Z(e){if(!(e==null||e.type!=="element"))return e.children??[]}function On({fileDiff:e,metrics:t,disableFileHeader:i,hunkSeparators:n,expandUnchanged:s,expandedHunks:r,collapsedContextThreshold:o,canHydratePartialDiff:a}){let l=fe(t,i),h=l;const d=s?!0:r,u=e.hunks.length-1;for(let c=0;c<e.hunks.length;c++){const f=e.hunks[c];if(f==null)throw new Error("computeEstimatedDiffHeights: invalid hunk index");const p=Re({isPartial:e.isPartial,rangeSize:f.collapsedBefore,expandedHunks:d,hunkIndex:c,collapsedContextThreshold:o}),g=(p.fromStart+p.fromEnd)*t.lineHeight;if(l+=g,h+=g,p.collapsedLines>0){const y=Le({type:n,metrics:t,hunkIndex:c,hunkSpecs:f.hunkSpecs})?.totalHeight??0;l+=y,h+=y}l+=f.splitLineCount*t.lineHeight,h+=f.unifiedLineCount*t.lineHeight;const S=Un(f);l+=S.split*t.lineHeight,h+=S.unified*t.lineHeight;const C=c===u?ke({fileDiff:e,hunkIndex:c,expandedHunks:d,collapsedContextThreshold:o,errorPrefix:"computeEstimatedDiffHeights"}):void 0;if(C!=null){const y=(C.fromStart+C.fromEnd)*t.lineHeight;if(l+=y,h+=y,C.collapsedLines>0){const v=ie({type:n,metrics:t})?.totalHeight??0;l+=v,h+=v}}else if(c===u&&e.isPartial&&a){const y=ie({type:n,metrics:t})?.totalHeight??0;l+=y,h+=y}}if(e.hunks.length>0){const c=Mt(t);l+=c,h+=c}return{splitHeight:l,unifiedHeight:h}}function Un(e){if(!e.noEOFCRAdditions&&!e.noEOFCRDeletions)return{split:0,unified:0};const t=e.hunkContent.at(-1);if(t==null)return{split:0,unified:0};if(t.type==="context"){const i=t.lines>0?1:0;return{split:i,unified:i}}return Bn(e,t)}function Bn(e,t){const i=(t.deletions>0&&e.noEOFCRDeletions?1:0)+(t.additions>0&&e.noEOFCRAdditions?1:0),n=t.deletions>0&&e.noEOFCRDeletions,s=t.additions>0&&e.noEOFCRAdditions;return{split:n||s?1:0,unified:i}}const st=3e3,Fe=new Map;let Vn=-1;var is=class extends Mn{__id=`little-virtualized-file-diff:${++Vn}`;renderType="virtualized";top;height=0;metrics;cache={heightDeltas:new Map,measuredHeightDeltaTotal:0,estimatedSplitHeight:void 0,estimatedUnifiedHeight:void 0,checkpoints:[],totalLines:0,fileAnnotationHeight:0,ghostTextRows:Fe,ghostTextRowsByIndex:new Map};isVisible=!1;isSetup=!1;virtualizer;layoutDirty=!0;forceRenderOverride;currentCollapsed;pendingHydratedDiff;pendingExpansions;pendingRender;constructor(e,t,i,n,s=!1){super(e,n,s),this.virtualizer=t,this.metrics=Ge(i)}setMetrics(e,t=!1){const i=Ge(e);!t&&pi(this.metrics,i)||(this.metrics=i,this.resetLayoutCache({includeEstimatedHeights:!0}))}setLineAnnotations(e){this.syncLineAnnotations(e)&&(this.forceRenderOverride=!0)}syncLineAnnotations(e){return e==null||!this.isNewAnnotations(e)||e.length===0&&this.getLatestAnnotations().length===0?!1:(super.setLineAnnotations(e),!0)}syncEditSessionAnnotationsFromEditor(e){return super.syncEditSessionAnnotationsFromEditor(e)?(this.forceRenderOverride=!0,!0):!1}setFileAnnotationHeight(e){const t=this.cache.fileAnnotationHeight;return e===t?!1:(this.cache.fileAnnotationHeight=e,this.cache.measuredHeightDeltaTotal+=e-t,!0)}hasFileAnnotations(e){const t=this.getLatestAnnotations();return gi(t)?t.some(i=>i.lineNumber!==0?!1:e.type==="new"?i.side==="additions":e.type==="deleted"?i.side==="deletions":!0):!1}getLineHeight(e,t=!1){return this.getEstimatedLineHeight(t)+(this.cache.heightDeltas.get(e)??0)}getEstimatedLineHeight(e=!1){const t=e?2:1;return this.metrics.lineHeight*t}setOptions(e){if(this.isAdvancedMode())throw new Error("VirtualizedFileDiff.setOptions cannot be used inside CodeView. Update CodeView options instead.");if(e==null)return;const{options:t}=this,i=!mi(t,e),n=i&&Kn(t,e);super.setOptions(e),n&&this.resetLayoutCache({forceSimpleRecompute:!0,includeEstimatedHeights:qn(t,e)}),i&&(this.forceRenderOverride=!0),i&&this.isSimpleMode()&&this.virtualizer.instanceChanged(this,n)}setThemeType(e){if(this.isAdvancedMode())throw new Error("VirtualizedFileDiff.setThemeType cannot be used inside CodeView. Update CodeView options instead.");super.setThemeType(e)}resetLayoutCache({forceSimpleRecompute:e=!1,includeEstimatedHeights:t=!1,resetRenderRange:i=!0}={}){this.layoutDirty=!0,this.cache.fileAnnotationHeight=0,this.cache.heightDeltas.clear(),this.cache.measuredHeightDeltaTotal=0,this.cache.ghostTextRows=Fe,this.cache.ghostTextRowsByIndex.size>0&&this.cache.ghostTextRowsByIndex.clear(),this.invalidateDerivedLayoutCache(t,i),e&&this.isSimpleMode()&&this.computeApproximateSize()}invalidateDerivedLayoutCache(e,t=!0){this.layoutDirty=!0,this.cache.checkpoints.length>0&&(this.cache.checkpoints.length=0),this.cache.totalLines!==0&&(this.cache.totalLines=0),e&&(this.cache.estimatedSplitHeight=void 0,this.cache.estimatedUnifiedHeight=void 0),this.renderRange!=null&&t&&(this.renderRange=void 0)}applyGhostTextRows(e,t){const{cache:{heightDeltas:i,ghostTextRows:n,ghostTextRowsByIndex:s},metrics:{lineHeight:r}}=this;if(n===t)return!1;const o=this.getDiffStyle(),a=new Map;for(const[h,d]of t){const u=this.getLineIndexForDiff(e,h+1,"additions");u!=null&&a.set(o==="split"?u[1]:u[0],d)}let l=!1;for(const h of new Set([...s.keys(),...a.keys()])){const d=((a.get(h)??0)-(s.get(h)??0))*r;if(d===0)continue;const u=(i.get(h)??0)+d;u===0?i.delete(h):i.set(h,u),this.cache.measuredHeightDeltaTotal+=d,l=!0}return this.cache.ghostTextRows=t,this.cache.ghostTextRowsByIndex=a,l}reconcileHeights(){let e=!1;const{options:{overflow:t="scroll"},metrics:{lineHeight:i}}=this,n=this.placeHolder!=null?this.getLayoutDiff():this.getRenderedDiff();if(this.fileContainer==null||n==null)return this.height!==0&&(e=!0),this.height=0,e;this.top=this.getVirtualizedTop(),e=this.applyGhostTextRows(n,this.editor?.__getGhostTextRows()??Fe);const{ghostTextRowsByIndex:s}=this.cache,r=t!=="scroll"||this.getLatestAnnotations().length>0||this.isResizeDebuggingEnabled();if(this.placeHolder!=null||!r&&this.cache.heightDeltas.size===0&&this.cache.fileAnnotationHeight===0)return e&&(this.computeApproximateSize(!0),this.setPlaceholderHeight(this.height)),e;const o=this.getDiffStyle(),a=o==="split"?[this.codeDeletions,this.codeAdditions]:[this.codeUnified];if(this.renderRange!=null&&Tt(this.renderRange)){const l=_n(a)??0;this.setFileAnnotationHeight(l)&&(e=!0)}for(const l of a){if(l==null)continue;const h=l.children[1];if(!(h instanceof HTMLElement))continue;const d=o==="split"&&l===this.codeDeletions;for(const u of h.children){if(!(u instanceof HTMLElement))continue;const c=u.dataset.lineIndex;if(c==null)continue;const f=Yn(c,o),p=s.get(f)??0;if(d&&p>0)continue;const g=this.cache.heightDeltas.get(f)??0;if(!r&&g===p*i)continue;let S=u.getBoundingClientRect().height+p*i,C=!1;u.nextElementSibling instanceof HTMLElement&&("lineAnnotation"in u.nextElementSibling.dataset||"noNewline"in u.nextElementSibling.dataset)&&("noNewline"in u.nextElementSibling.dataset&&(C=!0),S+=u.nextElementSibling.getBoundingClientRect().height);const y=this.getEstimatedLineHeight(C),v=S-y;v!==g&&(e=!0,this.cache.measuredHeightDeltaTotal+=v-g,v===0?this.cache.heightDeltas.delete(f):this.cache.heightDeltas.set(f,v))}}return(e||this.isResizeDebuggingEnabled())&&this.computeApproximateSize(!0),e}onRender=e=>this.fileContainer==null?!1:(e&&(this.top=this.getVirtualizedTop()),this.render());flushManagers(){super.flushManagers(),this.lineStateRefreshPending&&this.flushDeferredLineState()}updateCodeViewLayout(e,t,i,n){let s=!1,r=!1;const{pendingExpansions:o,pendingHydratedDiff:a,options:{collapsed:l=!1}}=this;if(a!=null&&(this.pendingHydratedDiff=void 0,a.expectedDiff===e&&(Object.assign(e,a.nextDiff),this.setHydratedState(a.files),this.installHydratedSessionDiff(e),this.forceRenderOverride=!0,s=!0,r=!0)),o!=null){this.pendingExpansions=void 0;for(const{hunkIndex:p,direction:g,expansionLineCountOverride:S}of o)this.hunksRenderer.expandHunk(p,g,S),this.forceRenderOverride=!0,r=!0}const h=this.updateExternalDiff(e,n),{pendingRenderDiff:d,layoutDiffChanged:u,renderedDiffChanged:c,annotationsChanged:f}=this.updatePendingRender(e,n);return!this.forceRenderOverride&&(h||c||f)&&(this.forceRenderOverride=!0),(i?.resetDiffLayoutCache===!0||u)&&(s=!0),(u||i?.resetDiffLayoutCache===!0&&i.includeEstimatedDiffHeights)&&(r=!0),i?.metrics!=null&&(this.metrics=Ge(i.metrics),s=!0,r=!0),this.currentCollapsed!==l&&(this.currentCollapsed=l,s=!0),s?this.resetLayoutCache({includeEstimatedHeights:r}):r&&this.invalidateDerivedLayoutCache(!0),this.top=t,this.computeApproximateSize(!1,d),this.height}getLinePosition(e,t="additions"){const i=this.getLayoutDiff();if(i==null||e<1)return;const n=this.getLineIndexForDiff(i,e,t);if(n==null)return;const{disableFileHeader:s=!1,expandUnchanged:r=!1,collapsed:o=!1,collapsedContextThreshold:a=1}=this.options,l=this.getDiffStyle(),h=this.getHunkSeparatorType(),d=l==="split"?n[1]:n[0];this.approximateLayoutCheckpoints(i);const u=fe(this.metrics,s),c=this.getLayoutCheckpointBeforeLineIndex(d);let f=c?.top??u+this.cache.fileAnnotationHeight;if(o)return{top:u,height:0};let p;return pe({diff:i,diffStyle:l,startingLine:c?.renderedLineIndex??0,expandedHunks:r?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:a,callback:({hunkIndex:g,hunk:S,collapsedBefore:C,collapsedAfter:y,deletionLine:v,additionLine:R})=>{const m=l==="split"?R?.splitLineIndex??v?.splitLineIndex:R?.unifiedLineIndex??v?.unifiedLineIndex;if(m==null)throw new Error("VirtualizedFileDiff.getLinePosition: missing line index data");if(C>0){const L=Le({type:h,metrics:this.metrics,hunkIndex:g,hunkSpecs:S?.hunkSpecs});if(L!=null){if(f+=L.gapBefore,d>=m-C&&d<m)return p={top:f,height:L.height},!0;f+=L.height+L.gapAfter}}const b=this.getLineHeight(m,(R?.noEOFCR??!1)||(v?.noEOFCR??!1));if(m===d)return p={top:f,height:b},!0;if(f+=b,y>0){const L=ie({type:h,metrics:this.metrics});if(L!=null){if(d>m&&d<=m+y)return p={top:f+L.gapBefore,height:L.height},!0;f+=L.totalHeight}}return!1}}),p}getEditorViewport(){return this.virtualizer.type==="simple"?this.virtualizer.getRoot():this.virtualizer.getContainerElement()}getNumericScrollAnchor(e){const t=this.getLayoutDiff();if(t==null)return;const{disableFileHeader:i=!1,expandUnchanged:n=!1,collapsed:s=!1,collapsedContextThreshold:r=1}=this.options;if(s)return;const o=this.getDiffStyle(),a=this.getHunkSeparatorType();this.approximateLayoutCheckpoints(t);const l=this.getLayoutCheckpointBeforeTop(e);let h=l?.top??fe(this.metrics,i)+this.cache.fileAnnotationHeight,d;return pe({diff:t,diffStyle:o,startingLine:l?.renderedLineIndex??0,expandedHunks:n?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:r,callback:({hunkIndex:u,hunk:c,collapsedBefore:f,collapsedAfter:p,deletionLine:g,additionLine:S})=>{const C=o==="split"?S?.splitLineIndex??g?.splitLineIndex:S?.unifiedLineIndex??g?.unifiedLineIndex;if(C==null)throw new Error("VirtualizedFileDiff.getNumericScrollAnchor: missing line index data");if(f>0){const v=Le({type:a,metrics:this.metrics,hunkIndex:u,hunkSpecs:c?.hunkSpecs});v!=null&&(h+=v.totalHeight)}if(h>=e&&(g!=null?d={lineNumber:g.lineNumber,side:"deletions",top:h}:S!=null&&(d={lineNumber:S.lineNumber,side:"additions",top:h}),d!=null))return!0;const y=this.getLineHeight(C,(S?.noEOFCR??!1)||(g?.noEOFCR??!1));if(h+=y,p>0){const v=ie({type:a,metrics:this.metrics});v!=null&&(h+=v.totalHeight)}return!1}}),d}getVirtualizedHeight(){return this.height}getAdvancedStickySpecs(e){const t=this.getLayoutDiff();if(this.top==null||t==null)return;if(this.options.collapsed===!0)return{topOffset:this.top,height:this.height};const i=e!=null?this.computeRenderRangeFromWindow(t,this.top,e):this.renderRange;if(i==null)return;const{bufferBefore:n,bufferAfter:s,totalLines:r}=i;let o=0;if(r===0){const a=e??this.virtualizer.getWindowSpecs();this.top<a.top&&(o=s)}return{topOffset:this.top+n+o,height:this.height-(n+s)}}cleanUp(e=!1){const t=this.cache.ghostTextRows.size>0;t&&(this.layoutDirty=!0);const i=e&&this.isAdvancedMode()&&this.fileContainer!=null&&(t||!D(this.getRenderedDiff(),this.getLatestDiff()));this.fileContainer!=null&&this.isSimpleMode()&&this.getSimpleVirtualizer()?.disconnect(this.fileContainer),e||(this.resetLayoutCache({includeEstimatedHeights:!0}),this.pendingExpansions=void 0,this.pendingHydratedDiff=void 0),this.pendingRender=void 0,this.isSetup=!1,super.cleanUp(e),i&&this.virtualizer.instanceChanged(this,!0)}expandHunk=(e,t,i)=>{this.fileDiff!=null&&(this.loadFilesIfNecessary(),this.isAdvancedMode()?(this.pendingExpansions??=[],this.pendingExpansions.push({hunkIndex:e,direction:t,expansionLineCountOverride:i})):(this.hunksRenderer.expandHunk(e,t,i),this.resetLayoutCache({includeEstimatedHeights:!0}),this.computeApproximateSize()),this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0))};async handleFilesLoaded(e,t){if(!(this.fileDiff!==e||!e.isPartial)){if(this.isAdvancedMode()){const i=Ze("clone",e,t);if(await it(()=>this.primeHighlightCache(i)),this.fileDiff!==e)return;this.pendingHydratedDiff={expectedDiff:e,nextDiff:i,files:t}}else{if(Ze("merge",e,t),this.setHydratedState(t),!this.installHydratedSessionDiff(e)&&(await it(()=>this.primeHighlightCache(e)),this.fileDiff!==e))return;this.resetLayoutCache({includeEstimatedHeights:!0}),this.computeApproximateSize()}this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0)}}loadFilesIfNecessary(){if(this.pendingHydratedDiff!=null){if(this.pendingHydratedDiff.expectedDiff===this.fileDiff)return;this.pendingHydratedDiff=void 0}super.loadFilesIfNecessary()}isLineRenderable(e){if(super.isLineRenderable(e))return!0;const{pendingExpansions:t}=this,i=this.getRenderedDiff();if(t==null||t.length===0||i==null)return!1;const{expansionLineCount:n=100,collapsedContextThreshold:s=1}=this.options,r=new Map(this.hunksRenderer.getExpandedHunksMap());for(const o of t){const a={...r.get(o.hunkIndex)??{fromStart:0,fromEnd:0}},l=o.expansionLineCountOverride??n;(o.direction==="up"||o.direction==="both")&&(a.fromStart+=l),(o.direction==="down"||o.direction==="both")&&(a.fromEnd+=l),r.set(o.hunkIndex,a)}return Ft({fileDiff:i,lineNumber:e,expandedHunks:r,collapsedContextThreshold:s})}invalidateEditSessionLayout(){this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache({forceSimpleRecompute:this.isSimpleMode(),includeEstimatedHeights:!0,resetRenderRange:!1}),this.isSimpleMode()||this.computeApproximateSize(!0),this.getSimpleVirtualizer()?.requestHeightReconcile(this)}escalateEditSessionRender(){this.invalidateEditSessionLayout(),!(!this.enabled||this.fileDiff==null)&&(this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0))}shouldSelfHealEditSession(){return!this.isAdvancedMode()&&super.shouldSelfHealEditSession()}setVisibility(e){this.isAdvancedMode()||this.fileContainer==null||(this.renderRange=void 0,e&&!this.isVisible?(this.top=this.getVirtualizedTop(),this.isVisible=!0):!e&&this.isVisible&&(this.isVisible=!1,this.rerender()))}rerender(){if(!this.enabled||this.fileDiff==null&&this.additionFile==null&&this.deletionFile==null)return;const e=this.getLatestDiff(),t=e==null?void 0:this.hunksRenderer.getDiffForNextRender(e);this.isSimpleMode()&&(this.pendingRender=void 0),this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!D(this.getRenderedDiff(),t))}syncGhostTextRows(){const e=this.getAdvancedVirtualizer();e!=null?(e.capturePendingLayoutAnchor(),this.layoutDirty=!0,e.instanceChanged(this,!0)):this.getSimpleVirtualizer()?.requestHeightReconcile(this)}applyDocumentChange(e,t,i=!1){const{renderRange:n}=this;this.getAdvancedVirtualizer()?.capturePendingLayoutAnchor(),super.applyDocumentChange(e,t),this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache({forceSimpleRecompute:this.isSimpleMode(),includeEstimatedHeights:!0,resetRenderRange:!1});const s=this.getRenderedDiff();if(!this.isSimpleMode())this.computeApproximateSize(!0);else if(i&&n!=null&&s!=null){const r=this.virtualizer.getWindowSpecs(),o=this.computeRenderRangeFromWindow(s,this.top??0,r);o.bufferAfter!==n.bufferAfter&&this.updateBuffers(o)}this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0)}computeApproximateSize(e=!1,t=this.getLayoutDiff()){const i=this.isResizeDebuggingEnabled();if(!e&&!this.layoutDirty&&!i)return;const n=this.height===0;if(this.height=0,this.cache.checkpoints=[],this.cache.totalLines=0,t==null){this.layoutDirty=!1;return}this.applyGhostTextRows(t,this.editor?.__getGhostTextRows()??Fe);const{disableFileHeader:s=!1,collapsed:r=!1}=this.options,o=fe(this.metrics,s);if(this.height+=o,r){this.layoutDirty=!1;return}this.height=this.getActiveEstimatedHeight(t)+this.cache.measuredHeightDeltaTotal,i&&!n&&this.validateComputedHeight(t),this.layoutDirty=!1}getLayoutDiff(){return this.pendingRender?.diff??this.getRenderedDiff()}getActiveEstimatedHeight(e=this.getLayoutDiff()){this.ensureEstimatedDiffHeights(e);const t=this.getDiffStyle()==="split"?this.cache.estimatedSplitHeight:this.cache.estimatedUnifiedHeight;if(t==null)throw new Error("VirtualizedFileDiff.getActiveEstimatedHeight: missing estimated height");return t}ensureEstimatedDiffHeights(e=this.getLayoutDiff()){if(e==null){this.cache.estimatedSplitHeight=void 0,this.cache.estimatedUnifiedHeight=void 0;return}if(this.cache.estimatedSplitHeight!=null&&this.cache.estimatedUnifiedHeight!=null)return;const{disableFileHeader:t=!1,expandUnchanged:i=!1,collapsedContextThreshold:n=1}=this.options,{splitHeight:s,unifiedHeight:r}=On({fileDiff:e,metrics:this.metrics,disableFileHeader:t,hunkSeparators:this.getHunkSeparatorType(),expandUnchanged:i,expandedHunks:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:n,canHydratePartialDiff:qe(e,this.options.loadDiffFiles!=null)});this.cache.estimatedSplitHeight=s,this.cache.estimatedUnifiedHeight=r}validateComputedHeight(e=this.getLayoutDiff()){if(this.fileContainer==null||e==null)return;const t=this.fileContainer.getBoundingClientRect();t.height!==this.height?console.log("VirtualizedFileDiff.computeApproximateSize: computed height doesnt match",{name:e.name,elementHeight:t.height,computedHeight:this.height}):console.log("VirtualizedFileDiff.computeApproximateSize: computed height IS CORRECT")}render({fileContainer:e,fileDiff:t,forceRender:i=!1,lineAnnotations:n,...s}={}){const r=nt(s,"VirtualizedFileDiff.render"),o=r!=null,a=r?.oldFile,l=r?.newFile,h=o&&(!At(a,this.deletionFile)||!At(l,this.additionFile));let d=t??this.fileDiff;t==null&&o&&(h||this.fileDiff==null)&&(d=se(r.oldFile,r.newFile,this.options.parseDiffOptions));const{forceRenderOverride:u,isSetup:c}=this;this.forceRenderOverride=void 0;const f=d!=null&&!D(this.fileDiff,d),p=f||h;if(e=this.getOrCreateFileContainer(e),d==null)return console.error("VirtualizedFileDiff.render: attempting to virtually render when we dont have the correct data"),!1;f&&this.updateExternalDiff(d,n);const{pendingRenderDiff:g,layoutDiffChanged:S,renderedDiffChanged:C,annotationsChanged:y}=this.pendingRender!=null&&this.pendingRender.latestDiff===(this.getLatestDiff(d)??d)?{pendingRenderDiff:this.pendingRender.diff,layoutDiffChanged:!1,renderedDiffChanged:!1,annotationsChanged:this.syncLineAnnotations(n)}:this.updatePendingRender(d,n);if(S&&this.resetLayoutCache({includeEstimatedHeights:!0}),c)this.top??=this.getVirtualizedTop(),this.layoutDirty&&this.isSimpleMode()&&(this.getSimpleVirtualizer()?.markDOMDirty(),this.computeApproximateSize(!1,g));else{this.computeApproximateSize(!1,g);const b=this.getSimpleVirtualizer();if(this.top??=this.getVirtualizedTop(),this.isAdvancedMode())this.isVisible=!0;else{if(b==null)throw new Error("VirtualizedFileDiff.render: simple virtualizer is not available");b.connect(e,this),this.isVisible=b.isInstanceVisible(this.top??0,this.height)}this.isSetup=!0}if(!this.isVisible&&this.isSimpleMode()&&(!p||!c))return r!=null&&(this.deletionFile=a,this.additionFile=l),f&&this.clearReusableHeader(),this.renderPlaceholder(this.height);const v=this.virtualizer.getWindowSpecs(),R=this.top??0,m=this.computeRenderRangeFromWindow(g,R,v);return super.render({fileDiff:d,fileContainer:e,renderRange:m,lineAnnotations:n,forceRender:(u??i)||y||C||f,...r,...s})}finalizeRender(){if(!D(this.getRenderedDiff(),this.pendingRender?.diff))throw new Error("VirtualizedFileDiff.render: rendered a different diff than its prepared layout");this.pendingRender=void 0,this.isSimpleMode()&&this.getSimpleVirtualizer()?.requestHeightReconcile(this)}updatePendingRender(e,t){const i=this.getLatestDiff(e)??e,n=this.getRenderedDiff(),{pendingRender:s}=this,r=s?.diff??n,o=this.hunksRenderer.getDiffForNextRender(i);return this.pendingRender={latestDiff:i,diff:o},{pendingRenderDiff:o,annotationsChanged:this.syncLineAnnotations(t),layoutDiffChanged:!D(r,o),renderedDiffChanged:!D(n,o)}}syncVirtualizedTop(){this.top=this.getVirtualizedTop()}shouldDisableVirtualizationBuffers(){return this.isAdvancedMode()||super.shouldDisableVirtualizationBuffers()}shouldGuardRebuildScroll(){return!1}isSimpleMode(){return this.virtualizer.type==="simple"}isAdvancedMode(){return this.virtualizer.type==="advanced"}getVirtualizedTop(){return this.virtualizer.type==="advanced"?this.virtualizer.getLocalTopForInstance(this):this.fileContainer!=null?this.virtualizer.getOffsetInScrollContainer(this.fileContainer):0}getSimpleVirtualizer(){return this.virtualizer.type==="simple"?this.virtualizer:void 0}getAdvancedVirtualizer(){return this.virtualizer.type==="advanced"?this.virtualizer:void 0}isResizeDebuggingEnabled(){return this.getSimpleVirtualizer()?.config.resizeDebugging??!1}getDiffStyle(){return this.options.diffStyle??"split"}getHunkSeparatorType(){return Xn(this.options.hunkSeparators)}approximateLayoutCheckpoints(e){if(!this.layoutDirty&&this.cache.checkpoints.length>0||e.hunks.length===0||this.options.collapsed===!0)return;const{disableFileHeader:t=!1,expandUnchanged:i=!1,collapsedContextThreshold:n=1}=this.options,s=e.hunks.length-1,r=qe(e,this.options.loadDiffFiles!=null),o=this.getDiffStyle(),a=this.getHunkSeparatorType(),l=i?!0:this.hunksRenderer.getExpandedHunksMap(),h=Gn(this.cache.heightDeltas);let d=fe(this.metrics,t)+this.cache.fileAnnotationHeight,u=0;const c=({rowCount:f,startLineIndex:p,preSeparatorHeight:g=0,postSeparatorHeight:S=0,metadataOffsets:C=[]})=>{if(f<=0)return;const y=u,v=u+f;let R=Wn(y);for(;R<v;){const m=R-y,b=d+(m>0?g:0)+m*this.metrics.lineHeight+$n(C,m)*this.metrics.lineHeight+xt(h,p,p+m);this.cache.checkpoints.push({renderedLineIndex:R,lineIndex:p+m,top:b}),R+=st}d+=g+f*this.metrics.lineHeight+C.length*this.metrics.lineHeight+xt(h,p,p+f)+S,u=v};for(let f=0;f<e.hunks.length;f++){const p=e.hunks[f];if(p==null)throw new Error("VirtualizedFileDiff.approximateLayoutCheckpoints: invalid hunk index");const g=Re({isPartial:e.isPartial,rangeSize:p.collapsedBefore,expandedHunks:l,hunkIndex:f,collapsedContextThreshold:n}),S=g.collapsedLines>0?Le({type:a,metrics:this.metrics,hunkIndex:f,hunkSpecs:p.hunkSpecs})?.totalHeight??0:0;c({rowCount:g.fromStart,startLineIndex:(o==="split"?p.splitLineStart:p.unifiedLineStart)-g.rangeSize});let C=S;c({rowCount:g.fromEnd,startLineIndex:(o==="split"?p.splitLineStart:p.unifiedLineStart)-g.fromEnd,preSeparatorHeight:C}),g.fromEnd>0&&(C=0);const y=f===s?ke({fileDiff:e,hunkIndex:f,expandedHunks:l,collapsedContextThreshold:n,errorPrefix:"VirtualizedFileDiff"}):void 0,v=y!=null&&y.collapsedLines>0?ie({type:a,metrics:this.metrics})?.totalHeight??0:f===s&&r?ie({type:a,metrics:this.metrics})?.totalHeight??0:0,R=y!=null?y.fromStart+y.fromEnd:0,m=o==="split"?p.splitLineCount:p.unifiedLineCount,b=o==="split"?p.splitLineStart:p.unifiedLineStart;c({rowCount:m,startLineIndex:b,preSeparatorHeight:C,postSeparatorHeight:R===0?v:0,metadataOffsets:jn({diffStyle:o,hunk:p,rowCount:m})}),y!=null&&R>0&&c({rowCount:R,startLineIndex:b+m,postSeparatorHeight:v})}this.cache.totalLines=u}getLayoutCheckpointBeforeLineIndex(e){if(e<=0||this.cache.checkpoints.length===0)return;let t=0,i=this.cache.checkpoints.length-1,n;for(;t<=i;){const s=t+i>>1,r=this.cache.checkpoints[s];if(r==null)throw new Error("VirtualizedFileDiff: invalid checkpoint index");r.lineIndex<=e?(n=r,t=s+1):i=s-1}return n}getLayoutCheckpointBeforeTop(e,t){let i=0,n=this.cache.checkpoints.length-1,s=-1;for(;i<=n;){const r=i+n>>1,o=this.cache.checkpoints[r];if(o==null)throw new Error("VirtualizedFileDiff: invalid checkpoint index");o.top<=e?(s=r,i=r+1):n=r-1}if(t==null)return s>=0?this.cache.checkpoints[s]:void 0;for(let r=s;r>=0;r--){const o=this.cache.checkpoints[r];if(o==null)throw new Error("VirtualizedFileDiff: invalid checkpoint index");if(o.renderedLineIndex%t===0)return o}}getExpandedLineCount(e,t){let i=0;if(e.isPartial){for(const a of e.hunks)i+=t==="split"?a.splitLineCount:a.unifiedLineCount;return i}const{expandUnchanged:n=!1,collapsedContextThreshold:s=1}=this.options,r=n?!0:this.hunksRenderer.getExpandedHunksMap();for(const[a,l]of e.hunks.entries()){const h=t==="split"?l.splitLineCount:l.unifiedLineCount;i+=h;const d=Math.max(l.collapsedBefore,0),{fromStart:u,fromEnd:c,renderAll:f}=Re({isPartial:e.isPartial,rangeSize:d,expandedHunks:r,hunkIndex:a,collapsedContextThreshold:s});d>0&&(i+=f?d:u+c)}const o=ke({fileDiff:e,hunkIndex:e.hunks.length-1,expandedHunks:r,collapsedContextThreshold:s,errorPrefix:"VirtualizedFileDiff"});return o!=null&&(i+=o.fromStart+o.fromEnd),i}getLayoutLineCount(e,t){const i=this.getExpandedLineCount(e,t),n=t==="split"?e.splitLineCount:e.unifiedLineCount;return Math.max(i,n,e.additionLines.length,e.deletionLines.length,this.cache.totalLines)}computeRenderRangeFromWindow(e,t,{top:i,bottom:n}){const{disableFileHeader:s=!1,expandUnchanged:r=!1,collapsedContextThreshold:o=1}=this.options,{hunkLineCount:a,lineHeight:l}=this.metrics,h=this.getDiffStyle(),d=this.getHunkSeparatorType(),u=qe(e,this.options.loadDiffFiles!=null),c=this.height;let f=this.getLayoutLineCount(e,h);const p=fe(this.metrics,s),g=e.hunks.length>0?Mt(this.metrics):0,{fileAnnotationHeight:S}=this.cache,C=p+S,y=Math.max(0,c-p-S-g),v=this.hasFileAnnotations(e),R=t+p,m=S>0&&v&&R<n&&R+S>i;if(t<i-c||t>n)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:c-p-g};if(f<=a||e.hunks.length===0)return{startingLine:0,totalLines:a,bufferBefore:0,bufferAfter:0};this.approximateLayoutCheckpoints(e),f=this.getLayoutLineCount(e,h);const b=Math.ceil(Math.max(n-i,0)/l),L=Math.ceil(b/a)*a+a,F=L/a,ae=F,k=[],M=(i+n)/2,le=this.getLayoutCheckpointBeforeTop(Math.max(0,i-t-L*l*2),a);let I=t+(le?.top??C),G=le?.renderedLineIndex??0,Q,H,x;if(pe({diff:e,diffStyle:h,startingLine:le?.renderedLineIndex??0,expandedHunks:r?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:o,callback:({hunkIndex:ge,hunk:W,collapsedBefore:Be,collapsedAfter:Ve,deletionLine:ee,additionLine:$})=>{const A=$!=null?$.splitLineIndex:ee.splitLineIndex,z=$!=null?$.unifiedLineIndex:ee.unifiedLineIndex,U=($?.noEOFCR??!1)||(ee?.noEOFCR??!1),te=ge===e.hunks.length-1&&W!=null&&(h==="split"?A===W.splitLineStart+W.splitLineCount-1:z===W.unifiedLineStart+W.unifiedLineCount-1),B=(Be>0?Le({type:d,metrics:this.metrics,hunkIndex:ge,hunkSpecs:W?.hunkSpecs}):void 0)?.totalHeight??0;I+=B;const V=G%a===0,J=Math.floor(G/a);if(V&&(k[J]=I-(t+C+B),x!=null)){if(x<=0)return!0;x--}const N=this.getLineHeight(h==="split"?A:z,U);if(I>i-N&&I<n&&(Q??=J),H==null&&I+N>M&&(H=J),x==null&&I>=n&&V&&(x=ae),G++,I+=N,Ve>0||te&&u){const xe=ie({type:d,metrics:this.metrics});xe!=null&&(I<n&&I+xe.totalHeight>i&&(Q??=J),H==null&&I+xe.totalHeight>M&&(H=J),I+=xe.totalHeight)}return!1}}),Q==null)if(m)Q=0,H=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:c-p-g};H??=Q;const X=Math.round(H-F/2),de=Math.max(0,Math.ceil(f/a)-F),E=Math.max(0,Math.min(X,de)),w=E*a,T=X<0?L+X*a:L,O=k[E]??0,Y=w===0?0:S+O,he=E+T/a,He=he<k.length?y-k[he]:y-(I-t-C);return{startingLine:w,totalLines:T,bufferBefore:Y,bufferAfter:Math.max(0,He)}}};function _n(e){let t;for(const i of e){if(i==null)continue;const n=i.children[1];if(n instanceof HTMLElement)for(const s of n.children)s instanceof HTMLElement&&s.dataset.lineAnnotation===Si&&(t=Math.max(t??0,s.getBoundingClientRect().height))}return t}function Gn(e){const t=Array.from(e).sort((r,o)=>r[0]-o[0]),i=[],n=[0];let s=0;for(const[r,o]of t)i.push(r),s+=o,n.push(s);return{lineIndexes:i,prefixTotals:n}}function xt({lineIndexes:e,prefixTotals:t},i,n){if(i>=n||e.length===0)return 0;const s=wt(e,i);return(t[wt(e,n)]??0)-(t[s]??0)}function wt(e,t){let i=0,n=e.length;for(;i<n;){const s=i+n>>1,r=e[s];if(r==null)throw new Error("VirtualizedFileDiff: invalid prefix index");r<t?i=s+1:n=s}return i}function Wn(e){return Math.ceil(e/st)*st}function $n(e,t){let i=0;for(const n of e)n<t&&i++;return i}function jn({diffStyle:e,hunk:t,rowCount:i}){if(i<=0||!t.noEOFCRAdditions&&!t.noEOFCRDeletions)return[];const n=t.hunkContent.at(-1);if(n==null)return[];if(n.type==="context")return[i-1];const s=Math.max(n.deletions,n.additions),r=n.deletions+n.additions;if(e==="split")return s>0&&(t.noEOFCRAdditions||t.noEOFCRDeletions)?[i-1]:[];const o=[],a=i-r;return n.deletions>0&&t.noEOFCRDeletions&&o.push(a+n.deletions-1),n.additions>0&&t.noEOFCRAdditions&&o.push(i-1),o}function Kn(e,t){return(e.diffStyle??"split")!==(t.diffStyle??"split")||(e.overflow??"scroll")!==(t.overflow??"scroll")||(e.collapsed??!1)!==(t.collapsed??!1)||(e.disableLineNumbers??!1)!==(t.disableLineNumbers??!1)||(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||(e.diffIndicators??"bars")!==(t.diffIndicators??"bars")||(e.hunkSeparators??"line-info")!==(t.hunkSeparators??"line-info")||!!e.loadDiffFiles!=!!t.loadDiffFiles||(e.expandUnchanged??!1)!==(t.expandUnchanged??!1)||(e.collapsedContextThreshold??1)!==(t.collapsedContextThreshold??1)||e.unsafeCSS!==t.unsafeCSS}function qn(e,t){return(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||(e.hunkSeparators??"line-info")!==(t.hunkSeparators??"line-info")||!!e.loadDiffFiles!=!!t.loadDiffFiles||(e.expandUnchanged??!1)!==(t.expandUnchanged??!1)||(e.collapsedContextThreshold??1)!==(t.collapsedContextThreshold??1)}function qe(e,t){return e.isPartial&&t&&(e.type==="change"||e.type==="rename-changed")}function Xn(e){return typeof e=="function"?"custom":e??"line-info"}function At(e,t){return e==null||t==null?e==null&&t==null:It(e,t)}function Yn(e,t){const[i,n]=e.split(",").map(Number);return t==="split"?n:i}export{Mn as F,is as V};