@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.
- package/README.md +32 -24
- package/bin/cli.js +1 -3
- package/bin/cli.test.js +40 -16
- package/bin/lib/DOCUMENTATION.md +6 -5
- package/bin/lib/cli-args.js +6 -1
- package/bin/lib/cli-args.test.js +34 -0
- package/bin/lib/cli-lifecycle.js +0 -1
- package/bin/lib/cli-network.js +8 -2
- package/bin/lib/cli-process.js +1 -1
- package/bin/lib/cli-settings-accessors.test.js +21 -13
- package/bin/lib/cli-startup.js +17 -11
- package/bin/lib/cli-startup.test.js +92 -2
- package/bin/lib/commands-connect-url.js +8 -1
- package/bin/lib/commands-schedule.js +8 -2
- package/bin/lib/commands-serve.js +15 -21
- package/bin/lib/commands-update.js +12 -24
- package/bin/lib/commands-update.test.js +14 -46
- package/dist/assets/DiffView-Cv9MSXl1.js +4 -0
- package/dist/assets/FilePreviewCommentMenu-D4kLseHj.js +4 -0
- package/dist/assets/FilesView-BVoD8I2x.js +14 -0
- package/dist/assets/{GitView-DzuzhIPx.js → GitView-Bzb8p-ew.js} +4 -4
- package/dist/assets/GuestSurfacePane-Crdbvsxo.js +1 -0
- package/dist/assets/InProgressOperationBanner-CwMjNQgk.js +2 -0
- package/dist/assets/{JsonTreeView-B_EPRjzy.js → JsonTreeView-DRKHZfsn.js} +1 -1
- package/dist/assets/MarkdownImageGallery-DZtqT1Zn.js +1 -0
- package/dist/assets/MarkdownRendererImpl-CqG7HCNd.js +10 -0
- package/dist/assets/OnboardingScreen-DMIxwYK5.js +1 -0
- package/dist/assets/{PatchDiff-6yh1csza.js → PatchDiff-CUcCg1jk.js} +1 -1
- package/dist/assets/PierreDiffViewer-CnnR-dnD.js +228 -0
- package/dist/assets/PlanView-RCBadcY7.js +5 -0
- package/dist/assets/SettingsView-CjBjZFRO.js +30 -0
- package/dist/assets/SettingsWindow-DyM7QuhI.js +1 -0
- package/dist/assets/SubmoduleDiffSummary-BWIfgMED.js +1 -0
- package/dist/assets/ToolOutputDialog-Q0P3FuAi.js +15 -0
- package/dist/assets/ToolPartDiffPreview-p7qR9FpU.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-BTJVRkyo.js → VirtualizedFileDiff-CFpjL8Ns.js} +3 -3
- package/dist/assets/{Virtualizer-xCEYz34p.js → Virtualizer-C0IsclZn.js} +1 -1
- package/dist/assets/WalkthroughView-DI31zD02.js +4 -0
- package/dist/assets/appThemeRegistry-B9gkFq9i.js +1 -0
- package/dist/assets/{computeVirtualFileMetrics-CmPe29DM.js → computeVirtualFileMetrics-C2WM6JC2.js} +2 -2
- package/dist/assets/de-YKfk5MmC.js +14 -0
- package/dist/assets/es-_gwT0kr-.js +20 -0
- package/dist/assets/fileTreeStatus-D438yi8M.js +1 -0
- package/dist/assets/fr-DqzvXmIm.js +18 -0
- package/dist/assets/index-BLaHKdtx.js +1 -0
- package/dist/assets/index-BkMXRrVQ.css +1 -0
- package/dist/assets/index-DxNa7xYB.js +65 -0
- package/dist/assets/initializeSharedPreferences-Bck5EAWP.js +1 -0
- package/dist/assets/{isDiffPlainText-CQmDCnEv.js → isDiffPlainText-Dgbw8VKk.js} +1 -1
- package/dist/assets/{isFilePlainText-CYBUzW4I.js → isFilePlainText-_ZS5UYRj.js} +1 -1
- package/dist/assets/ja-B-GFYhQE.js +20 -0
- package/dist/assets/ko-mzksfqDC.js +20 -0
- package/dist/assets/main-C5Xx8dn_.js +2 -0
- package/dist/assets/main-CfBSQM1H.js +990 -0
- package/dist/assets/markdownCore-BmWwW1ll.js +7 -0
- package/dist/assets/miniChat-mnKwy4vQ.js +2 -0
- package/dist/assets/mobile-DeEQd0wZ.js +2 -0
- package/dist/assets/nl-CWQr6NSq.js +20 -0
- package/dist/assets/{parseDiffFromFile-Cy0PNxun.js → parseDiffFromFile-BUgn-T9p.js} +2 -2
- package/dist/assets/patchFileDiff-Dt8LhgBh.js +13 -0
- package/dist/assets/pl-UmRcDUX2.js +20 -0
- package/dist/assets/pt-BR-BSLybvVF.js +20 -0
- package/dist/assets/relocateRestoredSession-B5E9xb3T.js +1 -0
- package/dist/assets/renderElectronMiniChatApp-C0a9A5_J.js +2 -0
- package/dist/assets/renderMobileApp-BNncg3Pk.js +25 -0
- package/dist/assets/runtimeEndpointReset-CZ5aafpl.js +62 -0
- package/dist/assets/{selectionMarkdown-TkYk5h9l.js → selectionMarkdown-CUN3wUld.js} +9 -9
- package/dist/assets/{sessionOwnership-Bs1xbRfB.js → sessionOwnership-BSuxCEhb.js} +1 -1
- package/dist/assets/shikiHighlight-DHDx-6eM.js +1 -0
- package/dist/assets/space-apply-DM_2pRW7.js +1 -0
- package/dist/assets/space-close-Bpomt8z0.js +1 -0
- package/dist/assets/{surface-B6n7wJtt.js → surface-C-jQaGnL.js} +1 -1
- package/dist/assets/{textMateThemeFromAppTheme-CDlKffWz.js → textMateThemeFromAppTheme-DlsTphbY.js} +1 -1
- package/dist/assets/tr-gaTrX_HK.js +11 -0
- package/dist/assets/uk-CnJF6ykl.js +20 -0
- package/dist/assets/{useAppFontEffects-DCqCVGlT.js → useAppFontEffects-DGlvOqP_.js} +194 -233
- package/dist/assets/useInlineCommentController-kMN4Wg_D.js +2 -0
- package/dist/assets/{useRootScrollLock-BowwS8kq.js → useRootScrollLock-DMPpvpNP.js} +2 -2
- package/dist/assets/{vendor-base-ui-DX96QhTP.js → vendor-base-ui-Det7U81h.js} +1 -1
- package/dist/assets/{vendor-codemirror-autocomplete-DW1FQz9_.js → vendor-codemirror-autocomplete-BSHQHbKu.js} +1 -1
- package/dist/assets/{vendor-codemirror-commands-DpmhalwN.js → vendor-codemirror-commands-C4G_dPWe.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-angular-BqExbN1M.js → vendor-codemirror-lang-angular-B6LbBGHB.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-cpp-DZA36HfS.js → vendor-codemirror-lang-cpp-BWWXBx7W.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-css-B07blnnZ.js → vendor-codemirror-lang-css-Cayfb29q.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-go-BM8K9D1-.js → vendor-codemirror-lang-go-BoKlCNKw.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-html-DaH9adfE.js → vendor-codemirror-lang-html-BQWerHsJ.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-java-CsdC0viz.js → vendor-codemirror-lang-java-DWX7Fq_K.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-javascript-CpGYXGuo.js → vendor-codemirror-lang-javascript-DbpEcZM0.js} +2 -2
- package/dist/assets/{vendor-codemirror-lang-jinja-BBeGzXw5.js → vendor-codemirror-lang-jinja-D1JIJRA7.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-json-58T70Hqs.js → vendor-codemirror-lang-json-BzgckzmB.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-less-BI-xCA59.js → vendor-codemirror-lang-less-B9EpDXFi.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-liquid-zEcMa-zy.js → vendor-codemirror-lang-liquid-9U7kRbSf.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-markdown-BLKnlLP4.js → vendor-codemirror-lang-markdown-D2TEBIvZ.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-php-9f35M83-.js → vendor-codemirror-lang-php-BT6sDVzE.js} +1 -1
- package/dist/assets/vendor-codemirror-lang-python-jAMtYiA9.js +3 -0
- package/dist/assets/{vendor-codemirror-lang-rust-MNDL_jZQ.js → vendor-codemirror-lang-rust-CVO56EiL.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sass-p9epsSNm.js → vendor-codemirror-lang-sass-DZlOoUWu.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sql-Bqzh0EXX.js → vendor-codemirror-lang-sql-fZ6t1DPw.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-vue-BnNUWV-p.js → vendor-codemirror-lang-vue-DxbqrLiE.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-wast-C2a-oLmk.js → vendor-codemirror-lang-wast-DyU1Gt-I.js} +1 -1
- package/dist/assets/vendor-codemirror-lang-xml-C9a_K5_p.js +1 -0
- package/dist/assets/{vendor-codemirror-lang-yaml-C0sjswB0.js → vendor-codemirror-lang-yaml-Cptq8l0e.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-ByBn5zIW.js → vendor-codemirror-language-DufXoQvE.js} +2 -2
- package/dist/assets/vendor-codemirror-language-data-CtwSWKtX.js +2 -0
- package/dist/assets/{vendor-codemirror-search-ib-sHD5W.js → vendor-codemirror-search-CvXM_pZg.js} +1 -1
- package/dist/assets/{vendor-codemirror-state-G3UuR-be.js → vendor-codemirror-state-Dek9sMtw.js} +1 -1
- package/dist/assets/{vendor-codemirror-view-Bniqp7p5.js → vendor-codemirror-view-1e0FQ6Wn.js} +1 -1
- package/dist/assets/vendor-framer-motion-DxDVhOLc.js +9 -0
- package/dist/assets/vendor-katex-CuQvj9-L.js +257 -0
- package/dist/assets/vendor-katex-DdZNUVNG.css +1 -0
- package/dist/assets/{vendor-motion-dom-DcCgeG69.js → vendor-motion-dom-HXPOMxb7.js} +1 -1
- package/dist/assets/{vendor-opencode-client-DHzhmLwV.js → vendor-opencode-client-BmFcUkbQ.js} +1 -1
- package/dist/assets/{vendor-replit-codemirror-vim-DkzqxN2H.js → vendor-replit-codemirror-vim-BlJRn-cW.js} +2 -2
- package/dist/assets/{vendor-tanstack-react-virtual-H_JmXOFV.js → vendor-tanstack-react-virtual-CvuLsk7D.js} +1 -1
- package/dist/assets/{vendor-tanstack-virtual-core-Dxc8hSTB.js → vendor-tanstack-virtual-core-DPaNcJcT.js} +1 -1
- package/dist/assets/zh-CN-t2vigSB1.js +20 -0
- package/dist/assets/zh-TW-jAgqBokB.js +20 -0
- package/dist/index.html +6 -6
- package/dist/mini-chat.html +6 -6
- package/dist/mobile.html +6 -6
- package/package.json +8 -5
- package/server/index.js +80 -36
- package/server/lib/agent-memory/actions.js +1 -6
- package/server/lib/agent-memory/routes.js +1 -2
- package/server/lib/agent-memory/runtime.js +1 -8
- package/server/lib/agent-tool/DOCUMENTATION.md +7 -3
- package/server/lib/agent-tool/runtime.js +3 -6
- package/server/lib/agent-tool/runtime.test.js +0 -2
- package/server/lib/browser-control/DOCUMENTATION.md +6 -0
- package/server/lib/changelog/update-notes.js +1 -1
- package/server/lib/context-obligatory/runtime.js +1 -2
- package/server/lib/dev-tunnel/DOCUMENTATION.md +8 -0
- package/server/lib/dev-tunnel/client.js +21 -10
- package/server/lib/dev-tunnel/tunnel.test.js +34 -0
- package/server/lib/dispatch-results/runtime.js +1 -1
- package/server/lib/enterprise-mode.d.ts +1 -0
- package/server/lib/enterprise-mode.js +13 -2
- package/server/lib/enterprise-mode.test.js +21 -0
- package/server/lib/event-stream/DOCUMENTATION.md +2 -2
- package/server/lib/event-stream/index.js +1 -3
- package/server/lib/event-stream/translate-v2.js +1 -9
- package/server/lib/event-stream/translate-v2.test.js +0 -11
- package/server/lib/fs/DOCUMENTATION.md +5 -2
- package/server/lib/fs/routes.js +62 -15
- package/server/lib/fs/routes.test.js +278 -48
- package/server/lib/fs/workspace-file-names.js +104 -0
- package/server/lib/fs/workspace-file-names.test.js +62 -0
- package/server/lib/git/DOCUMENTATION.md +17 -5
- package/server/lib/git/contributor-provenance-storage.js +9 -6
- package/server/lib/git/contributor-provenance-storage.test.js +29 -0
- package/server/lib/git/credential-broker.js +1 -1
- package/server/lib/git/credential-resolver.js +1 -4
- package/server/lib/git/credentials.js +1 -0
- package/server/lib/git/discovery-endpoint.js +1 -1
- package/server/lib/git/identity-provisioning.js +2 -1
- package/server/lib/git/identity-storage.js +3 -4
- package/server/lib/git/lfs-discovery.js +14 -14
- package/server/lib/git/lfs-discovery.test.js +16 -6
- package/server/lib/git/network-operation-plan.js +50 -62
- package/server/lib/git/network-operation-plan.test.js +103 -1
- package/server/lib/git/network-operation-registry.js +4 -6
- package/server/lib/git/network-operation-storage.js +4 -6
- package/server/lib/git/network-operations.js +12 -4
- package/server/lib/git/network-operations.test.js +19 -6
- package/server/lib/git/redaction.js +2 -1
- package/server/lib/git/repository-credential-runtime.js +5 -3
- package/server/lib/git/repository-credential-runtime.test.js +22 -0
- package/server/lib/git/routes.js +31 -137
- package/server/lib/git/routes.test.js +2 -2
- package/server/lib/git/service.js +143 -27
- package/server/lib/git/service.test.js +215 -1
- package/server/lib/git/ssh-credential-storage.js +1 -4
- package/server/lib/git/submodule-discovery.js +1 -1
- package/server/lib/git/worktree-bootstrap-storage.js +3 -4
- package/server/lib/git/worktree-bootstrap-storage.test.js +15 -0
- package/server/lib/git/worktree-creation.js +194 -0
- package/server/lib/git/worktree-creation.test.js +155 -0
- package/server/lib/github/DOCUMENTATION.md +11 -6
- package/server/lib/github/auth.js +2 -4
- package/server/lib/github/device-flow.js +2 -2
- package/server/lib/github/gh-cli-credential.js +1 -0
- package/server/lib/github/octokit.js +31 -0
- package/server/lib/github/pr-status.js +35 -18
- package/server/lib/github/pr-status.test.js +271 -3
- package/server/lib/github/reference-search.js +102 -13
- package/server/lib/github/reference-search.test.js +48 -7
- package/server/lib/github/routes.auth.test.js +18 -0
- package/server/lib/github/routes.js +360 -6
- package/server/lib/github/routes.mutations.test.js +239 -0
- package/server/lib/github/routes.test.js +134 -2
- package/server/lib/gitlab/DOCUMENTATION.md +5 -1
- package/server/lib/gitlab/auth-storage.test.js +1 -0
- package/server/lib/gitlab/mappers.js +30 -1
- package/server/lib/gitlab/resources.js +230 -6
- package/server/lib/gitlab/resources.test.js +179 -0
- package/server/lib/gitlab/routes.js +200 -6
- package/server/lib/gitlab/routes.test.js +186 -2
- package/server/lib/gitlab/validation.js +1 -5
- package/server/lib/guests/DOCUMENTATION.md +1 -1
- package/server/lib/guests/oauth.js +2 -2
- package/server/lib/guests/service.js +1 -1
- package/server/lib/guests/sockets.js +1 -1
- package/server/lib/injected-env.d.ts +8 -0
- package/server/lib/injected-env.js +50 -0
- package/server/lib/injected-env.test.js +56 -0
- package/server/lib/linear/DOCUMENTATION.md +5 -6
- package/server/lib/linear/issues.js +62 -4
- package/server/lib/linear/issues.test.js +68 -0
- package/server/lib/linear/oauth.js +5 -5
- package/server/lib/linear/parse.js +2 -9
- package/server/lib/message-queue/DOCUMENTATION.md +23 -1
- package/server/lib/message-queue/runtime.js +85 -12
- package/server/lib/message-queue/runtime.test.js +172 -2
- package/server/lib/notifications/apns-runtime.js +5 -6
- package/server/lib/notifications/apns-runtime.test.js +20 -4
- package/server/lib/openchamber-control/DOCUMENTATION.md +19 -1
- package/server/lib/openchamber-control/actions.js +2 -1
- package/server/lib/openchamber-control/service.js +119 -20
- package/server/lib/openchamber-control/service.test.js +166 -0
- package/server/lib/openchamber-sessions/archive-store.js +1 -6
- package/server/lib/openchamber-sessions/routes.js +47 -12
- package/server/lib/openchamber-sessions/routes.test.js +65 -2
- package/server/lib/openchamber-sessions/session-metadata-store.js +1 -6
- package/server/lib/opencode/DOCUMENTATION.md +22 -8
- package/server/lib/opencode/agents.js +62 -0
- package/server/lib/opencode/auth-state-runtime.js +3 -1
- package/server/lib/opencode/auth.d.ts +1 -1
- package/server/lib/opencode/auth.js +8 -0
- package/server/lib/opencode/auth.test.js +31 -0
- package/server/lib/opencode/config-entity-routes.js +16 -0
- package/server/lib/opencode/config-entity-v2.test.js +16 -1
- package/server/lib/opencode/config-paths.test.js +2 -2
- package/server/lib/opencode/config-v2.js +2 -4
- package/server/lib/opencode/feature-routes-runtime.js +89 -49
- package/server/lib/opencode/lifecycle.js +41 -21
- package/server/lib/opencode/lifecycle.test.js +50 -2
- package/server/lib/opencode/model-discovery.js +1 -1
- package/server/lib/opencode/model-discovery.test.js +17 -0
- package/server/lib/opencode/models-metadata.js +0 -2
- package/server/lib/opencode/openchamber-routes.test.js +3 -3
- package/server/lib/opencode/plugins.js +6 -9
- package/server/lib/opencode/provider-source-route.test.js +101 -3
- package/server/lib/opencode/providers-disabled.test.js +59 -0
- package/server/lib/opencode/providers.js +34 -0
- package/server/lib/opencode/proxy.js +11 -3
- package/server/lib/opencode/routes.js +40 -2
- package/server/lib/opencode/settings-helpers.js +27 -1
- package/server/lib/opencode/settings-helpers.test.js +19 -7
- package/server/lib/opencode/settings-registry.json +27 -16
- package/server/lib/opencode/settings-runtime.test.js +18 -0
- package/server/lib/opencode/shared-service-runtime.js +23 -104
- package/server/lib/opencode/shared.js +77 -46
- package/server/lib/opencode/shared.test.js +12 -12
- package/server/lib/opencode/shutdown-runtime.test.js +2 -3
- package/server/lib/opencode/skill-routes.js +123 -38
- package/server/lib/opencode/skill-routes.test.js +201 -0
- package/server/lib/opencode/skills.js +81 -34
- package/server/lib/opencode/skills.test.js +176 -21
- package/server/lib/opencode/startup-pipeline-runtime.js +6 -3
- package/server/lib/opencode/startup-pipeline-runtime.test.js +2 -1
- package/server/lib/opencode/watcher.test.js +0 -54
- package/server/lib/outbound-proxy.js +52 -0
- package/server/lib/outbound-proxy.test.js +55 -0
- package/server/lib/package-manager.js +23 -17
- package/server/lib/package-manager.test.js +5 -18
- package/server/lib/permission-auto-accept/DOCUMENTATION.md +1 -1
- package/server/lib/permission-auto-accept/runtime.js +19 -47
- package/server/lib/permission-auto-accept/runtime.test.js +2 -2
- package/server/lib/project-context/DOCUMENTATION.md +7 -1
- package/server/lib/project-context/routes.js +1 -2
- package/server/lib/project-context/runtime.js +12 -14
- package/server/lib/project-context/runtime.test.js +78 -2
- package/server/lib/projects/project-config.js +30 -15
- package/server/lib/projects/project-config.test.js +30 -0
- package/server/lib/projects/project-setup.js +1 -2
- package/server/lib/projects/routes.js +1 -2
- package/server/lib/quota/DOCUMENTATION.md +35 -7
- package/server/lib/quota/index.js +1 -0
- package/server/lib/quota/providers/claude/index.js +1 -1
- package/server/lib/quota/providers/cline-pass.js +1 -1
- package/server/lib/quota/providers/exe-dev.js +1 -1
- package/server/lib/quota/providers/google/index.js +1 -1
- package/server/lib/quota/providers/hyper.js +1 -1
- package/server/lib/quota/providers/kimi.js +116 -36
- package/server/lib/quota/providers/kimi.test.js +128 -3
- package/server/lib/quota/providers/opencode-go.js +144 -21
- package/server/lib/quota/providers/opencode-go.test.js +229 -6
- package/server/lib/quota/providers/openrouter.js +1 -1
- package/server/lib/quota/providers/zenmux.js +1 -1
- package/server/lib/quota/utils/auth.js +1 -0
- package/server/lib/quota/utils/transformers.js +2 -6
- package/server/lib/relay/DOCUMENTATION.md +18 -3
- package/server/lib/relay/e2ee.js +7 -7
- package/server/lib/relay/host-client.js +84 -13
- package/server/lib/relay/host-client.test.js +201 -1
- package/server/lib/relay/identity.js +6 -29
- package/server/lib/relay/identity.test.js +18 -28
- package/server/lib/relay/key-store.js +141 -0
- package/server/lib/relay/key-store.test.js +138 -0
- package/server/lib/relay/service.js +8 -8
- package/server/lib/relay/service.test.js +10 -5
- package/server/lib/relay/signing-key.js +13 -36
- package/server/lib/relay/tunnel-codec.js +10 -10
- package/server/lib/route-module-exports.test.js +22 -0
- package/server/lib/routing/DOCUMENTATION.md +23 -3
- package/server/lib/routing/cache.js +87 -0
- package/server/lib/routing/defaults.js +11 -0
- package/server/lib/routing/history.js +12 -4
- package/server/lib/routing/runtime.js +39 -3
- package/server/lib/routing/runtime.test.js +81 -2
- package/server/lib/routing/store.js +12 -1
- package/server/lib/routing/store.test.js +13 -0
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +59 -1
- package/server/lib/scheduled-tasks/existing-session.js +119 -0
- package/server/lib/scheduled-tasks/existing-session.test.js +350 -0
- package/server/lib/scheduled-tasks/loops.js +1 -8
- package/server/lib/scheduled-tasks/routes.js +8 -8
- package/server/lib/scheduled-tasks/runtime.js +103 -13
- package/server/lib/scheduled-tasks/runtime.test.js +48 -0
- package/server/lib/scheduled-tasks/service.js +33 -11
- package/server/lib/scheduled-tasks/service.test.js +128 -2
- package/server/lib/scheduled-tasks/session-defaults.js +27 -0
- package/server/lib/scheduled-tasks/session-defaults.test.js +19 -0
- package/server/lib/session-assist/context.js +1 -0
- package/server/lib/session-folders/routes.js +2 -2
- package/server/lib/session-goal/objectives.js +1 -1
- package/server/lib/session-knowledge/routes.js +2 -2
- package/server/lib/session-knowledge/runtime.js +1 -2
- package/server/lib/session-work/DOCUMENTATION.md +39 -14
- package/server/lib/session-work/questions.js +31 -2
- package/server/lib/session-work/runtime.js +22 -13
- package/server/lib/session-work/runtime.test.js +43 -26
- package/server/lib/session-work/state.js +10 -4
- package/server/lib/session-work/state.test.js +8 -1
- package/server/lib/shared/DOCUMENTATION.md +89 -0
- package/server/lib/shared/guards.js +53 -0
- package/server/lib/shared/guards.test.js +112 -0
- package/server/lib/skills-catalog/DOCUMENTATION.md +10 -8
- package/server/lib/skills-catalog/cache.js +3 -2
- package/server/lib/skills-catalog/curated-sources.js +5 -1
- package/server/lib/skills-catalog/git.js +107 -20
- package/server/lib/skills-catalog/git.test.js +78 -0
- package/server/lib/skills-catalog/install.js +21 -12
- package/server/lib/skills-catalog/scan.js +25 -15
- package/server/lib/skills-catalog/source.js +26 -1
- package/server/lib/skills-catalog/source.test.js +27 -0
- package/server/lib/source-control/DOCUMENTATION.md +2 -1
- package/server/lib/source-control/audit-storage.js +7 -6
- package/server/lib/source-control/audit-storage.test.js +11 -0
- package/server/lib/source-control/binding-service.js +2 -5
- package/server/lib/source-control/change-request-worktree.js +90 -0
- package/server/lib/source-control/change-request-worktree.test.js +121 -0
- package/server/lib/source-control/mutation-executor.js +1 -1
- package/server/lib/source-control/mutation-storage.js +11 -5
- package/server/lib/source-control/provider-instance.js +1 -2
- package/server/lib/source-control/repository-identity.js +1 -1
- package/server/lib/source-control/routes.js +14 -2
- package/server/lib/spaces/DOCUMENTATION.md +42 -17
- package/server/lib/spaces/command-stream.test.js +15 -0
- package/server/lib/spaces/dispatcher.js +7 -0
- package/server/lib/spaces/dispatcher.test.js +17 -0
- package/server/lib/spaces/hardening.js +2 -2
- package/server/lib/spaces/hardening.test.js +1 -1
- package/server/lib/spaces/host.js +2 -0
- package/server/lib/spaces/journey.js +66 -5
- package/server/lib/spaces/journey.test.js +95 -4
- package/server/lib/spaces/layout.js +1 -1
- package/server/lib/spaces/places/docker-disk.js +38 -14
- package/server/lib/spaces/places/docker-disk.test.js +80 -1
- package/server/lib/spaces/places/docker.js +35 -11
- package/server/lib/spaces/places/fake-docker.js +22 -3
- package/server/lib/spaces/places/memory-place.js +3 -0
- package/server/lib/spaces/places/packed.docker.live.test.js +1 -1
- package/server/lib/spaces/routes.js +5 -0
- package/server/lib/spaces/routes.test.js +4 -2
- package/server/lib/spaces/run-command.js +9 -2
- package/server/lib/spaces/tools.js +4 -5
- package/server/lib/spaces/tools.test.js +2 -2
- package/server/lib/terminal/runtime.js +18 -6
- package/server/lib/terminal/runtime.test.js +66 -0
- package/server/lib/tts/index.js +3 -0
- package/server/lib/tts/service.js +4 -2
- package/server/lib/walkthrough/DOCUMENTATION.md +3 -1
- package/server/lib/walkthrough/index.js +2 -3
- package/server/lib/walkthrough/pr-source.test.js +22 -0
- package/server/lib/walkthrough/sources.js +6 -1
- package/server/opencode-proxy.test.js +127 -0
- package/bin/lib/commands-startup.test.js +0 -15
- package/dist/assets/CodeMirrorCommentWidgets-CVDSjcrP.js +0 -1
- package/dist/assets/DiffView-Ct7vL3fD.js +0 -4
- package/dist/assets/FilesView-DT0uEYgT.js +0 -17
- package/dist/assets/GuestSurfacePane-DVvk1VPu.js +0 -1
- package/dist/assets/LinearIssuesView-C10MwA9h.js +0 -1
- package/dist/assets/MarkdownImageGallery-BbN_K_3d.js +0 -1
- package/dist/assets/MarkdownRendererImpl-BLt2Tkk9.js +0 -10
- package/dist/assets/OnboardingScreen-Bgp5A3WB.js +0 -1
- package/dist/assets/PierreDiffViewer-CWJLj-S-.js +0 -210
- package/dist/assets/PlanView-DsRWnsOI.js +0 -5
- package/dist/assets/PublishDialog-CCeKloRu.js +0 -2
- package/dist/assets/SettingsView-BuPPsNPp.js +0 -30
- package/dist/assets/SettingsWindow-CM5fL8Ot.js +0 -1
- package/dist/assets/SubmoduleDiffSummary-CfsMcfiQ.js +0 -1
- package/dist/assets/ToolOutputDialog-mZrfSofz.js +0 -15
- package/dist/assets/ToolPartDiffPreview-BUGCRYEL.js +0 -8
- package/dist/assets/WalkthroughView-ClBo7PPd.js +0 -4
- package/dist/assets/appThemeRegistry-CxzMxR-H.js +0 -1
- package/dist/assets/de-CBla4hjd.js +0 -14
- package/dist/assets/es-BmnZtxTD.js +0 -20
- package/dist/assets/fileTreeStatus-BSHFIGEg.js +0 -1
- package/dist/assets/fr-OVKIBUZO.js +0 -18
- package/dist/assets/index-CKCFKmjF.js +0 -1
- package/dist/assets/index-Dbx4V4GN.css +0 -1
- package/dist/assets/index-vQ1Pg1cr.js +0 -61
- package/dist/assets/ja-6v-yr-gE.js +0 -20
- package/dist/assets/ko-I_ZLvgQ9.js +0 -20
- package/dist/assets/main-CmO4dRtR.js +0 -2
- package/dist/assets/main-b9vqhlYM.js +0 -999
- package/dist/assets/markdownCore-BPEZRQfP.js +0 -7
- package/dist/assets/miniChat-B5Oi7B-6.js +0 -2
- package/dist/assets/mobile-CVtShif9.js +0 -2
- package/dist/assets/nl-DcvIJf46.js +0 -20
- package/dist/assets/patchFileDiff-CW3wCH1O.js +0 -13
- package/dist/assets/pl-JxCUl0sd.js +0 -20
- package/dist/assets/pt-BR-L89mjja2.js +0 -20
- package/dist/assets/relocateRestoredSession-DYh_9oBa.js +0 -1
- package/dist/assets/renderElectronMiniChatApp-BD-1JHSg.js +0 -2
- package/dist/assets/renderMobileApp-7s5InXt1.js +0 -25
- package/dist/assets/runtimeEndpointReset-DqLJC6L1.js +0 -53
- package/dist/assets/shikiHighlight-CXgZnvHh.js +0 -1
- package/dist/assets/space-apply-1trGVIl8.js +0 -1
- package/dist/assets/space-close-y7j-NuBv.js +0 -1
- package/dist/assets/tr-ka5J1flt.js +0 -11
- package/dist/assets/uk-PyGe6Q_u.js +0 -20
- package/dist/assets/useInlineCommentController-CrjSGCpi.js +0 -2
- package/dist/assets/vendor-codemirror-lang-python-B7ClrMIT.js +0 -3
- package/dist/assets/vendor-codemirror-lang-xml-C8tGnS64.js +0 -1
- package/dist/assets/vendor-codemirror-language-data-q2bKO1EM.js +0 -2
- package/dist/assets/vendor-framer-motion-Bq3iTZ6r.js +0 -1
- package/dist/assets/vendor-katex-CHD9BdDO.js +0 -257
- package/dist/assets/vendor-katex-Cp579UoJ.css +0 -1
- package/dist/assets/zh-CN-B0P2tybJ.js +0 -20
- package/dist/assets/zh-TW-Bs9C5cN8.js +0 -20
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{j7 as C}from"./useAppFontEffects-DGlvOqP_.js";const S=t=>{const n=Array.from(t.querySelectorAll("[data-md-code-line-content]"));if(n.length===0)return t.textContent??"";const r=n.map(e=>e.textContent??"").join(`
|
|
2
2
|
`);return t.hasAttribute("data-md-code-trailing-newline")?`${r}
|
|
3
|
-
`:r},N=1,k=3,w="[data-markdown-content]",L=["button","[data-md-action]","[data-md-menu]","[data-md-code-actions]",'[data-markdown="mermaid-toolbar"]',"[data-md-disclosure-icon]","[data-openchamber-markdown-image-label-icon]","[data-md-table-measure]",`[${C}]`,".katex-mathml","colgroup",'input:not([type="checkbox"])'].join(","),O=new Set(["ADDRESS","ARTICLE","ASIDE","BLOCKQUOTE","DETAILS","DIV","DL","FIGURE","FOOTER","H1","H2","H3","H4","H5","H6","HEADER","HR","LI","OL","P","PRE","SECTION","SUMMARY","TABLE","UL"]),
|
|
3
|
+
`:r},N=1,k=3,w="[data-markdown-content]",L=["button","[data-md-action]","[data-md-menu]","[data-md-code-actions]",'[data-markdown="mermaid-toolbar"]',"[data-md-disclosure-icon]","[data-openchamber-markdown-image-label-icon]","[data-md-table-measure]",`[${C}]`,".katex-mathml","colgroup",'input:not([type="checkbox"])'].join(","),O=new Set(["ADDRESS","ARTICLE","ASIDE","BLOCKQUOTE","DETAILS","DIV","DL","FIGURE","FOOTER","H1","H2","H3","H4","H5","H6","HEADER","HR","LI","OL","P","PRE","SECTION","SUMMARY","TABLE","UL"]),m=t=>t.nodeType===N,R=t=>t.matches(".katex-display")||t.matches('[data-markdown="mermaid-block"], [data-component="markdown-code"], [data-markdown="table-wrapper"]')?!0:O.has(t.tagName),g=(t,n)=>{let r=0,e=0;for(const o of t)e=o===n?e+1:0,r=Math.max(r,e);return r},x=(t,n)=>{const r="`".repeat(Math.max(3,g(t,"`")+1)),e=t.endsWith(`
|
|
4
4
|
`)?t:`${t}
|
|
5
5
|
`;return`${r}${n}
|
|
6
|
-
${e}${r}`},M=t=>{const n="`".repeat(g(t,"`")+1),r=t.startsWith("`")||t.endsWith("`")?" ":"";return`${n}${r}${t}${r}${n}`},h=(t,n)=>{const r=/^(\s*)([\s\S]*?)(\s*)$/.exec(t);return!r||!r[2]?t:`${r[1]}${n}${r[2]}${n}${r[3]}`},T=t=>t.querySelector('annotation[encoding="application/x-tex"]')?.textContent?.trim()||null,I=t=>{const n=t.tagName==="PRE"?t:t.querySelector("pre"),r=n?.getAttribute("data-md-lang");if(r&&r!=="text")return r;const e=n?.querySelector("code")?.className.match(/language-([\w+#.-]+)/)?.[1];return e&&e!=="text"?e:""},H=t=>{const n=t.querySelector("code");return n?S(n):t.textContent??""},_=t=>t.replace(/\|/g,"\\|").replace(/\n+/g," ").trim(),
|
|
6
|
+
${e}${r}`},M=t=>{const n="`".repeat(g(t,"`")+1),r=t.startsWith("`")||t.endsWith("`")?" ":"";return`${n}${r}${t}${r}${n}`},h=(t,n)=>{const r=/^(\s*)([\s\S]*?)(\s*)$/.exec(t);return!r||!r[2]?t:`${r[1]}${n}${r[2]}${n}${r[3]}`},T=t=>t.querySelector('annotation[encoding="application/x-tex"]')?.textContent?.trim()||null,I=t=>{const n=t.tagName==="PRE"?t:t.querySelector("pre"),r=n?.getAttribute("data-md-lang");if(r&&r!=="text")return r;const e=n?.querySelector("code")?.className.match(/language-([\w+#.-]+)/)?.[1];return e&&e!=="text"?e:""},H=t=>{const n=t.querySelector("code");return n?S(n):t.textContent??""},_=t=>t.replace(/\|/g,"\\|").replace(/\n+/g," ").trim(),j=(t,n)=>{const r=n==="plain",e=Array.from(t.querySelectorAll("tr")).map(i=>Array.from(i.children).filter(l=>l.tagName==="TH"||l.tagName==="TD").map(l=>{const d=u(l,n);return r?d.replace(/\s*\n+\s*/g," ").trim():_(d)})).filter(i=>i.length>0);if(e.length===0)return"";if(r)return e.map(i=>i.join(" ")).join(`
|
|
7
7
|
`);const o=Math.max(...e.map(i=>i.length)),a=i=>`| ${Array.from({length:o},(l,d)=>i[d]??"").join(" | ")} |`,[c,...s]=e;return[a(c),`| ${Array.from({length:o},()=>"---").join(" | ")} |`,...s.map(a)].join(`
|
|
8
8
|
`)},$=(t,n,r)=>t.split(`
|
|
9
9
|
`).map((e,o)=>(o===0?n:e?r:"")+e).join(`
|
|
10
|
-
`),y=t=>t==="plain"?"• ":"- ",
|
|
10
|
+
`),y=t=>t==="plain"?"• ":"- ",D=(t,n)=>n==="plain"?t?"☑ ":"☐ ":t?"[x] ":"[ ] ",B=(t,n)=>{const r=t.tagName==="OL";let e=Number.parseInt(t.getAttribute("start")??"1",10);Number.isFinite(e)||(e=1);const o=[];for(const a of Array.from(t.children)){if(a.tagName!=="LI")continue;const c=r?`${e}. `:y(n);e+=1;const s=a.querySelector(':scope > input[type="checkbox"], :scope > p > input[type="checkbox"]'),i=s?D(s.hasAttribute("checked"),n):"",l=p(a,`
|
|
11
11
|
`,n);o.push($(`${i}${l}`,c," ".repeat(c.length)))}return o.join(`
|
|
12
12
|
`)},z=(t,n)=>{const r=n==="plain";if(t.matches('[data-markdown="mermaid-block"]')){const e=t.getAttribute("data-md-source")??"";return r?e:x(e,"mermaid")}if(t.matches(".katex-display")){const e=T(t);return e?r?e:`$$
|
|
13
13
|
${e}
|
|
14
|
-
$$`:t.textContent??""}if(t.matches('[data-component="markdown-code"]')||t.tagName==="PRE"){const e=H(t);return r?e.replace(/\n$/,""):x(e,I(t))}if(t.matches('[data-markdown="table-wrapper"]')||t.tagName==="TABLE"){const e=t.tagName==="TABLE"?t:t.querySelector("table");return e?
|
|
15
|
-
`,n),y(n)," ");case"BLOCKQUOTE":{const e=
|
|
14
|
+
$$`:t.textContent??""}if(t.matches('[data-component="markdown-code"]')||t.tagName==="PRE"){const e=H(t);return r?e.replace(/\n$/,""):x(e,I(t))}if(t.matches('[data-markdown="table-wrapper"]')||t.tagName==="TABLE"){const e=t.tagName==="TABLE"?t:t.querySelector("table");return e?j(e,n):""}switch(t.tagName){case"H1":case"H2":case"H3":case"H4":case"H5":case"H6":{const e=u(t,n).trim();return r?e:`${"#".repeat(Number(t.tagName[1]))} ${e}`}case"HR":return r?"":"---";case"UL":case"OL":return B(t,n);case"LI":return $(p(t,`
|
|
15
|
+
`,n),y(n)," ");case"BLOCKQUOTE":{const e=p(t,`
|
|
16
16
|
|
|
17
17
|
`,n);return r?e:e.split(`
|
|
18
18
|
`).map(o=>o?`> ${o}`:">").join(`
|
|
@@ -25,9 +25,9 @@ $$`:t.textContent??""}if(t.matches('[data-component="markdown-code"]')||t.tagNam
|
|
|
25
25
|
|
|
26
26
|
${c}
|
|
27
27
|
|
|
28
|
-
</details>`}case"P":case"SUMMARY":return u(t,n).trim();default:return
|
|
28
|
+
</details>`}case"P":case"SUMMARY":return u(t,n).trim();default:return p(t,`
|
|
29
29
|
|
|
30
30
|
`,n)}},q=(t,n)=>{const r=n==="plain";if(t.matches(".katex")){const o=T(t),a=t.querySelector(".katex-html")?.textContent??t.textContent??"";return o?r?o:`$${o}$`:a}const e=()=>u(t,n);switch(t.tagName){case"STRONG":case"B":return r?e():h(e(),"**");case"EM":case"I":return r?e():h(e(),"*");case"DEL":case"S":case"STRIKE":return r?e():h(e(),"~~");case"CODE":{const o=t.textContent??"";return r?o:M(o)}case"BR":return`
|
|
31
|
-
`;case"IMG":{const o=t.getAttribute("alt")??"";if(r)return o;const a=t.getAttribute("src")??"";return a?``:""}case"INPUT":return"";case"A":{const o=e(),a=t.getAttribute("href")??"";return r||!a||t.getAttribute("data-openchamber-file-link")==="true"?o:o.trim()===a?a:`[${o}](${a})`}default:return e()}},A=(t,n)=>t.nodeType===k?{block:!1,text:t.textContent??""}:!
|
|
31
|
+
`;case"IMG":{const o=t.getAttribute("alt")??"";if(r)return o;const a=t.getAttribute("src")??"";return a?``:""}case"INPUT":return"";case"A":{const o=e(),a=t.getAttribute("href")??"";return r||!a||t.getAttribute("data-openchamber-file-link")==="true"?o:o.trim()===a?a:`[${o}](${a})`}default:return e()}},A=(t,n)=>t.nodeType===k?{block:!1,text:t.textContent??""}:!m(t)||t.matches(L)?null:R(t)?{block:!0,text:z(t,n)}:{block:!1,text:q(t,n)},f=(t,n,r)=>{const e=[];let o="";const a=()=>{const c=o.trim();c&&e.push(c),o=""};for(const c of t){const s=A(c,r);if(s){if(!s.block){o+=s.text;continue}a(),s.text.trim()&&e.push(s.text)}}return a(),e.join(n)},p=(t,n,r)=>f(Array.from(t.childNodes),n,r);function u(t,n){return Array.from(t.childNodes).map(r=>A(r,n)?.text??"").join("")}const E=(t,n="markdown")=>f(Array.from(t.childNodes),`
|
|
32
32
|
|
|
33
|
-
`,n),P=(t,n)=>{const r=n.createElement("template");return r.innerHTML=t,E(r.content,"plain")},b=t=>(
|
|
33
|
+
`,n),P=(t,n)=>{const r=n.createElement("template");return r.innerHTML=t,E(r.content,"plain")},b=t=>(m(t)?t:t.parentElement)?.closest(w)??null,U="p, h1, h2, h3, h4, h5, h6, li, td, th, summary, dt, dd",K=(t,n="markdown")=>{const r=b(t.startContainer);if(!r||r!==b(t.endContainer))return null;let e=t.cloneContents(),o=t.commonAncestorContainer;o.nodeType===k&&(o=o.parentNode);const a=o&&m(o)?o.closest(U):null;for(a&&r.contains(a)&&a!==r&&(o=null);o&&o!==r&&m(o);){const i=o.cloneNode(!1);i.appendChild(e),e=i,o=o.parentNode}const c=r.ownerDocument.createElement("div");c.appendChild(e);const s=E(c,n);return s.trim()?s:null},W=Object.freeze(Object.defineProperty({__proto__:null,getMarkdownSelectionText:K,renderedMarkdownHtmlToPlainText:P,serializeRenderedMarkdown:E},Symbol.toStringTag,{value:"Module"}));export{K as a,S as g,W as s};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{t as p,ck as S}from"./index-DxNa7xYB.js";const b=(n,i)=>n?i.kind!==n.kind?i.kind==="project":i.projectRoot.length!==n.projectRoot.length?i.projectRoot.length>n.projectRoot.length:i.projectId.localeCompare(n.projectId)<0:!0,w=(n,i,a)=>{b(n.get(i),a)&&n.set(i,a)},z=n=>p(n.directory)??p(n.project?.worktree),x=n=>n.projectID||n.project?.id||null,q=(n,i,a,d,h=[],P=[],m=[])=>{const u=new Map,f=new Map;for(const o of i){const t=p(o.normalizedPath);if(!t)continue;const e=f.get(t);(!e||o.id.localeCompare(e.id)<0)&&f.set(t,o),w(u,t,{projectId:o.id,projectRoot:t,scopeDirectory:t,kind:"project"})}if(!d)for(const[o,t]of a){const e=p(o),r=e?f.get(e):void 0;if(!(!r||!e))for(const s of t){const c=p(s.path);c&&w(u,c,{projectId:r.id,projectRoot:e,scopeDirectory:c,kind:"worktree"})}}if(!d)for(const o of m){const t=p(o.projectDirectory),e=p(o.directory),r=t?f.get(t):void 0;!r||!t||!e||w(u,e,{projectId:r.id,projectRoot:t,scopeDirectory:e,kind:"space",spaceId:o.id})}const j=new Map,k=new Set,y=(o,t)=>{const e=p(t??null),r=e?f.get(e):void 0,s=r&&e?{projectId:r.id,projectRoot:e,scopeDirectory:e,kind:"project"}:null;if(!j.has(o)){j.set(o,s);return}const c=j.get(o);(!c||!s||c.projectRoot!==s.projectRoot)&&j.set(o,null)};for(const o of P)o.id&&(k.add(o.id),y(o.id,o.worktree));for(const o of[...n,...h]){const t=o.project?.id;if(!t||k.has(t))continue;const e=p(o.project?.worktree??null);!e||!f.has(e)||y(t,o.project?.worktree)}const l=new Map,g=new Map,R=new Map,I=new Map,D=new Map,B=o=>{if(!o)return null;if(l.has(o))return l.get(o)??null;if(d){const s=u.get(o)??null;return l.set(o,s),s}const t=[];let e=o,r=null;for(;e;){if(l.has(e)){r=l.get(e)??null;break}if(t.push(e),r=u.get(e)??null,r)break;e=S(e)}for(const s of t)l.set(s,r);return r},O=(o,t,e)=>{for(const r of o){const c=B(z(r))??(d?null:j.get(x(r)??"")??null);if(!c)continue;g.set(r.id,c);const v=t.get(c.projectId);if(v?v.push(r):t.set(c.projectId,[r]),!e)continue;const M=e.get(c.scopeDirectory);M?M.add(r.id):e.set(c.scopeDirectory,new Set([r.id]))}};return O(n,R,D),O(h.filter(o=>!o.parentID),I),{bySessionId:g,sessionsByProject:R,archivedSessionsByProject:I,sessionsByScope:D,directoryResolutions:l.size}};export{q as c};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{R as m,j as y,c as Ce,f as Ne}from"./vendor-react-BUCujlKS.js";import{i as D,S as ye,E as Ee,o as N,l as I}from"./vendor-codemirror-state-Dek9sMtw.js";import{E as k,V as j,s as Re,f as Me,h as Pe,i as X,k as A,D as z,W as Fe}from"./vendor-codemirror-view-1e0FQ6Wn.js";import{h as Oe,k as Te,l as qe,j as ze}from"./vendor-codemirror-commands-C4G_dPWe.js";import{b as Le,y as We,H as Z,x as O,z as $e}from"./vendor-codemirror-language-DufXoQvE.js";import{a as C,g as q,b as J,c as ee,o as Ae,d as _e}from"./vendor-codemirror-search-CvXM_pZg.js";import{v as Be,g as He,V as _}from"./vendor-replit-codemirror-vim-BlJRn-cW.js";import{h as De,I as te,au as Ie,B as je,av as Ke,at as Ve,j6 as Ge,l9 as Ue}from"./useAppFontEffects-DGlvOqP_.js";import{a as t,c as Ye}from"./vendor-lezer-highlight-CDMHUZ74.js";const ke=ye.define(),Qe=4,T=D.define({create:()=>0,update(e,o){if(!C(o.state))return 0;for(const r of o.effects)r.is(ke)&&(e=r.value);return e},provide:e=>k.contentAttributes.from(e,o=>o>0?{style:`padding-top: ${o}px`}:{})}),oe=e=>parseFloat(getComputedStyle(e.contentDOM).paddingTop)||0,Xe=j.fromClass(class{constructor(e){this.view=e,e.requestMeasure({read:oe,write:o=>{this.padding=o}}),this.trackPanel()}observer=null;panel=null;padding=0;update(e){C(e.startState)!==C(e.state)&&this.trackPanel(),e.state.field(T)!==e.startState.field(T)&&this.view.requestMeasure({read:o=>({scrollTop:o.scrollDOM.scrollTop,padding:oe(o)}),write:({scrollTop:o,padding:r},a)=>{const c=r-this.padding;this.padding=r,o!==0&&(a.scrollDOM.scrollTop=c>0&&o<c?0:o+c)}})}destroy(){this.observer?.disconnect()}trackPanel(){this.view.requestMeasure({read:e=>C(e.state)?e.dom.querySelector(".cm-panels-top"):null,write:e=>{e!==this.panel&&(this.observer?.disconnect(),this.observer=null,this.panel=e,e&&(this.observer=new ResizeObserver(()=>this.syncSpace()),this.observer.observe(e)))}})}syncSpace(){const{panel:e,view:o}=this;if(!e||!C(o.state))return;const r=Math.ceil(e.getBoundingClientRect().bottom-o.scrollDOM.getBoundingClientRect().top)+Qe;r!==o.state.field(T)&&o.dispatch({effects:ke.of(r)})}});function re(){return[T,Xe]}const ne=["normal","visual","operatorPending"],Ze=new Map([["map",{contexts:ne,recursive:!0}],["noremap",{contexts:ne,recursive:!1}],["nmap",{contexts:["normal"],recursive:!0}],["nnoremap",{contexts:["normal"],recursive:!1}],["imap",{contexts:["insert"],recursive:!0}],["inoremap",{contexts:["insert"],recursive:!1}],["vmap",{contexts:["visual"],recursive:!0}],["vnoremap",{contexts:["visual"],recursive:!1}],["xmap",{contexts:["visual"],recursive:!0}],["xnoremap",{contexts:["visual"],recursive:!1}],["omap",{contexts:["operatorPending"],recursive:!0}],["onoremap",{contexts:["operatorPending"],recursive:!1}]]),Je=new Set(["<silent>","<nowait>","<buffer>","<unique>"]),et=/^(\S+)((?:\s+<[a-z]+>)*)\s+(\S+)\s+(.+)$/i;function tt(e){const o=[],r=[];return e.split(/\r?\n/).forEach((a,c)=>{const n=a.trim();if(!n||n.startsWith('"'))return;const s=et.exec(n),i=s?Ze.get(s[1]):void 0,p=s?s[2].trim().split(/\s+/).filter(Boolean).every(d=>Je.has(d.toLowerCase())):!1;if(!s||!i||!p||s[3].startsWith(":")){r.push(c+1);return}for(const d of i.contexts)o.push({context:d,lhs:s[3],rhs:s[4].trim(),recursive:i.recursive})}),{mappings:o,invalidLines:r}}const ot=e=>e!==null&&typeof e=="object"&&"updateStatus"in e&&typeof e.updateStatus=="function",rt=e=>{const o=document.createElement("div");o.className="cm-vim-panel";const r=He(e);if(!r)return{top:!1,dom:o};r.state.statusbar=o;const a=r.state.vimPlugin;return ot(a)&&a.updateStatus(),{top:!1,dom:o,destroy(){r.state.statusbar===o&&(r.state.statusbar=null)}}};function ae(e){return e?[Be(),Re.of(rt),Me()]:[]}let ce=null,se=[];function Pt(e){if(e===ce)return;for(const r of se)_.unmap(r.lhs,r.context);const{mappings:o}=tt(e);for(const r of o)r.recursive?_.map(r.lhs,r.rhs,r.context):_.noremap(r.lhs,r.rhs,r.context);se=o,ce=e}const nt={next:"Next match",prev:"Previous match",select:"Select all matches",replace:"Replace",replaceAll:"Replace all",close:"Close"},at={case:"Match case",re:"Regular expression",word:"Match whole word"};function ct(e){const o=e.querySelector(".cm-search");if(o){for(const[r,a]of Object.entries(nt)){const c=o.querySelector(`button[name="${r}"]`);c&&!c.title&&(c.title=a)}for(const[r,a]of Object.entries(at)){const n=o.querySelector(`input[name="${r}"]`)?.parentElement;n&&!n.title&&(n.title=a)}}}const B=new WeakMap;function st(e,o){const r=q(e.state);if(!r.valid)return B.delete(e),0;const a=B.get(e);if(!o&&a?.doc===e.state.doc&&a.query.eq(r))return a.total;const c=r.getCursor(e.state);let n=0;for(let s=c.next();!s.done;s=c.next())n+=1;return B.set(e,{query:r,doc:e.state.doc,total:n}),n}function it(e){const o=q(e.state);if(!o.valid)return 0;const r=e.state.selection.main,a=o.getCursor(e.state);let c=0,n=0;for(let s=a.next();!s.done;s=a.next()){const i=s.value;if(c+=1,n===0&&(n=c),r.from===i.from&&r.to===i.to||r.from<i.to&&r.to>i.from||i.from>=r.head)return c}return n}function ie(e,o,r=!1){const a=e.querySelector(".cm-search");if(!a)return;let c=a.querySelector(".cm-search-message");if(!c){c=document.createElement("span"),c.className="cm-search-message",c.setAttribute("aria-live","polite");const i=a.querySelector('button[name="next"]'),p=i?.parentNode===a?i:a.firstChild;a.insertBefore(c,p)}const n=st(o,r),s=n===0?0:it(o);c.textContent=n===0?"":`${s}/${n}`}const le=new N,ue=new N,de=new N,me=new N,pe=new N,fe=new N,ge=new N,be=e=>e,H=We,lt=Ae,ut=_e;class dt extends Fe{constructor(o,r){super(),this.id=o,this.containerMap=r}toDOM(){let o=this.containerMap.get(this.id);return o||(o=document.createElement("div"),o.className="oc-block-widget",o.dataset.widgetId=this.id,this.containerMap.set(this.id,o)),o}eq(o){return o.id===this.id}destroy(){}}const he=(e,o)=>!e||e.length===0?[]:D.define({create(r){const a=new I,c=[...e].sort((n,s)=>n.afterLine-s.afterLine);for(const n of c){const s=r.doc.lines;if(n.afterLine>s)continue;const i=r.doc.line(n.afterLine);a.add(i.to,i.to,z.widget({widget:new dt(n.id,o),block:!0,side:1}))}return a.finish()},update(r,a){return r.map(a.changes)},provide:r=>k.decorations.from(r)}),xe=e=>{if(!e)return[];const o=Math.max(1,e.start),r=Math.max(o,e.end);return j.fromClass(class{decorations;constructor(a){this.decorations=this.build(a)}update(a){(a.docChanged||a.viewportChanged)&&(this.decorations=this.build(a.view))}build(a){const c=new I;for(let n=o;n<=r&&n<=a.state.doc.lines;n+=1){const s=a.state.doc.line(n);c.add(s.from,s.from,z.line({class:"oc-cm-selected-line"}))}return c.finish()}},{decorations:a=>a.decorations})};function Ft({value:e,onChange:o,extensions:r,className:a,readOnly:c,lineNumbersConfig:n,highlightLines:s,onViewReady:i,onViewDestroy:p,blockWidgets:d,enableSearch:g,searchOpen:P,onSearchOpenChange:E,vimMode:x}){const F=m.useRef(null),b=m.useRef(null),L=m.useRef(e),K=m.useRef(o),V=m.useRef(i),G=m.useRef(p),U=m.useRef(E),R=m.useRef(d),W=m.useRef(x),$=m.useRef(new Map),[Se,Y]=m.useState([]),w=m.useCallback(l=>{const h=(l??[]).map(u=>{const f=$.current.get(u.id);return f?{id:u.id,content:u.content,container:f}:null}).filter(u=>u!==null);Y(u=>u.length===h.length&&u.every((f,v)=>{const M=h[v];return f.id===M.id&&f.content===M.content&&f.container===M.container})?u:h)},[]),S=m.useCallback(l=>{const h=F.current,u=l??b.current;if(!h||!u)return;const f=u.dom.querySelector(".cm-gutters"),v=f instanceof HTMLElement?f.getBoundingClientRect().width:0;h.style.setProperty("--oc-editor-gutter-width",`${v}px`)},[]);return m.useEffect(()=>{L.current=e},[e]),m.useEffect(()=>{K.current=o},[o]),m.useEffect(()=>{V.current=i,G.current=p},[i,p]),m.useEffect(()=>{U.current=E},[E]),m.useEffect(()=>{R.current=d,w(d)},[d,w]),m.useEffect(()=>{if(!F.current)return;const l=(()=>{if(typeof document>"u")return null;const u=document.querySelector('meta[name="csp-nonce"]')?.getAttribute("content");if(u)return u;const f=window.__OPENCHAMBER_CSP_NONCE__;return typeof f=="string"&&f.length>0?f:null})(),h=Ee.create({doc:L.current,extensions:[...l?[k.cspNonce.of(l)]:[],Pe({fixed:!0}),le.of(X(n)),Oe(),Le.of(" "),ge.of(ae(x)),A.of([Te,...qe,...ze]),k.updateListener.of(u=>{S(u.view),(u.viewportChanged||u.geometryChanged)&&w(R.current);const f=C(u.startState),v=C(u.state);f!==v&&U.current?.(v);const M=!q(u.startState).eq(q(u.state));if(v&&(f!==v||M||u.docChanged||u.selectionSet)&&ie(u.view.dom,u.view,f!==v||M||u.docChanged),!u.docChanged)return;const Q=u.state.doc.toString();L.current=Q,K.current(Q),w(R.current)}),ue.of(k.editable.of(!c)),de.of(r??[]),me.of(xe(s)),pe.of(he(d,$.current)),fe.of(g?[J({top:!0}),re(),A.of(be(ee))]:[])]});return b.current=new k({state:h,parent:F.current}),H(b.current,b.current.state.doc.length,200),b.current.requestMeasure(),requestAnimationFrame(()=>{S(b.current),w(R.current)}),b.current&&V.current?.(b.current),()=>{G.current?.(),b.current?.destroy(),b.current=null,Y([])}},[R,S,w]),m.useEffect(()=>{const l=b.current;l&&(l.dispatch({effects:[le.reconfigure(X(n)),ue.reconfigure(k.editable.of(!c)),de.reconfigure(r??[]),me.reconfigure(xe(s)),pe.reconfigure(he(d,$.current)),fe.reconfigure(g?[J({top:!0}),re(),A.of(be(ee))]:[])]}),H(l,l.state.doc.length,200),l.requestMeasure(),requestAnimationFrame(()=>{S(l),w(R.current)}))},[r,s,n,c,d,g,S,w]),m.useEffect(()=>{const l=b.current;if(!l){W.current=x;return}W.current!==x&&(W.current=x,l.dispatch({effects:ge.reconfigure(ae(x))}))},[x]),m.useEffect(()=>{const l=b.current;!l||g===!1||(P?(lt(l),requestAnimationFrame(()=>{ct(l.dom),ie(l.dom,l,!0)})):ut(l))},[P,g]),m.useEffect(()=>{const l=b.current;if(!l)return;const h=l.state.doc.toString();h!==e&&(l.dispatch({changes:{from:0,to:h.length,insert:e}}),H(l,l.state.doc.length,300),l.requestMeasure(),requestAnimationFrame(()=>S(l)))},[e,S]),y.jsxs(y.Fragment,{children:[y.jsx("div",{ref:F,className:De("oc-surface-code h-full w-full","[&_.cm-editor]:h-full [&_.cm-editor]:w-full","[&_.cm-scroller]:font-mono [&_.cm-scroller]:text-[var(--text-code)] [&_.cm-scroller]:leading-6",a)}),Se.map(l=>Ce.createPortal(l.content,l.container,l.id))]})}const Ot=e=>{const o=Ne.c(11),{currentMode:r,onToggle:a}=e,c=r==="preview",n=c?"Switch to edit mode":"Switch to preview mode",s=c?"Edit":"Preview";let i;o[0]!==c?(i=c?y.jsx(te,{name:"eye",className:"size-4","aria-hidden":"true"}):y.jsx(te,{name:"eye-off",className:"size-4","aria-hidden":"true"}),o[0]=c,o[1]=i):i=o[1];let p;o[2]!==n||o[3]!==a||o[4]!==i?(p=y.jsx(Ie,{asChild:!0,children:y.jsx(je,{variant:"ghost",size:"sm",onClick:a,"aria-label":n,className:"h-5 w-5 p-0",children:i})}),o[2]=n,o[3]=a,o[4]=i,o[5]=p):p=o[5];let d;o[6]!==s?(d=y.jsx(Ke,{sideOffset:8,children:s}),o[6]=s,o[7]=d):d=o[7];let g;return o[8]!==p||o[9]!==d?(g=y.jsxs(Ve,{children:[p,d]}),o[8]=p,o[9]=d,o[10]=g):g=o[10],g};function Tt(e,o){const r=e.metadata.variant==="dark",a=e.config?.fonts?.mono||"monospace",c=e.colors.syntax.highlights||{},n=Ge(e.colors.syntax),s=o?.fontSize?`${o.fontSize}px`:"var(--text-code)",i=e.colors.syntax.base.background,p=k.theme({"&":{backgroundColor:i,color:e.colors.syntax.base.foreground,fontSize:s,lineHeight:"1.5",position:"relative"},".cm-scroller":{fontFamily:`var(--font-mono, ${a})`,backgroundColor:i},".cm-comment":{color:e.colors.syntax.base.comment},".cm-keyword":{color:e.colors.syntax.base.keyword},".cm-string":{color:e.colors.syntax.base.string},".cm-string-2":{color:n.stringEscape||e.colors.syntax.base.string},".cm-number":{color:e.colors.syntax.base.number},".cm-operator":{color:e.colors.syntax.base.operator},".cm-punctuation":{color:n.punctuation||e.colors.syntax.base.comment},".cm-atom":{color:n.boolean||e.colors.syntax.base.number},".cm-builtin":{color:n.functionCall||e.colors.syntax.base.function},".cm-def":{color:n.variableGlobal||e.colors.syntax.base.variable},".cm-attribute":{color:n.variableOther||n.variableProperty||e.colors.syntax.base.operator},".cm-meta":{color:e.colors.syntax.base.comment},".cm-property":{color:n.variableProperty||e.colors.syntax.base.keyword},".cm-variable":{color:e.colors.syntax.base.variable},".cm-variable-2":{color:n.variableOther||e.colors.syntax.base.function},".cm-variable-3":{color:n.variableGlobal||e.colors.syntax.base.type},".cm-tag":{color:n.tag||e.colors.syntax.base.keyword},".cm-link":{color:n.url||e.colors.syntax.base.keyword,textDecoration:"underline"},".cm-content":{caretColor:e.colors.interactive.cursor},".cm-cursor, .cm-dropCursor":{borderLeftColor:e.colors.interactive.cursor},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:e.colors.interactive.selection},".cm-gutters":{backgroundColor:i,color:c.lineNumber||e.colors.syntax.base.comment,borderRight:`1px solid ${e.colors.interactive.border}`,position:"sticky",paddingRight:"8px",left:0,zIndex:2,boxShadow:`0 0 0 ${i}`},".cm-gutter":{backgroundColor:i},".cm-gutterElement":{backgroundColor:i},".cm-lineNumbers":{backgroundColor:i},".cm-lineNumbers .cm-gutterElement":{paddingLeft:"8px",paddingRight:"8px",minWidth:"42px"},".cm-activeLineGutter":{color:c.lineNumberActive||e.colors.syntax.base.foreground},".cm-activeLine":{backgroundColor:`color-mix(in srgb, ${e.colors.syntax.base.foreground} 5%, transparent)`},".cm-panels":{backgroundColor:"transparent",color:e.colors.surface.elevatedForeground,position:"absolute",top:"0",right:"0",left:"auto",width:"auto",zIndex:10,pointerEvents:"none"},".cm-panels-top":{borderBottom:"none",position:"absolute",top:"6px",right:"14px",left:"auto",width:"auto"},".cm-panels-bottom":{position:"static",width:"100%",pointerEvents:"auto"},".cm-panels-bottom .cm-vim-panel":{borderTop:`1px solid ${e.colors.interactive.border}`,backgroundColor:e.colors.surface.elevated,color:e.colors.surface.mutedForeground,fontFamily:"var(--font-mono)",fontSize:"12px",minHeight:"22px",padding:"2px 8px"},".cm-panel.cm-search":{pointerEvents:"auto",padding:"4px",backgroundColor:`color-mix(in srgb, ${e.colors.surface.elevated} 85%, transparent)`,border:`1px solid ${e.colors.interactive.border}`,borderRadius:"10px",boxShadow:`0 2px 8px color-mix(in srgb, ${e.colors.surface.background} 60%, transparent)`,width:"auto",minWidth:"360px",maxWidth:"480px"},".cm-search":{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"0",width:"100%",color:e.colors.surface.elevatedForeground,fontFamily:"inherit",fontSize:"13px",lineHeight:"1"},".cm-search br":{display:"none"},".cm-search .cm-textfield":{appearance:"none",height:"26px",margin:0,padding:"0 8px",borderRadius:"6px !important",border:`1px solid ${e.colors.interactive.border}`,backgroundColor:e.colors.surface.elevated,color:e.colors.surface.elevatedForeground,fontFamily:"inherit",fontSize:"12px",lineHeight:"1",outline:"none",transition:"border-color 150ms ease"},".cm-search .cm-textfield::placeholder":{color:e.colors.surface.mutedForeground,opacity:1},".cm-search .cm-textfield:focus":{borderColor:e.colors.interactive.borderFocus},'.cm-search .cm-textfield[name="search"]':{order:1,flex:"1 1 120px",maxWidth:"calc(100% - 142px)",minWidth:"100px"},".cm-search label":{order:2,display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"1px solid transparent",backgroundColor:"transparent",color:"transparent",cursor:"pointer",userSelect:"none",fontSize:"1px",lineHeight:"0",overflow:"hidden",position:"relative",transition:"background-color 120ms ease, border-color 120ms ease"},".cm-search label:hover":{backgroundColor:e.colors.interactive.hover},'.cm-search label:has(input[type="checkbox"]:checked)':{backgroundColor:e.colors.interactive.hover,borderColor:e.colors.interactive.border},'.cm-search [type="checkbox"]':{appearance:"none",WebkitAppearance:"none",width:"0",height:"0",margin:"0",padding:"0",border:"none",position:"absolute",opacity:"0",pointerEvents:"none"},".cm-search label::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"13px",fontWeight:"600",lineHeight:"1",fontFamily:"inherit",color:e.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search label:hover::after":{color:e.colors.surface.elevatedForeground},'.cm-search label:has(input[type="checkbox"]:checked)::after':{color:e.colors.surface.elevatedForeground},'.cm-search label:has(input[name="case"])::after':{content:'"Aa"',fontSize:"12px",letterSpacing:"-0.5px"},'.cm-search label:has(input[name="re"])::after':{content:'".*"',fontSize:"13px",fontFamily:"monospace"},'.cm-search label:has(input[name="word"])::after':{content:'"ab"',fontSize:"12px",textDecoration:"underline",textUnderlineOffset:"2px"},".cm-search .cm-search-message":{order:3,color:e.colors.surface.mutedForeground,backgroundColor:"transparent",border:"none",borderRadius:"0",padding:"0 6px",fontSize:"11px",whiteSpace:"nowrap",lineHeight:"26px"},".cm-search .cm-button":{appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:"transparent",cursor:"pointer",fontSize:"1px",fontWeight:"400",lineHeight:"0",overflow:"hidden",position:"relative",boxShadow:"none",transition:"background-color 120ms ease"},".cm-search .cm-button::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"15px",lineHeight:"1",color:e.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search .cm-button:hover":{backgroundColor:e.colors.interactive.hover},".cm-search .cm-button:hover::after":{color:e.colors.surface.elevatedForeground},".cm-search .cm-button:active":{backgroundColor:e.colors.interactive.active},".cm-search .cm-button:focus-visible":{outline:"none",boxShadow:`0 0 0 1px ${e.colors.interactive.focusRing}`},".cm-search .cm-button:disabled":{opacity:.4,cursor:"default",pointerEvents:"none"},'.cm-search .cm-button[name="prev"]':{order:21,marginTop:"2px"},'.cm-search .cm-button[name="prev"]::after':{content:'"↑"'},'.cm-search .cm-button[name="next"]':{order:22,marginTop:"2px"},'.cm-search .cm-button[name="next"]::after':{content:'"↓"'},'.cm-search .cm-button[name="select"]':{order:23,marginTop:"2px"},'.cm-search .cm-button[name="select"]::after':{content:'"≡"',fontSize:"17px"},'.cm-panel.cm-search button[name="close"]':{order:5,appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:"0 0 0 auto",padding:"0",borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:e.colors.surface.mutedForeground,cursor:"pointer",fontSize:"16px",lineHeight:"1",boxShadow:"none",position:"relative",overflow:"visible",transition:"background-color 120ms ease, color 120ms ease"},'.cm-panel.cm-search button[name="close"]:hover':{backgroundColor:e.colors.interactive.hover,color:e.colors.surface.elevatedForeground},'.cm-search .cm-button[name="replace"]':{order:24,marginTop:"2px"},'.cm-search .cm-button[name="replace"]::after':{content:'"⇄"'},'.cm-search .cm-button[name="replaceAll"], .cm-search .cm-button[name="replace-all"]':{order:25,marginTop:"2px"},'.cm-search .cm-button[name="replaceAll"]::after, .cm-search .cm-button[name="replace-all"]::after':{content:'"⇉"'},'.cm-search .cm-textfield[name="replace"]':{order:20,flex:"1 1 100%",maxWidth:"calc(100% - 142px)",minWidth:"80px",marginTop:"2px"},".cm-searchMatch":{backgroundColor:e.colors.interactive.selection,color:e.colors.interactive.selectionForeground,boxShadow:`inset 0 0 0 1px ${e.colors.interactive.border}`,borderRadius:"2px"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:e.colors.interactive.selection,color:e.colors.interactive.selectionForeground,boxShadow:`inset 0 0 0 1px ${e.colors.interactive.borderFocus}`},".cm-selectionMatch":{backgroundColor:e.colors.interactive.selection,boxShadow:`inset 0 0 0 1px ${e.colors.interactive.borderFocus}`,borderRadius:"2px"},".cm-selectionMatch-main":{backgroundColor:"transparent"},"&.cm-focused":{outline:"none"}},{dark:r}),d=Z.define([{tag:[t.comment,t.docComment,t.meta,t.documentMeta],class:"cm-comment"},{tag:[t.keyword,t.controlKeyword,t.moduleKeyword,t.definitionKeyword,t.modifier],class:"cm-keyword"},{tag:[t.operatorKeyword,t.operator,t.derefOperator,t.updateOperator,t.definitionOperator,t.typeOperator,t.controlOperator,t.logicOperator,t.bitwiseOperator,t.arithmeticOperator,t.compareOperator],class:"cm-operator"},{tag:[t.punctuation,t.separator,t.bracket,t.paren,t.brace,t.squareBracket,t.angleBracket],class:"cm-punctuation"},{tag:[t.string,t.regexp,t.attributeValue,t.special(t.string),t.monospace],class:"cm-string"},{tag:t.escape,class:"cm-string-2"},{tag:[t.number,t.bool,t.atom,t.null,t.self],class:"cm-number"},{tag:[t.function(t.variableName),t.function(t.definition(t.variableName)),t.function(t.propertyName),t.standard(t.variableName),t.special(t.variableName)],class:"cm-builtin"},{tag:t.definition(t.variableName),class:"cm-def"},{tag:[t.variableName,t.local(t.variableName),t.constant(t.variableName),t.literal],class:"cm-variable"},{tag:t.propertyName,class:"cm-property"},{tag:t.attributeName,class:"cm-attribute"},{tag:[t.className,t.typeName,t.namespace],class:"cm-variable-3"},{tag:[t.tagName,t.labelName,t.annotation,t.macroName],class:"cm-tag"},{tag:t.link,class:"cm-link"},{tag:[t.heading,t.heading1,t.heading2,t.heading3,t.heading4,t.heading5,t.heading6],class:"cm-keyword"}]),g=Z.define([{tag:[t.comment,t.docComment,t.meta,t.documentMeta],color:e.colors.syntax.base.comment},{tag:[t.keyword,t.controlKeyword,t.moduleKeyword,t.definitionKeyword,t.modifier],color:e.colors.syntax.base.keyword},{tag:[t.operatorKeyword,t.operator,t.derefOperator,t.updateOperator,t.definitionOperator,t.typeOperator,t.controlOperator,t.logicOperator,t.bitwiseOperator,t.arithmeticOperator,t.compareOperator],color:e.colors.syntax.base.operator},{tag:[t.string,t.regexp,t.attributeValue,t.special(t.string),t.monospace],color:e.colors.syntax.base.string},{tag:t.escape,color:n.stringEscape||e.colors.syntax.base.string},{tag:[t.number,t.bool,t.atom,t.null,t.self],color:e.colors.syntax.base.number},{tag:[t.function(t.variableName),t.function(t.definition(t.variableName)),t.function(t.propertyName),t.standard(t.variableName),t.special(t.variableName)],color:e.colors.syntax.base.function},{tag:t.definition(t.variableName),color:n.variableGlobal||e.colors.syntax.base.variable},{tag:[t.variableName,t.local(t.variableName),t.constant(t.variableName),t.literal],color:e.colors.syntax.base.variable},{tag:t.propertyName,color:n.variableProperty||e.colors.syntax.base.variable},{tag:t.attributeName,color:n.variableOther||e.colors.syntax.base.variable},{tag:[t.className,t.typeName,t.namespace],color:e.colors.syntax.base.type},{tag:[t.tagName,t.labelName,t.annotation,t.macroName],color:n.tag||e.colors.syntax.base.keyword},{tag:t.link,color:n.url||e.colors.syntax.base.function,textDecoration:"underline"},{tag:[t.punctuation,t.separator,t.bracket,t.paren,t.brace,t.squareBracket,t.angleBracket],color:n.punctuation||e.colors.syntax.base.comment}]);return o?.syntaxColors===!1?[p]:[p,O($e,{fallback:!0}),O(Ye),O(d),O(g)]}const mt=180,we=ye.define(),pt=1,ft=2,gt=4,ve=new Map,bt=(e,o)=>{const r=`${e}|${o}`,a=ve.get(r);if(a)return a;let c="";e&&(c+=`color:${e};`),o&pt&&(c+="font-style:italic;"),o&ft&&(c+="font-weight:bold;"),o>&&(c+="text-decoration:underline;");const n=z.mark({attributes:{style:c}});return ve.set(r,n),n},ht=(e,o)=>{const r=new I,a=e.state.doc,c=Math.min(o.length,a.lines);for(let n=0;n<c;n+=1){const s=o[n];if(!s||s.length===0)continue;const i=a.line(n+1);let p=i.from;for(const[d,g,P]of s){if(d<=0)continue;const E=p,x=Math.min(p+d,i.to);p+=d,!(x<=E)&&(!g&&!P||r.add(E,x,bt(g,P)))}}return r.finish()},xt=D.define({create(){return z.none},update(e,o){let r=e.map(o.changes);for(const a of o.effects)a.is(we)&&(r=a.value);return r},provide:e=>k.decorations.from(e)}),vt=e=>j.fromClass(class{timer;generation=0;constructor(o){this.tokenize(o)}update(o){o.docChanged&&this.schedule(o.view)}schedule(o){this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.timer=void 0,this.tokenize(o)},mt)}async tokenize(o){const r=++this.generation,a=o.state.doc.toString(),c=await Ue(a,e.language,e.themeName,e.theme);c&&r===this.generation&&o.state.doc.length===a.length&&o.dispatch({effects:we.of(ht(o,c))})}destroy(){this.timer&&clearTimeout(this.timer)}}),qt=e=>[xt,vt(e)];export{Ft as C,Ot as P,Pt as a,Tt as c,tt as p,qt as s};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{f as c}from"./vendor-react-BUCujlKS.js";import{fm as l,lg as p,lh as u}from"./useAppFontEffects-DGlvOqP_.js";import{g0 as _,eT as o,bg as i,B as h,eQ as d}from"./index-DxNa7xYB.js";const f="space",R=e=>e.normalize("NFKD").replace(/[̀-ͯ]/g,"").toLowerCase().replace(/[^a-z0-9._/-]+/g,"-").replace(/\/{2,}/g,"/").replace(/\.{2,}/g,".").replace(/-{2,}/g,"-").split("/").map(t=>t.replace(/^[-.]+|[-.]+$/g,"").replace(/\.lock$/,"")).filter(Boolean).join("/")||f,g=new Set(["changes_do_not_apply","changes_route_closed","changes_blocked_by_link"]),k=e=>{if(e.stillThere&&e.stillThere.count>0)return{kind:"part_thrown_away",stillThere:e.stillThere};const n=e.ignoredInTheWay?.paths[0];return n?{kind:"ignored_in_the_way",path:n}:e.filteredInTheWay&&e.filteredInTheWay.count>0?{kind:"filtered_in_the_way"}:{kind:"changes_closed"}},m=(e,n)=>{if(!(e instanceof d))return{kind:"other",failure:{code:"space_request_failed",message:e.message}};const{code:t,details:a}=e;if(g.has(t))return k(a);switch(t){case"changes_undecided":return{kind:"undecided"};case"changes_partly_applied":return{kind:"partly_applied"};case"nothing_to_apply":return{kind:"nothing_to_apply"};case"changes_too_large":case"patch_not_possible":return{kind:"too_large"};case"space_not_running":return{kind:"not_running"};case"invalid_branch_name":return{kind:"invalid_branch"};case"branch_exists":return{kind:"branch_exists",branch:a.branch??n??""};case"name_not_allowed_here":if(a.path)return{kind:"name_not_allowed",path:a.path};break;case"case_only_rename":if(a.path&&a.other)return{kind:"case_only_rename",path:a.path,other:a.other};break}return{kind:"other",failure:{code:t,message:e.message}}},T=e=>{switch(e.kind){case"changes_closed":case"part_thrown_away":case"ignored_in_the_way":case"filtered_in_the_way":case"undecided":case"partly_applied":return!0;default:return!1}},y=(e,n)=>{const t=`/spaces/${n}`;return e===t||e.startsWith(`${t}/`)},w=(e,n)=>{for(const t of e.activeSessionIds){const a=e.statusById.get(t);if(a&&y(a.directory,n))return!0}return!1},W=e=>{const n=c.c(2);let t;return n[0]!==e?(t=a=>w(a,e),n[0]=e,n[1]=t):t=n[1],l(t)},A=async(e,n)=>{const t=o();let a;try{a=await _(e,n)}catch(s){if(!(s instanceof Error))throw s;return t!==o()?{kind:"overtaken"}:(await i().catch(()=>{}),{kind:"refused",refusal:m(s,n.as==="branch"?n.branch:null)})}if(t!==o())return{kind:"overtaken"};if(a.applied.status==="nothing_to_apply")return{kind:"refused",refusal:{kind:"nothing_to_apply"}};const r=a.removal?.failures[0]??null;return r&&h.getState().noteAction(e,{kind:"failed",action:"remove",failure:r}),a.removal&&!r?(p(e,a.removal.chats),await u(e)):await i().catch(()=>{}),{kind:"applied",outcome:a}};export{A as a,R as b,T as c,m as d,w as i,W as u};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{gu as u,t as s,f7 as f,fm as S}from"./useAppFontEffects-DGlvOqP_.js";import{u as d,V as g,bg as j,B as c,t as l,a6 as h,a7 as y}from"./index-DxNa7xYB.js";import"./vendor-react-BUCujlKS.js";import{i as P}from"./space-apply-DM_2pRW7.js";import"./vendor-zod-CxRSdNoV.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-base-ui-Det7U81h.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-tanstack-react-virtual-CvuLsk7D.js";import"./vendor-tanstack-virtual-core-DPaNcJcT.js";import"./vendor-framer-motion-DxDVhOLc.js";import"./vendor-motion-dom-HXPOMxb7.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-codemirror-commands-C4G_dPWe.js";import"./vendor-codemirror-state-Dek9sMtw.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-1e0FQ6Wn.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-codemirror-language-DufXoQvE.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-DbpEcZM0.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-BSHQHbKu.js";import"./vendor-codemirror-lang-json-BzgckzmB.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-Cayfb29q.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-BQWerHsJ.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-D2TEBIvZ.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-CtwSWKtX.js";import"./vendor-codemirror-lang-python-jAMtYiA9.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-capacitor-core-B4EWRrHz.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-legendapp-list-DViGR95I.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-opencode-client-BmFcUkbQ.js";const e=(i,o)=>h(y.getState().dictionary,i,o),A=(i,o,a)=>{const p=l(o);return p===null?[]:Array.from(i.values()).filter(t=>t.state==="running"&&l(t.projectFolder.path??t.projectDirectory)===p&&!a(t.id))},Zt=async(i,o)=>{if(!d.getState().isolatedSpacesEnabled||g()||!await j().then(()=>!0,()=>!1))return;const p=c.getState().journey;if(!p)return;const t=A(p,i,r=>P(S.getState(),r));if(t.length===0)return;await Promise.all(t.map(r=>u(r.id,"stop")));let m=0;for(const r of t){const n=c.getState().actions.get(r.id);n?.kind==="failed"?s.error(e("spaces.close.stopFailed",{name:r.name,reason:f(e,n.failure)})):m+=1}m===1?s.success(e("spaces.close.stoppedSingle",{project:o})):m>1&&s.success(e("spaces.close.stoppedPlural",{count:m,project:o}))};export{A as spacesToStopOnClose,Zt as stopSpacesOfClosedProject};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const et=/https?:\/\/[^\s"'`<>]+/giu,bt=/[.,;!?]+$/;function St(s){let t=s.replace(bt,"");if(t.length===0)return t;const e=(i,r)=>{for(;t.endsWith(r);){const n=t.split(i).length-1,o=t.split(r).length-1;if(n>=o)return;t=t.slice(0,-1)}};return e("(",")"),e("[","]"),e("{","}"),t}function vt(s){const t=[];et.lastIndex=0;for(const e of s.matchAll(et)){const i=e[0],r=e.index??-1;if(r<0||i.length===0)continue;const n=St(i);n.length!==0&&t.push({text:n,start:r,end:r+n.length})}return t}function Mt(s,t){const e=t(s-1);if(!e)return null;let i=s,r=e;for(;i>1&&r.isWrapped;){const h=t(i-2);if(!h)return null;i-=1,r=h}const n=[];let o=0,l=i;for(;;){const h=t(l-1);if(!h)break;const c=t(l)?.isWrapped===!0,u=h.translateToString(!c);if(n.push({bufferLineNumber:l,text:u,startIndex:o,endIndex:o+u.length}),o+=u.length,!c)break;l+=1}return{text:n.map(h=>h.text).join(""),segments:n}}const Tt=["normal 400","normal 700","italic 400","italic 700"],Et=["i","M","W","0","@","#","."," "],kt=.01,At=/^(ui-monospace|ui-sans-serif|ui-serif|system-ui)$/i;function Ct(s){const t=s.trim();return t.length===0?"":/^(['"]).*\1$/.test(t)||/^[a-zA-Z][a-zA-Z0-9-]*$/.test(t)?t:`"${t.replaceAll('"',"")}"`}function J(s){const t=s.split(",").map(Ct).filter(e=>e.length>0&&!At.test(e));return t.length>0?t.join(", "):null}function xt(s){const t=s[0];return t===void 0||t<=0||s.some(e=>!Number.isFinite(e)||e<=0)?!0:s.every(e=>Math.abs(e-t)<kt)}let I;function Pt(s){const t=J(s);if(t===null)return!0;try{if(I===void 0&&(I=document.createElement("canvas").getContext("2d")),I===null)return!0;const e=I;for(const i of Tt){e.font=`${i} 32px ${t}, monospace`;const r=Et.map(n=>e.measureText(n).width);if(!xt(r))return!1}return!0}catch{return!0}}const Lt=["Unidentified","Backquote","Backslash","BracketLeft","BracketRight","Comma","Digit0","Digit1","Digit2","Digit3","Digit4","Digit5","Digit6","Digit7","Digit8","Digit9","Equal","IntlBackslash","IntlRo","IntlYen","KeyA","KeyB","KeyC","KeyD","KeyE","KeyF","KeyG","KeyH","KeyI","KeyJ","KeyK","KeyL","KeyM","KeyN","KeyO","KeyP","KeyQ","KeyR","KeyS","KeyT","KeyU","KeyV","KeyW","KeyX","KeyY","KeyZ","Minus","Period","Quote","Semicolon","Slash","AltLeft","AltRight","Backspace","CapsLock","ContextMenu","ControlLeft","ControlRight","Enter","MetaLeft","MetaRight","ShiftLeft","ShiftRight","Space","Tab","Convert","KanaMode","NonConvert","Delete","End","Help","Home","Insert","PageDown","PageUp","ArrowDown","ArrowLeft","ArrowRight","ArrowUp","NumLock","Numpad0","Numpad1","Numpad2","Numpad3","Numpad4","Numpad5","Numpad6","Numpad7","Numpad8","Numpad9","NumpadAdd","NumpadBackspace","NumpadClear","NumpadClearEntry","NumpadComma","NumpadDecimal","NumpadDivide","NumpadEnter","NumpadEqual","NumpadMemoryAdd","NumpadMemoryClear","NumpadMemoryRecall","NumpadMemoryStore","NumpadMemorySubtract","NumpadMultiply","NumpadParenLeft","NumpadParenRight","NumpadSubtract","NumpadSeparator","NumpadArrowUp","NumpadArrowDown","NumpadArrowRight","NumpadArrowLeft","NumpadBegin","NumpadHome","NumpadEnd","NumpadInsert","NumpadDelete","NumpadPageUp","NumpadPageDown","Escape","F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12","F13","F14","F15","F16","F17","F18","F19","F20","F21","F22","F23","F24","F25","Fn","FnLock","PrintScreen","ScrollLock","Pause","BrowserBack","BrowserFavorites","BrowserForward","BrowserHome","BrowserRefresh","BrowserSearch","BrowserStop","Eject","LaunchApp1","LaunchApp2","LaunchMail","MediaPlayPause","MediaSelect","MediaStop","MediaTrackNext","MediaTrackPrevious","Power","Sleep","AudioVolumeDown","AudioVolumeMute","AudioVolumeUp","WakeUp","Copy","Cut","Paste"],Rt=new Map(Lt.map((s,t)=>[s,t]));function Ft(s){return Rt.get(s)??0}const Dt=new Map([["!","1"],["@","2"],["#","3"],["$","4"],["%","5"],["^","6"],["&","7"],["*","8"],["(","9"],[")","0"],["~","`"],["_","-"],["+","="],["{","["],["}","]"],["|","\\"],[":",";"],['"',"'"],["<",","],[">","."],["?","/"]]);let Y;function It(){if(Y)return Y;const t=globalThis.navigator?.keyboard?.getLayoutMap().catch(()=>{})??Promise.resolve(void 0);return Y=t,t}function Nt(s){return!s.shiftKey||s.ctrlKey||s.altKey||s.metaKey?0:[...s.key].length===1?1:0}function zt(s,t){if([...s.key].length!==1)return 0;const e=t?.get(s.code);if(e&&[...e].length===1)return e.codePointAt(0)??0;if(/^[A-Z]$/u.test(s.key))return s.key.charCodeAt(0)+32;if(s.shiftKey){const i=Dt.get(s.key);if(i)return i.codePointAt(0)??0;const r=s.key.toLowerCase();return r!==s.key&&[...r].length===1?r.codePointAt(0)??0:0}return s.key.codePointAt(0)??0}const V=new TextDecoder,Bt=new URL("/assets/ghostty-vt-DdA0Zryv.wasm",import.meta.url),Ut=Uint8Array.from([0,97,115,109,1,0,0,0,1,8,1,96,4,127,127,127,127,0,2,29,1,3,101,110,118,21,111,112,101,110,99,104,97,109,98,101,114,95,119,114,105,116,101,95,112,116,121,0,0,3,2,1,0,5,3,1,0,16,6,9,1,127,1,65,128,128,192,0,11,7,30,2,6,109,101,109,111,114,121,2,0,17,103,104,111,115,116,116,121,95,119,114,105,116,101,95,112,116,121,0,1,10,18,1,16,0,32,0,32,1,32,2,32,3,16,128,128,128,128,0,11]);class Q{memory;layouts;exports;memoryView;ptyWriters=new Map;nextPtyWriterId=1;writePtyFunctionIndex=0;constructor(t){this.exports=t.exports;const e=t.exports.memory;if(!(e instanceof WebAssembly.Memory))throw new Error("libghostty-vt did not export WebAssembly memory");this.memory=e,this.memoryView=new DataView(e.buffer);const i=this.call("ghostty_type_json"),r=new Uint8Array(e.buffer);let n=i;for(;n<r.length&&r[n]!==0;)n+=1;this.layouts=JSON.parse(V.decode(r.subarray(i,n)))}static async load(t){const e=t??await Ot(),i={current:null},r={env:{log:(l,h)=>{const a=i.current?.exports.memory;if(!(a instanceof WebAssembly.Memory))return;const c=V.decode(new Uint8Array(a.buffer,l,h));console.debug("[libghostty-vt]",c)}}},n=await WebAssembly.instantiate(e,r);i.current=n.instance;const o=new Q(n.instance);return await o.installWritePtyTrampoline(),o}call(t,...e){const i=this.exports[t];if(!(i instanceof Function))throw new Error(`libghostty-vt export is unavailable: ${t}`);return i(...e)}layout(t){const e=this.layouts[t];if(!e)throw new Error(`libghostty-vt type layout is unavailable: ${t}`);return e}alloc(t){const e=this.call("ghostty_wasm_alloc_u8_array",t);if(e===0)throw new Error(`libghostty-vt failed to allocate ${t} bytes`);return new Uint8Array(this.memory.buffer,e,t).fill(0),e}free(t,e){t!==0&&this.call("ghostty_wasm_free_u8_array",t,e)}allocOpaque(){const t=this.call("ghostty_wasm_alloc_opaque");if(t===0)throw new Error("libghostty-vt failed to allocate an opaque pointer");return new DataView(this.memory.buffer).setUint32(t,0,!0),t}freeOpaque(t){t!==0&&this.call("ghostty_wasm_free_opaque",t)}readPointer(t){return this.currentMemoryView().getUint32(t,!0)}attachPtyWriter(t,e){if(this.writePtyFunctionIndex===0)throw new Error("libghostty-vt PTY callback trampoline is unavailable");const i=this.nextPtyWriterId++;return this.ptyWriters.set(i,e),this.call("ghostty_terminal_set",t,0,i),this.call("ghostty_terminal_set",t,1,this.writePtyFunctionIndex),i}detachPtyWriter(t,e){this.call("ghostty_terminal_set",t,1,0),this.call("ghostty_terminal_set",t,0,0),this.ptyWriters.delete(e)}view(t,e){return new DataView(this.memory.buffer,t,e)}bytes(t,e){return new Uint8Array(this.memory.buffer,t,e)}currentMemoryView(){return this.memoryView.buffer!==this.memory.buffer&&(this.memoryView=new DataView(this.memory.buffer)),this.memoryView}setField(t,e,i,r){const n=this.layout(e).fields[i];if(!n)throw new Error(`libghostty-vt field is unavailable: ${e}.${i}`);const o=this.currentMemoryView(),l=t+n.offset;switch(n.type){case"bool":case"u8":o.setUint8(l,r);return;case"u16":o.setUint16(l,r,!0);return;case"i32":o.setInt32(l,r,!0);return;case"u32":case"enum":o.setUint32(l,r,!0);return;case"u64":o.setBigUint64(l,BigInt(r),!0);return;default:throw new Error(`Unsupported libghostty-vt field type: ${n.type}`)}}readField(t,e,i){const r=this.layout(e).fields[i];if(!r)throw new Error(`libghostty-vt field is unavailable: ${e}.${i}`);const n=this.currentMemoryView(),o=t+r.offset;switch(r.type){case"bool":case"u8":return n.getUint8(o);case"u16":return n.getUint16(o,!0);case"i32":return n.getInt32(o,!0);case"u32":case"enum":return n.getUint32(o,!0);case"u64":return Number(n.getBigUint64(o,!0));default:throw new Error(`Unsupported libghostty-vt field type: ${r.type}`)}}async installWritePtyTrampoline(){const e=(await WebAssembly.instantiate(Ut,{env:{openchamber_write_pty:(n,o,l,h)=>{const a=this.ptyWriters.get(o);!a||h===0||a(V.decode(new Uint8Array(this.memory.buffer,l,h)))}}})).instance.exports.ghostty_write_pty,i=this.exports.__indirect_function_table;if(!(e instanceof Function)||!(i instanceof WebAssembly.Table))throw new Error("libghostty-vt did not expose its callback table");const r=i.length;i.grow(1),i.set(r,e),this.writePtyFunctionIndex=r}}async function Ot(){const s=await fetch(Bt);if(!s.ok)throw new Error(`Unable to load libghostty-vt (${s.status})`);return s.arrayBuffer()}let H=null;function Kt(){return H??=Q.load().catch(s=>{throw H=null,s}),H}const S=0,N=-3,Wt=1e4,z=16,E={cols:1,rows:2,dirty:3,rowIterator:4,background:5,foreground:6,cursor:7,cursorHasValue:8,cursorStyle:10,cursorVisible:11,cursorBlinking:12,cursorInViewport:14,cursorX:15,cursorY:16},q={dirty:1,raw:2,cells:3},P={raw:1,style:2,graphemesLength:3,graphemes:4,background:5,foreground:6,selected:7},Gt={wide:3},Yt={spacerTail:2},it=256;function Vt(s){const t=new Uint8Array(it*3),e=(r,n)=>{t[r*3]=n.r,t[r*3+1]=n.g,t[r*3+2]=n.b},i=[0,95,135,175,215,255];for(let r=16;r<232;r+=1){const n=r-16;e(r,{r:i[Math.floor(n/36)%6]??0,g:i[Math.floor(n/6)%6]??0,b:i[n%6]??0})}for(let r=232;r<it;r+=1){const n=8+(r-232)*10;e(r,{r:n,g:n,b:n})}return s.slice(0,16).forEach((r,n)=>e(n,r)),t}const B=new TextDecoder,$=new TextEncoder;function Ht(s,t){const e=(i,r)=>Math.floor((i*155+r*100)/255);return{r:e(s.r,t.r),g:e(s.g,t.g),b:e(s.b,t.b)}}function qt(s,t){return s.r===t.r&&s.g===t.g&&s.b===t.b}function $t(s,t){if(t===1)return String.fromCodePoint(s.getUint32(0,!0));const e=4096;let i="";for(let r=0;r<t;r+=e){const n=Math.min(e,t-r),o=new Array(n);for(let l=0;l<n;l+=1)o[l]=s.getUint32((r+l)*4,!0);i+=String.fromCodePoint(...o)}return i}class tt{runtime;terminalSlot=0;terminal=0;renderStateSlot=0;renderState=0;rowIteratorSlot=0;rowCellsSlot=0;keyEncoderSlot=0;keyEncoder=0;keyEventSlot=0;keyEvent=0;mouseEncoderSlot=0;mouseEncoder=0;mouseEventSlot=0;mouseEvent=0;ptyWriterId=0;ptyWriter=null;scratch=0;graphemes=0;graphemeCapacity=0;style=0;scrollbar=0;rows=[];disposed=!1;keyboardLayoutMap;constructor(t){this.runtime=t,It().then(e=>{this.disposed||(this.keyboardLayoutMap=e)})}static async create(t,e,i,r,n,o){const l=new tt(await Kt());try{return l.initialize(t,e,i,r,n,o),l}catch(h){throw l.dispose(),h}}initialize(t,e,i,r,n,o){const l=this.runtime.layout("GhosttyTerminalOptions").size,h=this.runtime.alloc(l);this.runtime.setField(h,"GhosttyTerminalOptions","cols",t),this.runtime.setField(h,"GhosttyTerminalOptions","rows",e),this.runtime.setField(h,"GhosttyTerminalOptions","max_scrollback",Wt),this.terminalSlot=this.runtime.allocOpaque();const a=this.runtime.call("ghostty_terminal_new",0,this.terminalSlot,h);this.runtime.free(h,l),this.assertSuccess("ghostty_terminal_new",a),this.terminal=this.runtime.readPointer(this.terminalSlot),this.applyDefaultCursorBlink(),this.ptyWriter=o,this.ptyWriterId=this.runtime.attachPtyWriter(this.terminal,o),this.renderStateSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_render_state_new",this.runtime.call("ghostty_render_state_new",0,this.renderStateSlot)),this.renderState=this.runtime.readPointer(this.renderStateSlot),this.rowIteratorSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_render_state_row_iterator_new",this.runtime.call("ghostty_render_state_row_iterator_new",0,this.rowIteratorSlot)),this.rowCellsSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_render_state_row_cells_new",this.runtime.call("ghostty_render_state_row_cells_new",0,this.rowCellsSlot)),this.keyEncoderSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_key_encoder_new",this.runtime.call("ghostty_key_encoder_new",0,this.keyEncoderSlot)),this.keyEncoder=this.runtime.readPointer(this.keyEncoderSlot),this.keyEventSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_key_event_new",this.runtime.call("ghostty_key_event_new",0,this.keyEventSlot)),this.keyEvent=this.runtime.readPointer(this.keyEventSlot),this.mouseEncoderSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_mouse_encoder_new",this.runtime.call("ghostty_mouse_encoder_new",0,this.mouseEncoderSlot)),this.mouseEncoder=this.runtime.readPointer(this.mouseEncoderSlot),this.mouseEventSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_mouse_event_new",this.runtime.call("ghostty_mouse_event_new",0,this.mouseEventSlot)),this.mouseEvent=this.runtime.readPointer(this.mouseEventSlot),this.scratch=this.runtime.alloc(16);const c=this.runtime.layout("GhosttyStyle").size;this.style=this.runtime.alloc(c),this.runtime.setField(this.style,"GhosttyStyle","size",c),this.scrollbar=this.runtime.alloc(this.runtime.layout("GhosttyTerminalScrollbar").size),this.setTheme(n),this.resize(t,e,i,r)}write(t){this.ensureActive();const e=t instanceof Uint8Array?t:$.encode(t);if(e.length===0)return;const i=this.runtime.alloc(e.length);this.runtime.bytes(i,e.length).set(e),this.runtime.call("ghostty_terminal_vt_write",this.terminal,i,e.length),this.runtime.free(i,e.length)}resetAndWrite(t){if(this.ensureActive(),this.runtime.call("ghostty_terminal_reset",this.terminal),this.applyDefaultCursorBlink(),this.rows=[],t.length===0)return;const e=this.ptyWriter;this.ptyWriterId!==0&&(this.runtime.detachPtyWriter(this.terminal,this.ptyWriterId),this.ptyWriterId=0);try{this.write(t)}finally{e!==null&&!this.disposed&&(this.ptyWriterId=this.runtime.attachPtyWriter(this.terminal,e))}}resize(t,e,i,r){this.ensureActive(),this.assertSuccess("ghostty_terminal_resize",this.runtime.call("ghostty_terminal_resize",this.terminal,Math.max(1,Math.min(65535,t)),Math.max(1,Math.min(65535,e)),Math.max(1,Math.round(i)),Math.max(1,Math.round(r))))}applyDefaultCursorBlink(){const t=this.runtime.alloc(1);this.runtime.bytes(t,1)[0]=1,this.runtime.call("ghostty_terminal_set",this.terminal,23,t),this.runtime.free(t,1)}setTheme(t){this.ensureActive();const e=this.runtime.alloc(3);for(const[n,o]of[[11,t.foreground],[12,t.background],[13,t.cursor]])this.runtime.bytes(e,3).set([o.r,o.g,o.b]),this.runtime.call("ghostty_terminal_set",this.terminal,n,e);if(this.runtime.free(e,3),t.palette===void 0){this.runtime.call("ghostty_terminal_set",this.terminal,14,0);return}const i=Vt(t.palette),r=this.runtime.alloc(i.length);this.runtime.bytes(r,i.length).set(i),this.runtime.call("ghostty_terminal_set",this.terminal,14,r),this.runtime.free(r,i.length)}scroll(t){this.ensureActive();const e=this.runtime.layout("GhosttyTerminalScrollViewport"),i=this.runtime.alloc(e.size);this.runtime.setField(i,"GhosttyTerminalScrollViewport","tag",2);const r=e.fields.value;this.runtime.view(i+r.offset,r.size).setInt32(0,t,!0),this.runtime.call("ghostty_terminal_scroll_viewport",this.terminal,i),this.runtime.free(i,e.size)}scrollToBottom(){this.ensureActive();const t=this.runtime.layout("GhosttyTerminalScrollViewport"),e=this.runtime.alloc(t.size);this.runtime.setField(e,"GhosttyTerminalScrollViewport","tag",1),this.runtime.call("ghostty_terminal_scroll_viewport",this.terminal,e),this.runtime.free(e,t.size)}isViewportActive(){return this.ensureActive(),this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_terminal_get",this.terminal,32,this.scratch)===S&&this.runtime.bytes(this.scratch,1)[0]!==0}scrollbarState(){this.ensureActive();const t=this.runtime.layout("GhosttyTerminalScrollbar");return this.runtime.bytes(this.scrollbar,t.size).fill(0),this.runtime.call("ghostty_terminal_get",this.terminal,9,this.scrollbar)!==S?null:{total:this.runtime.readField(this.scrollbar,"GhosttyTerminalScrollbar","total"),offset:this.runtime.readField(this.scrollbar,"GhosttyTerminalScrollbar","offset"),len:this.runtime.readField(this.scrollbar,"GhosttyTerminalScrollbar","len")}}isMouseTracking(){return this.ensureActive(),this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_terminal_get",this.terminal,11,this.scratch)===S&&this.runtime.bytes(this.scratch,1)[0]!==0}isMouseAnyEventTracking(){return this.ensureActive(),this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_terminal_mode_get",this.terminal,1003,this.scratch)===S&&this.runtime.bytes(this.scratch,1)[0]!==0}isAlternateScreen(){return this.ensureActive(),this.runtime.bytes(this.scratch,4).fill(0),this.runtime.call("ghostty_terminal_get",this.terminal,6,this.scratch)===S&&this.runtime.view(this.scratch,4).getUint32(0,!0)===1}isApplicationCursorKeys(){return this.ensureActive(),this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_terminal_mode_get",this.terminal,1,this.scratch)===S&&this.runtime.bytes(this.scratch,1)[0]!==0}encodeMacWordShortcut(t,e){if(this.ensureActive(),!t.altKey||t.ctrlKey||t.metaKey||t.shiftKey||t.isComposing)return null;let i;switch(t.key){case"ArrowLeft":i="\x1Bb";break;case"ArrowRight":i="\x1Bf";break;case"Backspace":i="";break;default:return null}return!/mac/i.test(e)||this.isAlternateScreen()||this.runtime.call("ghostty_terminal_get",this.terminal,8,this.scratch)!==S||this.runtime.bytes(this.scratch,1)[0]!==0?null:i}encodeKey(t,e="press"){this.ensureActive(),this.runtime.call("ghostty_key_encoder_setopt_from_terminal",this.keyEncoder,this.terminal),this.runtime.call("ghostty_key_event_set_action",this.keyEvent,e==="release"?0:t.repeat?2:1),this.runtime.call("ghostty_key_event_set_key",this.keyEvent,Ft(t.code));const i=(t.shiftKey?1:0)|(t.ctrlKey?2:0)|(t.altKey?4:0)|(t.metaKey?8:0)|(t.getModifierState("CapsLock")?16:0)|(t.getModifierState("NumLock")?32:0);this.runtime.call("ghostty_key_event_set_mods",this.keyEvent,i),this.runtime.call("ghostty_key_event_set_consumed_mods",this.keyEvent,Nt(t)),this.runtime.call("ghostty_key_event_set_composing",this.keyEvent,t.isComposing?1:0),this.runtime.call("ghostty_key_event_set_unshifted_codepoint",this.keyEvent,zt(t,this.keyboardLayoutMap));const r=t.key.length===1?t.key:"",n=$.encode(r),o=n.length===0?0:this.runtime.alloc(n.length);o!==0&&this.runtime.bytes(o,n.length).set(n),this.runtime.call("ghostty_key_event_set_utf8",this.keyEvent,o,n.length);const l=this.runtime.call("ghostty_wasm_alloc_usize"),h=this.encodeOutput(l,(a,c)=>this.runtime.call("ghostty_key_encoder_encode",this.keyEncoder,this.keyEvent,a,c,l));return this.runtime.call("ghostty_wasm_free_usize",l),o!==0&&this.runtime.free(o,n.length),h}encodePaste(t){this.ensureActive();const e=$.encode(t);if(e.length===0)return"";const i=this.runtime.alloc(e.length);this.runtime.bytes(i,e.length).set(e),this.runtime.bytes(this.scratch,1)[0]=0;const r=this.runtime.call("ghostty_terminal_mode_get",this.terminal,2004,this.scratch)===S&&this.runtime.bytes(this.scratch,1)[0]!==0,n=this.runtime.call("ghostty_wasm_alloc_usize");let o="";const l=this.runtime.call("ghostty_paste_encode",i,e.length,r?1:0,0,0,n),h=this.runtime.view(n,4).getUint32(0,!0);if(l===N&&h>0){const a=this.runtime.alloc(h),c=this.runtime.call("ghostty_paste_encode",i,e.length,r?1:0,a,h,n),u=this.runtime.view(n,4).getUint32(0,!0);o=c===S?B.decode(this.runtime.bytes(a,u)):"",this.runtime.free(a,h)}return this.runtime.call("ghostty_wasm_free_usize",n),this.runtime.free(i,e.length),o}encodeMouse(t){this.ensureActive(),this.runtime.call("ghostty_mouse_encoder_setopt_from_terminal",this.mouseEncoder,this.terminal);const e=this.runtime.layout("GhosttyMouseEncoderSize"),i=this.runtime.alloc(e.size);for(const[a,c]of[["size",e.size],["screen_width",t.screenWidth],["screen_height",t.screenHeight],["cell_width",t.cellWidth],["cell_height",t.cellHeight],["padding_top",t.paddingTop],["padding_bottom",t.paddingBottom],["padding_right",t.paddingRight],["padding_left",t.paddingLeft]])this.runtime.setField(i,"GhosttyMouseEncoderSize",a,Math.max(0,Math.round(c)));this.runtime.call("ghostty_mouse_encoder_setopt",this.mouseEncoder,2,i),this.runtime.free(i,e.size),this.runtime.bytes(this.scratch,1)[0]=t.anyButtonPressed?1:0,this.runtime.call("ghostty_mouse_encoder_setopt",this.mouseEncoder,3,this.scratch),this.runtime.bytes(this.scratch,1)[0]=1,this.runtime.call("ghostty_mouse_encoder_setopt",this.mouseEncoder,4,this.scratch),this.runtime.call("ghostty_mouse_event_set_action",this.mouseEvent,t.action==="press"?0:t.action==="release"?1:2),t.button===null?this.runtime.call("ghostty_mouse_event_clear_button",this.mouseEvent):this.runtime.call("ghostty_mouse_event_set_button",this.mouseEvent,t.button),this.runtime.call("ghostty_mouse_event_set_mods",this.mouseEvent,t.mods);const r=this.runtime.layout("GhosttyMousePosition"),n=this.runtime.alloc(r.size),o=this.runtime.view(n,r.size);o.setFloat32(r.fields.x.offset,t.x,!0),o.setFloat32(r.fields.y.offset,t.y,!0),this.runtime.call("ghostty_mouse_event_set_position",this.mouseEvent,n),this.runtime.free(n,r.size);const l=this.runtime.call("ghostty_wasm_alloc_usize"),h=this.encodeOutput(l,(a,c)=>this.runtime.call("ghostty_mouse_encoder_encode",this.mouseEncoder,this.mouseEvent,a,c,l));return this.runtime.call("ghostty_wasm_free_usize",l),h}setSelection(t,e){this.ensureActive();const i=this.runtime.layout("GhosttySelection"),r=this.runtime.layout("GhosttyGridRef").size,n=this.runtime.alloc(i.size);let o=0,l=0;try{this.runtime.setField(n,"GhosttySelection","size",i.size),o=this.gridRef(t.x,t.y,t.tag??1),l=this.gridRef(e.x,e.y,e.tag??1);const h=i.fields.start,a=i.fields.end;this.runtime.bytes(n+h.offset,h.size).set(this.runtime.bytes(o,h.size)),this.runtime.bytes(n+a.offset,a.size).set(this.runtime.bytes(l,a.size)),this.runtime.call("ghostty_terminal_set",this.terminal,21,n)}finally{this.runtime.free(o,r),this.runtime.free(l,r),this.runtime.free(n,i.size)}}selectAll(){this.ensureActive();const t=this.runtime.layout("GhosttySelection"),e=this.runtime.alloc(t.size);this.runtime.setField(e,"GhosttySelection","size",t.size),this.runtime.call("ghostty_terminal_select_all",this.terminal,e)===S&&this.runtime.call("ghostty_terminal_set",this.terminal,21,e),this.runtime.free(e,t.size)}selectWord(t,e){return this.selectAt("GhosttyTerminalSelectWordOptions","ghostty_terminal_select_word",t,e)}selectLine(t,e){return this.selectAt("GhosttyTerminalSelectLineOptions","ghostty_terminal_select_line",t,e)}hyperlinkAt(t,e){this.ensureActive();const i=this.gridRef(t,e),r=this.runtime.call("ghostty_wasm_alloc_usize"),n=this.runtime.call("ghostty_grid_ref_hyperlink_uri",i,0,0,r),o=this.runtime.view(r,4).getUint32(0,!0);let l=null;if(n===N&&o>0){const h=this.runtime.alloc(o),a=this.runtime.call("ghostty_grid_ref_hyperlink_uri",i,h,o,r),c=this.runtime.view(r,4).getUint32(0,!0);a===S&&c>0&&(l=B.decode(this.runtime.bytes(h,c))),this.runtime.free(h,o)}return this.runtime.call("ghostty_wasm_free_usize",r),this.runtime.free(i,this.runtime.layout("GhosttyGridRef").size),l}clearSelection(){this.ensureActive(),this.runtime.call("ghostty_terminal_set",this.terminal,21,0)}snapshot(){this.ensureActive(),this.assertSuccess("ghostty_render_state_update",this.runtime.call("ghostty_render_state_update",this.renderState,this.terminal));const t=this.getU16(E.cols),e=this.getU16(E.rows),i=this.getU32(E.dirty),r=this.getColor(E.foreground,{r:229,g:231,b:235}),n=this.getColor(E.background,{r:0,g:0,b:0}),l=this.getBool(E.cursorHasValue)?this.getColor(E.cursor,r):r,h=this.getBool(E.cursorInViewport),a=this.getBool(E.cursorVisible)&&h,c=h?this.getU16(E.cursorX):-1,u=h?this.getU16(E.cursorY):-1;(this.rows.length!==e||this.rows.some(m=>m.cells.length!==t))&&(this.rows=Array.from({length:e},()=>({cells:Array.from({length:t},()=>this.emptyCell(r,n)),text:"",isWrapContinuation:!1,wrapsToNext:!1})));const d=new Set;if(i!==0){this.assertSuccess("ghostty_render_state_get(row iterator)",this.runtime.call("ghostty_render_state_get",this.renderState,E.rowIterator,this.rowIteratorSlot));const m=this.runtime.readPointer(this.rowIteratorSlot);let g=0;for(;g<e&&this.runtime.call("ghostty_render_state_row_iterator_next",m)!==0;)(i===2||this.getRowBool(m,q.dirty))&&(this.rows[g]=this.readRow(m,t,r,n),d.add(g),this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_render_state_row_set",m,0,this.scratch)),g+=1;this.runtime.view(this.scratch,4).setUint32(0,0,!0),this.runtime.call("ghostty_render_state_set",this.renderState,0,this.scratch)}return{cols:t,rows:e,foreground:r,background:n,cursor:l,cursorX:c,cursorY:u,cursorVisible:a,cursorBlinking:this.getBool(E.cursorBlinking),cursorStyle:this.getU32(E.cursorStyle),dirtyRows:d,rowData:this.rows}}selectionText(){this.ensureActive();const t=this.runtime.alloc(z),e=this.runtime.view(t,z);e.setUint32(0,z,!0),e.setUint32(4,0,!0),e.setUint8(8,1),e.setUint8(9,1),e.setUint32(12,0,!0);const i=this.runtime.call("ghostty_wasm_alloc_usize"),r=this.runtime.call("ghostty_terminal_selection_format_buf",this.terminal,t,0,0,i),n=this.runtime.view(i,4).getUint32(0,!0);let o="";if(r===N&&n>0){const l=this.runtime.alloc(n),h=this.runtime.call("ghostty_terminal_selection_format_buf",this.terminal,t,l,n,i),a=this.runtime.view(i,4).getUint32(0,!0);h===S&&(o=B.decode(this.runtime.bytes(l,a))),this.runtime.free(l,n)}return this.runtime.call("ghostty_wasm_free_usize",i),this.runtime.free(t,z),o}viewportPointToScreen(t,e){return this.convertPoint(t,e,1,2)}screenPointToViewport(t,e){return this.convertPoint(t,e,2,1)}convertPoint(t,e,i,r){this.ensureActive();const n=this.gridRef(t,e,i),o=this.pointFromGridRef(n,r);return this.runtime.free(n,this.runtime.layout("GhosttyGridRef").size),o}dispose(){if(!this.disposed){if(this.disposed=!0,this.mouseEvent&&this.runtime.call("ghostty_mouse_event_free",this.mouseEvent),this.mouseEncoder&&this.runtime.call("ghostty_mouse_encoder_free",this.mouseEncoder),this.keyEvent&&this.runtime.call("ghostty_key_event_free",this.keyEvent),this.keyEncoder&&this.runtime.call("ghostty_key_encoder_free",this.keyEncoder),this.rowCellsSlot){const t=this.runtime.readPointer(this.rowCellsSlot);t&&this.runtime.call("ghostty_render_state_row_cells_free",t)}if(this.rowIteratorSlot){const t=this.runtime.readPointer(this.rowIteratorSlot);t&&this.runtime.call("ghostty_render_state_row_iterator_free",t)}this.renderState&&this.runtime.call("ghostty_render_state_free",this.renderState),this.terminal&&(this.ptyWriterId&&this.runtime.detachPtyWriter(this.terminal,this.ptyWriterId),this.runtime.call("ghostty_terminal_free",this.terminal)),this.style&&this.runtime.free(this.style,this.runtime.layout("GhosttyStyle").size),this.scrollbar&&this.runtime.free(this.scrollbar,this.runtime.layout("GhosttyTerminalScrollbar").size),this.scratch&&this.runtime.free(this.scratch,16),this.graphemes&&this.runtime.free(this.graphemes,this.graphemeCapacity);for(const t of[this.mouseEventSlot,this.mouseEncoderSlot,this.keyEventSlot,this.keyEncoderSlot,this.rowCellsSlot,this.rowIteratorSlot,this.renderStateSlot,this.terminalSlot])this.runtime.freeOpaque(t)}}encodeOutput(t,e){const i=e(0,0),r=this.runtime.view(t,4).getUint32(0,!0);if(i===S&&r===0||i!==N||r===0)return"";const n=this.runtime.alloc(r),o=e(n,r),l=this.runtime.view(t,4).getUint32(0,!0),h=o===S?B.decode(this.runtime.bytes(n,l)):"";return this.runtime.free(n,r),h}readRow(t,e,i,r){this.assertSuccess("ghostty_render_state_row_get(raw)",this.runtime.call("ghostty_render_state_row_get",t,q.raw,this.scratch));const n=this.runtime.view(this.scratch,8).getBigUint64(0,!0);this.runtime.bytes(this.scratch+8,1)[0]=0,this.assertSuccess("ghostty_row_get(wrap continuation)",this.runtime.call("ghostty_row_get",n,2,this.scratch+8));const o=this.runtime.bytes(this.scratch+8,1)[0]!==0;this.runtime.bytes(this.scratch+8,1)[0]=0,this.assertSuccess("ghostty_row_get(wrap)",this.runtime.call("ghostty_row_get",n,1,this.scratch+8));const l=this.runtime.bytes(this.scratch+8,1)[0]!==0;this.assertSuccess("ghostty_render_state_row_get(cells)",this.runtime.call("ghostty_render_state_row_get",t,q.cells,this.rowCellsSlot));const h=this.runtime.readPointer(this.rowCellsSlot),{size:a,fields:c}=this.runtime.layout("GhosttyStyle"),u=[];for(;u.length<e&&this.runtime.call("ghostty_render_state_row_cells_next",h)!==0;){let d=this.getCellColor(h,P.foreground,i),m=this.getCellColor(h,P.background,r);this.runtime.bytes(this.style,a).fill(0),this.runtime.setField(this.style,"GhosttyStyle","size",a),this.runtime.call("ghostty_render_state_row_cells_get",h,P.style,this.style);const g=this.getCellU32(h,P.graphemesLength);let y="";if(g>0){const v=g*4;if(v>this.graphemeCapacity){const p=Math.max(v,this.graphemeCapacity*2),w=this.runtime.alloc(p);this.runtime.free(this.graphemes,this.graphemeCapacity),this.graphemes=w,this.graphemeCapacity=p}if(this.runtime.call("ghostty_render_state_row_cells_get",h,P.graphemes,this.graphemes)===S){const p=this.runtime.view(this.graphemes,v);y=$t(p,g)}}let f=0;if(y.length===0&&u.at(-1)?.text.length){this.assertSuccess("ghostty_render_state_row_cells_get(raw)",this.runtime.call("ghostty_render_state_row_cells_get",h,P.raw,this.scratch));const v=this.runtime.view(this.scratch,8).getBigUint64(0,!0);this.runtime.view(this.scratch+8,4).setUint32(0,0,!0),this.assertSuccess("ghostty_cell_get(wide)",this.runtime.call("ghostty_cell_get",v,Gt.wide,this.scratch+8)),f=this.runtime.view(this.scratch+8,4).getUint32(0,!0)}const _=this.getCellBool(h,P.selected),b=this.runtime.view(this.style,a);b.getUint8(c.inverse.offset)!==0&&([d,m]=[m,d]),b.getUint8(c.faint.offset)!==0&&(d=Ht(d,m)),u.push({text:y,wide:f,foreground:d,background:m,bold:b.getUint8(c.bold.offset)!==0,italic:b.getUint8(c.italic.offset)!==0,invisible:b.getUint8(c.invisible.offset)!==0,strikethrough:b.getUint8(c.strikethrough.offset)!==0,overline:b.getUint8(c.overline.offset)!==0,underline:b.getInt32(c.underline.offset,!0)!==0,selected:_})}for(;u.length<e;)u.push(this.emptyCell(i,r));return{cells:u,text:u.map(d=>d.text||" ").join("").trimEnd(),isWrapContinuation:o,wrapsToNext:l}}gridRef(t,e,i=1){const r=this.runtime.layout("GhosttyPoint"),n=this.runtime.alloc(r.size);this.runtime.setField(n,"GhosttyPoint","tag",i);const o=r.fields.value,l=o.offset,h=this.runtime.view(n+l,o.size);h.setUint16(0,Math.max(0,t),!0),h.setUint32(4,Math.max(0,e),!0);const a=this.runtime.layout("GhosttyGridRef").size,c=this.runtime.alloc(a);this.runtime.setField(c,"GhosttyGridRef","size",a);const u=this.runtime.call("ghostty_terminal_grid_ref",this.terminal,n,c);return this.runtime.free(n,r.size),u!==S&&(this.runtime.free(c,a),this.assertSuccess("ghostty_terminal_grid_ref",u)),c}selectAt(t,e,i,r){this.ensureActive();const n=this.runtime.layout(t),o=this.runtime.layout("GhosttySelection"),l=this.runtime.alloc(n.size);let h=0,a=0,c=null;try{this.runtime.setField(l,t,"size",n.size),h=this.gridRef(i,r);const u=n.fields.ref;if(this.runtime.bytes(l+u.offset,u.size).set(this.runtime.bytes(h,u.size)),a=this.runtime.alloc(o.size),this.runtime.setField(a,"GhosttySelection","size",o.size),this.runtime.call(e,this.terminal,l,a)===S){const m=a+o.fields.start.offset,g=a+o.fields.end.offset,y=this.pointFromGridRef(m,1),f=this.pointFromGridRef(g,1),_=this.pointFromGridRef(m,2),b=this.pointFromGridRef(g,2);y&&f&&_&&b&&(c={viewport:{start:y,end:f},screen:{start:_,end:b}}),this.runtime.call("ghostty_terminal_set",this.terminal,21,a)}}finally{this.runtime.free(a,o.size),this.runtime.free(h,this.runtime.layout("GhosttyGridRef").size),this.runtime.free(l,n.size)}return c}pointFromGridRef(t,e){const i=this.runtime.layout("GhosttyPointCoordinate"),r=this.runtime.alloc(i.size),o=this.runtime.call("ghostty_terminal_point_from_grid_ref",this.terminal,t,e,r)===S?{x:this.runtime.readField(r,"GhosttyPointCoordinate","x"),y:this.runtime.readField(r,"GhosttyPointCoordinate","y")}:null;return this.runtime.free(r,i.size),o}getU16(t){return this.runtime.bytes(this.scratch,2).fill(0),this.assertSuccess("ghostty_render_state_get",this.runtime.call("ghostty_render_state_get",this.renderState,t,this.scratch)),this.runtime.view(this.scratch,2).getUint16(0,!0)}getU32(t){return this.runtime.bytes(this.scratch,4).fill(0),this.assertSuccess("ghostty_render_state_get",this.runtime.call("ghostty_render_state_get",this.renderState,t,this.scratch)),this.runtime.view(this.scratch,4).getUint32(0,!0)}getBool(t){return this.runtime.bytes(this.scratch,1)[0]=0,this.assertSuccess("ghostty_render_state_get",this.runtime.call("ghostty_render_state_get",this.renderState,t,this.scratch)),this.runtime.bytes(this.scratch,1)[0]!==0}getColor(t,e){return this.runtime.bytes(this.scratch,3).fill(0),this.runtime.call("ghostty_render_state_get",this.renderState,t,this.scratch)===S?this.readColor(this.scratch):e}getRowBool(t,e){return this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_render_state_row_get",t,e,this.scratch)===S&&this.runtime.bytes(this.scratch,1)[0]!==0}getCellU32(t,e){return this.runtime.bytes(this.scratch,4).fill(0),this.runtime.call("ghostty_render_state_row_cells_get",t,e,this.scratch)===S?this.runtime.view(this.scratch,4).getUint32(0,!0):0}getCellBool(t,e){return this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_render_state_row_cells_get",t,e,this.scratch)===S&&this.runtime.bytes(this.scratch,1)[0]!==0}getCellColor(t,e,i){return this.runtime.bytes(this.scratch,3).fill(0),this.runtime.call("ghostty_render_state_row_cells_get",t,e,this.scratch)===S?this.readColor(this.scratch):i}readColor(t){const e=this.runtime.bytes(t,3);return{r:e[0]??0,g:e[1]??0,b:e[2]??0}}emptyCell(t,e){return{text:"",wide:0,foreground:t,background:e,bold:!1,italic:!1,invisible:!1,strikethrough:!1,overline:!1,underline:!1,selected:!1}}assertSuccess(t,e){if(e!==S)throw new Error(`${t} failed with result ${e}`)}ensureActive(){if(this.disposed)throw new Error("libghostty-vt terminal has been disposed")}}function K(s,t){return qt(s,t)}const ct=9472,Xt=9599,ut=9600,dt=9631,mt=57520,ft=57523,Zt=1,pt=2,A=3,jt="0011 0022 1100 2200 0011 0022 1100 2200 0011 0022 1100 2200 0101 0102 0201 0202 0110 0120 0210 0220 1001 1002 2001 2002 1010 1020 2010 2020 1101 1102 2101 1201 2201 2102 1202 2202 1110 1120 2110 1210 2210 2120 1220 2220 0111 0121 0112 0122 0211 0221 0212 0222 1011 1021 1012 1022 2011 2021 2012 2022 1111 1121 1112 1122 2111 1211 2211 2121 2112 1221 1212 2122 1222 2221 2212 2222 0011 0022 1100 2200 0033 3300 0103 0301 0303 0130 0310 0330 1003 3001 3003 1030 3010 3030 1103 3301 3303 1130 3310 3330 0133 0311 0333 1033 3011 3033 1133 3311 3333 0101 0110 1010 1001 0000 0000 0000 0010 1000 0001 0100 0020 2000 0002 0200 0012 1200 0021 2100",Jt=jt.split(" "),Qt=new Set([9476,9477,9478,9479]),te=new Set([9480,9481,9482,9483]),ee=new Set([9548,9549,9550,9551]),ie=new Map([[9600,[[0,0,1,1/2]]],[9601,[[0,7/8,1,1/8]]],[9602,[[0,6/8,1,2/8]]],[9603,[[0,5/8,1,3/8]]],[9604,[[0,1/2,1,1/2]]],[9605,[[0,3/8,1,5/8]]],[9606,[[0,2/8,1,6/8]]],[9607,[[0,1/8,1,7/8]]],[9608,[[0,0,1,1]]],[9609,[[0,0,7/8,1]]],[9610,[[0,0,6/8,1]]],[9611,[[0,0,5/8,1]]],[9612,[[0,0,1/2,1]]],[9613,[[0,0,3/8,1]]],[9614,[[0,0,2/8,1]]],[9615,[[0,0,1/8,1]]],[9616,[[1/2,0,1/2,1]]],[9620,[[0,0,1,1/8]]],[9621,[[7/8,0,1/8,1]]],[9622,[[0,1/2,1/2,1/2]]],[9623,[[1/2,1/2,1/2,1/2]]],[9624,[[0,0,1/2,1/2]]],[9625,[[0,0,1/2,1],[1/2,1/2,1/2,1/2]]],[9626,[[0,0,1/2,1/2],[1/2,1/2,1/2,1/2]]],[9627,[[0,0,1,1/2],[0,1/2,1/2,1/2]]],[9628,[[0,0,1,1/2],[1/2,1/2,1/2,1/2]]],[9629,[[1/2,0,1/2,1/2]]],[9630,[[1/2,0,1/2,1/2],[0,1/2,1/2,1/2]]],[9631,[[1/2,0,1/2,1/2],[0,1/2,1,1/2]]]]),se=new Map([[9617,.25],[9618,.5],[9619,.75]]);function W(s){if(s.length===0||s.length>2)return!1;const t=s.codePointAt(0);return t===void 0||String.fromCodePoint(t)!==s?!1:t>=ct&&t<=Xt||t>=ut&&t<=dt||t>=mt&&t<=ft}function st(s,t){return`rgba(${s.r}, ${s.g}, ${s.b}, ${t})`}function re(s){const t=Math.round(s.x),e=Math.round(s.x+s.width),i=Math.round(s.y),r=Math.round(s.y+s.height),n=Math.max(1,Math.round(s.width/8));return{left:t,right:e,top:i,bottom:r,centerX:Math.round(s.x+s.width/2),centerY:Math.round(s.y+s.height/2),stroke:n,gap:n+1}}function x(s,t){return s===pt?t*3:t}function L(s,t,e,i,r){e<=t||s.fillRect(t,i-Math.floor(r/2),e-t,r)}function R(s,t,e,i,r){e<=t||s.fillRect(i-Math.floor(r/2),t,r,e-t)}function ne(s,t,e,i,r){const n=x(i,t.stroke),o=e?t.left:t.top,l=e?t.right:t.bottom,h=t.stroke,a=l-o,c=Math.max(1,Math.floor((a-h*(r-1))/r));for(let u=0;u<r;u+=1){const d=o+u*(c+h),m=u===r-1?l:d+c;e?L(s,d,m,t.centerY,n):R(s,d,m,t.centerX,n)}}function oe(s,t,e){const i=Number(e[0]),r=Number(e[1]),n=Number(e[2]),o=Number(e[3]),{centerX:l,centerY:h,stroke:a,gap:c}=t,u=M=>M===Zt||M===pt,d=Math.max(x(i,a),x(r,a),a),m=Math.max(x(n,a),x(o,a),a),g=l-Math.floor(d/2),y=g+d,f=h-Math.floor(m/2),_=f+m,b=i===A||r===A,v=n===A||o===A;u(n)&&L(s,t.left,b?l-c:y,h,x(n,a)),u(o)&&L(s,b?l+c:g,t.right,h,x(o,a)),u(i)&&R(s,t.top,v?h-c:_,l,x(i,a)),u(r)&&R(s,v?h+c:f,t.bottom,l,x(r,a));const p=(M,T)=>M===A?l-T*c:u(M)?l:l+T*c,w=(M,T)=>M===A?h-T*c:u(M)?h:h+T*c;n===A&&(L(s,t.left,p(i,1),h-c,a),L(s,t.left,p(r,1),h+c,a)),o===A&&(L(s,p(i,-1),t.right,h-c,a),L(s,p(r,-1),t.right,h+c,a)),i===A&&(R(s,t.top,w(n,1),l-c,a),R(s,t.top,w(o,1),l+c,a)),r===A&&(R(s,w(n,-1),t.bottom,l-c,a),R(s,w(o,-1),t.bottom,l+c,a))}function le(s,t,e){const{centerX:i,centerY:r,stroke:n}=t,o=e===9581||e===9584,l=e===9581||e===9582,h=o?t.right:t.left,a=l?t.bottom:t.top,c=Math.min(Math.abs(h-i),Math.abs(a-r)),u=o?1:-1,d=l?1:-1,m=n%2/2,g=i+m,y=r+m;s.beginPath(),s.moveTo(h,y),s.lineTo(g+u*c,y),s.quadraticCurveTo(g,y,g,y+d*c),s.lineTo(g,a),s.lineWidth=n,s.lineCap="butt",s.stroke()}function he(s,t,e){s.lineWidth=t.stroke,s.lineCap="butt",s.beginPath(),(e===9585||e===9587)&&(s.moveTo(t.right,t.top),s.lineTo(t.left,t.bottom)),(e===9586||e===9587)&&(s.moveTo(t.left,t.top),s.lineTo(t.right,t.bottom)),s.stroke()}function ae(s,t,e){const{left:i,right:r,top:n,bottom:o,centerY:l}=t,h=e===57520||e===57521,a=h?r:i,c=h?i:r;if(s.beginPath(),s.moveTo(c,n),s.lineTo(a,l),s.lineTo(c,o),e===57520||e===57522){s.closePath(),s.fill();return}s.lineWidth=t.stroke,s.lineCap="butt",s.stroke()}function rt(s,t,e,i){if(!W(t))return!1;const r=t.codePointAt(0)??0,n=re(e),o=st(i,1);if(s.fillStyle=o,s.strokeStyle=o,r>=ut&&r<=dt){const a=se.get(r);if(a!==void 0)return s.fillStyle=st(i,a),s.fillRect(n.left,n.top,n.right-n.left,n.bottom-n.top),!0;const c=n.right-n.left,u=n.bottom-n.top;for(const[d,m,g,y]of ie.get(r)??[]){const f=n.left+Math.round(d*c),_=n.left+Math.round((d+g)*c),b=n.top+Math.round(m*u),v=n.top+Math.round((m+y)*u);s.fillRect(f,b,Math.max(1,_-f),Math.max(1,v-b))}return!0}if(r>=mt&&r<=ft)return ae(s,n,r),!0;if(r>=9581&&r<=9584)return le(s,n,r),!0;if(r>=9585&&r<=9587)return he(s,n,r),!0;const l=Jt[r-ct]??"0000",h=Qt.has(r)?3:te.has(r)?4:ee.has(r)?2:0;if(h>0){const a=l[2]!=="0";return ne(s,n,a,Number(a?l[2]:l[0]),h),!0}return oe(s,n,l),!0}const ce="rgba(72, 122, 191, 0.35)";function C(s){return`rgb(${s.r}, ${s.g}, ${s.b})`}function ue(s,t){return K(s.foreground,t.foreground)&&s.bold===t.bold&&s.italic===t.italic&&s.invisible===t.invisible}function de(s,t,e){let i=t+1;for(;i<s.length;){const r=s[i];if(!r)break;if(r.wide===Yt.spacerTail){i+=1;continue}if(r.text.length===0||!e(r))break;i+=1}return i}function nt(s,t,e){const i=s.italic?"italic":"normal",r=s.bold?"700":"400";return`${i} ${r} ${t}px ${e}`}function X(s,t,e){s.font=`normal 400 ${t}px ${e}`;const i=s.measureText("M"),r=s.measureText("Mg"),n=r.actualBoundingBoxAscent||t,o=r.actualBoundingBoxDescent,l=n+o,h=Math.max(1,Math.round(t*1.35),Math.ceil(l));return{width:Math.max(1,i.width),height:h,baseline:Math.round((h-l)/2+n)}}function ot(s,t,e,i){return{cols:Math.max(1,Math.floor((s-i*2)/e.width)),rows:Math.max(1,Math.floor((t-i*2)/e.height))}}function me(s){const{context:t,snapshot:e,metrics:i,fontSize:r,fontFamily:n,padding:o,forceFull:l,cursorOn:h,previousCursorY:a}=s,c=s.focused??!0,u=s.selectionBackground??ce,d=s.hoveredLinkRange??null,m=s.originY??o,g=l?Array.from({length:e.rows},(y,f)=>f):[...e.dirtyRows];a!=null&&a>=0&&!g.includes(a)&&g.push(a),e.cursorVisible&&e.cursorY>=0&&!g.includes(e.cursorY)&&g.push(e.cursorY),l&&(t.save(),t.resetTransform(),t.fillStyle=C(e.background),t.fillRect(0,0,t.canvas.width,t.canvas.height),t.restore()),t.textBaseline="alphabetic";for(const y of g){const f=e.rowData[y];if(!f)continue;const _=m+y*i.height;t.fillStyle=C(e.background),t.fillRect(o,_,e.cols*i.width,i.height);let b=0;for(;b<f.cells.length;){const p=f.cells[b];if(!p)break;let w=b+1;for(;w<f.cells.length;){const M=f.cells[w];if(!M||M.selected!==p.selected||!K(M.background,p.background))break;w+=1}if(p.selected||!K(p.background,e.background)){const M=o+b*i.width,T=(w-b)*i.width;K(p.background,e.background)||(t.fillStyle=C(p.background),t.fillRect(M,_,T,i.height)),p.selected&&(t.fillStyle=u,t.fillRect(M,_,T,i.height))}b=w}let v=0;for(;v<f.cells.length;){const p=f.cells[v];if(!p)break;if(p.text.length===0){v+=1;continue}if(W(p.text)){p.invisible||rt(t,p.text,{x:o+v*i.width,y:_,width:i.width,height:i.height},p.foreground),v+=1;continue}const w=de(f.cells,v,T=>ue(T,p)&&!W(T.text)),M=f.cells.slice(v,w).map(T=>T.text).join("");!p.invisible&&M.trim().length>0&&(t.save(),t.beginPath(),t.rect(o+v*i.width,_,(w-v)*i.width,i.height),t.clip(),t.font=nt(p,r,n),t.fillStyle=C(p.foreground),t.fillText(M,o+v*i.width,_+i.baseline,(w-v)*i.width),t.restore()),v=w}for(let p=0;p<f.cells.length;p+=1){const w=f.cells[p],M=d!==null&&y>=d.start.y&&y<=d.end.y&&(y>d.start.y||p>=d.start.x)&&(y<d.end.y||p<=d.end.x);if(!w||!w.underline&&!w.strikethrough&&!w.overline&&!M)continue;t.fillStyle=C(w.foreground);const T=o+p*i.width;(w.underline||M)&&t.fillRect(T,_+i.height-2,i.width,1),w.strikethrough&&t.fillRect(T,_+Math.floor(i.height*.55),i.width,1),w.overline&&t.fillRect(T,_+1,i.width,1)}}if(h&&e.cursorVisible&&e.cursorX>=0&&e.cursorY>=0){const y=o+e.cursorX*i.width,f=m+e.cursorY*i.height;if(t.fillStyle=C(e.cursor),!c)t.strokeStyle=C(e.cursor),t.strokeRect(y+.5,f+.5,i.width-1,i.height-1);else if(e.cursorStyle===0)t.fillRect(y,f,2,i.height);else if(e.cursorStyle===2)t.fillRect(y,f+i.height-2,i.width,2);else if(e.cursorStyle===3)t.strokeStyle=C(e.cursor),t.strokeRect(y+.5,f+.5,i.width-1,i.height-1);else{t.fillRect(y,f,i.width,i.height);const _=e.rowData[e.cursorY]?.cells[e.cursorX];_?.text&&W(_.text)?rt(t,_.text,{x:y,y:f,width:i.width,height:i.height},e.background):_?.text&&(t.font=nt(_,r,n),t.fillStyle=C(e.background),t.fillText(_.text,y,f+i.baseline,i.width))}}}const fe=new URL("/assets/SymbolsNerdFontMono-Regular-aK5vsLov.woff2",import.meta.url).href,pe=13,ye=6,ge=32,we=500,_e=1e3,D=s=>/mac|iphone|ipad|ipod/i.test(s),be='"Symbols Nerd Font Mono", "Symbols Nerd Font", "JetBrainsMono Nerd Font", "JetBrainsMono NF", "FiraCode Nerd Font", "Hack Nerd Font", "MesloLGS NF", "CaskaydiaCove Nerd Font", "PowerlineSymbols", monospace',G='"SF Mono", "SFMono-Regular", Menlo, Consolas, "Liberation Mono", '+be,k=4,Se=18,ve=500,Me="iMW0@# .",Te=["normal 400","normal 700","italic 400","italic 700"];let U=null;function Ee(){return U!==null||(U=(async()=>{try{const s=new FontFace("Symbols Nerd Font Mono",`url(${fe})`);document.fonts.add(await s.load())}catch{}})()),U}function yt(s){const t=s===void 0?null:J(s);return t===null?G:`${t}, ${G}`}function gt(s){const t=s===void 0?null:J(s);return t===null||!Pt(t)?G:yt(t)}async function lt(s,t,e){const i=yt(s),r=((n,o)=>document.fonts.load(n,o).then(()=>{}));try{await Promise.all(Te.map(n=>r(`${n} ${t}px ${i}`,Me)))}catch{}return(e?.resolve??gt)(s)}function Z(s){return s===void 0||!Number.isFinite(s)?pe:Math.max(ye,Math.min(ge,Math.round(s)))}function ke(s){return s.focused&&s.cursorBlinking&&s.cursorVisible&&!s.reducedMotion}function Ae(s,t,e,i,r){if(!r)return t;const n=s-t*2-e*i;return t+Math.max(0,n)}function j(s,t){const e=Math.max(0,s.total),i=Math.max(0,Math.min(s.len,e)),r=Math.max(0,e-i);if(t<=0||i<=0||r===0)return null;const n=Math.min(t,Math.max(Se,t*i/e)),o=Math.max(0,t-n),l=Math.max(0,Math.min(s.offset,r));return{thumbHeight:n,thumbTop:o*(l/r),maxOffset:r}}function Ce(s,t,e,i){const r=j(s,t);if(r===null)return 0;const n=Math.max(0,t-r.thumbHeight);if(n===0)return 0;const o=Math.max(0,Math.min(e-i,n));return Math.round(o/n*r.maxOffset)}function xe(s){const{bounds:t,clientX:e,clientY:i,cols:r,rows:n,metrics:o,padding:l,originY:h}=s,a=e-t.left-l,c=i-t.top-h;return a<0||c<0||a>=r*o.width||c>=n*o.height?null:{x:Math.floor(a/o.width),y:Math.floor(c/o.height)}}function Pe(s,t){const e=s.cells.map(i=>i.text||" ").join("");return t?e.trimEnd():e}function wt(s,t){let e=0;for(let i=0;i<t;i+=1)e+=s.cells[i]?.text.length||1;return e}function ht(s,t){for(let e=0;e<s.cells.length;e+=1){const i=wt(s,e+1);if(t<i)return e}return Math.max(0,s.cells.length-1)}function Le(s,t,e){const i=Mt(t+1,u=>{const d=s[u];return d?{isWrapped:d.isWrapContinuation,translateToString:(m=!1)=>Pe(d,m)}:null});if(!i)return null;const r=i.segments[0];if(r&&s[r.bufferLineNumber-1]?.isWrapContinuation)return null;const n=i.segments.find(u=>u.bufferLineNumber===t+1),o=s[t];if(!n||!o)return null;const l=i.segments.at(-1),h=l?s[l.bufferLineNumber-1]:void 0,a=h!==void 0&&h.wrapsToNext,c=n.startIndex+wt(o,e);for(const u of vt(i.text))if(c>=u.start&&c<u.end){if(u.end===i.text.length&&a)return null;const d=i.segments.find(f=>u.start>=f.startIndex&&u.start<f.endIndex),m=i.segments.find(f=>u.end-1>=f.startIndex&&u.end-1<f.endIndex),g=d?s[d.bufferLineNumber-1]:void 0,y=m?s[m.bufferLineNumber-1]:void 0;return!d||!m||!g||!y?null:{text:u.text,range:{start:{x:ht(g,u.start-d.startIndex),y:d.bufferLineNumber-1},end:{x:ht(y,u.end-1-m.startIndex),y:m.bufferLineNumber-1}}}}return null}function Re(s,t=navigator.platform){return s.key.toLowerCase()!=="c"?!1:D(t)?s.metaKey:s.ctrlKey}function Fe(s,t){s.value=t,t.length!==0&&s.select()}function De(s,t){t.length===0||s.value!==t||(s.value="")}function Ie(s,t){return s.length===0||!t?{preventDefault:!1,claimWriteFallback:!1}:(t.setData("text/plain",s),{preventDefault:!0,claimWriteFallback:!0})}function Ne(s,t=navigator.platform){const e=s.key.toLowerCase();return e==="insert"&&!D(t)?s.shiftKey&&!s.ctrlKey&&!s.metaKey:e!=="v"?!1:D(t)?s.metaKey:s.ctrlKey&&s.shiftKey}function ze(s){return s.inputType===""||s.inputType==="insertCompositionText"||s.inputType==="insertFromComposition"}function at(s,t){return s.isComposing||t||s.key==="Process"||s.keyCode===229}function Be(s){return s.getModifierState("AltGraph")&&[...s.key].length===1}function O(s,t){return s&&!t.shiftKey&&!t.ctrlKey&&!t.metaKey}function Ue(s,t,e){const i=s==="motion"?t:"";return{send:t.length>0&&(s!=="motion"||t!==e),nextMotionData:i}}function Oe(s,t,e){return{tracking:t,motionData:s===t?e:""}}function Ke(s,t,e,i){const r=s.deltaMode===1?s.deltaY*t:s.deltaMode===2?s.deltaY*e*t:s.deltaY,n=i+r/t,o=Math.trunc(n);return{rows:o,remainder:n-o}}function We(s,t){return s===0?"":(s<0?t?"\x1BOA":"\x1B[A":t?"\x1BOB":"\x1B[B").repeat(Math.abs(s))}function F(s,t=navigator.platform){return D(t)?s.metaKey&&!s.ctrlKey:s.ctrlKey&&!s.metaKey}function Ge(s){switch(s){case 0:return 1;case 1:return 3;case 2:return 2;case 3:return 4;case 4:return 5;default:return null}}function Ye(s,t){return{count:s!==null&&t.timeStamp-s.time<=we&&Math.hypot(t.clientX-s.x,t.clientY-s.y)<=4?s.count>=3?1:s.count+1:1,time:t.timeStamp,x:t.clientX,y:t.clientY}}class _t{canvas;input;scrollbar;cols=1;rows=1;mount;context;core;options;visible;hasSize=!1;metrics;fontFamily;requestedFontFamily;fontSize;fontEpoch=0;pendingFontEpoch=null;resizeObserver;scrollbarThumb;snapshot=null;frame=0;cursorTimer=null;compositionInputToSuppress=null;compositionSuppressionTimer=null;cursorOn=!0;renderedCursorY=null;forceFullRender=!0;scrollbarDirty=!0;scrollbarState=null;scrollbarPointerId=null;scrollbarPointerOffset=0;disposed=!1;resizeNotifyTimer=null;originY=k;mountHeight=0;selectionEnd=null;selectionAnchorScreen=null;selectionEndScreen=null;selectionMode="cell";selectionBase=null;selectionScrollTimer=null;selectionScrollDelta=0;selectionPointer=null;mouseReportingPointerId=null;mouseReportingButton=null;linkActivationPointerId=null;hoveredLink=null;hoverPointer=null;linkModifierActive=!1;selectionClickSequence=null;selectionMoved=!1;composing=!1;focused=!1;resizeNotified=!1;canvasConfigured=!1;theme;suppressedKeyCodes=new Set;pasteShortcutToken=0;copyShortcutToken=0;clearSelectionAfterCopy=!1;primedCopySelection="";wheelRemainder=0;lastMouseMotionData="";mouseAnyEventTracking=!1;dprMedia=null;reducedMotionMedia=window.matchMedia?.("(prefers-reduced-motion: reduce)");inputLeft=-1;inputTop=-1;lastTouchPointerAt=Number.NEGATIVE_INFINITY;constructor(t,e,i,r,n,o,l,h,a,c){this.mount=t,this.canvas=e,this.input=i,this.scrollbar=r,this.scrollbarThumb=n,this.context=o,this.core=l,this.mouseAnyEventTracking=l.isMouseAnyEventTracking(),this.metrics=h,this.options=c,this.visible=c.visible??!0,this.theme=c.theme,this.fontFamily=a,this.requestedFontFamily=c.font?.family,this.fontSize=Z(c.font?.size),this.resizeObserver=new ResizeObserver(()=>this.fit()),this.installEvents(),this.watchDevicePixelRatio(),this.reducedMotionMedia?.addEventListener("change",this.onReducedMotionChange),document.fonts.addEventListener("loadingdone",this.onFontsLoaded),this.resizeObserver.observe(t)}static async create(t,e){const i=document.createElement("canvas");i.className="oc-terminal-canvas",i.setAttribute("aria-hidden","true");const r=document.createElement("textarea");r.className="oc-terminal-input",r.setAttribute("aria-label",e.labels.input),r.setAttribute("autocorrect","off"),r.autocapitalize="off",r.autocomplete="off",r.spellcheck=!1;const n=document.createElement("div");n.className="oc-terminal-scrollbar",n.setAttribute("role","scrollbar"),n.setAttribute("aria-label",e.labels.scrollbar),n.setAttribute("aria-orientation","vertical"),n.tabIndex=-1,n.hidden=!0;const o=document.createElement("div");o.className="oc-terminal-scrollbar-thumb",n.append(o),t.replaceChildren(i,r,n);const l=window.devicePixelRatio||1;t.clientWidth>0&&t.clientHeight>0&&(i.width=Math.max(1,Math.round(t.clientWidth*l)),i.height=Math.max(1,Math.round(t.clientHeight*l)));const h=i.getContext("2d",{alpha:!1,willReadFrequently:!0});if(!h)throw new Error("Canvas 2D is unavailable");h.fillStyle=`rgb(${e.theme.background.r}, ${e.theme.background.g}, ${e.theme.background.b})`,h.fillRect(0,0,i.width,i.height);const a=Z(e.font?.size);try{await Ee()}catch{}const c=await lt(e.font?.family,a),u=X(h,a,c),d=ot(t.clientWidth,t.clientHeight,u,k),m=await tt.create(d.cols,d.rows,u.width,u.height,e.theme,e.onData),g=new _t(t,i,r,n,o,h,m,u,c,e);return g.fit(),g}setVisible(t){if(!(this.disposed||this.visible===t)){if(this.visible=t,this.cursorOn=!0,this.forceFullRender=!0,this.scrollbarDirty=!0,!t){this.cancelRender(),this.setSelectionAutoscroll(0);return}this.fit()}}write(t){this.disposed||(this.core.write(t),this.synchronizeMouseTrackingState(),this.cursorOn=!0,this.scrollbarDirty=!0,this.requestRender())}resetAndWrite(t,e){if(this.disposed)return;this.lastMouseMotionData="";const i=e!==void 0&&(e.cols!==this.cols||e.rows!==this.rows);i&&this.core.resize(e.cols,e.rows,this.metrics.width,this.metrics.height);try{this.core.resetAndWrite(t)}finally{i&&this.core.resize(this.cols,this.rows,this.metrics.width,this.metrics.height)}this.synchronizeMouseTrackingState(),this.cursorOn=!0,this.forceFullRender=!0,this.scrollbarDirty=!0,this.requestRender()}setTheme(t){this.disposed||(this.theme=t,this.core.setTheme(t),this.forceFullRender=!0,this.requestRender())}async setFont(t){if(this.disposed)return;const e=Z(t.size),i=++this.fontEpoch;this.pendingFontEpoch=i;const r=await lt(t.family,e);this.disposed||i!==this.fontEpoch||(this.pendingFontEpoch=null,this.fontFamily=r,this.requestedFontFamily=t.family,this.fontSize=e,this.applyFontMetrics())}applyFontMetrics(){this.metrics=X(this.context,this.fontSize,this.fontFamily),this.core.resize(this.cols,this.rows,this.metrics.width,this.metrics.height),this.inputLeft=-1,this.inputTop=-1,this.forceFullRender=!0,this.scrollbarDirty=!0,this.fit(),this.requestRender()}onReducedMotionChange=()=>{this.disposed||(this.cursorOn=!0,this.requestRender())};onFontsLoaded=()=>{if(this.disposed||this.pendingFontEpoch!==null)return;const t=gt(this.requestedFontFamily);if(t!==this.fontFamily){this.fontFamily=t,this.applyFontMetrics();return}const e=X(this.context,this.fontSize,this.fontFamily);e.width===this.metrics.width&&e.height===this.metrics.height&&e.baseline===this.metrics.baseline||this.applyFontMetrics()};fit(){if(this.disposed||!this.visible)return!1;const t=this.mount.clientWidth,e=this.mount.clientHeight;if(t<=0||e<=0)return this.hasSize=!1,this.forceFullRender=!0,this.cancelRender(),!1;this.hasSize=!0;const i=window.devicePixelRatio||1,r=Math.max(1,Math.round(t*i)),n=Math.max(1,Math.round(e*i));let o=!1;(this.canvas.width!==r||this.canvas.height!==n||!this.canvasConfigured)&&(this.canvas.width=r,this.canvas.height=n,this.context.setTransform(i,0,0,i,0,0),this.canvasConfigured=!0,this.forceFullRender=!0,this.scrollbarDirty=!0,o=!0);const l=ot(t,e,this.metrics,k);return this.mountHeight=e,(l.cols!==this.cols||l.rows!==this.rows||!this.resizeNotified)&&(this.cols=l.cols,this.rows=l.rows,this.core.resize(l.cols,l.rows,this.metrics.width,this.metrics.height),this.notifyResize(),this.forceFullRender=!0,this.scrollbarDirty=!0,o=!0),(o||this.forceFullRender)&&this.renderFrame(),!0}notifyResize(){this.resizeNotified=!0,this.resizeNotifyTimer!==null&&window.clearTimeout(this.resizeNotifyTimer),this.resizeNotifyTimer=window.setTimeout(()=>{this.resizeNotifyTimer=null,this.disposed||this.options.onResize(this.cols,this.rows)},150)}focus(){this.disposed||!this.visible||this.input.focus({preventScroll:!0})}async pasteFromClipboard(t,e=()=>!0){const i=++this.pasteShortcutToken,r=await t();if(this.disposed||this.pasteShortcutToken!==i||!e()||(this.pasteShortcutToken+=1,r.length===0))return;const n=this.core.encodePaste(r);n.length>0&&this.options.onData(n)}hasSelection(){return this.core.selectionText().length>0}getSelection(){return this.core.selectionText()}getSelectionPosition(){return!this.selectionAnchorScreen||!this.selectionEndScreen||!this.hasSelection()?null:this.selectionAnchorScreen.y<this.selectionEndScreen.y||this.selectionAnchorScreen.y===this.selectionEndScreen.y&&this.selectionAnchorScreen.x<=this.selectionEndScreen.x?{start:this.selectionAnchorScreen,end:this.selectionEndScreen}:{start:this.selectionEndScreen,end:this.selectionAnchorScreen}}getSelectionEndClientRect(){const t=this.getSelectionPosition();if(!t)return null;const e=this.core.screenPointToViewport(t.end.x,t.end.y);if(!e)return null;const i=this.canvas.getBoundingClientRect();return{right:i.left+k+(e.x+1)*this.metrics.width,bottom:i.top+this.originY+(e.y+1)*this.metrics.height}}clearSelection(){this.clearPrimedCopy(),this.core.clearSelection(),this.selectionEnd=null,this.selectionAnchorScreen=null,this.selectionEndScreen=null,this.selectionMode="cell",this.selectionBase=null,this.setSelectionAutoscroll(0),this.options.onSelectionChange?.(),this.forceFullRender=!0,this.requestRender()}scrollToBottom(){this.core.scrollToBottom(),this.forceFullRender=!0,this.scrollbarDirty=!0,this.requestRender()}isAtBottom(){return this.core.isViewportActive()}refresh(){this.disposed||(this.forceFullRender=!0,this.scrollbarDirty=!0,this.requestRender())}scrollLines(t){this.disposed||this.scrollViewport(t)}selectWordAt(t,e){if(this.disposed)return!1;const i=this.cellAt(t,e),r=this.core.selectWord(i.x,i.y);return r?(this.selectionMode="word",this.selectionMoved=!1,this.selectionBase=r.screen,this.selectionEnd=r.viewport.end,this.selectionAnchorScreen=r.screen.start,this.selectionEndScreen=r.screen.end,this.options.onSelectionChange?.(),this.forceFullRender=!0,this.requestRender(),!0):!1}extendSelectionTo(t,e){if(this.disposed||this.selectionAnchorScreen===null)return;const i=this.cellAt(t,e);i.x===this.selectionEnd?.x&&i.y===this.selectionEnd.y||this.extendSelectionToPoint(t,e)}dispose(){this.disposed||(this.disposed=!0,this.resizeObserver.disconnect(),document.fonts.removeEventListener("loadingdone",this.onFontsLoaded),this.dprMedia?.removeEventListener("change",this.onDevicePixelRatioChange),this.dprMedia=null,this.reducedMotionMedia?.removeEventListener("change",this.onReducedMotionChange),this.selectionScrollTimer!==null&&window.clearInterval(this.selectionScrollTimer),this.resizeNotifyTimer!==null&&(window.clearTimeout(this.resizeNotifyTimer),this.resizeNotifyTimer=null,this.options.onResize(this.cols,this.rows)),this.cancelRender(),this.compositionSuppressionTimer!==null&&window.clearTimeout(this.compositionSuppressionTimer),this.removeEvents(),this.core.dispose(),(this.canvas.parentElement===this.mount||this.input.parentElement===this.mount||this.scrollbar.parentElement===this.mount)&&(this.canvas.remove(),this.input.remove(),this.scrollbar.remove()))}onKeyDown=t=>{if(this.updateLinkModifier(t),Be(t)||this.options.beforeKey?.(t)===!1){this.suppressedKeyCodes.add(t.code);return}if(Re(t)&&this.hasSelection()){const r=this.getSelection();if(this.primeCopy(r),t.shiftKey)t.preventDefault(),document.execCommand("copy");else{this.clearSelectionAfterCopy=!t.shiftKey&&!D(navigator.platform);const n=navigator.clipboard;if(n){const o=++this.copyShortcutToken;Promise.resolve().then(()=>{this.disposed||this.copyShortcutToken!==o||n.writeText(r).then(()=>{this.disposed||this.copyShortcutToken!==o||this.clearSelectionAfterCopy&&(this.clearSelectionAfterCopy=!1,this.clearSelection())},()=>{this.copyShortcutToken===o&&(this.clearSelectionAfterCopy=!1)})})}}this.suppressedKeyCodes.add(t.code);return}if(Ne(t)){this.suppressedKeyCodes.add(t.code);const r=navigator.clipboard;if(r){const n=++this.pasteShortcutToken;r.readText().then(o=>{this.disposed||this.pasteShortcutToken!==n||(this.pasteShortcutToken+=1,o.length>0&&this.options.onData(this.core.encodePaste(o)))},()=>{})}return}if(at(t,this.composing))return;this.clearPrimedCopy();const e=this.core.encodeMacWordShortcut(t,navigator.platform),i=e??this.core.encodeKey(t);i.length!==0&&(e!==null?this.suppressedKeyCodes.add(t.code):this.suppressedKeyCodes.delete(t.code),t.preventDefault(),t.stopPropagation(),this.options.onData(i))};onKeyUp=t=>{if(this.updateLinkModifier(t),this.suppressedKeyCodes.delete(t.code)||at(t,this.composing))return;const e=this.core.encodeKey(t,"release");e.length!==0&&(t.preventDefault(),t.stopPropagation(),this.options.onData(e))};onFocus=()=>{this.focused=!0,this.cursorOn=!0,this.requestRender()};onBlur=()=>{this.focused=!1,this.linkModifierActive=!1,this.refreshHoveredLink(),this.cursorOn=!0,this.requestRender()};onDevicePixelRatioChange=()=>{this.watchDevicePixelRatio(),this.fit()};watchDevicePixelRatio(){this.dprMedia?.removeEventListener("change",this.onDevicePixelRatioChange),this.dprMedia=window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`),this.dprMedia.addEventListener("change",this.onDevicePixelRatioChange)}primeCopy(t){this.primedCopySelection=t,Fe(this.input,t)}clearPrimedCopy(){De(this.input,this.primedCopySelection),this.primedCopySelection=""}onCopyEvent=t=>{const e=this.hasSelection()?this.getSelection():this.input.value;this.primeCopy(e);const i=Ie(e,t.clipboardData);i.preventDefault&&t.preventDefault(),i.claimWriteFallback&&(this.copyShortcutToken+=1,this.clearSelectionAfterCopy&&(this.clearSelectionAfterCopy=!1,this.clearSelection()))};onPaste=t=>{t.preventDefault();const e=t.clipboardData?.getData("text/plain")??"";e.length!==0&&(this.pasteShortcutToken+=1,this.options.onData(this.core.encodePaste(e)))};onCompositionStart=()=>{this.clearPrimedCopy(),this.clearCompositionInputSuppression(),this.composing=!0};onCompositionEnd=t=>{this.composing=!1;const e=this.input.value||t.data;e.length>0&&this.options.onData(e),this.input.value="",this.compositionInputToSuppress=e,this.compositionSuppressionTimer=window.setTimeout(()=>{this.compositionInputToSuppress=null,this.compositionSuppressionTimer=null},100)};onInput=t=>{const e=t;if(this.composing||e.isComposing)return;const i=this.input.value||e.data||"";if(i===this.compositionInputToSuppress&&ze(e)){this.clearCompositionInputSuppression(),this.input.value="";return}this.clearCompositionInputSuppression(),i.length>0&&this.options.onData(i),this.input.value=""};clearCompositionInputSuppression(){this.compositionSuppressionTimer!==null&&(window.clearTimeout(this.compositionSuppressionTimer),this.compositionSuppressionTimer=null),this.compositionInputToSuppress=null}ignoresTouchPointer(t){return t.pointerType!=="touch"||this.options.handleTouchPointer!==!1?!1:(this.lastTouchPointerAt=t.timeStamp,!0)}onPointerDown=t=>{if(this.ignoresTouchPointer(t))return;if(this.focus(),O(this.core.isMouseTracking(),t)){const n=Ge(t.button);if(n===null)return;t.preventDefault(),t.stopPropagation(),this.clearHoveredLink("default"),this.mouseReportingPointerId=t.pointerId,this.mouseReportingButton=n,this.sendMouse("press",n,t),this.canvas.setPointerCapture(t.pointerId);return}if(t.button!==0)return;if(F(t)){t.preventDefault(),t.stopPropagation(),this.linkActivationPointerId=t.pointerId,this.canvas.setPointerCapture(t.pointerId);return}this.clearHoveredLink();const e=this.cellAt(t.clientX,t.clientY);this.selectionMoved=!1,this.selectionClickSequence=Ye(this.selectionClickSequence,t);const i=this.selectionClickSequence.count;this.selectionMode=i>=3?"line":i===2?"word":"cell";const r=this.selectionMode==="line"?this.core.selectLine(e.x,e.y):this.selectionMode==="word"?this.core.selectWord(e.x,e.y):null;if(r)this.selectionBase=r.screen,this.selectionEnd=r.viewport.end,this.selectionAnchorScreen=r.screen.start,this.selectionEndScreen=r.screen.end,this.options.onSelectionChange?.();else{this.selectionMode="cell",this.selectionBase=null,this.selectionEnd=e;const n=this.core.viewportPointToScreen(e.x,e.y);this.selectionAnchorScreen=n,this.selectionEndScreen=n,n?this.core.setSelection({...n,tag:2},{...n,tag:2}):this.core.setSelection(e,e)}this.forceFullRender=!0,this.canvas.setPointerCapture(t.pointerId),this.requestRender()};onPointerMove=t=>{if(this.ignoresTouchPointer(t)||this.linkActivationPointerId===t.pointerId)return;const e=this.synchronizeMouseTrackingState();if(this.mouseReportingPointerId===t.pointerId||O(e,t)){t.preventDefault(),this.hoverPointer={x:t.clientX,y:t.clientY},this.linkModifierActive=F(t),this.setHoveredLink(null),this.canvas.style.cursor="default",this.sendMouse("motion",this.buttonFromButtons(t.buttons),t);return}if(this.lastMouseMotionData="",!this.selectionAnchorScreen||!this.canvas.hasPointerCapture(t.pointerId)){this.updateHoverCursor(t);return}this.clearHoveredLink(),this.selectionPointer={x:t.clientX,y:t.clientY};const i=this.canvas.getBoundingClientRect();this.setSelectionAutoscroll(t.clientY<i.top?-1:t.clientY>i.bottom?1:0);const r=this.cellAt(t.clientX,t.clientY);r.x===this.selectionEnd?.x&&r.y===this.selectionEnd.y||this.extendSelectionToPoint(t.clientX,t.clientY)};extendSelectionToPoint(t,e){const i=this.selectionAnchorScreen;if(i===null)return;const r=this.cellAt(t,e);this.selectionMoved=!0,this.selectionEnd=r;const n=this.selectionMode==="line"?this.core.selectLine(r.x,r.y):this.selectionMode==="word"?this.core.selectWord(r.x,r.y):null,o=this.core.viewportPointToScreen(r.x,r.y);if(o===null)return;const l=this.selectionBase,h=l!==null&&(o.y<l.start.y||o.y===l.start.y&&o.x<l.start.x),a=l===null?i:h?l.end:l.start,c=n===null?o:h?n.screen.start:n.screen.end;this.selectionAnchorScreen=a,this.selectionEndScreen=c,this.core.setSelection({...a,tag:2},{...c,tag:2}),this.options.onSelectionChange?.(),this.forceFullRender=!0,this.requestRender()}setSelectionAutoscroll(t){if(this.selectionScrollDelta=t,t===0){this.selectionScrollTimer!==null&&(window.clearInterval(this.selectionScrollTimer),this.selectionScrollTimer=null);return}this.selectionScrollTimer===null&&(this.selectionScrollTimer=window.setInterval(()=>{if(this.disposed||this.selectionScrollDelta===0)return;this.scrollViewport(this.selectionScrollDelta);const e=this.selectionPointer;e&&this.extendSelectionToPoint(e.x,e.y)},80))}updateHoverCursor(t){this.hoverPointer={x:t.clientX,y:t.clientY},this.linkModifierActive=F(t),this.refreshHoveredLink()}updateLinkModifier(t){const e=F(t);e!==this.linkModifierActive&&(this.linkModifierActive=e,this.refreshHoveredLink())}onPointerLeave=()=>{this.lastMouseMotionData="",this.clearHoveredLink()};clearHoveredLink(t=""){this.hoverPointer=null,this.setHoveredLink(null),this.canvas.style.cursor=t}refreshHoveredLink(){const t=this.hoverPointer,e=t&&this.linkModifierActive?this.linkAt(t.x,t.y):null;this.setHoveredLink(e)}setHoveredLink(t){const e=this.hoveredLink,i=e?.text===t?.text&&e?.range.start.x===t?.range.start.x&&e?.range.start.y===t?.range.start.y&&e?.range.end.x===t?.range.end.x&&e?.range.end.y===t?.range.end.y;this.canvas.style.cursor=t?"pointer":"",!i&&(this.hoveredLink=t,this.forceFullRender=!0,this.requestRender())}onPointerUp=t=>{if(!this.ignoresTouchPointer(t)){if(this.setSelectionAutoscroll(0),this.linkActivationPointerId===t.pointerId){if(t.preventDefault(),t.stopPropagation(),this.linkActivationPointerId=null,this.canvas.hasPointerCapture(t.pointerId)&&this.canvas.releasePointerCapture(t.pointerId),t.type!=="pointercancel"){const e=this.linkAt(t.clientX,t.clientY);e&&this.options.onLinkActivate?.(e.text,t)}return}if(this.mouseReportingPointerId===t.pointerId){t.preventDefault(),t.stopPropagation(),this.sendMouse("release",this.mouseReportingButton,t),this.mouseReportingPointerId=null,this.mouseReportingButton=null,this.canvas.hasPointerCapture(t.pointerId)&&this.canvas.releasePointerCapture(t.pointerId),t.type==="pointercancel"?this.clearHoveredLink():(this.hoverPointer={x:t.clientX,y:t.clientY},this.linkModifierActive=F(t),this.refreshHoveredLink());return}this.canvas.hasPointerCapture(t.pointerId)&&this.canvas.releasePointerCapture(t.pointerId),t.button===0&&(!this.selectionMoved&&this.selectionMode==="cell"&&this.clearSelection(),this.options.onSelectionChange?.())}};onWheel=t=>{if(t.deltaY===0)return;t.preventDefault();const e=Ke(t,this.metrics.height,this.rows,this.wheelRemainder);if(this.wheelRemainder=e.remainder,e.rows===0)return;const i=Math.abs(e.rows);if(O(this.core.isMouseTracking(),t)){const r=e.rows<0?4:5;for(let n=0;n<i;n+=1)this.sendMouse("press",r,t);return}if(this.core.isAlternateScreen()){this.options.onData(We(e.rows,this.core.isApplicationCursorKeys()));return}this.scrollViewport(e.rows)};onMouseDown=t=>{t.button===0&&t.preventDefault(),!(t.timeStamp-this.lastTouchPointerAt<_e)&&this.focus()};onContextMenu=t=>{if(O(this.core.isMouseTracking(),t)){t.preventDefault();return}this.options.onContextMenu?.(t)};onScrollbarPointerDown=t=>{if(t.button!==0)return;const e=this.readScrollbarState();if(e===null)return;const i=this.scrollbar.getBoundingClientRect(),r=j(e,i.height);r!==null&&(t.preventDefault(),t.stopPropagation(),this.scrollbarPointerId=t.pointerId,this.scrollbarPointerOffset=t.target===this.scrollbarThumb?t.clientY-i.top-r.thumbTop:r.thumbHeight/2,this.scrollbar.setPointerCapture(t.pointerId),this.scrollbarToPointer(t.clientY,i))};onScrollbarPointerMove=t=>{t.pointerId!==this.scrollbarPointerId||this.scrollbarState===null||(t.preventDefault(),this.scrollbarToPointer(t.clientY,this.scrollbar.getBoundingClientRect()))};onScrollbarPointerUp=t=>{t.pointerId===this.scrollbarPointerId&&(t.preventDefault(),this.scrollbarPointerId=null,this.scrollbar.hasPointerCapture(t.pointerId)&&this.scrollbar.releasePointerCapture(t.pointerId))};onScrollbarKeyDown=t=>{const e=this.readScrollbarState();if(e===null)return;let i=0;switch(t.key){case"ArrowUp":i=-1;break;case"ArrowDown":i=1;break;case"PageUp":i=-Math.max(1,e.len);break;case"PageDown":i=Math.max(1,e.len);break;case"Home":i=-e.offset;break;case"End":i=e.total-e.len-e.offset;break;default:return}t.preventDefault(),t.stopPropagation(),this.scrollViewport(i)};installEvents(){this.input.addEventListener("keydown",this.onKeyDown),this.input.addEventListener("keyup",this.onKeyUp),this.input.addEventListener("focus",this.onFocus),this.input.addEventListener("blur",this.onBlur),this.input.addEventListener("input",this.onInput),this.input.addEventListener("paste",this.onPaste),this.input.addEventListener("copy",this.onCopyEvent),this.input.addEventListener("compositionstart",this.onCompositionStart),this.input.addEventListener("compositionend",this.onCompositionEnd),this.canvas.addEventListener("pointerdown",this.onPointerDown),this.canvas.addEventListener("pointermove",this.onPointerMove),this.canvas.addEventListener("pointerleave",this.onPointerLeave),this.canvas.addEventListener("pointerup",this.onPointerUp),this.canvas.addEventListener("pointercancel",this.onPointerUp),this.canvas.addEventListener("wheel",this.onWheel,{passive:!1}),this.canvas.addEventListener("mousedown",this.onMouseDown),this.canvas.addEventListener("contextmenu",this.onContextMenu),this.scrollbar.addEventListener("pointerdown",this.onScrollbarPointerDown),this.scrollbar.addEventListener("pointermove",this.onScrollbarPointerMove),this.scrollbar.addEventListener("pointerup",this.onScrollbarPointerUp),this.scrollbar.addEventListener("pointercancel",this.onScrollbarPointerUp),this.scrollbar.addEventListener("keydown",this.onScrollbarKeyDown)}removeEvents(){this.input.removeEventListener("keydown",this.onKeyDown),this.input.removeEventListener("keyup",this.onKeyUp),this.input.removeEventListener("focus",this.onFocus),this.input.removeEventListener("blur",this.onBlur),this.input.removeEventListener("input",this.onInput),this.input.removeEventListener("paste",this.onPaste),this.input.removeEventListener("copy",this.onCopyEvent),this.input.removeEventListener("compositionstart",this.onCompositionStart),this.input.removeEventListener("compositionend",this.onCompositionEnd),this.canvas.removeEventListener("pointerdown",this.onPointerDown),this.canvas.removeEventListener("pointermove",this.onPointerMove),this.canvas.removeEventListener("pointerleave",this.onPointerLeave),this.canvas.removeEventListener("pointerup",this.onPointerUp),this.canvas.removeEventListener("pointercancel",this.onPointerUp),this.canvas.removeEventListener("wheel",this.onWheel),this.canvas.removeEventListener("mousedown",this.onMouseDown),this.canvas.removeEventListener("contextmenu",this.onContextMenu),this.scrollbar.removeEventListener("pointerdown",this.onScrollbarPointerDown),this.scrollbar.removeEventListener("pointermove",this.onScrollbarPointerMove),this.scrollbar.removeEventListener("pointerup",this.onScrollbarPointerUp),this.scrollbar.removeEventListener("pointercancel",this.onScrollbarPointerUp),this.scrollbar.removeEventListener("keydown",this.onScrollbarKeyDown)}scrollViewport(t){let e=Math.trunc(t);const i=this.readScrollbarState();if(i!==null){const r=Math.max(0,i.total-i.len),n=Math.max(0,Math.min(i.offset+e,r));e=n-i.offset,this.scrollbarState={...i,offset:n}}e!==0&&(this.core.scroll(e),this.forceFullRender=!0,this.scrollbarDirty=!0,this.requestRender())}scrollbarToPointer(t,e){const i=this.scrollbarState;if(i===null)return;const r=Ce(i,e.height,t-e.top,this.scrollbarPointerOffset);this.scrollViewport(r-i.offset)}updateScrollbar(){const t=this.readScrollbarState(),e=t===null?null:j(t,Math.max(0,this.mount.clientHeight-k*2));this.scrollbar.hidden=e===null,!(t===null||e===null)&&(this.scrollbar.setAttribute("aria-valuemin","0"),this.scrollbar.setAttribute("aria-valuemax",String(e.maxOffset)),this.scrollbar.setAttribute("aria-valuenow",String(Math.max(0,Math.min(t.offset,e.maxOffset)))),this.scrollbarThumb.style.height=`${e.thumbHeight}px`,this.scrollbarThumb.style.transform=`translateY(${e.thumbTop}px)`)}readScrollbarState(){const t=this.core.scrollbarState();return this.scrollbarState=t,t}requestRender(){this.disposed||!this.visible||!this.hasSize||this.frame!==0||(this.frame=window.requestAnimationFrame(()=>{this.frame=0,this.renderFrame()}))}cancelRender(){this.frame!==0&&(window.cancelAnimationFrame(this.frame),this.frame=0),this.cursorTimer!==null&&(window.clearTimeout(this.cursorTimer),this.cursorTimer=null)}renderFrame(){if(this.disposed||!this.visible)return;if(this.frame!==0&&(window.cancelAnimationFrame(this.frame),this.frame=0),this.mount.clientWidth===0||this.mount.clientHeight===0){this.hasSize=!1,this.forceFullRender=!0,this.cancelRender();return}this.snapshot=this.core.snapshot(),this.blinkEnabled()||(this.cursorOn=!0);const t=this.readScrollbarState(),e=t!==null&&t.total>t.len,i=Ae(this.mountHeight,k,this.rows,this.metrics.height,e);i!==this.originY&&(this.originY=i,this.forceFullRender=!0),this.refreshHoveredLink(),me({context:this.context,snapshot:this.snapshot,metrics:this.metrics,fontSize:this.fontSize,fontFamily:this.fontFamily,padding:k,originY:this.originY,forceFull:this.forceFullRender,cursorOn:this.cursorOn,previousCursorY:this.renderedCursorY,focused:this.focused,hoveredLinkRange:this.hoveredLink?.range??null,selectionBackground:this.theme.selectionBackground}),this.positionInput(),this.renderedCursorY=this.cursorOn&&this.snapshot.cursorVisible&&this.snapshot.cursorY>=0?this.snapshot.cursorY:null,this.scrollbarDirty&&(this.scrollbarDirty=!1,this.updateScrollbar()),this.forceFullRender=!1,this.scheduleCursorBlink()}scheduleCursorBlink(){this.cursorTimer!==null&&window.clearTimeout(this.cursorTimer),this.cursorTimer=null,this.blinkEnabled()&&(this.cursorTimer=window.setTimeout(()=>{this.cursorTimer=null,this.cursorOn=!this.cursorOn,this.requestRender()},ve))}blinkEnabled(){const t=this.snapshot;return!t||!this.visible||!this.hasSize?!1:ke({focused:this.focused,cursorBlinking:t.cursorBlinking,cursorVisible:t.cursorVisible,reducedMotion:this.reducedMotionMedia?.matches??!1})}positionInput(){const t=this.snapshot;if(!t||!t.cursorVisible||t.cursorX<0||t.cursorY<0)return;const e=k+t.cursorX*this.metrics.width,i=this.originY+t.cursorY*this.metrics.height;e===this.inputLeft&&i===this.inputTop||(this.inputLeft=e,this.inputTop=i,this.input.style.left=`${e}px`,this.input.style.top=`${i}px`,this.input.style.height=`${this.metrics.height}px`)}cellAt(t,e){const i=this.canvas.getBoundingClientRect();return{x:Math.max(0,Math.min(this.cols-1,Math.floor((t-i.left-k)/this.metrics.width))),y:Math.max(0,Math.min(this.rows-1,Math.floor((e-i.top-this.originY)/this.metrics.height)))}}linkAt(t,e){if(!this.snapshot)return null;const i=xe({bounds:this.canvas.getBoundingClientRect(),clientX:t,clientY:e,cols:this.cols,rows:this.rows,metrics:this.metrics,padding:k,originY:this.originY});if(!i)return null;const r=this.core.hyperlinkAt(i.x,i.y);if(r){const n={...i},o={...i};for(;;){const l=n.x>0?{x:n.x-1,y:n.y}:n.y>0&&this.snapshot.rowData[n.y]?.isWrapContinuation?{x:this.cols-1,y:n.y-1}:null;if(!l||this.core.hyperlinkAt(l.x,l.y)!==r)break;n.x=l.x,n.y=l.y}for(;;){const l=o.x+1<this.cols?{x:o.x+1,y:o.y}:o.y+1<this.rows&&this.snapshot.rowData[o.y]?.wrapsToNext?{x:0,y:o.y+1}:null;if(!l||this.core.hyperlinkAt(l.x,l.y)!==r)break;o.x=l.x,o.y=l.y}return{text:r,range:{start:n,end:o}}}return Le(this.snapshot.rowData,i.y,i.x)}sendMouse(t,e,i){const r=this.canvas.getBoundingClientRect(),n=this.core.encodeMouse({action:t,button:e,mods:(i.shiftKey?1:0)|(i.ctrlKey?2:0)|(i.altKey?4:0)|(i.metaKey?8:0),x:Math.max(0,i.clientX-r.left),y:Math.max(0,i.clientY-r.top),screenWidth:r.width,screenHeight:r.height,cellWidth:this.metrics.width,cellHeight:this.metrics.height,paddingLeft:k,paddingRight:k,paddingTop:this.originY,paddingBottom:Math.max(0,r.height-this.originY-this.rows*this.metrics.height),anyButtonPressed:i.buttons!==0}),o=Ue(t,n,this.lastMouseMotionData);this.lastMouseMotionData=o.nextMotionData,o.send&&this.options.onData(n)}synchronizeMouseTrackingState(){const t=this.core.isMouseAnyEventTracking(),e=Oe(this.mouseAnyEventTracking,t,this.lastMouseMotionData);return this.mouseAnyEventTracking=e.tracking,this.lastMouseMotionData=e.motionData,t}buttonFromButtons(t){return(t&1)!==0?1:(t&4)!==0?3:(t&2)!==0?2:(t&8)!==0?4:(t&16)!==0?5:null}}export{G as DEFAULT_TERMINAL_FONT_FAMILY,_t as GhosttyTerminalSurface,Ye as advanceTerminalSelectionClickSequence,Re as isTerminalCopyShortcut,F as isTerminalLinkPointerGesture,Ne as isTerminalPasteShortcut,lt as loadTerminalFontFamily,Ue as resolveTerminalMouseData,ke as shouldBlinkTerminalCursor,Ae as terminalContentOriginY,Z as terminalFontSize,xe as terminalGridCellAt,Le as terminalLinkAtPositionWithRange,j as terminalScrollbarGeometry,Ce as terminalScrollbarOffsetAtPointer,We as terminalWheelArrowData,Ke as terminalWheelDeltaRows};
|
|
1
|
+
const et=/https?:\/\/[^\s"'`<>]+/giu,bt=/[.,;!?]+$/;function St(s){let t=s.replace(bt,"");if(t.length===0)return t;const e=(i,r)=>{for(;t.endsWith(r);){const n=t.split(i).length-1,o=t.split(r).length-1;if(n>=o)return;t=t.slice(0,-1)}};return e("(",")"),e("[","]"),e("{","}"),t}function vt(s){const t=[];et.lastIndex=0;for(const e of s.matchAll(et)){const i=e[0],r=e.index??-1;if(r<0||i.length===0)continue;const n=St(i);n.length!==0&&t.push({text:n,start:r,end:r+n.length})}return t}function Mt(s,t){const e=t(s-1);if(!e)return null;let i=s,r=e;for(;i>1&&r.isWrapped;){const h=t(i-2);if(!h)return null;i-=1,r=h}const n=[];let o=0,l=i;for(;;){const h=t(l-1);if(!h)break;const c=t(l)?.isWrapped===!0,u=h.translateToString(!c);if(n.push({bufferLineNumber:l,text:u,startIndex:o,endIndex:o+u.length}),o+=u.length,!c)break;l+=1}return{text:n.map(h=>h.text).join(""),segments:n}}const Tt=["normal 400","normal 700","italic 400","italic 700"],Et=["i","M","W","0","@","#","."," "],kt=.01,At=/^(ui-monospace|ui-sans-serif|ui-serif|system-ui)$/i;function Ct(s){const t=s.trim();return t.length===0?"":/^(['"]).*\1$/.test(t)||/^[a-zA-Z][a-zA-Z0-9-]*$/.test(t)?t:`"${t.replaceAll('"',"")}"`}function J(s){const t=s.split(",").map(Ct).filter(e=>e.length>0&&!At.test(e));return t.length>0?t.join(", "):null}function xt(s){const t=s[0];return t===void 0||t<=0||s.some(e=>!Number.isFinite(e)||e<=0)?!0:s.every(e=>Math.abs(e-t)<kt)}let I;function Pt(s){const t=J(s);if(t===null)return!0;try{if(I===void 0&&(I=document.createElement("canvas").getContext("2d")),I===null)return!0;const e=I;for(const i of Tt){e.font=`${i} 32px ${t}, monospace`;const r=Et.map(n=>e.measureText(n).width);if(!xt(r))return!1}return!0}catch{return!0}}const Rt=["Unidentified","Backquote","Backslash","BracketLeft","BracketRight","Comma","Digit0","Digit1","Digit2","Digit3","Digit4","Digit5","Digit6","Digit7","Digit8","Digit9","Equal","IntlBackslash","IntlRo","IntlYen","KeyA","KeyB","KeyC","KeyD","KeyE","KeyF","KeyG","KeyH","KeyI","KeyJ","KeyK","KeyL","KeyM","KeyN","KeyO","KeyP","KeyQ","KeyR","KeyS","KeyT","KeyU","KeyV","KeyW","KeyX","KeyY","KeyZ","Minus","Period","Quote","Semicolon","Slash","AltLeft","AltRight","Backspace","CapsLock","ContextMenu","ControlLeft","ControlRight","Enter","MetaLeft","MetaRight","ShiftLeft","ShiftRight","Space","Tab","Convert","KanaMode","NonConvert","Delete","End","Help","Home","Insert","PageDown","PageUp","ArrowDown","ArrowLeft","ArrowRight","ArrowUp","NumLock","Numpad0","Numpad1","Numpad2","Numpad3","Numpad4","Numpad5","Numpad6","Numpad7","Numpad8","Numpad9","NumpadAdd","NumpadBackspace","NumpadClear","NumpadClearEntry","NumpadComma","NumpadDecimal","NumpadDivide","NumpadEnter","NumpadEqual","NumpadMemoryAdd","NumpadMemoryClear","NumpadMemoryRecall","NumpadMemoryStore","NumpadMemorySubtract","NumpadMultiply","NumpadParenLeft","NumpadParenRight","NumpadSubtract","NumpadSeparator","NumpadArrowUp","NumpadArrowDown","NumpadArrowRight","NumpadArrowLeft","NumpadBegin","NumpadHome","NumpadEnd","NumpadInsert","NumpadDelete","NumpadPageUp","NumpadPageDown","Escape","F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12","F13","F14","F15","F16","F17","F18","F19","F20","F21","F22","F23","F24","F25","Fn","FnLock","PrintScreen","ScrollLock","Pause","BrowserBack","BrowserFavorites","BrowserForward","BrowserHome","BrowserRefresh","BrowserSearch","BrowserStop","Eject","LaunchApp1","LaunchApp2","LaunchMail","MediaPlayPause","MediaSelect","MediaStop","MediaTrackNext","MediaTrackPrevious","Power","Sleep","AudioVolumeDown","AudioVolumeMute","AudioVolumeUp","WakeUp","Copy","Cut","Paste"],Lt=new Map(Rt.map((s,t)=>[s,t]));function Ft(s){return Lt.get(s)??0}const Dt=new Map([["!","1"],["@","2"],["#","3"],["$","4"],["%","5"],["^","6"],["&","7"],["*","8"],["(","9"],[")","0"],["~","`"],["_","-"],["+","="],["{","["],["}","]"],["|","\\"],[":",";"],['"',"'"],["<",","],[">","."],["?","/"]]);let Y;function It(){if(Y)return Y;const t=globalThis.navigator?.keyboard?.getLayoutMap().catch(()=>{})??Promise.resolve(void 0);return Y=t,t}function Nt(s){return!s.shiftKey||s.ctrlKey||s.altKey||s.metaKey?0:[...s.key].length===1?1:0}function zt(s,t){if([...s.key].length!==1)return 0;const e=t?.get(s.code);if(e&&[...e].length===1)return e.codePointAt(0)??0;if(/^[A-Z]$/u.test(s.key))return s.key.charCodeAt(0)+32;if(s.shiftKey){const i=Dt.get(s.key);if(i)return i.codePointAt(0)??0;const r=s.key.toLowerCase();return r!==s.key&&[...r].length===1?r.codePointAt(0)??0:0}return s.key.codePointAt(0)??0}const H=new TextDecoder,Bt=new URL("/assets/ghostty-vt-DdA0Zryv.wasm",import.meta.url),Ot=Uint8Array.from([0,97,115,109,1,0,0,0,1,8,1,96,4,127,127,127,127,0,2,29,1,3,101,110,118,21,111,112,101,110,99,104,97,109,98,101,114,95,119,114,105,116,101,95,112,116,121,0,0,3,2,1,0,5,3,1,0,16,6,9,1,127,1,65,128,128,192,0,11,7,30,2,6,109,101,109,111,114,121,2,0,17,103,104,111,115,116,116,121,95,119,114,105,116,101,95,112,116,121,0,1,10,18,1,16,0,32,0,32,1,32,2,32,3,16,128,128,128,128,0,11]);class Q{memory;layouts;exports;memoryView;ptyWriters=new Map;nextPtyWriterId=1;writePtyFunctionIndex=0;constructor(t){this.exports=t.exports;const e=t.exports.memory;if(!(e instanceof WebAssembly.Memory))throw new Error("libghostty-vt did not export WebAssembly memory");this.memory=e,this.memoryView=new DataView(e.buffer);const i=this.call("ghostty_type_json"),r=new Uint8Array(e.buffer);let n=i;for(;n<r.length&&r[n]!==0;)n+=1;this.layouts=JSON.parse(H.decode(r.subarray(i,n)))}static async load(t){const e=t??await Ut(),i={current:null},r={env:{log:(l,h)=>{const a=i.current?.exports.memory;if(!(a instanceof WebAssembly.Memory))return;const c=H.decode(new Uint8Array(a.buffer,l,h));console.debug("[libghostty-vt]",c)}}},n=await WebAssembly.instantiate(e,r);i.current=n.instance;const o=new Q(n.instance);return await o.installWritePtyTrampoline(),o}call(t,...e){const i=this.exports[t];if(!(i instanceof Function))throw new Error(`libghostty-vt export is unavailable: ${t}`);return i(...e)}layout(t){const e=this.layouts[t];if(!e)throw new Error(`libghostty-vt type layout is unavailable: ${t}`);return e}alloc(t){const e=this.call("ghostty_wasm_alloc_u8_array",t);if(e===0)throw new Error(`libghostty-vt failed to allocate ${t} bytes`);return new Uint8Array(this.memory.buffer,e,t).fill(0),e}free(t,e){t!==0&&this.call("ghostty_wasm_free_u8_array",t,e)}allocOpaque(){const t=this.call("ghostty_wasm_alloc_opaque");if(t===0)throw new Error("libghostty-vt failed to allocate an opaque pointer");return new DataView(this.memory.buffer).setUint32(t,0,!0),t}freeOpaque(t){t!==0&&this.call("ghostty_wasm_free_opaque",t)}readPointer(t){return this.currentMemoryView().getUint32(t,!0)}attachPtyWriter(t,e){if(this.writePtyFunctionIndex===0)throw new Error("libghostty-vt PTY callback trampoline is unavailable");const i=this.nextPtyWriterId++;return this.ptyWriters.set(i,e),this.call("ghostty_terminal_set",t,0,i),this.call("ghostty_terminal_set",t,1,this.writePtyFunctionIndex),i}detachPtyWriter(t,e){this.call("ghostty_terminal_set",t,1,0),this.call("ghostty_terminal_set",t,0,0),this.ptyWriters.delete(e)}view(t,e){return new DataView(this.memory.buffer,t,e)}bytes(t,e){return new Uint8Array(this.memory.buffer,t,e)}currentMemoryView(){return this.memoryView.buffer!==this.memory.buffer&&(this.memoryView=new DataView(this.memory.buffer)),this.memoryView}setField(t,e,i,r){const n=this.layout(e).fields[i];if(!n)throw new Error(`libghostty-vt field is unavailable: ${e}.${i}`);const o=this.currentMemoryView(),l=t+n.offset;switch(n.type){case"bool":case"u8":o.setUint8(l,r);return;case"u16":o.setUint16(l,r,!0);return;case"i32":o.setInt32(l,r,!0);return;case"u32":case"enum":o.setUint32(l,r,!0);return;case"u64":o.setBigUint64(l,BigInt(r),!0);return;default:throw new Error(`Unsupported libghostty-vt field type: ${n.type}`)}}readField(t,e,i){const r=this.layout(e).fields[i];if(!r)throw new Error(`libghostty-vt field is unavailable: ${e}.${i}`);const n=this.currentMemoryView(),o=t+r.offset;switch(r.type){case"bool":case"u8":return n.getUint8(o);case"u16":return n.getUint16(o,!0);case"i32":return n.getInt32(o,!0);case"u32":case"enum":return n.getUint32(o,!0);case"u64":return Number(n.getBigUint64(o,!0));default:throw new Error(`Unsupported libghostty-vt field type: ${r.type}`)}}async installWritePtyTrampoline(){const e=(await WebAssembly.instantiate(Ot,{env:{openchamber_write_pty:(n,o,l,h)=>{const a=this.ptyWriters.get(o);!a||h===0||a(H.decode(new Uint8Array(this.memory.buffer,l,h)))}}})).instance.exports.ghostty_write_pty,i=this.exports.__indirect_function_table;if(!(e instanceof Function)||!(i instanceof WebAssembly.Table))throw new Error("libghostty-vt did not expose its callback table");const r=i.length;i.grow(1),i.set(r,e),this.writePtyFunctionIndex=r}}async function Ut(){const s=await fetch(Bt);if(!s.ok)throw new Error(`Unable to load libghostty-vt (${s.status})`);return s.arrayBuffer()}let V=null;function Kt(){return V??=Q.load().catch(s=>{throw V=null,s}),V}const S=0,N=-3,Wt=1e4,z=16,E={cols:1,rows:2,dirty:3,rowIterator:4,background:5,foreground:6,cursor:7,cursorHasValue:8,cursorStyle:10,cursorVisible:11,cursorBlinking:12,cursorInViewport:14,cursorX:15,cursorY:16},q={dirty:1,raw:2,cells:3},P={raw:1,style:2,graphemesLength:3,graphemes:4,background:5,foreground:6,selected:7},Gt={wide:3},Yt={spacerTail:2},it=256;function Ht(s){const t=new Uint8Array(it*3),e=(r,n)=>{t[r*3]=n.r,t[r*3+1]=n.g,t[r*3+2]=n.b},i=[0,95,135,175,215,255];for(let r=16;r<232;r+=1){const n=r-16;e(r,{r:i[Math.floor(n/36)%6]??0,g:i[Math.floor(n/6)%6]??0,b:i[n%6]??0})}for(let r=232;r<it;r+=1){const n=8+(r-232)*10;e(r,{r:n,g:n,b:n})}return s.slice(0,16).forEach((r,n)=>e(n,r)),t}const B=new TextDecoder,$=new TextEncoder;function Vt(s,t){const e=(i,r)=>Math.floor((i*155+r*100)/255);return{r:e(s.r,t.r),g:e(s.g,t.g),b:e(s.b,t.b)}}function qt(s,t){return s.r===t.r&&s.g===t.g&&s.b===t.b}function $t(s,t){if(t===1)return String.fromCodePoint(s.getUint32(0,!0));const e=4096;let i="";for(let r=0;r<t;r+=e){const n=Math.min(e,t-r),o=new Array(n);for(let l=0;l<n;l+=1)o[l]=s.getUint32((r+l)*4,!0);i+=String.fromCodePoint(...o)}return i}class tt{runtime;terminalSlot=0;terminal=0;renderStateSlot=0;renderState=0;rowIteratorSlot=0;rowCellsSlot=0;keyEncoderSlot=0;keyEncoder=0;keyEventSlot=0;keyEvent=0;mouseEncoderSlot=0;mouseEncoder=0;mouseEventSlot=0;mouseEvent=0;ptyWriterId=0;ptyWriter=null;scratch=0;graphemes=0;graphemeCapacity=0;style=0;scrollbar=0;rows=[];disposed=!1;keyboardLayoutMap;constructor(t){this.runtime=t,It().then(e=>{this.disposed||(this.keyboardLayoutMap=e)})}static async create(t,e,i,r,n,o){const l=new tt(await Kt());try{return l.initialize(t,e,i,r,n,o),l}catch(h){throw l.dispose(),h}}initialize(t,e,i,r,n,o){const l=this.runtime.layout("GhosttyTerminalOptions").size,h=this.runtime.alloc(l);this.runtime.setField(h,"GhosttyTerminalOptions","cols",t),this.runtime.setField(h,"GhosttyTerminalOptions","rows",e),this.runtime.setField(h,"GhosttyTerminalOptions","max_scrollback",Wt),this.terminalSlot=this.runtime.allocOpaque();const a=this.runtime.call("ghostty_terminal_new",0,this.terminalSlot,h);this.runtime.free(h,l),this.assertSuccess("ghostty_terminal_new",a),this.terminal=this.runtime.readPointer(this.terminalSlot),this.applyDefaultCursorBlink(),this.ptyWriter=o,this.ptyWriterId=this.runtime.attachPtyWriter(this.terminal,o),this.renderStateSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_render_state_new",this.runtime.call("ghostty_render_state_new",0,this.renderStateSlot)),this.renderState=this.runtime.readPointer(this.renderStateSlot),this.rowIteratorSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_render_state_row_iterator_new",this.runtime.call("ghostty_render_state_row_iterator_new",0,this.rowIteratorSlot)),this.rowCellsSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_render_state_row_cells_new",this.runtime.call("ghostty_render_state_row_cells_new",0,this.rowCellsSlot)),this.keyEncoderSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_key_encoder_new",this.runtime.call("ghostty_key_encoder_new",0,this.keyEncoderSlot)),this.keyEncoder=this.runtime.readPointer(this.keyEncoderSlot),this.keyEventSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_key_event_new",this.runtime.call("ghostty_key_event_new",0,this.keyEventSlot)),this.keyEvent=this.runtime.readPointer(this.keyEventSlot),this.mouseEncoderSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_mouse_encoder_new",this.runtime.call("ghostty_mouse_encoder_new",0,this.mouseEncoderSlot)),this.mouseEncoder=this.runtime.readPointer(this.mouseEncoderSlot),this.mouseEventSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_mouse_event_new",this.runtime.call("ghostty_mouse_event_new",0,this.mouseEventSlot)),this.mouseEvent=this.runtime.readPointer(this.mouseEventSlot),this.scratch=this.runtime.alloc(16);const c=this.runtime.layout("GhosttyStyle").size;this.style=this.runtime.alloc(c),this.runtime.setField(this.style,"GhosttyStyle","size",c),this.scrollbar=this.runtime.alloc(this.runtime.layout("GhosttyTerminalScrollbar").size),this.setTheme(n),this.resize(t,e,i,r)}write(t){this.ensureActive();const e=t instanceof Uint8Array?t:$.encode(t);if(e.length===0)return;const i=this.runtime.alloc(e.length);this.runtime.bytes(i,e.length).set(e),this.runtime.call("ghostty_terminal_vt_write",this.terminal,i,e.length),this.runtime.free(i,e.length)}resetAndWrite(t){if(this.ensureActive(),this.runtime.call("ghostty_terminal_reset",this.terminal),this.applyDefaultCursorBlink(),this.rows=[],t.length===0)return;const e=this.ptyWriter;this.ptyWriterId!==0&&(this.runtime.detachPtyWriter(this.terminal,this.ptyWriterId),this.ptyWriterId=0);try{this.write(t)}finally{e!==null&&!this.disposed&&(this.ptyWriterId=this.runtime.attachPtyWriter(this.terminal,e))}}resize(t,e,i,r){this.ensureActive(),this.assertSuccess("ghostty_terminal_resize",this.runtime.call("ghostty_terminal_resize",this.terminal,Math.max(1,Math.min(65535,t)),Math.max(1,Math.min(65535,e)),Math.max(1,Math.round(i)),Math.max(1,Math.round(r))))}applyDefaultCursorBlink(){const t=this.runtime.alloc(1);this.runtime.bytes(t,1)[0]=1,this.runtime.call("ghostty_terminal_set",this.terminal,23,t),this.runtime.free(t,1)}setTheme(t){this.ensureActive();const e=this.runtime.alloc(3);for(const[n,o]of[[11,t.foreground],[12,t.background],[13,t.cursor]])this.runtime.bytes(e,3).set([o.r,o.g,o.b]),this.runtime.call("ghostty_terminal_set",this.terminal,n,e);if(this.runtime.free(e,3),t.palette===void 0){this.runtime.call("ghostty_terminal_set",this.terminal,14,0);return}const i=Ht(t.palette),r=this.runtime.alloc(i.length);this.runtime.bytes(r,i.length).set(i),this.runtime.call("ghostty_terminal_set",this.terminal,14,r),this.runtime.free(r,i.length)}scroll(t){this.ensureActive();const e=this.runtime.layout("GhosttyTerminalScrollViewport"),i=this.runtime.alloc(e.size);this.runtime.setField(i,"GhosttyTerminalScrollViewport","tag",2);const r=e.fields.value;this.runtime.view(i+r.offset,r.size).setInt32(0,t,!0),this.runtime.call("ghostty_terminal_scroll_viewport",this.terminal,i),this.runtime.free(i,e.size)}scrollToBottom(){this.ensureActive();const t=this.runtime.layout("GhosttyTerminalScrollViewport"),e=this.runtime.alloc(t.size);this.runtime.setField(e,"GhosttyTerminalScrollViewport","tag",1),this.runtime.call("ghostty_terminal_scroll_viewport",this.terminal,e),this.runtime.free(e,t.size)}isViewportActive(){return this.ensureActive(),this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_terminal_get",this.terminal,32,this.scratch)===S&&this.runtime.bytes(this.scratch,1)[0]!==0}scrollbarState(){this.ensureActive();const t=this.runtime.layout("GhosttyTerminalScrollbar");return this.runtime.bytes(this.scrollbar,t.size).fill(0),this.runtime.call("ghostty_terminal_get",this.terminal,9,this.scrollbar)!==S?null:{total:this.runtime.readField(this.scrollbar,"GhosttyTerminalScrollbar","total"),offset:this.runtime.readField(this.scrollbar,"GhosttyTerminalScrollbar","offset"),len:this.runtime.readField(this.scrollbar,"GhosttyTerminalScrollbar","len")}}isMouseTracking(){return this.ensureActive(),this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_terminal_get",this.terminal,11,this.scratch)===S&&this.runtime.bytes(this.scratch,1)[0]!==0}isMouseAnyEventTracking(){return this.ensureActive(),this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_terminal_mode_get",this.terminal,1003,this.scratch)===S&&this.runtime.bytes(this.scratch,1)[0]!==0}isAlternateScreen(){return this.ensureActive(),this.runtime.bytes(this.scratch,4).fill(0),this.runtime.call("ghostty_terminal_get",this.terminal,6,this.scratch)===S&&this.runtime.view(this.scratch,4).getUint32(0,!0)===1}isApplicationCursorKeys(){return this.ensureActive(),this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_terminal_mode_get",this.terminal,1,this.scratch)===S&&this.runtime.bytes(this.scratch,1)[0]!==0}encodeMacWordShortcut(t,e){if(this.ensureActive(),!t.altKey||t.ctrlKey||t.metaKey||t.shiftKey||t.isComposing)return null;let i;switch(t.key){case"ArrowLeft":i="\x1Bb";break;case"ArrowRight":i="\x1Bf";break;case"Backspace":i="";break;default:return null}return!/mac/i.test(e)||this.isAlternateScreen()||this.runtime.call("ghostty_terminal_get",this.terminal,8,this.scratch)!==S||this.runtime.bytes(this.scratch,1)[0]!==0?null:i}encodeKey(t,e="press"){this.ensureActive(),this.runtime.call("ghostty_key_encoder_setopt_from_terminal",this.keyEncoder,this.terminal),this.runtime.call("ghostty_key_event_set_action",this.keyEvent,e==="release"?0:t.repeat?2:1),this.runtime.call("ghostty_key_event_set_key",this.keyEvent,Ft(t.code));const i=(t.shiftKey?1:0)|(t.ctrlKey?2:0)|(t.altKey?4:0)|(t.metaKey?8:0)|(t.getModifierState("CapsLock")?16:0)|(t.getModifierState("NumLock")?32:0);this.runtime.call("ghostty_key_event_set_mods",this.keyEvent,i),this.runtime.call("ghostty_key_event_set_consumed_mods",this.keyEvent,Nt(t)),this.runtime.call("ghostty_key_event_set_composing",this.keyEvent,t.isComposing?1:0),this.runtime.call("ghostty_key_event_set_unshifted_codepoint",this.keyEvent,zt(t,this.keyboardLayoutMap));const r=t.key.length===1?t.key:"",n=$.encode(r),o=n.length===0?0:this.runtime.alloc(n.length);o!==0&&this.runtime.bytes(o,n.length).set(n),this.runtime.call("ghostty_key_event_set_utf8",this.keyEvent,o,n.length);const l=this.runtime.call("ghostty_wasm_alloc_usize"),h=this.encodeOutput(l,(a,c)=>this.runtime.call("ghostty_key_encoder_encode",this.keyEncoder,this.keyEvent,a,c,l));return this.runtime.call("ghostty_wasm_free_usize",l),o!==0&&this.runtime.free(o,n.length),h}encodePaste(t){this.ensureActive();const e=$.encode(t);if(e.length===0)return"";const i=this.runtime.alloc(e.length);this.runtime.bytes(i,e.length).set(e),this.runtime.bytes(this.scratch,1)[0]=0;const r=this.runtime.call("ghostty_terminal_mode_get",this.terminal,2004,this.scratch)===S&&this.runtime.bytes(this.scratch,1)[0]!==0,n=this.runtime.call("ghostty_wasm_alloc_usize");let o="";const l=this.runtime.call("ghostty_paste_encode",i,e.length,r?1:0,0,0,n),h=this.runtime.view(n,4).getUint32(0,!0);if(l===N&&h>0){const a=this.runtime.alloc(h),c=this.runtime.call("ghostty_paste_encode",i,e.length,r?1:0,a,h,n),u=this.runtime.view(n,4).getUint32(0,!0);o=c===S?B.decode(this.runtime.bytes(a,u)):"",this.runtime.free(a,h)}return this.runtime.call("ghostty_wasm_free_usize",n),this.runtime.free(i,e.length),o}encodeMouse(t){this.ensureActive(),this.runtime.call("ghostty_mouse_encoder_setopt_from_terminal",this.mouseEncoder,this.terminal);const e=this.runtime.layout("GhosttyMouseEncoderSize"),i=this.runtime.alloc(e.size);for(const[a,c]of[["size",e.size],["screen_width",t.screenWidth],["screen_height",t.screenHeight],["cell_width",t.cellWidth],["cell_height",t.cellHeight],["padding_top",t.paddingTop],["padding_bottom",t.paddingBottom],["padding_right",t.paddingRight],["padding_left",t.paddingLeft]])this.runtime.setField(i,"GhosttyMouseEncoderSize",a,Math.max(0,Math.round(c)));this.runtime.call("ghostty_mouse_encoder_setopt",this.mouseEncoder,2,i),this.runtime.free(i,e.size),this.runtime.bytes(this.scratch,1)[0]=t.anyButtonPressed?1:0,this.runtime.call("ghostty_mouse_encoder_setopt",this.mouseEncoder,3,this.scratch),this.runtime.bytes(this.scratch,1)[0]=1,this.runtime.call("ghostty_mouse_encoder_setopt",this.mouseEncoder,4,this.scratch),this.runtime.call("ghostty_mouse_event_set_action",this.mouseEvent,t.action==="press"?0:t.action==="release"?1:2),t.button===null?this.runtime.call("ghostty_mouse_event_clear_button",this.mouseEvent):this.runtime.call("ghostty_mouse_event_set_button",this.mouseEvent,t.button),this.runtime.call("ghostty_mouse_event_set_mods",this.mouseEvent,t.mods);const r=this.runtime.layout("GhosttyMousePosition"),n=this.runtime.alloc(r.size),o=this.runtime.view(n,r.size);o.setFloat32(r.fields.x.offset,t.x,!0),o.setFloat32(r.fields.y.offset,t.y,!0),this.runtime.call("ghostty_mouse_event_set_position",this.mouseEvent,n),this.runtime.free(n,r.size);const l=this.runtime.call("ghostty_wasm_alloc_usize"),h=this.encodeOutput(l,(a,c)=>this.runtime.call("ghostty_mouse_encoder_encode",this.mouseEncoder,this.mouseEvent,a,c,l));return this.runtime.call("ghostty_wasm_free_usize",l),h}setSelection(t,e){this.ensureActive();const i=this.runtime.layout("GhosttySelection"),r=this.runtime.layout("GhosttyGridRef").size,n=this.runtime.alloc(i.size);let o=0,l=0;try{this.runtime.setField(n,"GhosttySelection","size",i.size),o=this.gridRef(t.x,t.y,t.tag??1),l=this.gridRef(e.x,e.y,e.tag??1);const h=i.fields.start,a=i.fields.end;this.runtime.bytes(n+h.offset,h.size).set(this.runtime.bytes(o,h.size)),this.runtime.bytes(n+a.offset,a.size).set(this.runtime.bytes(l,a.size)),this.runtime.call("ghostty_terminal_set",this.terminal,21,n)}finally{this.runtime.free(o,r),this.runtime.free(l,r),this.runtime.free(n,i.size)}}selectAll(){this.ensureActive();const t=this.runtime.layout("GhosttySelection"),e=this.runtime.alloc(t.size);this.runtime.setField(e,"GhosttySelection","size",t.size),this.runtime.call("ghostty_terminal_select_all",this.terminal,e)===S&&this.runtime.call("ghostty_terminal_set",this.terminal,21,e),this.runtime.free(e,t.size)}selectWord(t,e){return this.selectAt("GhosttyTerminalSelectWordOptions","ghostty_terminal_select_word",t,e)}selectLine(t,e){return this.selectAt("GhosttyTerminalSelectLineOptions","ghostty_terminal_select_line",t,e)}hyperlinkAt(t,e){this.ensureActive();const i=this.gridRef(t,e),r=this.runtime.call("ghostty_wasm_alloc_usize"),n=this.runtime.call("ghostty_grid_ref_hyperlink_uri",i,0,0,r),o=this.runtime.view(r,4).getUint32(0,!0);let l=null;if(n===N&&o>0){const h=this.runtime.alloc(o),a=this.runtime.call("ghostty_grid_ref_hyperlink_uri",i,h,o,r),c=this.runtime.view(r,4).getUint32(0,!0);a===S&&c>0&&(l=B.decode(this.runtime.bytes(h,c))),this.runtime.free(h,o)}return this.runtime.call("ghostty_wasm_free_usize",r),this.runtime.free(i,this.runtime.layout("GhosttyGridRef").size),l}clearSelection(){this.ensureActive(),this.runtime.call("ghostty_terminal_set",this.terminal,21,0)}snapshot(){this.ensureActive(),this.assertSuccess("ghostty_render_state_update",this.runtime.call("ghostty_render_state_update",this.renderState,this.terminal));const t=this.getU16(E.cols),e=this.getU16(E.rows),i=this.getU32(E.dirty),r=this.getColor(E.foreground,{r:229,g:231,b:235}),n=this.getColor(E.background,{r:0,g:0,b:0}),l=this.getBool(E.cursorHasValue)?this.getColor(E.cursor,r):r,h=this.getBool(E.cursorInViewport),a=this.getBool(E.cursorVisible)&&h,c=h?this.getU16(E.cursorX):-1,u=h?this.getU16(E.cursorY):-1;(this.rows.length!==e||this.rows.some(m=>m.cells.length!==t))&&(this.rows=Array.from({length:e},()=>({cells:Array.from({length:t},()=>this.emptyCell(r,n)),text:"",isWrapContinuation:!1,wrapsToNext:!1})));const d=new Set;if(i!==0){this.assertSuccess("ghostty_render_state_get(row iterator)",this.runtime.call("ghostty_render_state_get",this.renderState,E.rowIterator,this.rowIteratorSlot));const m=this.runtime.readPointer(this.rowIteratorSlot);let g=0;for(;g<e&&this.runtime.call("ghostty_render_state_row_iterator_next",m)!==0;)(i===2||this.getRowBool(m,q.dirty))&&(this.rows[g]=this.readRow(m,t,r,n),d.add(g),this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_render_state_row_set",m,0,this.scratch)),g+=1;this.runtime.view(this.scratch,4).setUint32(0,0,!0),this.runtime.call("ghostty_render_state_set",this.renderState,0,this.scratch)}return{cols:t,rows:e,foreground:r,background:n,cursor:l,cursorX:c,cursorY:u,cursorVisible:a,cursorBlinking:this.getBool(E.cursorBlinking),cursorStyle:this.getU32(E.cursorStyle),dirtyRows:d,rowData:this.rows}}selectionText(){this.ensureActive();const t=this.runtime.alloc(z),e=this.runtime.view(t,z);e.setUint32(0,z,!0),e.setUint32(4,0,!0),e.setUint8(8,1),e.setUint8(9,1),e.setUint32(12,0,!0);const i=this.runtime.call("ghostty_wasm_alloc_usize"),r=this.runtime.call("ghostty_terminal_selection_format_buf",this.terminal,t,0,0,i),n=this.runtime.view(i,4).getUint32(0,!0);let o="";if(r===N&&n>0){const l=this.runtime.alloc(n),h=this.runtime.call("ghostty_terminal_selection_format_buf",this.terminal,t,l,n,i),a=this.runtime.view(i,4).getUint32(0,!0);h===S&&(o=B.decode(this.runtime.bytes(l,a))),this.runtime.free(l,n)}return this.runtime.call("ghostty_wasm_free_usize",i),this.runtime.free(t,z),o}viewportPointToScreen(t,e){return this.convertPoint(t,e,1,2)}screenPointToViewport(t,e){return this.convertPoint(t,e,2,1)}convertPoint(t,e,i,r){this.ensureActive();const n=this.gridRef(t,e,i),o=this.pointFromGridRef(n,r);return this.runtime.free(n,this.runtime.layout("GhosttyGridRef").size),o}dispose(){if(!this.disposed){if(this.disposed=!0,this.mouseEvent&&this.runtime.call("ghostty_mouse_event_free",this.mouseEvent),this.mouseEncoder&&this.runtime.call("ghostty_mouse_encoder_free",this.mouseEncoder),this.keyEvent&&this.runtime.call("ghostty_key_event_free",this.keyEvent),this.keyEncoder&&this.runtime.call("ghostty_key_encoder_free",this.keyEncoder),this.rowCellsSlot){const t=this.runtime.readPointer(this.rowCellsSlot);t&&this.runtime.call("ghostty_render_state_row_cells_free",t)}if(this.rowIteratorSlot){const t=this.runtime.readPointer(this.rowIteratorSlot);t&&this.runtime.call("ghostty_render_state_row_iterator_free",t)}this.renderState&&this.runtime.call("ghostty_render_state_free",this.renderState),this.terminal&&(this.ptyWriterId&&this.runtime.detachPtyWriter(this.terminal,this.ptyWriterId),this.runtime.call("ghostty_terminal_free",this.terminal)),this.style&&this.runtime.free(this.style,this.runtime.layout("GhosttyStyle").size),this.scrollbar&&this.runtime.free(this.scrollbar,this.runtime.layout("GhosttyTerminalScrollbar").size),this.scratch&&this.runtime.free(this.scratch,16),this.graphemes&&this.runtime.free(this.graphemes,this.graphemeCapacity);for(const t of[this.mouseEventSlot,this.mouseEncoderSlot,this.keyEventSlot,this.keyEncoderSlot,this.rowCellsSlot,this.rowIteratorSlot,this.renderStateSlot,this.terminalSlot])this.runtime.freeOpaque(t)}}encodeOutput(t,e){const i=e(0,0),r=this.runtime.view(t,4).getUint32(0,!0);if(i===S&&r===0||i!==N||r===0)return"";const n=this.runtime.alloc(r),o=e(n,r),l=this.runtime.view(t,4).getUint32(0,!0),h=o===S?B.decode(this.runtime.bytes(n,l)):"";return this.runtime.free(n,r),h}readRow(t,e,i,r){this.assertSuccess("ghostty_render_state_row_get(raw)",this.runtime.call("ghostty_render_state_row_get",t,q.raw,this.scratch));const n=this.runtime.view(this.scratch,8).getBigUint64(0,!0);this.runtime.bytes(this.scratch+8,1)[0]=0,this.assertSuccess("ghostty_row_get(wrap continuation)",this.runtime.call("ghostty_row_get",n,2,this.scratch+8));const o=this.runtime.bytes(this.scratch+8,1)[0]!==0;this.runtime.bytes(this.scratch+8,1)[0]=0,this.assertSuccess("ghostty_row_get(wrap)",this.runtime.call("ghostty_row_get",n,1,this.scratch+8));const l=this.runtime.bytes(this.scratch+8,1)[0]!==0;this.assertSuccess("ghostty_render_state_row_get(cells)",this.runtime.call("ghostty_render_state_row_get",t,q.cells,this.rowCellsSlot));const h=this.runtime.readPointer(this.rowCellsSlot),{size:a,fields:c}=this.runtime.layout("GhosttyStyle"),u=[];for(;u.length<e&&this.runtime.call("ghostty_render_state_row_cells_next",h)!==0;){let d=this.getCellColor(h,P.foreground,i),m=this.getCellColor(h,P.background,r);this.runtime.bytes(this.style,a).fill(0),this.runtime.setField(this.style,"GhosttyStyle","size",a),this.runtime.call("ghostty_render_state_row_cells_get",h,P.style,this.style);const g=this.getCellU32(h,P.graphemesLength);let y="";if(g>0){const v=g*4;if(v>this.graphemeCapacity){const p=Math.max(v,this.graphemeCapacity*2),w=this.runtime.alloc(p);this.runtime.free(this.graphemes,this.graphemeCapacity),this.graphemes=w,this.graphemeCapacity=p}if(this.runtime.call("ghostty_render_state_row_cells_get",h,P.graphemes,this.graphemes)===S){const p=this.runtime.view(this.graphemes,v);y=$t(p,g)}}let f=0;if(y.length===0&&u.at(-1)?.text.length){this.assertSuccess("ghostty_render_state_row_cells_get(raw)",this.runtime.call("ghostty_render_state_row_cells_get",h,P.raw,this.scratch));const v=this.runtime.view(this.scratch,8).getBigUint64(0,!0);this.runtime.view(this.scratch+8,4).setUint32(0,0,!0),this.assertSuccess("ghostty_cell_get(wide)",this.runtime.call("ghostty_cell_get",v,Gt.wide,this.scratch+8)),f=this.runtime.view(this.scratch+8,4).getUint32(0,!0)}const _=this.getCellBool(h,P.selected),b=this.runtime.view(this.style,a);b.getUint8(c.inverse.offset)!==0&&([d,m]=[m,d]),b.getUint8(c.faint.offset)!==0&&(d=Vt(d,m)),u.push({text:y,wide:f,foreground:d,background:m,bold:b.getUint8(c.bold.offset)!==0,italic:b.getUint8(c.italic.offset)!==0,invisible:b.getUint8(c.invisible.offset)!==0,strikethrough:b.getUint8(c.strikethrough.offset)!==0,overline:b.getUint8(c.overline.offset)!==0,underline:b.getInt32(c.underline.offset,!0)!==0,selected:_})}for(;u.length<e;)u.push(this.emptyCell(i,r));return{cells:u,text:u.map(d=>d.text||" ").join("").trimEnd(),isWrapContinuation:o,wrapsToNext:l}}gridRef(t,e,i=1){const r=this.runtime.layout("GhosttyPoint"),n=this.runtime.alloc(r.size);this.runtime.setField(n,"GhosttyPoint","tag",i);const o=r.fields.value,l=o.offset,h=this.runtime.view(n+l,o.size);h.setUint16(0,Math.max(0,t),!0),h.setUint32(4,Math.max(0,e),!0);const a=this.runtime.layout("GhosttyGridRef").size,c=this.runtime.alloc(a);this.runtime.setField(c,"GhosttyGridRef","size",a);const u=this.runtime.call("ghostty_terminal_grid_ref",this.terminal,n,c);return this.runtime.free(n,r.size),u!==S&&(this.runtime.free(c,a),this.assertSuccess("ghostty_terminal_grid_ref",u)),c}selectAt(t,e,i,r){this.ensureActive();const n=this.runtime.layout(t),o=this.runtime.layout("GhosttySelection"),l=this.runtime.alloc(n.size);let h=0,a=0,c=null;try{this.runtime.setField(l,t,"size",n.size),h=this.gridRef(i,r);const u=n.fields.ref;if(this.runtime.bytes(l+u.offset,u.size).set(this.runtime.bytes(h,u.size)),a=this.runtime.alloc(o.size),this.runtime.setField(a,"GhosttySelection","size",o.size),this.runtime.call(e,this.terminal,l,a)===S){const m=a+o.fields.start.offset,g=a+o.fields.end.offset,y=this.pointFromGridRef(m,1),f=this.pointFromGridRef(g,1),_=this.pointFromGridRef(m,2),b=this.pointFromGridRef(g,2);y&&f&&_&&b&&(c={viewport:{start:y,end:f},screen:{start:_,end:b}}),this.runtime.call("ghostty_terminal_set",this.terminal,21,a)}}finally{this.runtime.free(a,o.size),this.runtime.free(h,this.runtime.layout("GhosttyGridRef").size),this.runtime.free(l,n.size)}return c}pointFromGridRef(t,e){const i=this.runtime.layout("GhosttyPointCoordinate"),r=this.runtime.alloc(i.size),o=this.runtime.call("ghostty_terminal_point_from_grid_ref",this.terminal,t,e,r)===S?{x:this.runtime.readField(r,"GhosttyPointCoordinate","x"),y:this.runtime.readField(r,"GhosttyPointCoordinate","y")}:null;return this.runtime.free(r,i.size),o}getU16(t){return this.runtime.bytes(this.scratch,2).fill(0),this.assertSuccess("ghostty_render_state_get",this.runtime.call("ghostty_render_state_get",this.renderState,t,this.scratch)),this.runtime.view(this.scratch,2).getUint16(0,!0)}getU32(t){return this.runtime.bytes(this.scratch,4).fill(0),this.assertSuccess("ghostty_render_state_get",this.runtime.call("ghostty_render_state_get",this.renderState,t,this.scratch)),this.runtime.view(this.scratch,4).getUint32(0,!0)}getBool(t){return this.runtime.bytes(this.scratch,1)[0]=0,this.assertSuccess("ghostty_render_state_get",this.runtime.call("ghostty_render_state_get",this.renderState,t,this.scratch)),this.runtime.bytes(this.scratch,1)[0]!==0}getColor(t,e){return this.runtime.bytes(this.scratch,3).fill(0),this.runtime.call("ghostty_render_state_get",this.renderState,t,this.scratch)===S?this.readColor(this.scratch):e}getRowBool(t,e){return this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_render_state_row_get",t,e,this.scratch)===S&&this.runtime.bytes(this.scratch,1)[0]!==0}getCellU32(t,e){return this.runtime.bytes(this.scratch,4).fill(0),this.runtime.call("ghostty_render_state_row_cells_get",t,e,this.scratch)===S?this.runtime.view(this.scratch,4).getUint32(0,!0):0}getCellBool(t,e){return this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_render_state_row_cells_get",t,e,this.scratch)===S&&this.runtime.bytes(this.scratch,1)[0]!==0}getCellColor(t,e,i){return this.runtime.bytes(this.scratch,3).fill(0),this.runtime.call("ghostty_render_state_row_cells_get",t,e,this.scratch)===S?this.readColor(this.scratch):i}readColor(t){const e=this.runtime.bytes(t,3);return{r:e[0]??0,g:e[1]??0,b:e[2]??0}}emptyCell(t,e){return{text:"",wide:0,foreground:t,background:e,bold:!1,italic:!1,invisible:!1,strikethrough:!1,overline:!1,underline:!1,selected:!1}}assertSuccess(t,e){if(e!==S)throw new Error(`${t} failed with result ${e}`)}ensureActive(){if(this.disposed)throw new Error("libghostty-vt terminal has been disposed")}}function K(s,t){return qt(s,t)}const ct=9472,Xt=9599,ut=9600,dt=9631,mt=57520,ft=57523,Zt=1,pt=2,A=3,jt="0011 0022 1100 2200 0011 0022 1100 2200 0011 0022 1100 2200 0101 0102 0201 0202 0110 0120 0210 0220 1001 1002 2001 2002 1010 1020 2010 2020 1101 1102 2101 1201 2201 2102 1202 2202 1110 1120 2110 1210 2210 2120 1220 2220 0111 0121 0112 0122 0211 0221 0212 0222 1011 1021 1012 1022 2011 2021 2012 2022 1111 1121 1112 1122 2111 1211 2211 2121 2112 1221 1212 2122 1222 2221 2212 2222 0011 0022 1100 2200 0033 3300 0103 0301 0303 0130 0310 0330 1003 3001 3003 1030 3010 3030 1103 3301 3303 1130 3310 3330 0133 0311 0333 1033 3011 3033 1133 3311 3333 0101 0110 1010 1001 0000 0000 0000 0010 1000 0001 0100 0020 2000 0002 0200 0012 1200 0021 2100",Jt=jt.split(" "),Qt=new Set([9476,9477,9478,9479]),te=new Set([9480,9481,9482,9483]),ee=new Set([9548,9549,9550,9551]),ie=new Map([[9600,[[0,0,1,1/2]]],[9601,[[0,7/8,1,1/8]]],[9602,[[0,6/8,1,2/8]]],[9603,[[0,5/8,1,3/8]]],[9604,[[0,1/2,1,1/2]]],[9605,[[0,3/8,1,5/8]]],[9606,[[0,2/8,1,6/8]]],[9607,[[0,1/8,1,7/8]]],[9608,[[0,0,1,1]]],[9609,[[0,0,7/8,1]]],[9610,[[0,0,6/8,1]]],[9611,[[0,0,5/8,1]]],[9612,[[0,0,1/2,1]]],[9613,[[0,0,3/8,1]]],[9614,[[0,0,2/8,1]]],[9615,[[0,0,1/8,1]]],[9616,[[1/2,0,1/2,1]]],[9620,[[0,0,1,1/8]]],[9621,[[7/8,0,1/8,1]]],[9622,[[0,1/2,1/2,1/2]]],[9623,[[1/2,1/2,1/2,1/2]]],[9624,[[0,0,1/2,1/2]]],[9625,[[0,0,1/2,1],[1/2,1/2,1/2,1/2]]],[9626,[[0,0,1/2,1/2],[1/2,1/2,1/2,1/2]]],[9627,[[0,0,1,1/2],[0,1/2,1/2,1/2]]],[9628,[[0,0,1,1/2],[1/2,1/2,1/2,1/2]]],[9629,[[1/2,0,1/2,1/2]]],[9630,[[1/2,0,1/2,1/2],[0,1/2,1/2,1/2]]],[9631,[[1/2,0,1/2,1/2],[0,1/2,1,1/2]]]]),se=new Map([[9617,.25],[9618,.5],[9619,.75]]);function W(s){if(s.length===0||s.length>2)return!1;const t=s.codePointAt(0);return t===void 0||String.fromCodePoint(t)!==s?!1:t>=ct&&t<=Xt||t>=ut&&t<=dt||t>=mt&&t<=ft}function st(s,t){return`rgba(${s.r}, ${s.g}, ${s.b}, ${t})`}function re(s){const t=Math.round(s.x),e=Math.round(s.x+s.width),i=Math.round(s.y),r=Math.round(s.y+s.height),n=Math.max(1,Math.round(s.width/8));return{left:t,right:e,top:i,bottom:r,centerX:Math.round(s.x+s.width/2),centerY:Math.round(s.y+s.height/2),stroke:n,gap:n+1}}function x(s,t){return s===pt?t*3:t}function R(s,t,e,i,r){e<=t||s.fillRect(t,i-Math.floor(r/2),e-t,r)}function L(s,t,e,i,r){e<=t||s.fillRect(i-Math.floor(r/2),t,r,e-t)}function ne(s,t,e,i,r){const n=x(i,t.stroke),o=e?t.left:t.top,l=e?t.right:t.bottom,h=t.stroke,a=l-o,c=Math.max(1,Math.floor((a-h*(r-1))/r));for(let u=0;u<r;u+=1){const d=o+u*(c+h),m=u===r-1?l:d+c;e?R(s,d,m,t.centerY,n):L(s,d,m,t.centerX,n)}}function oe(s,t,e){const i=Number(e[0]),r=Number(e[1]),n=Number(e[2]),o=Number(e[3]),{centerX:l,centerY:h,stroke:a,gap:c}=t,u=M=>M===Zt||M===pt,d=Math.max(x(i,a),x(r,a),a),m=Math.max(x(n,a),x(o,a),a),g=l-Math.floor(d/2),y=g+d,f=h-Math.floor(m/2),_=f+m,b=i===A||r===A,v=n===A||o===A;u(n)&&R(s,t.left,b?l-c:y,h,x(n,a)),u(o)&&R(s,b?l+c:g,t.right,h,x(o,a)),u(i)&&L(s,t.top,v?h-c:_,l,x(i,a)),u(r)&&L(s,v?h+c:f,t.bottom,l,x(r,a));const p=(M,T)=>M===A?l-T*c:u(M)?l:l+T*c,w=(M,T)=>M===A?h-T*c:u(M)?h:h+T*c;n===A&&(R(s,t.left,p(i,1),h-c,a),R(s,t.left,p(r,1),h+c,a)),o===A&&(R(s,p(i,-1),t.right,h-c,a),R(s,p(r,-1),t.right,h+c,a)),i===A&&(L(s,t.top,w(n,1),l-c,a),L(s,t.top,w(o,1),l+c,a)),r===A&&(L(s,w(n,-1),t.bottom,l-c,a),L(s,w(o,-1),t.bottom,l+c,a))}function le(s,t,e){const{centerX:i,centerY:r,stroke:n}=t,o=e===9581||e===9584,l=e===9581||e===9582,h=o?t.right:t.left,a=l?t.bottom:t.top,c=Math.min(Math.abs(h-i),Math.abs(a-r)),u=o?1:-1,d=l?1:-1,m=n%2/2,g=i+m,y=r+m;s.beginPath(),s.moveTo(h,y),s.lineTo(g+u*c,y),s.quadraticCurveTo(g,y,g,y+d*c),s.lineTo(g,a),s.lineWidth=n,s.lineCap="butt",s.stroke()}function he(s,t,e){s.lineWidth=t.stroke,s.lineCap="butt",s.beginPath(),(e===9585||e===9587)&&(s.moveTo(t.right,t.top),s.lineTo(t.left,t.bottom)),(e===9586||e===9587)&&(s.moveTo(t.left,t.top),s.lineTo(t.right,t.bottom)),s.stroke()}function ae(s,t,e){const{left:i,right:r,top:n,bottom:o,centerY:l}=t,h=e===57520||e===57521,a=h?r:i,c=h?i:r;if(s.beginPath(),s.moveTo(c,n),s.lineTo(a,l),s.lineTo(c,o),e===57520||e===57522){s.closePath(),s.fill();return}s.lineWidth=t.stroke,s.lineCap="butt",s.stroke()}function rt(s,t,e,i){if(!W(t))return!1;const r=t.codePointAt(0)??0,n=re(e),o=st(i,1);if(s.fillStyle=o,s.strokeStyle=o,r>=ut&&r<=dt){const a=se.get(r);if(a!==void 0)return s.fillStyle=st(i,a),s.fillRect(n.left,n.top,n.right-n.left,n.bottom-n.top),!0;const c=n.right-n.left,u=n.bottom-n.top;for(const[d,m,g,y]of ie.get(r)??[]){const f=n.left+Math.round(d*c),_=n.left+Math.round((d+g)*c),b=n.top+Math.round(m*u),v=n.top+Math.round((m+y)*u);s.fillRect(f,b,Math.max(1,_-f),Math.max(1,v-b))}return!0}if(r>=mt&&r<=ft)return ae(s,n,r),!0;if(r>=9581&&r<=9584)return le(s,n,r),!0;if(r>=9585&&r<=9587)return he(s,n,r),!0;const l=Jt[r-ct]??"0000",h=Qt.has(r)?3:te.has(r)?4:ee.has(r)?2:0;if(h>0){const a=l[2]!=="0";return ne(s,n,a,Number(a?l[2]:l[0]),h),!0}return oe(s,n,l),!0}const ce="rgba(72, 122, 191, 0.35)";function C(s){return`rgb(${s.r}, ${s.g}, ${s.b})`}function ue(s,t){return K(s.foreground,t.foreground)&&s.bold===t.bold&&s.italic===t.italic&&s.invisible===t.invisible}function de(s,t,e){let i=t+1;for(;i<s.length;){const r=s[i];if(!r)break;if(r.wide===Yt.spacerTail){i+=1;continue}if(r.text.length===0||!e(r))break;i+=1}return i}function nt(s,t,e){const i=s.italic?"italic":"normal",r=s.bold?"700":"400";return`${i} ${r} ${t}px ${e}`}function X(s,t,e){s.font=`normal 400 ${t}px ${e}`;const i=s.measureText("M"),r=s.measureText("Mg"),n=r.actualBoundingBoxAscent||t,o=r.actualBoundingBoxDescent,l=n+o,h=Math.max(1,Math.round(t*1.35),Math.ceil(l));return{width:Math.max(1,i.width),height:h,baseline:Math.round((h-l)/2+n)}}function ot(s,t,e,i){return{cols:Math.max(1,Math.floor((s-i*2)/e.width)),rows:Math.max(1,Math.floor((t-i*2)/e.height))}}function me(s){const{context:t,snapshot:e,metrics:i,fontSize:r,fontFamily:n,padding:o,forceFull:l,cursorOn:h,previousCursorY:a}=s,c=s.focused??!0,u=s.selectionBackground??ce,d=s.hoveredLinkRange??null,m=s.originY??o,g=l?Array.from({length:e.rows},(y,f)=>f):[...e.dirtyRows];a!=null&&a>=0&&!g.includes(a)&&g.push(a),e.cursorVisible&&e.cursorY>=0&&!g.includes(e.cursorY)&&g.push(e.cursorY),l&&(t.save(),t.resetTransform(),t.fillStyle=C(e.background),t.fillRect(0,0,t.canvas.width,t.canvas.height),t.restore()),t.textBaseline="alphabetic";for(const y of g){const f=e.rowData[y];if(!f)continue;const _=m+y*i.height;t.fillStyle=C(e.background),t.fillRect(o,_,e.cols*i.width,i.height);let b=0;for(;b<f.cells.length;){const p=f.cells[b];if(!p)break;let w=b+1;for(;w<f.cells.length;){const M=f.cells[w];if(!M||M.selected!==p.selected||!K(M.background,p.background))break;w+=1}if(p.selected||!K(p.background,e.background)){const M=o+b*i.width,T=(w-b)*i.width;K(p.background,e.background)||(t.fillStyle=C(p.background),t.fillRect(M,_,T,i.height)),p.selected&&(t.fillStyle=u,t.fillRect(M,_,T,i.height))}b=w}let v=0;for(;v<f.cells.length;){const p=f.cells[v];if(!p)break;if(p.text.length===0){v+=1;continue}if(W(p.text)){p.invisible||rt(t,p.text,{x:o+v*i.width,y:_,width:i.width,height:i.height},p.foreground),v+=1;continue}const w=de(f.cells,v,T=>ue(T,p)&&!W(T.text)),M=f.cells.slice(v,w).map(T=>T.text).join("");!p.invisible&&M.trim().length>0&&(t.save(),t.beginPath(),t.rect(o+v*i.width,_,(w-v)*i.width,i.height),t.clip(),t.font=nt(p,r,n),t.fillStyle=C(p.foreground),t.fillText(M,o+v*i.width,_+i.baseline,(w-v)*i.width),t.restore()),v=w}for(let p=0;p<f.cells.length;p+=1){const w=f.cells[p],M=d!==null&&y>=d.start.y&&y<=d.end.y&&(y>d.start.y||p>=d.start.x)&&(y<d.end.y||p<=d.end.x);if(!w||!w.underline&&!w.strikethrough&&!w.overline&&!M)continue;t.fillStyle=C(w.foreground);const T=o+p*i.width;(w.underline||M)&&t.fillRect(T,_+i.height-2,i.width,1),w.strikethrough&&t.fillRect(T,_+Math.floor(i.height*.55),i.width,1),w.overline&&t.fillRect(T,_+1,i.width,1)}}if(h&&e.cursorVisible&&e.cursorX>=0&&e.cursorY>=0){const y=o+e.cursorX*i.width,f=m+e.cursorY*i.height;if(t.fillStyle=C(e.cursor),!c)t.strokeStyle=C(e.cursor),t.strokeRect(y+.5,f+.5,i.width-1,i.height-1);else if(e.cursorStyle===0)t.fillRect(y,f,2,i.height);else if(e.cursorStyle===2)t.fillRect(y,f+i.height-2,i.width,2);else if(e.cursorStyle===3)t.strokeStyle=C(e.cursor),t.strokeRect(y+.5,f+.5,i.width-1,i.height-1);else{t.fillRect(y,f,i.width,i.height);const _=e.rowData[e.cursorY]?.cells[e.cursorX];_?.text&&W(_.text)?rt(t,_.text,{x:y,y:f,width:i.width,height:i.height},e.background):_?.text&&(t.font=nt(_,r,n),t.fillStyle=C(e.background),t.fillText(_.text,y,f+i.baseline,i.width))}}}const fe=new URL("/assets/SymbolsNerdFontMono-Regular-aK5vsLov.woff2",import.meta.url).href,pe=13,ye=6,ge=32,we=500,_e=1e3,D=s=>/mac|iphone|ipad|ipod/i.test(s),be='"Symbols Nerd Font Mono", "Symbols Nerd Font", "JetBrainsMono Nerd Font", "JetBrainsMono NF", "FiraCode Nerd Font", "Hack Nerd Font", "MesloLGS NF", "CaskaydiaCove Nerd Font", "PowerlineSymbols", monospace',G='"SF Mono", "SFMono-Regular", Menlo, Consolas, "Liberation Mono", '+be,k=4,Se=18,ve=500,Me="iMW0@# .",Te=["normal 400","normal 700","italic 400","italic 700"];let O=null;function Ee(){return O!==null||(O=(async()=>{try{const s=new FontFace("Symbols Nerd Font Mono",`url(${fe})`);document.fonts.add(await s.load())}catch{}})()),O}function yt(s){const t=s===void 0?null:J(s);return t===null?G:`${t}, ${G}`}function gt(s){const t=s===void 0?null:J(s);return t===null||!Pt(t)?G:yt(t)}async function lt(s,t,e){const i=yt(s),r=((n,o)=>document.fonts.load(n,o).then(()=>{}));try{await Promise.all(Te.map(n=>r(`${n} ${t}px ${i}`,Me)))}catch{}return(e?.resolve??gt)(s)}function Z(s){return s===void 0||!Number.isFinite(s)?pe:Math.max(ye,Math.min(ge,Math.round(s)))}function ke(s){return s.focused&&s.cursorBlinking&&s.cursorVisible&&!s.reducedMotion}function Ae(s,t,e,i,r){if(!r)return t;const n=s-t*2-e*i;return t+Math.max(0,n)}function j(s,t){const e=Math.max(0,s.total),i=Math.max(0,Math.min(s.len,e)),r=Math.max(0,e-i);if(t<=0||i<=0||r===0)return null;const n=Math.min(t,Math.max(Se,t*i/e)),o=Math.max(0,t-n),l=Math.max(0,Math.min(s.offset,r));return{thumbHeight:n,thumbTop:o*(l/r),maxOffset:r}}function Ce(s,t,e,i){const r=j(s,t);if(r===null)return 0;const n=Math.max(0,t-r.thumbHeight);if(n===0)return 0;const o=Math.max(0,Math.min(e-i,n));return Math.round(o/n*r.maxOffset)}function xe(s){const{bounds:t,clientX:e,clientY:i,cols:r,rows:n,metrics:o,padding:l,originY:h}=s,a=e-t.left-l,c=i-t.top-h;return a<0||c<0||a>=r*o.width||c>=n*o.height?null:{x:Math.floor(a/o.width),y:Math.floor(c/o.height)}}function Pe(s,t){const e=s.cells.map(i=>i.text||" ").join("");return t?e.trimEnd():e}function wt(s,t){let e=0;for(let i=0;i<t;i+=1)e+=s.cells[i]?.text.length||1;return e}function ht(s,t){for(let e=0;e<s.cells.length;e+=1){const i=wt(s,e+1);if(t<i)return e}return Math.max(0,s.cells.length-1)}function Re(s,t,e){const i=Mt(t+1,u=>{const d=s[u];return d?{isWrapped:d.isWrapContinuation,translateToString:(m=!1)=>Pe(d,m)}:null});if(!i)return null;const r=i.segments[0];if(r&&s[r.bufferLineNumber-1]?.isWrapContinuation)return null;const n=i.segments.find(u=>u.bufferLineNumber===t+1),o=s[t];if(!n||!o)return null;const l=i.segments.at(-1),h=l?s[l.bufferLineNumber-1]:void 0,a=h!==void 0&&h.wrapsToNext,c=n.startIndex+wt(o,e);for(const u of vt(i.text))if(c>=u.start&&c<u.end){if(u.end===i.text.length&&a)return null;const d=i.segments.find(f=>u.start>=f.startIndex&&u.start<f.endIndex),m=i.segments.find(f=>u.end-1>=f.startIndex&&u.end-1<f.endIndex),g=d?s[d.bufferLineNumber-1]:void 0,y=m?s[m.bufferLineNumber-1]:void 0;return!d||!m||!g||!y?null:{text:u.text,range:{start:{x:ht(g,u.start-d.startIndex),y:d.bufferLineNumber-1},end:{x:ht(y,u.end-1-m.startIndex),y:m.bufferLineNumber-1}}}}return null}function Le(s,t=navigator.platform){return s.key.toLowerCase()!=="c"?!1:D(t)?s.metaKey:s.ctrlKey}function Fe(s,t){s.value=t,t.length!==0&&s.select()}function De(s,t){t.length===0||s.value!==t||(s.value="")}function Ie(s,t){return s.length===0||!t?{preventDefault:!1,claimWriteFallback:!1}:(t.setData("text/plain",s),{preventDefault:!0,claimWriteFallback:!0})}function Ne(s,t=navigator.platform){const e=s.key.toLowerCase();return e==="insert"&&!D(t)?s.shiftKey&&!s.ctrlKey&&!s.metaKey:e!=="v"?!1:D(t)?s.metaKey:s.ctrlKey&&s.shiftKey}const ze=1e3;class Be{token=0;owedNativePastes=0;lastShortcutReadAt=0;beginRead(){return++this.token}settleRead(t,e,i){return this.token!==t?!1:(this.token+=1,e&&(this.expireOwedPastes(i),this.owedNativePastes+=1,this.lastShortcutReadAt=i),!0)}settleNativePaste(t){return this.token+=1,this.expireOwedPastes(t),this.owedNativePastes===0?!0:(this.owedNativePastes-=1,!1)}expireOwedPastes(t){t-this.lastShortcutReadAt>ze&&(this.owedNativePastes=0)}}function Oe(s){return s.inputType===""||s.inputType==="insertCompositionText"||s.inputType==="insertFromComposition"}function at(s,t){return s.isComposing||t||s.key==="Process"||s.keyCode===229}function Ue(s){return s.getModifierState("AltGraph")&&[...s.key].length===1}function U(s,t){return s&&!t.shiftKey&&!t.ctrlKey&&!t.metaKey}function Ke(s,t,e){const i=s==="motion"?t:"";return{send:t.length>0&&(s!=="motion"||t!==e),nextMotionData:i}}function We(s,t,e){return{tracking:t,motionData:s===t?e:""}}function Ge(s,t,e,i){const r=s.deltaMode===1?s.deltaY*t:s.deltaMode===2?s.deltaY*e*t:s.deltaY,n=i+r/t,o=Math.trunc(n);return{rows:o,remainder:n-o}}function Ye(s,t){return s===0?"":(s<0?t?"\x1BOA":"\x1B[A":t?"\x1BOB":"\x1B[B").repeat(Math.abs(s))}function F(s,t=navigator.platform){return D(t)?s.metaKey&&!s.ctrlKey:s.ctrlKey&&!s.metaKey}function He(s){switch(s){case 0:return 1;case 1:return 3;case 2:return 2;case 3:return 4;case 4:return 5;default:return null}}function Ve(s,t){return{count:s!==null&&t.timeStamp-s.time<=we&&Math.hypot(t.clientX-s.x,t.clientY-s.y)<=4?s.count>=3?1:s.count+1:1,time:t.timeStamp,x:t.clientX,y:t.clientY}}class _t{canvas;input;scrollbar;cols=1;rows=1;mount;context;core;options;visible;hasSize=!1;metrics;fontFamily;requestedFontFamily;fontSize;fontEpoch=0;pendingFontEpoch=null;resizeObserver;scrollbarThumb;snapshot=null;frame=0;cursorTimer=null;compositionInputToSuppress=null;compositionSuppressionTimer=null;cursorOn=!0;renderedCursorY=null;forceFullRender=!0;scrollbarDirty=!0;scrollbarState=null;scrollbarPointerId=null;scrollbarPointerOffset=0;disposed=!1;resizeNotifyTimer=null;originY=k;mountHeight=0;selectionEnd=null;selectionAnchorScreen=null;selectionEndScreen=null;selectionMode="cell";selectionBase=null;selectionScrollTimer=null;selectionScrollDelta=0;selectionPointer=null;mouseReportingPointerId=null;mouseReportingButton=null;linkActivationPointerId=null;hoveredLink=null;hoverPointer=null;linkModifierActive=!1;selectionClickSequence=null;selectionMoved=!1;composing=!1;focused=!1;resizeNotified=!1;canvasConfigured=!1;theme;suppressedKeyCodes=new Set;pasteArbiter=new Be;copyShortcutToken=0;clearSelectionAfterCopy=!1;primedCopySelection="";wheelRemainder=0;lastMouseMotionData="";mouseAnyEventTracking=!1;dprMedia=null;reducedMotionMedia=window.matchMedia?.("(prefers-reduced-motion: reduce)");inputLeft=-1;inputTop=-1;lastTouchPointerAt=Number.NEGATIVE_INFINITY;constructor(t,e,i,r,n,o,l,h,a,c){this.mount=t,this.canvas=e,this.input=i,this.scrollbar=r,this.scrollbarThumb=n,this.context=o,this.core=l,this.mouseAnyEventTracking=l.isMouseAnyEventTracking(),this.metrics=h,this.options=c,this.visible=c.visible??!0,this.theme=c.theme,this.fontFamily=a,this.requestedFontFamily=c.font?.family,this.fontSize=Z(c.font?.size),this.resizeObserver=new ResizeObserver(()=>this.fit()),this.installEvents(),this.watchDevicePixelRatio(),this.reducedMotionMedia?.addEventListener("change",this.onReducedMotionChange),document.fonts.addEventListener("loadingdone",this.onFontsLoaded),this.resizeObserver.observe(t)}static async create(t,e){const i=document.createElement("canvas");i.className="oc-terminal-canvas",i.setAttribute("aria-hidden","true");const r=document.createElement("textarea");r.className="oc-terminal-input",r.setAttribute("aria-label",e.labels.input),r.setAttribute("autocorrect","off"),r.autocapitalize="off",r.autocomplete="off",r.spellcheck=!1;const n=document.createElement("div");n.className="oc-terminal-scrollbar",n.setAttribute("role","scrollbar"),n.setAttribute("aria-label",e.labels.scrollbar),n.setAttribute("aria-orientation","vertical"),n.tabIndex=-1,n.hidden=!0;const o=document.createElement("div");o.className="oc-terminal-scrollbar-thumb",n.append(o),t.replaceChildren(i,r,n);const l=window.devicePixelRatio||1;t.clientWidth>0&&t.clientHeight>0&&(i.width=Math.max(1,Math.round(t.clientWidth*l)),i.height=Math.max(1,Math.round(t.clientHeight*l)));const h=i.getContext("2d",{alpha:!1,willReadFrequently:!0});if(!h)throw new Error("Canvas 2D is unavailable");h.fillStyle=`rgb(${e.theme.background.r}, ${e.theme.background.g}, ${e.theme.background.b})`,h.fillRect(0,0,i.width,i.height);const a=Z(e.font?.size);try{await Ee()}catch{}const c=await lt(e.font?.family,a),u=X(h,a,c),d=ot(t.clientWidth,t.clientHeight,u,k),m=await tt.create(d.cols,d.rows,u.width,u.height,e.theme,e.onData),g=new _t(t,i,r,n,o,h,m,u,c,e);return g.fit(),g}setVisible(t){if(!(this.disposed||this.visible===t)){if(this.visible=t,this.cursorOn=!0,this.forceFullRender=!0,this.scrollbarDirty=!0,!t){this.cancelRender(),this.setSelectionAutoscroll(0);return}this.fit()}}write(t){this.disposed||(this.core.write(t),this.synchronizeMouseTrackingState(),this.cursorOn=!0,this.scrollbarDirty=!0,this.requestRender())}resetAndWrite(t,e){if(this.disposed)return;this.lastMouseMotionData="";const i=e!==void 0&&(e.cols!==this.cols||e.rows!==this.rows);i&&this.core.resize(e.cols,e.rows,this.metrics.width,this.metrics.height);try{this.core.resetAndWrite(t)}finally{i&&this.core.resize(this.cols,this.rows,this.metrics.width,this.metrics.height)}this.synchronizeMouseTrackingState(),this.cursorOn=!0,this.forceFullRender=!0,this.scrollbarDirty=!0,this.requestRender()}setTheme(t){this.disposed||(this.theme=t,this.core.setTheme(t),this.forceFullRender=!0,this.requestRender())}async setFont(t){if(this.disposed)return;const e=Z(t.size),i=++this.fontEpoch;this.pendingFontEpoch=i;const r=await lt(t.family,e);this.disposed||i!==this.fontEpoch||(this.pendingFontEpoch=null,this.fontFamily=r,this.requestedFontFamily=t.family,this.fontSize=e,this.applyFontMetrics())}applyFontMetrics(){this.metrics=X(this.context,this.fontSize,this.fontFamily),this.core.resize(this.cols,this.rows,this.metrics.width,this.metrics.height),this.inputLeft=-1,this.inputTop=-1,this.forceFullRender=!0,this.scrollbarDirty=!0,this.fit(),this.requestRender()}onReducedMotionChange=()=>{this.disposed||(this.cursorOn=!0,this.requestRender())};onFontsLoaded=()=>{if(this.disposed||this.pendingFontEpoch!==null)return;const t=gt(this.requestedFontFamily);if(t!==this.fontFamily){this.fontFamily=t,this.applyFontMetrics();return}const e=X(this.context,this.fontSize,this.fontFamily);e.width===this.metrics.width&&e.height===this.metrics.height&&e.baseline===this.metrics.baseline||this.applyFontMetrics()};fit(){if(this.disposed||!this.visible)return!1;const t=this.mount.clientWidth,e=this.mount.clientHeight;if(t<=0||e<=0)return this.hasSize=!1,this.forceFullRender=!0,this.cancelRender(),!1;this.hasSize=!0;const i=window.devicePixelRatio||1,r=Math.max(1,Math.round(t*i)),n=Math.max(1,Math.round(e*i));let o=!1;(this.canvas.width!==r||this.canvas.height!==n||!this.canvasConfigured)&&(this.canvas.width=r,this.canvas.height=n,this.context.setTransform(i,0,0,i,0,0),this.canvasConfigured=!0,this.forceFullRender=!0,this.scrollbarDirty=!0,o=!0);const l=ot(t,e,this.metrics,k);return this.mountHeight=e,(l.cols!==this.cols||l.rows!==this.rows||!this.resizeNotified)&&(this.cols=l.cols,this.rows=l.rows,this.core.resize(l.cols,l.rows,this.metrics.width,this.metrics.height),this.notifyResize(),this.forceFullRender=!0,this.scrollbarDirty=!0,o=!0),(o||this.forceFullRender)&&this.renderFrame(),!0}notifyResize(){this.resizeNotified=!0,this.resizeNotifyTimer!==null&&window.clearTimeout(this.resizeNotifyTimer),this.resizeNotifyTimer=window.setTimeout(()=>{this.resizeNotifyTimer=null,this.disposed||this.options.onResize(this.cols,this.rows)},150)}focus(){this.disposed||!this.visible||this.input.focus({preventScroll:!0})}async pasteFromClipboard(t,e=()=>!0){const i=this.pasteArbiter.beginRead(),r=await t();if(this.disposed||!e()||!this.pasteArbiter.settleRead(i,!1,performance.now())||r.length===0)return;const n=this.core.encodePaste(r);n.length>0&&this.options.onData(n)}hasSelection(){return this.core.selectionText().length>0}getSelection(){return this.core.selectionText()}getSelectionPosition(){return!this.selectionAnchorScreen||!this.selectionEndScreen||!this.hasSelection()?null:this.selectionAnchorScreen.y<this.selectionEndScreen.y||this.selectionAnchorScreen.y===this.selectionEndScreen.y&&this.selectionAnchorScreen.x<=this.selectionEndScreen.x?{start:this.selectionAnchorScreen,end:this.selectionEndScreen}:{start:this.selectionEndScreen,end:this.selectionAnchorScreen}}getSelectionEndClientRect(){const t=this.getSelectionPosition();if(!t)return null;const e=this.core.screenPointToViewport(t.end.x,t.end.y);if(!e)return null;const i=this.canvas.getBoundingClientRect();return{right:i.left+k+(e.x+1)*this.metrics.width,bottom:i.top+this.originY+(e.y+1)*this.metrics.height}}clearSelection(){this.clearPrimedCopy(),this.core.clearSelection(),this.selectionEnd=null,this.selectionAnchorScreen=null,this.selectionEndScreen=null,this.selectionMode="cell",this.selectionBase=null,this.setSelectionAutoscroll(0),this.options.onSelectionChange?.(),this.forceFullRender=!0,this.requestRender()}scrollToBottom(){this.core.scrollToBottom(),this.forceFullRender=!0,this.scrollbarDirty=!0,this.requestRender()}isAtBottom(){return this.core.isViewportActive()}refresh(){this.disposed||(this.forceFullRender=!0,this.scrollbarDirty=!0,this.requestRender())}scrollLines(t){this.disposed||this.scrollViewport(t)}selectWordAt(t,e){if(this.disposed)return!1;const i=this.cellAt(t,e),r=this.core.selectWord(i.x,i.y);return r?(this.selectionMode="word",this.selectionMoved=!1,this.selectionBase=r.screen,this.selectionEnd=r.viewport.end,this.selectionAnchorScreen=r.screen.start,this.selectionEndScreen=r.screen.end,this.options.onSelectionChange?.(),this.forceFullRender=!0,this.requestRender(),!0):!1}extendSelectionTo(t,e){if(this.disposed||this.selectionAnchorScreen===null)return;const i=this.cellAt(t,e);i.x===this.selectionEnd?.x&&i.y===this.selectionEnd.y||this.extendSelectionToPoint(t,e)}dispose(){this.disposed||(this.disposed=!0,this.resizeObserver.disconnect(),document.fonts.removeEventListener("loadingdone",this.onFontsLoaded),this.dprMedia?.removeEventListener("change",this.onDevicePixelRatioChange),this.dprMedia=null,this.reducedMotionMedia?.removeEventListener("change",this.onReducedMotionChange),this.selectionScrollTimer!==null&&window.clearInterval(this.selectionScrollTimer),this.resizeNotifyTimer!==null&&(window.clearTimeout(this.resizeNotifyTimer),this.resizeNotifyTimer=null,this.options.onResize(this.cols,this.rows)),this.cancelRender(),this.compositionSuppressionTimer!==null&&window.clearTimeout(this.compositionSuppressionTimer),this.removeEvents(),this.core.dispose(),(this.canvas.parentElement===this.mount||this.input.parentElement===this.mount||this.scrollbar.parentElement===this.mount)&&(this.canvas.remove(),this.input.remove(),this.scrollbar.remove()))}onKeyDown=t=>{if(this.updateLinkModifier(t),Ue(t)||this.options.beforeKey?.(t)===!1){this.suppressedKeyCodes.add(t.code);return}if(Le(t)&&this.hasSelection()){const r=this.getSelection();if(this.primeCopy(r),t.shiftKey)t.preventDefault(),document.execCommand("copy");else{this.clearSelectionAfterCopy=!t.shiftKey&&!D(navigator.platform);const n=navigator.clipboard;if(n){const o=++this.copyShortcutToken;Promise.resolve().then(()=>{this.disposed||this.copyShortcutToken!==o||n.writeText(r).then(()=>{this.disposed||this.copyShortcutToken!==o||this.clearSelectionAfterCopy&&(this.clearSelectionAfterCopy=!1,this.clearSelection())},()=>{this.copyShortcutToken===o&&(this.clearSelectionAfterCopy=!1)})})}}this.suppressedKeyCodes.add(t.code);return}if(Ne(t)){this.suppressedKeyCodes.add(t.code);const r=navigator.clipboard;if(r){const n=this.pasteArbiter.beginRead();r.readText().then(o=>{this.disposed||this.pasteArbiter.settleRead(n,o.length>0,performance.now())&&o.length>0&&this.options.onData(this.core.encodePaste(o))},()=>{})}return}if(at(t,this.composing))return;this.clearPrimedCopy();const e=this.core.encodeMacWordShortcut(t,navigator.platform),i=e??this.core.encodeKey(t);i.length!==0&&(e!==null?this.suppressedKeyCodes.add(t.code):this.suppressedKeyCodes.delete(t.code),t.preventDefault(),t.stopPropagation(),this.options.onData(i))};onKeyUp=t=>{if(this.updateLinkModifier(t),this.suppressedKeyCodes.delete(t.code)||at(t,this.composing))return;const e=this.core.encodeKey(t,"release");e.length!==0&&(t.preventDefault(),t.stopPropagation(),this.options.onData(e))};onFocus=()=>{this.focused=!0,this.cursorOn=!0,this.requestRender()};onBlur=()=>{this.focused=!1,this.linkModifierActive=!1,this.refreshHoveredLink(),this.cursorOn=!0,this.requestRender()};onDevicePixelRatioChange=()=>{this.watchDevicePixelRatio(),this.fit()};watchDevicePixelRatio(){this.dprMedia?.removeEventListener("change",this.onDevicePixelRatioChange),this.dprMedia=window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`),this.dprMedia.addEventListener("change",this.onDevicePixelRatioChange)}primeCopy(t){this.primedCopySelection=t,Fe(this.input,t)}clearPrimedCopy(){De(this.input,this.primedCopySelection),this.primedCopySelection=""}onCopyEvent=t=>{const e=this.hasSelection()?this.getSelection():this.input.value;this.primeCopy(e);const i=Ie(e,t.clipboardData);i.preventDefault&&t.preventDefault(),i.claimWriteFallback&&(this.copyShortcutToken+=1,this.clearSelectionAfterCopy&&(this.clearSelectionAfterCopy=!1,this.clearSelection()))};onPaste=t=>{t.preventDefault();const e=t.clipboardData?.getData("text/plain")??"";e.length!==0&&this.pasteArbiter.settleNativePaste(performance.now())&&this.options.onData(this.core.encodePaste(e))};onCompositionStart=()=>{this.clearPrimedCopy(),this.clearCompositionInputSuppression(),this.composing=!0};onCompositionEnd=t=>{this.composing=!1;const e=this.input.value||t.data;e.length>0&&this.options.onData(e),this.input.value="",this.compositionInputToSuppress=e,this.compositionSuppressionTimer=window.setTimeout(()=>{this.compositionInputToSuppress=null,this.compositionSuppressionTimer=null},100)};onInput=t=>{const e=t;if(this.composing||e.isComposing)return;const i=this.input.value||e.data||"";if(i===this.compositionInputToSuppress&&Oe(e)){this.clearCompositionInputSuppression(),this.input.value="";return}this.clearCompositionInputSuppression(),i.length>0&&this.options.onData(i),this.input.value=""};clearCompositionInputSuppression(){this.compositionSuppressionTimer!==null&&(window.clearTimeout(this.compositionSuppressionTimer),this.compositionSuppressionTimer=null),this.compositionInputToSuppress=null}ignoresTouchPointer(t){return t.pointerType!=="touch"||this.options.handleTouchPointer!==!1?!1:(this.lastTouchPointerAt=t.timeStamp,!0)}onPointerDown=t=>{if(this.ignoresTouchPointer(t))return;if(this.focus(),U(this.core.isMouseTracking(),t)){const n=He(t.button);if(n===null)return;t.preventDefault(),t.stopPropagation(),this.clearHoveredLink("default"),this.mouseReportingPointerId=t.pointerId,this.mouseReportingButton=n,this.sendMouse("press",n,t),this.canvas.setPointerCapture(t.pointerId);return}if(t.button!==0)return;if(F(t)){t.preventDefault(),t.stopPropagation(),this.linkActivationPointerId=t.pointerId,this.canvas.setPointerCapture(t.pointerId);return}this.clearHoveredLink();const e=this.cellAt(t.clientX,t.clientY);this.selectionMoved=!1,this.selectionClickSequence=Ve(this.selectionClickSequence,t);const i=this.selectionClickSequence.count;this.selectionMode=i>=3?"line":i===2?"word":"cell";const r=this.selectionMode==="line"?this.core.selectLine(e.x,e.y):this.selectionMode==="word"?this.core.selectWord(e.x,e.y):null;if(r)this.selectionBase=r.screen,this.selectionEnd=r.viewport.end,this.selectionAnchorScreen=r.screen.start,this.selectionEndScreen=r.screen.end,this.options.onSelectionChange?.();else{this.selectionMode="cell",this.selectionBase=null,this.selectionEnd=e;const n=this.core.viewportPointToScreen(e.x,e.y);this.selectionAnchorScreen=n,this.selectionEndScreen=n,n?this.core.setSelection({...n,tag:2},{...n,tag:2}):this.core.setSelection(e,e)}this.forceFullRender=!0,this.canvas.setPointerCapture(t.pointerId),this.requestRender()};onPointerMove=t=>{if(this.ignoresTouchPointer(t)||this.linkActivationPointerId===t.pointerId)return;const e=this.synchronizeMouseTrackingState();if(this.mouseReportingPointerId===t.pointerId||U(e,t)){t.preventDefault(),this.hoverPointer={x:t.clientX,y:t.clientY},this.linkModifierActive=F(t),this.setHoveredLink(null),this.canvas.style.cursor="default",this.sendMouse("motion",this.buttonFromButtons(t.buttons),t);return}if(this.lastMouseMotionData="",!this.selectionAnchorScreen||!this.canvas.hasPointerCapture(t.pointerId)){this.updateHoverCursor(t);return}this.clearHoveredLink(),this.selectionPointer={x:t.clientX,y:t.clientY};const i=this.canvas.getBoundingClientRect();this.setSelectionAutoscroll(t.clientY<i.top?-1:t.clientY>i.bottom?1:0);const r=this.cellAt(t.clientX,t.clientY);r.x===this.selectionEnd?.x&&r.y===this.selectionEnd.y||this.extendSelectionToPoint(t.clientX,t.clientY)};extendSelectionToPoint(t,e){const i=this.selectionAnchorScreen;if(i===null)return;const r=this.cellAt(t,e);this.selectionMoved=!0,this.selectionEnd=r;const n=this.selectionMode==="line"?this.core.selectLine(r.x,r.y):this.selectionMode==="word"?this.core.selectWord(r.x,r.y):null,o=this.core.viewportPointToScreen(r.x,r.y);if(o===null)return;const l=this.selectionBase,h=l!==null&&(o.y<l.start.y||o.y===l.start.y&&o.x<l.start.x),a=l===null?i:h?l.end:l.start,c=n===null?o:h?n.screen.start:n.screen.end;this.selectionAnchorScreen=a,this.selectionEndScreen=c,this.core.setSelection({...a,tag:2},{...c,tag:2}),this.options.onSelectionChange?.(),this.forceFullRender=!0,this.requestRender()}setSelectionAutoscroll(t){if(this.selectionScrollDelta=t,t===0){this.selectionScrollTimer!==null&&(window.clearInterval(this.selectionScrollTimer),this.selectionScrollTimer=null);return}this.selectionScrollTimer===null&&(this.selectionScrollTimer=window.setInterval(()=>{if(this.disposed||this.selectionScrollDelta===0)return;this.scrollViewport(this.selectionScrollDelta);const e=this.selectionPointer;e&&this.extendSelectionToPoint(e.x,e.y)},80))}updateHoverCursor(t){this.hoverPointer={x:t.clientX,y:t.clientY},this.linkModifierActive=F(t),this.refreshHoveredLink()}updateLinkModifier(t){const e=F(t);e!==this.linkModifierActive&&(this.linkModifierActive=e,this.refreshHoveredLink())}onPointerLeave=()=>{this.lastMouseMotionData="",this.clearHoveredLink()};clearHoveredLink(t=""){this.hoverPointer=null,this.setHoveredLink(null),this.canvas.style.cursor=t}refreshHoveredLink(){const t=this.hoverPointer,e=t&&this.linkModifierActive?this.linkAt(t.x,t.y):null;this.setHoveredLink(e)}setHoveredLink(t){const e=this.hoveredLink,i=e?.text===t?.text&&e?.range.start.x===t?.range.start.x&&e?.range.start.y===t?.range.start.y&&e?.range.end.x===t?.range.end.x&&e?.range.end.y===t?.range.end.y;this.canvas.style.cursor=t?"pointer":"",!i&&(this.hoveredLink=t,this.forceFullRender=!0,this.requestRender())}onPointerUp=t=>{if(!this.ignoresTouchPointer(t)){if(this.setSelectionAutoscroll(0),this.linkActivationPointerId===t.pointerId){if(t.preventDefault(),t.stopPropagation(),this.linkActivationPointerId=null,this.canvas.hasPointerCapture(t.pointerId)&&this.canvas.releasePointerCapture(t.pointerId),t.type!=="pointercancel"){const e=this.linkAt(t.clientX,t.clientY);e&&this.options.onLinkActivate?.(e.text,t)}return}if(this.mouseReportingPointerId===t.pointerId){t.preventDefault(),t.stopPropagation(),this.sendMouse("release",this.mouseReportingButton,t),this.mouseReportingPointerId=null,this.mouseReportingButton=null,this.canvas.hasPointerCapture(t.pointerId)&&this.canvas.releasePointerCapture(t.pointerId),t.type==="pointercancel"?this.clearHoveredLink():(this.hoverPointer={x:t.clientX,y:t.clientY},this.linkModifierActive=F(t),this.refreshHoveredLink());return}this.canvas.hasPointerCapture(t.pointerId)&&this.canvas.releasePointerCapture(t.pointerId),t.button===0&&(!this.selectionMoved&&this.selectionMode==="cell"&&this.clearSelection(),this.options.onSelectionChange?.())}};onWheel=t=>{if(t.deltaY===0)return;t.preventDefault();const e=Ge(t,this.metrics.height,this.rows,this.wheelRemainder);if(this.wheelRemainder=e.remainder,e.rows===0)return;const i=Math.abs(e.rows);if(U(this.core.isMouseTracking(),t)){const r=e.rows<0?4:5;for(let n=0;n<i;n+=1)this.sendMouse("press",r,t);return}if(this.core.isAlternateScreen()){this.options.onData(Ye(e.rows,this.core.isApplicationCursorKeys()));return}this.scrollViewport(e.rows)};onMouseDown=t=>{t.button===0&&t.preventDefault(),!(t.timeStamp-this.lastTouchPointerAt<_e)&&this.focus()};onContextMenu=t=>{if(U(this.core.isMouseTracking(),t)){t.preventDefault();return}this.options.onContextMenu?.(t)};onScrollbarPointerDown=t=>{if(t.button!==0)return;const e=this.readScrollbarState();if(e===null)return;const i=this.scrollbar.getBoundingClientRect(),r=j(e,i.height);r!==null&&(t.preventDefault(),t.stopPropagation(),this.scrollbarPointerId=t.pointerId,this.scrollbarPointerOffset=t.target===this.scrollbarThumb?t.clientY-i.top-r.thumbTop:r.thumbHeight/2,this.scrollbar.setPointerCapture(t.pointerId),this.scrollbarToPointer(t.clientY,i))};onScrollbarPointerMove=t=>{t.pointerId!==this.scrollbarPointerId||this.scrollbarState===null||(t.preventDefault(),this.scrollbarToPointer(t.clientY,this.scrollbar.getBoundingClientRect()))};onScrollbarPointerUp=t=>{t.pointerId===this.scrollbarPointerId&&(t.preventDefault(),this.scrollbarPointerId=null,this.scrollbar.hasPointerCapture(t.pointerId)&&this.scrollbar.releasePointerCapture(t.pointerId))};onScrollbarKeyDown=t=>{const e=this.readScrollbarState();if(e===null)return;let i=0;switch(t.key){case"ArrowUp":i=-1;break;case"ArrowDown":i=1;break;case"PageUp":i=-Math.max(1,e.len);break;case"PageDown":i=Math.max(1,e.len);break;case"Home":i=-e.offset;break;case"End":i=e.total-e.len-e.offset;break;default:return}t.preventDefault(),t.stopPropagation(),this.scrollViewport(i)};installEvents(){this.input.addEventListener("keydown",this.onKeyDown),this.input.addEventListener("keyup",this.onKeyUp),this.input.addEventListener("focus",this.onFocus),this.input.addEventListener("blur",this.onBlur),this.input.addEventListener("input",this.onInput),this.input.addEventListener("paste",this.onPaste),this.input.addEventListener("copy",this.onCopyEvent),this.input.addEventListener("compositionstart",this.onCompositionStart),this.input.addEventListener("compositionend",this.onCompositionEnd),this.canvas.addEventListener("pointerdown",this.onPointerDown),this.canvas.addEventListener("pointermove",this.onPointerMove),this.canvas.addEventListener("pointerleave",this.onPointerLeave),this.canvas.addEventListener("pointerup",this.onPointerUp),this.canvas.addEventListener("pointercancel",this.onPointerUp),this.canvas.addEventListener("wheel",this.onWheel,{passive:!1}),this.canvas.addEventListener("mousedown",this.onMouseDown),this.canvas.addEventListener("contextmenu",this.onContextMenu),this.scrollbar.addEventListener("pointerdown",this.onScrollbarPointerDown),this.scrollbar.addEventListener("pointermove",this.onScrollbarPointerMove),this.scrollbar.addEventListener("pointerup",this.onScrollbarPointerUp),this.scrollbar.addEventListener("pointercancel",this.onScrollbarPointerUp),this.scrollbar.addEventListener("keydown",this.onScrollbarKeyDown)}removeEvents(){this.input.removeEventListener("keydown",this.onKeyDown),this.input.removeEventListener("keyup",this.onKeyUp),this.input.removeEventListener("focus",this.onFocus),this.input.removeEventListener("blur",this.onBlur),this.input.removeEventListener("input",this.onInput),this.input.removeEventListener("paste",this.onPaste),this.input.removeEventListener("copy",this.onCopyEvent),this.input.removeEventListener("compositionstart",this.onCompositionStart),this.input.removeEventListener("compositionend",this.onCompositionEnd),this.canvas.removeEventListener("pointerdown",this.onPointerDown),this.canvas.removeEventListener("pointermove",this.onPointerMove),this.canvas.removeEventListener("pointerleave",this.onPointerLeave),this.canvas.removeEventListener("pointerup",this.onPointerUp),this.canvas.removeEventListener("pointercancel",this.onPointerUp),this.canvas.removeEventListener("wheel",this.onWheel),this.canvas.removeEventListener("mousedown",this.onMouseDown),this.canvas.removeEventListener("contextmenu",this.onContextMenu),this.scrollbar.removeEventListener("pointerdown",this.onScrollbarPointerDown),this.scrollbar.removeEventListener("pointermove",this.onScrollbarPointerMove),this.scrollbar.removeEventListener("pointerup",this.onScrollbarPointerUp),this.scrollbar.removeEventListener("pointercancel",this.onScrollbarPointerUp),this.scrollbar.removeEventListener("keydown",this.onScrollbarKeyDown)}scrollViewport(t){let e=Math.trunc(t);const i=this.readScrollbarState();if(i!==null){const r=Math.max(0,i.total-i.len),n=Math.max(0,Math.min(i.offset+e,r));e=n-i.offset,this.scrollbarState={...i,offset:n}}e!==0&&(this.core.scroll(e),this.forceFullRender=!0,this.scrollbarDirty=!0,this.requestRender())}scrollbarToPointer(t,e){const i=this.scrollbarState;if(i===null)return;const r=Ce(i,e.height,t-e.top,this.scrollbarPointerOffset);this.scrollViewport(r-i.offset)}updateScrollbar(){const t=this.readScrollbarState(),e=t===null?null:j(t,Math.max(0,this.mount.clientHeight-k*2));this.scrollbar.hidden=e===null,!(t===null||e===null)&&(this.scrollbar.setAttribute("aria-valuemin","0"),this.scrollbar.setAttribute("aria-valuemax",String(e.maxOffset)),this.scrollbar.setAttribute("aria-valuenow",String(Math.max(0,Math.min(t.offset,e.maxOffset)))),this.scrollbarThumb.style.height=`${e.thumbHeight}px`,this.scrollbarThumb.style.transform=`translateY(${e.thumbTop}px)`)}readScrollbarState(){const t=this.core.scrollbarState();return this.scrollbarState=t,t}requestRender(){this.disposed||!this.visible||!this.hasSize||this.frame!==0||(this.frame=window.requestAnimationFrame(()=>{this.frame=0,this.renderFrame()}))}cancelRender(){this.frame!==0&&(window.cancelAnimationFrame(this.frame),this.frame=0),this.cursorTimer!==null&&(window.clearTimeout(this.cursorTimer),this.cursorTimer=null)}renderFrame(){if(this.disposed||!this.visible)return;if(this.frame!==0&&(window.cancelAnimationFrame(this.frame),this.frame=0),this.mount.clientWidth===0||this.mount.clientHeight===0){this.hasSize=!1,this.forceFullRender=!0,this.cancelRender();return}this.snapshot=this.core.snapshot(),this.blinkEnabled()||(this.cursorOn=!0);const t=this.readScrollbarState(),e=t!==null&&t.total>t.len,i=Ae(this.mountHeight,k,this.rows,this.metrics.height,e);i!==this.originY&&(this.originY=i,this.forceFullRender=!0),this.refreshHoveredLink(),me({context:this.context,snapshot:this.snapshot,metrics:this.metrics,fontSize:this.fontSize,fontFamily:this.fontFamily,padding:k,originY:this.originY,forceFull:this.forceFullRender,cursorOn:this.cursorOn,previousCursorY:this.renderedCursorY,focused:this.focused,hoveredLinkRange:this.hoveredLink?.range??null,selectionBackground:this.theme.selectionBackground}),this.positionInput(),this.renderedCursorY=this.cursorOn&&this.snapshot.cursorVisible&&this.snapshot.cursorY>=0?this.snapshot.cursorY:null,this.scrollbarDirty&&(this.scrollbarDirty=!1,this.updateScrollbar()),this.forceFullRender=!1,this.scheduleCursorBlink()}scheduleCursorBlink(){this.cursorTimer!==null&&window.clearTimeout(this.cursorTimer),this.cursorTimer=null,this.blinkEnabled()&&(this.cursorTimer=window.setTimeout(()=>{this.cursorTimer=null,this.cursorOn=!this.cursorOn,this.requestRender()},ve))}blinkEnabled(){const t=this.snapshot;return!t||!this.visible||!this.hasSize?!1:ke({focused:this.focused,cursorBlinking:t.cursorBlinking,cursorVisible:t.cursorVisible,reducedMotion:this.reducedMotionMedia?.matches??!1})}positionInput(){const t=this.snapshot;if(!t||!t.cursorVisible||t.cursorX<0||t.cursorY<0)return;const e=k+t.cursorX*this.metrics.width,i=this.originY+t.cursorY*this.metrics.height;e===this.inputLeft&&i===this.inputTop||(this.inputLeft=e,this.inputTop=i,this.input.style.left=`${e}px`,this.input.style.top=`${i}px`,this.input.style.height=`${this.metrics.height}px`)}cellAt(t,e){const i=this.canvas.getBoundingClientRect();return{x:Math.max(0,Math.min(this.cols-1,Math.floor((t-i.left-k)/this.metrics.width))),y:Math.max(0,Math.min(this.rows-1,Math.floor((e-i.top-this.originY)/this.metrics.height)))}}linkAt(t,e){if(!this.snapshot)return null;const i=xe({bounds:this.canvas.getBoundingClientRect(),clientX:t,clientY:e,cols:this.cols,rows:this.rows,metrics:this.metrics,padding:k,originY:this.originY});if(!i)return null;const r=this.core.hyperlinkAt(i.x,i.y);if(r){const n={...i},o={...i};for(;;){const l=n.x>0?{x:n.x-1,y:n.y}:n.y>0&&this.snapshot.rowData[n.y]?.isWrapContinuation?{x:this.cols-1,y:n.y-1}:null;if(!l||this.core.hyperlinkAt(l.x,l.y)!==r)break;n.x=l.x,n.y=l.y}for(;;){const l=o.x+1<this.cols?{x:o.x+1,y:o.y}:o.y+1<this.rows&&this.snapshot.rowData[o.y]?.wrapsToNext?{x:0,y:o.y+1}:null;if(!l||this.core.hyperlinkAt(l.x,l.y)!==r)break;o.x=l.x,o.y=l.y}return{text:r,range:{start:n,end:o}}}return Re(this.snapshot.rowData,i.y,i.x)}sendMouse(t,e,i){const r=this.canvas.getBoundingClientRect(),n=this.core.encodeMouse({action:t,button:e,mods:(i.shiftKey?1:0)|(i.ctrlKey?2:0)|(i.altKey?4:0)|(i.metaKey?8:0),x:Math.max(0,i.clientX-r.left),y:Math.max(0,i.clientY-r.top),screenWidth:r.width,screenHeight:r.height,cellWidth:this.metrics.width,cellHeight:this.metrics.height,paddingLeft:k,paddingRight:k,paddingTop:this.originY,paddingBottom:Math.max(0,r.height-this.originY-this.rows*this.metrics.height),anyButtonPressed:i.buttons!==0}),o=Ke(t,n,this.lastMouseMotionData);this.lastMouseMotionData=o.nextMotionData,o.send&&this.options.onData(n)}synchronizeMouseTrackingState(){const t=this.core.isMouseAnyEventTracking(),e=We(this.mouseAnyEventTracking,t,this.lastMouseMotionData);return this.mouseAnyEventTracking=e.tracking,this.lastMouseMotionData=e.motionData,t}buttonFromButtons(t){return(t&1)!==0?1:(t&4)!==0?3:(t&2)!==0?2:(t&8)!==0?4:(t&16)!==0?5:null}}export{G as DEFAULT_TERMINAL_FONT_FAMILY,_t as GhosttyTerminalSurface,Be as TerminalPasteArbiter,Ve as advanceTerminalSelectionClickSequence,Le as isTerminalCopyShortcut,F as isTerminalLinkPointerGesture,Ne as isTerminalPasteShortcut,lt as loadTerminalFontFamily,Ke as resolveTerminalMouseData,ke as shouldBlinkTerminalCursor,Ae as terminalContentOriginY,Z as terminalFontSize,xe as terminalGridCellAt,Re as terminalLinkAtPositionWithRange,j as terminalScrollbarGeometry,Ce as terminalScrollbarOffsetAtPointer,Ye as terminalWheelArrowData,Ge as terminalWheelDeltaRows};
|