@crunchloop/ghostty-web 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +314 -0
- package/dist/__vite-browser-external-2447137e.js +4 -0
- package/dist/__vite-browser-external-b3701507.cjs +1 -0
- package/dist/ghostty-vt.wasm +0 -0
- package/dist/ghostty-web.cjs.js +15 -0
- package/dist/ghostty-web.d.ts +2445 -0
- package/dist/ghostty-web.es.js +3389 -0
- package/dist/headless.cjs.js +5 -0
- package/dist/headless.d.ts +1271 -0
- package/dist/headless.es.js +34 -0
- package/dist/terminal-core-0895062a.cjs +5 -0
- package/dist/terminal-core-b557858d.js +4708 -0
- package/ghostty-vt.wasm +0 -0
- package/package.json +97 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Coder
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
# ghostty-web
|
|
2
|
+
|
|
3
|
+
[](https://npmjs.com/package/ghostty-web) [](https://npmjs.com/package/ghostty-web) [](https://npmjs.com/package/ghostty-web) [](./LICENSE)
|
|
4
|
+
|
|
5
|
+
[Ghostty](https://github.com/ghostty-org/ghostty) for the web with [xterm.js](https://github.com/xtermjs/xterm.js) API compatibility — giving you a proper VT100 implementation in the browser.
|
|
6
|
+
|
|
7
|
+
- Migrate from xterm by changing your import: `@xterm/xterm` → `ghostty-web`
|
|
8
|
+
- WASM-compiled parser from Ghostty—the same code that runs the native app
|
|
9
|
+
- Zero runtime dependencies, ~400KB WASM bundle
|
|
10
|
+
|
|
11
|
+
Originally created for [Mux](https://github.com/coder/mux) (a desktop app for isolated, parallel agentic development), but designed to be used anywhere.
|
|
12
|
+
|
|
13
|
+
## Try It
|
|
14
|
+
|
|
15
|
+
- [Live Demo](https://ghostty.ondis.co) on an ephemeral VM (thank you to Greg from [disco.cloud](https://disco.cloud) for hosting).
|
|
16
|
+
|
|
17
|
+
- On your computer:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npx @ghostty-web/demo@next
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
This starts a local HTTP server with a real shell on `http://localhost:8080`. Works best on Linux and macOS.
|
|
24
|
+
|
|
25
|
+

|
|
26
|
+
|
|
27
|
+
## Comparison with xterm.js
|
|
28
|
+
|
|
29
|
+
xterm.js is everywhere—VS Code, Hyper, countless web terminals. But it has fundamental issues:
|
|
30
|
+
|
|
31
|
+
| Issue | xterm.js | ghostty-web |
|
|
32
|
+
| ---------------------------------------- | ---------------------------------------------------------------- | -------------------------- |
|
|
33
|
+
| **Complex scripts** (Devanagari, Arabic) | Rendering issues | ✓ Proper grapheme handling |
|
|
34
|
+
| **XTPUSHSGR/XTPOPSGR** | [Not supported](https://github.com/xtermjs/xterm.js/issues/2570) | ✓ Full support |
|
|
35
|
+
|
|
36
|
+
xterm.js reimplements terminal emulation in JavaScript. Every escape sequence, every edge case, every Unicode quirk—all hand-coded. Ghostty's emulator is the same battle-tested code that runs the native Ghostty app.
|
|
37
|
+
|
|
38
|
+
### Keyboard encoding
|
|
39
|
+
|
|
40
|
+
Keyboard input is encoded by Ghostty's key encoder. Byte sequences largely match xterm.js's defaults — Home/End honor DECCKM, Shift+nav and Shift+F-keys preserve the Shift modifier in the emitted CSI sequence, non-BMP characters pass through, Arrow keys honor cursor-application mode. Two deliberate differences:
|
|
41
|
+
|
|
42
|
+
- **Shift+Enter is distinguishable from Enter** (emitted as `\x1b[27;2;13~` rather than bare `\r`, following fixterms), so modern line editors and REPLs can treat Shift+Enter as a newline-without-submit.
|
|
43
|
+
- **Kitty keyboard protocol and xterm modifyOtherKeys state 2 are supported** when an app enables them. xterm.js implements only the traditional escape sequences.
|
|
44
|
+
|
|
45
|
+
If you need byte-for-byte xterm.js behavior for a specific key (e.g. Shift+Enter mapped to `\r` for tools that don't understand the fixterms sequence), intercept it in `attachCustomKeyEventHandler` and emit the bytes you want via `term.input(bytes, true)`:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
term.attachCustomKeyEventHandler((e) => {
|
|
49
|
+
if (e.key === 'Enter' && e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) {
|
|
50
|
+
term.input('\r', true); // fires onData with '\r'
|
|
51
|
+
return true; // suppress the default encoder path
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Installation
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
npm install ghostty-web
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Usage
|
|
64
|
+
|
|
65
|
+
ghostty-web aims to be API-compatible with the xterm.js API.
|
|
66
|
+
|
|
67
|
+
```javascript
|
|
68
|
+
import { init, Terminal } from 'ghostty-web';
|
|
69
|
+
|
|
70
|
+
await init();
|
|
71
|
+
|
|
72
|
+
const term = new Terminal({
|
|
73
|
+
fontSize: 14,
|
|
74
|
+
theme: {
|
|
75
|
+
background: '#1a1b26',
|
|
76
|
+
foreground: '#a9b1d6',
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
term.open(document.getElementById('terminal'));
|
|
81
|
+
term.onData((data) => websocket.send(data));
|
|
82
|
+
websocket.onmessage = (e) => term.write(e.data);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
For a comprehensive client ↔ server example, refer to the [demo](./demo/index.html).
|
|
86
|
+
|
|
87
|
+
## Headless Mode
|
|
88
|
+
|
|
89
|
+
`TerminalCore` provides a headless terminal (no DOM, no canvas) for server-side rendering,
|
|
90
|
+
testing, or non-browser environments:
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
import { init, TerminalCore } from 'ghostty-web';
|
|
94
|
+
|
|
95
|
+
await init();
|
|
96
|
+
|
|
97
|
+
const term = new TerminalCore({ cols: 80, rows: 24 });
|
|
98
|
+
term.write('Hello World\r\n');
|
|
99
|
+
|
|
100
|
+
const line = term.buffer.active.getLine(0);
|
|
101
|
+
// inspect line cells...
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
`Terminal` extends `TerminalCore` with all browser rendering, input handling, and addon support.
|
|
105
|
+
|
|
106
|
+
## Shell Integration (OSC 133)
|
|
107
|
+
|
|
108
|
+
ghostty-web understands [OSC 133](https://iterm2.com/documentation-escape-codes.html) shell
|
|
109
|
+
integration sequences, letting you hook into shell prompt and command lifecycle events:
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
term.onPromptStart(() => {
|
|
113
|
+
console.log('Shell prompt started');
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
term.onPromptEnd(() => {
|
|
117
|
+
console.log('Shell prompt ended — user can now type');
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
term.onCommandStart(() => {
|
|
121
|
+
console.log('Command execution began');
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
term.onCommandEnd((e) => {
|
|
125
|
+
console.log('Command finished, exit code:', e.exitCode);
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Shells that support OSC 133 (fish, bash with the integration script, zsh with the plugin) emit
|
|
130
|
+
these sequences automatically.
|
|
131
|
+
|
|
132
|
+
## Cursor Shape (OSC 22)
|
|
133
|
+
|
|
134
|
+
Applications can request cursor shape changes via `OSC 22`:
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
term.onMouseCursorChange((cursor) => {
|
|
138
|
+
// cursor is a CSS cursor string: 'default', 'text', 'pointer', etc.
|
|
139
|
+
document.body.style.cursor = cursor;
|
|
140
|
+
});
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Focus Events (DEC mode 1004)
|
|
144
|
+
|
|
145
|
+
When an application enables focus tracking (`\x1b[?1004h`), ghostty-web fires focus/blur
|
|
146
|
+
sequences to the PTY and emits events:
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
term.onFocus(() => console.log('terminal focused'));
|
|
150
|
+
term.onBlur(() => console.log('terminal blurred'));
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Synchronized Output (DEC mode 2026)
|
|
154
|
+
|
|
155
|
+
ghostty-web respects the synchronized output mode (`\x1b[?2026h` / `\x1b[?2026l`),
|
|
156
|
+
deferring rendering until the application signals it is ready. A timeout guard prevents
|
|
157
|
+
indefinite hangs.
|
|
158
|
+
|
|
159
|
+
## Dynamic Theming
|
|
160
|
+
|
|
161
|
+
Themes can be set at construction time or updated at runtime:
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
// At construction
|
|
165
|
+
const term = new Terminal({ theme: { background: '#000', foreground: '#fff' } });
|
|
166
|
+
|
|
167
|
+
// At runtime (triggers a re-render)
|
|
168
|
+
term.options.theme = {
|
|
169
|
+
background: '#1e1e2e',
|
|
170
|
+
foreground: '#cdd6f4',
|
|
171
|
+
cursor: '#f5e0dc',
|
|
172
|
+
black: '#45475a',
|
|
173
|
+
red: '#f38ba8',
|
|
174
|
+
// ...all 16 ANSI colors supported
|
|
175
|
+
};
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Selection API
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
// Programmatic selection
|
|
182
|
+
term.select(col, row, length); // select N characters starting at col/row
|
|
183
|
+
term.selectAll(); // select all visible content
|
|
184
|
+
term.clearSelection(); // clear selection
|
|
185
|
+
term.hasSelection(); // boolean
|
|
186
|
+
term.getSelectionPosition(); // { start: {x, y}, end: {x, y} } | null
|
|
187
|
+
|
|
188
|
+
// Event
|
|
189
|
+
term.onSelectionChange(() => {
|
|
190
|
+
console.log('Selection changed');
|
|
191
|
+
});
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Mouse selection (click-drag), `selectAll`, `clearSelection`, and `getSelectionPosition`
|
|
195
|
+
all work out of the box.
|
|
196
|
+
|
|
197
|
+
## Scrolling API
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
term.scrollToTop();
|
|
201
|
+
term.scrollToBottom();
|
|
202
|
+
term.scrollLines(n); // positive = down, negative = up
|
|
203
|
+
term.scrollPages(n); // scroll by viewport height
|
|
204
|
+
|
|
205
|
+
term.onScroll((viewportY) => {
|
|
206
|
+
console.log('Scrolled to viewport offset', viewportY);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
// Keep viewport pinned when new output arrives
|
|
210
|
+
term.options.preserveScrollOnWrite = true;
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## FitAddon
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
import { init, Terminal } from 'ghostty-web';
|
|
217
|
+
import { FitAddon } from 'ghostty-web/addons/fit';
|
|
218
|
+
|
|
219
|
+
await init();
|
|
220
|
+
const term = new Terminal();
|
|
221
|
+
const fitAddon = new FitAddon();
|
|
222
|
+
term.loadAddon(fitAddon);
|
|
223
|
+
term.open(document.getElementById('terminal'));
|
|
224
|
+
|
|
225
|
+
fitAddon.fit(); // resize terminal to fill container
|
|
226
|
+
const dims = fitAddon.proposeDimensions(); // { cols, rows }
|
|
227
|
+
|
|
228
|
+
window.addEventListener('resize', () => fitAddon.fit());
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Addon API
|
|
232
|
+
|
|
233
|
+
ghostty-web supports the xterm.js addon interface:
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
const addon = {
|
|
237
|
+
activate(terminal) {
|
|
238
|
+
// receives the Terminal instance
|
|
239
|
+
},
|
|
240
|
+
dispose() {
|
|
241
|
+
// called when terminal is disposed
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
term.loadAddon(addon);
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## Events Reference
|
|
249
|
+
|
|
250
|
+
| Event | Payload | Description |
|
|
251
|
+
| --------------------- | ----------------------- | --------------------------------------- |
|
|
252
|
+
| `onData` | `string` | Raw bytes from keyboard / `input()` |
|
|
253
|
+
| `onWrite` | `string \| Uint8Array` | Data written to the terminal |
|
|
254
|
+
| `onWriteParsed` | — | After all buffered writes are processed |
|
|
255
|
+
| `onRender` | `{ start, end }` | After a render frame (row range) |
|
|
256
|
+
| `onResize` | `{ cols, rows }` | Terminal resized |
|
|
257
|
+
| `onScroll` | `number` | Viewport Y offset changed |
|
|
258
|
+
| `onLineFeed` | — | Line feed received |
|
|
259
|
+
| `onCursorMove` | — | Cursor position changed |
|
|
260
|
+
| `onSelectionChange` | — | Selection changed |
|
|
261
|
+
| `onTitleChange` | `string` | OSC 0/2 title escape |
|
|
262
|
+
| `onBell` | — | BEL character received |
|
|
263
|
+
| `onFocus` | — | Terminal focused (mode 1004) |
|
|
264
|
+
| `onBlur` | — | Terminal blurred (mode 1004) |
|
|
265
|
+
| `onPromptStart` | — | OSC 133;A — prompt started |
|
|
266
|
+
| `onPromptEnd` | — | OSC 133;B — prompt ended |
|
|
267
|
+
| `onCommandStart` | — | OSC 133;C — command execution started |
|
|
268
|
+
| `onCommandEnd` | `{ exitCode?: number }` | OSC 133;D — command finished |
|
|
269
|
+
| `onMouseCursorChange` | `string` | OSC 22 CSS cursor string |
|
|
270
|
+
|
|
271
|
+
## Development
|
|
272
|
+
|
|
273
|
+
ghostty-web builds from Ghostty's source with a [patch](./patches/ghostty-wasm-api.patch) to expose additional
|
|
274
|
+
functionality.
|
|
275
|
+
|
|
276
|
+
> Requires Zig and Bun.
|
|
277
|
+
|
|
278
|
+
```bash
|
|
279
|
+
bun run build
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### Getting the WASM without Zig
|
|
283
|
+
|
|
284
|
+
If you don't have Zig installed, you can pull the pre-built WASM from the latest npm release:
|
|
285
|
+
|
|
286
|
+
```bash
|
|
287
|
+
npm pack ghostty-web@latest
|
|
288
|
+
tar xf ghostty-web-*.tgz
|
|
289
|
+
cp package/ghostty-vt.wasm .
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### Running E2E Tests
|
|
293
|
+
|
|
294
|
+
```bash
|
|
295
|
+
bun run test:e2e
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
Tests use [Playwright](https://playwright.dev/) with Chromium. The dev server starts automatically.
|
|
299
|
+
|
|
300
|
+
```bash
|
|
301
|
+
bun run test:e2e:headed # watch tests run in a real browser
|
|
302
|
+
bun run test:e2e:ui # Playwright UI mode
|
|
303
|
+
bun run test:e2e:report # open HTML report
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
Mitchell Hashimoto (author of Ghostty) has [been working](https://mitchellh.com/writing/libghostty-is-coming) on `libghostty` which makes this all possible. The patches are very minimal thanks to the work the Ghostty team has done, and we expect them to get smaller.
|
|
307
|
+
|
|
308
|
+
This library will eventually consume a native Ghostty WASM distribution once available, and will continue to provide an xterm.js compatible API.
|
|
309
|
+
|
|
310
|
+
At Coder we're big fans of Ghostty, so kudos to that team for all the amazing work.
|
|
311
|
+
|
|
312
|
+
## License
|
|
313
|
+
|
|
314
|
+
[MIT](./LICENSE)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={};exports.default=e;
|
|
Binary file
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./terminal-core-0895062a.cjs"),q={KeyA:a.Key.A,KeyB:a.Key.B,KeyC:a.Key.C,KeyD:a.Key.D,KeyE:a.Key.E,KeyF:a.Key.F,KeyG:a.Key.G,KeyH:a.Key.H,KeyI:a.Key.I,KeyJ:a.Key.J,KeyK:a.Key.K,KeyL:a.Key.L,KeyM:a.Key.M,KeyN:a.Key.N,KeyO:a.Key.O,KeyP:a.Key.P,KeyQ:a.Key.Q,KeyR:a.Key.R,KeyS:a.Key.S,KeyT:a.Key.T,KeyU:a.Key.U,KeyV:a.Key.V,KeyW:a.Key.W,KeyX:a.Key.X,KeyY:a.Key.Y,KeyZ:a.Key.Z,Digit1:a.Key.ONE,Digit2:a.Key.TWO,Digit3:a.Key.THREE,Digit4:a.Key.FOUR,Digit5:a.Key.FIVE,Digit6:a.Key.SIX,Digit7:a.Key.SEVEN,Digit8:a.Key.EIGHT,Digit9:a.Key.NINE,Digit0:a.Key.ZERO,Enter:a.Key.ENTER,Escape:a.Key.ESCAPE,Backspace:a.Key.BACKSPACE,Tab:a.Key.TAB,Space:a.Key.SPACE,Minus:a.Key.MINUS,Equal:a.Key.EQUAL,BracketLeft:a.Key.BRACKET_LEFT,BracketRight:a.Key.BRACKET_RIGHT,Backslash:a.Key.BACKSLASH,Semicolon:a.Key.SEMICOLON,Quote:a.Key.QUOTE,Backquote:a.Key.GRAVE,Comma:a.Key.COMMA,Period:a.Key.PERIOD,Slash:a.Key.SLASH,CapsLock:a.Key.CAPS_LOCK,F1:a.Key.F1,F2:a.Key.F2,F3:a.Key.F3,F4:a.Key.F4,F5:a.Key.F5,F6:a.Key.F6,F7:a.Key.F7,F8:a.Key.F8,F9:a.Key.F9,F10:a.Key.F10,F11:a.Key.F11,F12:a.Key.F12,PrintScreen:a.Key.PRINT_SCREEN,ScrollLock:a.Key.SCROLL_LOCK,Pause:a.Key.PAUSE,Insert:a.Key.INSERT,Home:a.Key.HOME,PageUp:a.Key.PAGE_UP,Delete:a.Key.DELETE,End:a.Key.END,PageDown:a.Key.PAGE_DOWN,ArrowRight:a.Key.RIGHT,ArrowLeft:a.Key.LEFT,ArrowDown:a.Key.DOWN,ArrowUp:a.Key.UP,NumLock:a.Key.NUM_LOCK,NumpadDivide:a.Key.KP_DIVIDE,NumpadMultiply:a.Key.KP_MULTIPLY,NumpadSubtract:a.Key.KP_MINUS,NumpadAdd:a.Key.KP_PLUS,NumpadEnter:a.Key.KP_ENTER,Numpad1:a.Key.KP_1,Numpad2:a.Key.KP_2,Numpad3:a.Key.KP_3,Numpad4:a.Key.KP_4,Numpad5:a.Key.KP_5,Numpad6:a.Key.KP_6,Numpad7:a.Key.KP_7,Numpad8:a.Key.KP_8,Numpad9:a.Key.KP_9,Numpad0:a.Key.KP_0,NumpadDecimal:a.Key.KP_PERIOD,IntlBackslash:a.Key.INTL_BACKSLASH,ContextMenu:a.Key.CONTEXT_MENU,F13:a.Key.F13,F14:a.Key.F14,F15:a.Key.F15,F16:a.Key.F16,F17:a.Key.F17,F18:a.Key.F18,F19:a.Key.F19,F20:a.Key.F20,F21:a.Key.F21,F22:a.Key.F22,F23:a.Key.F23,F24:a.Key.F24},B=class x{constructor(t,i,e,s,r,n,o,h,c,l){this.keydownListener=null,this.keypressListener=null,this.pasteListener=null,this.beforeInputListener=null,this.compositionStartListener=null,this.compositionUpdateListener=null,this.compositionEndListener=null,this.mousedownListener=null,this.mouseupListener=null,this.mousemoveListener=null,this.wheelListener=null,this.isComposing=!1,this.compositionJustEnded=!1,this.pendingKeyAfterComposition=null,this.isDisposed=!1,this.mouseButtonsPressed=0,this.lastKeyDownData=null,this.lastKeyDownTime=0,this.lastPasteData=null,this.lastPasteTime=0,this.lastPasteSource=null,this.lastCompositionData=null,this.lastCompositionTime=0,this.lastBeforeInputData=null,this.lastBeforeInputTime=0,this.syncedEncoderOptions=new Map,this.decoder=new TextDecoder,this.encoder=t.createKeyEncoder(),this.encoder.setOption(a.KeyEncoderOption.ALT_ESC_PREFIX,!0),this.container=i,this.inputElement=c,this.onDataCallback=e,this.onBellCallback=s,this.onKeyCallback=r,this.customKeyEventHandler=n,this.getModeCallback=o,this.onCopyCallback=h,this.mouseConfig=l,this.attach()}setCustomKeyEventHandler(t){this.customKeyEventHandler=t}attach(){typeof this.container.hasAttribute=="function"&&typeof this.container.setAttribute=="function"&&(this.container.hasAttribute("tabindex")||this.container.setAttribute("tabindex","0"),this.container.style&&(this.container.style.outline="none")),this.keydownListener=this.handleKeyDown.bind(this),this.container.addEventListener("keydown",this.keydownListener),this.pasteListener=this.handlePaste.bind(this),this.container.addEventListener("paste",this.pasteListener),this.inputElement&&this.inputElement!==this.container&&this.inputElement.addEventListener("paste",this.pasteListener),this.inputElement&&(this.beforeInputListener=this.handleBeforeInput.bind(this),this.inputElement.addEventListener("beforeinput",this.beforeInputListener));const t=this.inputElement||this.container;this.compositionStartListener=this.handleCompositionStart.bind(this),t.addEventListener("compositionstart",this.compositionStartListener),this.compositionUpdateListener=this.handleCompositionUpdate.bind(this),t.addEventListener("compositionupdate",this.compositionUpdateListener),this.compositionEndListener=this.handleCompositionEnd.bind(this),t.addEventListener("compositionend",this.compositionEndListener),this.mousedownListener=this.handleMouseDown.bind(this),this.container.addEventListener("mousedown",this.mousedownListener),this.mouseupListener=this.handleMouseUp.bind(this),this.container.addEventListener("mouseup",this.mouseupListener),this.mousemoveListener=this.handleMouseMove.bind(this),this.container.addEventListener("mousemove",this.mousemoveListener),this.wheelListener=this.handleWheel.bind(this),this.container.addEventListener("wheel",this.wheelListener,{passive:!1})}mapKeyCode(t){return q[t]??null}syncEncoderOption(t,i){this.syncedEncoderOptions.get(t)!==i&&(this.encoder.setOption(t,i),this.syncedEncoderOptions.set(t,i))}extractModifiers(t){let i=a.Mods.NONE;return t.shiftKey&&(i|=a.Mods.SHIFT),t.ctrlKey&&(i|=a.Mods.CTRL),t.altKey&&(i|=a.Mods.ALT),t.metaKey&&(i|=a.Mods.SUPER),i}handleKeyDown(t){if(this.isDisposed||t.isComposing||t.keyCode===229)return;if(this.isComposing){this.pendingKeyAfterComposition=t.key,t.preventDefault();return}if(this.compositionJustEnded){this.compositionJustEnded=!1;return}if(this.onKeyCallback&&this.onKeyCallback({key:t.key,domEvent:t}),this.customKeyEventHandler&&this.customKeyEventHandler(t)){t.preventDefault();return}if((t.ctrlKey||t.metaKey)&&t.code==="KeyV"){const n=this.encoder.encode({key:a.Key.V,mods:t.ctrlKey?a.Mods.CTRL:a.Mods.SUPER,action:a.KeyAction.PRESS});n.length>0&&this.onDataCallback(new TextDecoder().decode(n));return}if(t.metaKey&&t.code==="KeyC"){this.onCopyCallback&&this.onCopyCallback()&&t.preventDefault();return}const i=this.mapKeyCode(t.code);if(i===null)return;const e=this.extractModifiers(t);let s;if(t.key.length>0&&t.key!=="Dead"&&t.key!=="Unidentified"){const n=t.key.codePointAt(0),o=n!==void 0&&n>65535?2:1;t.key.length===o&&(t.altKey&&n!==void 0&&n>127?t.code.startsWith("Key")&&t.code.length===4&&(s=t.code[3].toLowerCase()):s=t.key)}this.getModeCallback&&(this.syncEncoderOption(a.KeyEncoderOption.CURSOR_KEY_APPLICATION,this.getModeCallback(1)),this.syncEncoderOption(a.KeyEncoderOption.KEYPAD_KEY_APPLICATION,this.getModeCallback(66))),t.preventDefault(),t.stopPropagation();let r;try{const n=this.encoder.encode({action:a.KeyAction.PRESS,key:i,mods:e,utf8:s});r=n.length===0?"":this.decoder.decode(n)}catch(n){console.warn("Failed to encode key:",t.code,n);return}r.length>0&&(this.onDataCallback(r),this.recordKeyDownData(r))}handlePaste(t){if(this.isDisposed)return;const i=t.clipboardData;if(!i)return;const e=i.getData("text/plain");e&&(t.preventDefault(),t.stopPropagation(),!this.shouldIgnorePasteEvent(e,"paste")&&(this.emitPasteData(e),this.recordPasteData(e,"paste")))}handleBeforeInput(t){if(this.isDisposed||this.isComposing||t.isComposing)return;const i=t.inputType,e=t.data??"";let s=null;switch(i){case"insertText":case"insertReplacementText":s=e.length>0?e.replace(/\n/g,"\r"):null;break;case"insertLineBreak":case"insertParagraph":s="\r";break;case"deleteContentBackward":s="";break;case"deleteContentForward":s="\x1B[3~";break;case"insertFromPaste":if(!e)return;if(this.shouldIgnorePasteEvent(e,"beforeinput")){t.preventDefault(),t.stopPropagation();return}t.preventDefault(),t.stopPropagation(),this.emitPasteData(e),this.recordPasteData(e,"beforeinput");return;default:return}if(s){if(this.shouldIgnoreBeforeInput(s)){t.preventDefault(),t.stopPropagation();return}if(e&&this.shouldIgnoreBeforeInputFromComposition(e)){t.preventDefault(),t.stopPropagation();return}t.preventDefault(),t.stopPropagation(),this.onDataCallback(s),e&&this.recordBeforeInputData(e)}}handleCompositionStart(t){this.isDisposed||(this.isComposing=!0)}handleCompositionUpdate(t){this.isDisposed}handleCompositionEnd(t){if(this.isDisposed)return;this.isComposing=!1;const i=t.data;if(i&&i.length>0){if(this.shouldIgnoreCompositionEnd(i)){this.cleanupCompositionTextNodes(),this.processPendingKeyAfterComposition();return}this.onDataCallback(i),this.recordCompositionData(i)}this.cleanupCompositionTextNodes(),this.processPendingKeyAfterComposition()}processPendingKeyAfterComposition(){if(this.pendingKeyAfterComposition){const t=this.pendingKeyAfterComposition;this.pendingKeyAfterComposition=null,this.onDataCallback(t)}}cleanupCompositionTextNodes(){if(this.container&&this.container.childNodes)for(let t=this.container.childNodes.length-1;t>=0;t--){const i=this.container.childNodes[t];i.nodeType===3&&this.container.removeChild(i)}}pixelToCell(t){if(!this.mouseConfig)return null;const i=this.mouseConfig.getCellDimensions(),e=this.mouseConfig.getCanvasOffset();if(i.width<=0||i.height<=0)return null;const s=t.clientX-e.left,r=t.clientY-e.top,n=Math.floor(s/i.width)+1,o=Math.floor(r/i.height)+1;return{col:Math.max(1,n),row:Math.max(1,o)}}getMouseModifiers(t){let i=0;return t.shiftKey&&(i|=4),t.metaKey&&(i|=8),t.ctrlKey&&(i|=16),i}encodeMouseSGR(t,i,e,s,r){return`\x1B[<${t+r};${i};${e}${s?"m":"M"}`}encodeMouseX10(t,i,e,s){const r=t+s+32,n=String.fromCharCode(Math.min(i+32,255)),o=String.fromCharCode(Math.min(e+32,255));return`\x1B[M${String.fromCharCode(r)}${n}${o}`}sendMouseEvent(t,i,e,s,r){var c,l;const n=this.getMouseModifiers(r),o=((l=(c=this.mouseConfig)==null?void 0:c.hasSgrMouseMode)==null?void 0:l.call(c))??!0;let h;if(o)h=this.encodeMouseSGR(t,i,e,s,n);else{const u=s?3:t;h=this.encodeMouseX10(u,i,e,n)}this.onDataCallback(h)}handleMouseDown(t){var s;if(this.isDisposed||!((s=this.mouseConfig)!=null&&s.hasMouseTracking()))return;const i=this.pixelToCell(t);if(!i)return;const e=t.button;this.mouseButtonsPressed|=1<<e,this.sendMouseEvent(e,i.col,i.row,!1,t)}handleMouseUp(t){var s;if(this.isDisposed||!((s=this.mouseConfig)!=null&&s.hasMouseTracking()))return;const i=this.pixelToCell(t);if(!i)return;const e=t.button;this.mouseButtonsPressed&=~(1<<e),this.sendMouseEvent(e,i.col,i.row,!0,t)}handleMouseMove(t){var n,o,h;if(this.isDisposed||!((n=this.mouseConfig)!=null&&n.hasMouseTracking()))return;const i=((o=this.getModeCallback)==null?void 0:o.call(this,1002))??!1,e=((h=this.getModeCallback)==null?void 0:h.call(this,1003))??!1;if(!i&&!e||i&&!e&&this.mouseButtonsPressed===0)return;const s=this.pixelToCell(t);if(!s)return;let r=32;this.mouseButtonsPressed&1?r+=0:this.mouseButtonsPressed&2?r+=1:this.mouseButtonsPressed&4&&(r+=2),this.sendMouseEvent(r,s.col,s.row,!1,t)}handleWheel(t){var i;this.isDisposed||(i=this.mouseConfig)!=null&&i.hasMouseTracking()&&(this.sendWheelMouseEvent(t),t.preventDefault())}handleWheelEvent(t){this.isDisposed||this.sendWheelMouseEvent(t)}sendWheelMouseEvent(t){const i=this.pixelToCell(t);if(!i)return;const e=t.deltaY<0?64:65;this.sendMouseEvent(e,i.col,i.row,!1,t)}emitPasteData(t){var e;((e=this.getModeCallback)==null?void 0:e.call(this,2004))??!1?this.onDataCallback("\x1B[200~"+t+"\x1B[201~"):this.onDataCallback(t)}recordKeyDownData(t){this.lastKeyDownData=t,this.lastKeyDownTime=this.getNow()}recordPasteData(t,i){this.lastPasteData=t,this.lastPasteTime=this.getNow(),this.lastPasteSource=i}shouldIgnoreBeforeInput(t){if(!this.lastKeyDownData)return!1;const e=this.getNow()-this.lastKeyDownTime<x.BEFORE_INPUT_IGNORE_MS&&this.lastKeyDownData===t;return this.lastKeyDownData=null,e}shouldIgnoreBeforeInputFromComposition(t){if(!this.lastCompositionData)return!1;const e=this.getNow()-this.lastCompositionTime<x.BEFORE_INPUT_IGNORE_MS&&this.lastCompositionData===t;return e&&(this.lastCompositionData=null),e}shouldIgnoreCompositionEnd(t){if(!this.lastBeforeInputData)return!1;const e=this.getNow()-this.lastBeforeInputTime<x.BEFORE_INPUT_IGNORE_MS&&this.lastBeforeInputData===t;return e&&(this.lastBeforeInputData=null),e}recordBeforeInputData(t){this.lastBeforeInputData=t,this.lastBeforeInputTime=this.getNow()}recordCompositionData(t){this.lastCompositionData=t,this.lastCompositionTime=this.getNow()}shouldIgnorePasteEvent(t,i){if(!this.lastPasteData||this.lastPasteSource===i)return!1;const s=this.getNow()-this.lastPasteTime<x.BEFORE_INPUT_IGNORE_MS&&this.lastPasteData===t;return s&&(this.lastPasteData=null,this.lastPasteSource=null),s}getNow(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}dispose(){if(this.isDisposed)return;this.keydownListener&&(this.container.removeEventListener("keydown",this.keydownListener),this.keydownListener=null),this.keypressListener&&(this.container.removeEventListener("keypress",this.keypressListener),this.keypressListener=null),this.pasteListener&&(this.container.removeEventListener("paste",this.pasteListener),this.inputElement&&this.inputElement!==this.container&&this.inputElement.removeEventListener("paste",this.pasteListener),this.pasteListener=null),this.beforeInputListener&&this.inputElement&&(this.inputElement.removeEventListener("beforeinput",this.beforeInputListener),this.beforeInputListener=null);const t=this.inputElement||this.container;this.compositionStartListener&&(t.removeEventListener("compositionstart",this.compositionStartListener),this.compositionStartListener=null),this.compositionUpdateListener&&(t.removeEventListener("compositionupdate",this.compositionUpdateListener),this.compositionUpdateListener=null),this.compositionEndListener&&(t.removeEventListener("compositionend",this.compositionEndListener),this.compositionEndListener=null),this.mousedownListener&&(this.container.removeEventListener("mousedown",this.mousedownListener),this.mousedownListener=null),this.mouseupListener&&(this.container.removeEventListener("mouseup",this.mouseupListener),this.mouseupListener=null),this.mousemoveListener&&(this.container.removeEventListener("mousemove",this.mousemoveListener),this.mousemoveListener=null),this.wheelListener&&(this.container.removeEventListener("wheel",this.wheelListener),this.wheelListener=null),this.isDisposed=!0}isActive(){return!this.isDisposed}};B.BEFORE_INPUT_IGNORE_MS=100;let F=B;class O{constructor(t){this.terminal=t,this.providers=[],this.linkCache=new Map,this.scannedRows=new Set}registerProvider(t){this.providers.push(t),this.invalidateCache()}async getLinkAt(t,i){const e=this.terminal.buffer.active.getLine(i);if(!(!e||t<0||t>=e.length||!e.getCell(t))){for(const r of this.linkCache.values())if(this.isPositionInLink(t,i,r))return r;this.scannedRows.has(i)||await this.scanRow(i);for(const r of this.linkCache.values())if(this.isPositionInLink(t,i,r))return r}}async scanRow(t){this.scannedRows.add(t);const i=[];for(const e of this.providers){const s=await new Promise(r=>{e.provideLinks(t,r)});s&&i.push(...s)}for(const e of i)this.cacheLink(e)}cacheLink(t){const{start:i,end:e}=t.range,s=`r${i.y}:${i.x}-${e.x}`;this.linkCache.has(s)||this.linkCache.set(s,t)}isPositionInLink(t,i,e){const{start:s,end:r}=e.range;return i<s.y||i>r.y?!1:s.y===r.y?t>=s.x&&t<=r.x:i===s.y?t>=s.x:i===r.y?t<=r.x:!0}invalidateCache(){this.linkCache.clear(),this.scannedRows.clear()}invalidateRows(t,i){for(let s=t;s<=i;s++)this.scannedRows.delete(s);const e=[];for(const[s,r]of this.linkCache.entries()){const{start:n,end:o}=r.range;(n.y>=t&&n.y<=i||o.y>=t&&o.y<=i||n.y<t&&o.y>i)&&e.push(s)}for(const s of e)this.linkCache.delete(s)}dispose(){var t;this.linkCache.clear(),this.scannedRows.clear();for(const i of this.providers)(t=i.dispose)==null||t.call(i);this.providers=[]}}class Y{constructor(t){this.terminal=t}provideLinks(t,i){const e=[],s=new Set,r=this.terminal.buffer.active.getLine(t);if(!r){i(void 0);return}for(let n=0;n<r.length;n++){if(s.has(n))continue;const o=r.getCell(n);if(!o||o.getHyperlinkId()===0||!this.terminal.wasmTerm)continue;const c=this.terminal.wasmTerm.getScrollbackLength(),l=t-c;let u;if(l<0?u=this.terminal.wasmTerm.getScrollbackHyperlinkUri(t,n):u=this.terminal.wasmTerm.getHyperlinkUri(l,n),u){let d=n;for(let m=n+1;m<r.length;m++){const g=r.getCell(m);if(!g||g.getHyperlinkId()===0||(l<0?this.terminal.wasmTerm.getScrollbackHyperlinkUri(t,m):this.terminal.wasmTerm.getHyperlinkUri(l,m))!==u)break;d=m}for(let m=n;m<=d;m++)s.add(m);const p={start:{x:n,y:t},end:{x:d,y:t}};e.push({text:u,range:p,activate:m=>{(m.ctrlKey||m.metaKey)&&window.open(u,"_blank","noopener,noreferrer")}})}}i(e.length>0?e:void 0)}findLinkRange(t,i,e){const s=this.terminal.buffer.active;let r=i,n=e;for(;n>0;){const l=s.getLine(r);if(!l)break;const u=l.getCell(n-1);if(!u||u.getHyperlinkId()!==t)break;n--}if(n===0&&r>0){let l=r-1;for(;l>=0;){const u=s.getLine(l);if(!u||u.length===0)break;const d=u.getCell(u.length-1);if(!d||d.getHyperlinkId()!==t)break;r=l,n=0;for(let p=u.length-1;p>=0;p--){const m=u.getCell(p);if(!m||m.getHyperlinkId()!==t){n=p+1;break}}if(n===0)l--;else break}}let o=i,h=e;const c=s.getLine(o);if(c){for(;h<c.length-1;){const l=c.getCell(h+1);if(!l||l.getHyperlinkId()!==t)break;h++}if(h===c.length-1){let l=o+1;const u=s.length;for(;l<u;){const d=s.getLine(l);if(!d||d.length===0)break;const p=d.getCell(0);if(!p||p.getHyperlinkId()!==t)break;o=l,h=0;for(let m=0;m<d.length;m++){const g=d.getCell(m);if(!g)break;if(g.getHyperlinkId()!==t){h=m-1;break}h=m}if(h===d.length-1)l++;else break}}}return{start:{x:n,y:r},end:{x:h,y:o}}}dispose(){}}const K=class E{constructor(t){this.terminal=t}provideLinks(t,i){const e=[],s=this.terminal.buffer.active.getLine(t);if(!s){i(void 0);return}const r=this.lineToText(s);E.URL_REGEX.lastIndex=0;let n=E.URL_REGEX.exec(r);for(;n!==null;){let o=n[0];const h=n.index;let c=n.index+o.length-1;const l=o.replace(E.TRAILING_PUNCTUATION,"");for(l.length<o.length&&(o=l,c=h+o.length-1);o.endsWith(")");){const u=o.split("(").length-1;if(o.split(")").length-1>u)o=o.slice(0,-1),c--;else break}o.length>8&&e.push({text:o,range:{start:{x:h,y:t},end:{x:c,y:t}},activate:u=>{(u.ctrlKey||u.metaKey)&&window.open(o,"_blank","noopener,noreferrer")}}),n=E.URL_REGEX.exec(r)}i(e.length>0?e:void 0)}lineToText(t){const i=[];for(let e=0;e<t.length;e++){const s=t.getCell(e);if(!s){i.push(" ");continue}const r=s.getCodepoint();r===0||r<32?i.push(" "):i.push(String.fromCodePoint(r))}return i.join("")}dispose(){}};K.URL_REGEX=/(?:https?:\/\/|mailto:|ftp:\/\/|ssh:\/\/|git:\/\/|tel:|magnet:|gemini:\/\/|gopher:\/\/|news:)[\w\-.~:\/?#@!$&*+,;=%()]+/gi;K.TRAILING_PUNCTUATION=/[.,;!?\]]+$/;let N=K;const $=[773,781,782,784,786,829,830,831,838,842,843,844,848,849,850,855,859,867,868,869,870,871,872,873,874,875,876,877,878,879,1155,1156,1157,1158,1159,1426,1427,1428,1429,1431,1432,1433,1436,1437,1438,1439,1440,1441,1448,1449,1451,1452,1455,1476,1552,1553,1554,1555,1556,1557,1558,1559,1623,1624,1625,1626,1627,1629,1630,1750,1751,1752,1753,1754,1755,1756,1759,1760,1761,1762,1764,1767,1768,1771,1772,1840,1842,1843,1845,1846,1850,1853,1855,1856,1857,1859,1861,1863,1865,1866,2027,2028,2029,2030,2031,2032,2033,2035,2070,2071,2072,2073,2075,2076,2077,2078,2079,2080,2081,2082,2083,2085,2086,2087,2089,2090,2091,2092,2093,2385,2387,2388,3970,3971,3974,3975,4957,4958,4959,6109,6458,6679,6773,6774,6775,6776,6777,6778,6779,6780,7019,7021,7022,7023,7024,7025,7026,7027,7376,7377,7378,7386,7387,7392,7616,7617,7619,7620,7621,7622,7623,7624,7625,7627,7628,7633,7634,7635,7636,7637,7638,7639,7640,7641,7642,7643,7644,7645,7646,7647,7648,7649,7650,7651,7652,7653,7654,7678,8400,8401,8404,8405,8406,8407,8411,8412,8417,8423,8425,8432,11503,11504,11505,11744,11745,11746,11747,11748,11749,11750,11751,11752,11753,11754,11755,11756,11757,11758,11759,11760,11761,11762,11763,11764,11765,11766,11767,11768,11769,11770,11771,11772,11773,11774,11775,42607,42620,42621,42736,42737,43232,43233,43234,43235,43236,43237,43238,43239,43240,43241,43242,43243,43244,43245,43246,43247,43248,43249,43696,43698,43699,43703,43704,43710,43711,43713,65056,65057,65058,65059,65060,65061,65062,68111,68152,119173,119174,119175,119176,119177,119210,119211,119212,119213,119362,119363,119364],Q=new Map($.map((v,t)=>[v,t]));function D(v){return Q.get(v)??-1}const X=1109742,T={foreground:"#d4d4d4",background:"#1e1e1e",cursor:"#ffffff",cursorAccent:"#1e1e1e",selectionBackground:"#d4d4d4",selectionForeground:"#1e1e1e",black:"#000000",red:"#cd3131",green:"#0dbc79",yellow:"#e5e510",blue:"#2472c8",magenta:"#bc3fbc",cyan:"#11a8cd",white:"#e5e5e5",brightBlack:"#666666",brightRed:"#f14c4c",brightGreen:"#23d18b",brightYellow:"#f5f543",brightBlue:"#3b8eea",brightMagenta:"#d670d6",brightCyan:"#29b8db",brightWhite:"#ffffff"};function _(v,t){return v.width===t.width&&v.height===t.height&&v.format===t.format&&v.dataPtr===t.data.byteOffset&&v.dataLen===t.data.length}class U{constructor(t,i={}){this.cursorVisible=!0,this.lastCursorPosition={x:0,y:0},this.onRequestRender=null,this.lastViewportY=0,this.currentBuffer=null,this.kittyImageCache=new Map,this.kittyVirtualPlacements=new Map,this.currentDirectPlacements=[],this.lastKittyDirectSigs=new Map,this.kittyDamagedRows=new Set,this.currentRenderBuffer=null,this.currentKittyGraphics=null,this.currentSelectionCoords=null,this.hoveredHyperlinkId=0,this.previousHoveredHyperlinkId=0,this.hoveredLinkRange=null,this.previousHoveredLinkRange=null,this.canvas=t;const e=t.getContext("2d",{alpha:!0});if(!e)throw new Error("Failed to get 2D rendering context");this.ctx=e,this.fontSize=i.fontSize??15,this.fontFamily=i.fontFamily??"monospace",this.cursorStyle=i.cursorStyle??"block",this.cursorBlink=i.cursorBlink??!1,this.theme={...T,...i.theme},this.devicePixelRatio=i.devicePixelRatio??window.devicePixelRatio??1,this.palette=[this.theme.black,this.theme.red,this.theme.green,this.theme.yellow,this.theme.blue,this.theme.magenta,this.theme.cyan,this.theme.white,this.theme.brightBlack,this.theme.brightRed,this.theme.brightGreen,this.theme.brightYellow,this.theme.brightBlue,this.theme.brightMagenta,this.theme.brightCyan,this.theme.brightWhite],this.metrics=this.measureFont(),this.cursorBlink&&this.startCursorBlink()}buildFontString(t=""){const i=this.fontFamily.split(",").map(e=>{const s=e.trim();return s.startsWith('"')||s.startsWith("'")||!s.includes(" ")?s:`"${s}"`}).join(", ");return`${t}${this.fontSize}px ${i}`}measureFont(){const i=document.createElement("canvas").getContext("2d");i.font=this.buildFontString();const e=i.measureText("M"),s=e.fontBoundingBoxAscent||e.actualBoundingBoxAscent||this.fontSize*.8,r=e.fontBoundingBoxDescent||e.actualBoundingBoxDescent||this.fontSize*.2,n=this.devicePixelRatio,o=Math.ceil(e.width*n)/n,h=Math.ceil((s+r)*n)/n,c=Math.ceil(s*n)/n;return{width:o,height:h,baseline:c}}remeasureFont(){this.metrics=this.measureFont()}rgbToCSS(t,i,e){return`rgb(${t}, ${i}, ${e})`}resize(t,i){const e=t*this.metrics.width,s=i*this.metrics.height;this.canvas.style.width=`${e}px`,this.canvas.style.height=`${s}px`,this.canvas.width=e*this.devicePixelRatio,this.canvas.height=s*this.devicePixelRatio,this.ctx.scale(this.devicePixelRatio,this.devicePixelRatio),this.ctx.textBaseline="alphabetic",this.ctx.textAlign="left",this.ctx.fillStyle=this.theme.background,this.ctx.fillRect(0,0,e,s)}render(t,i=!1,e=0,s,r=1){var y;this.currentBuffer=t,this.currentRenderBuffer=t;const n=t.getCursor(),o=t.getDimensions();this.precomputeKittyState(t,o.rows);const h=s?s.getScrollbackLength():0;(y=t.needsFullRedraw)!=null&&y.call(t)&&(i=!0),(this.canvas.width!==o.cols*this.metrics.width*this.devicePixelRatio||this.canvas.height!==o.rows*this.metrics.height*this.devicePixelRatio)&&(this.resize(o.cols,o.rows),i=!0),e!==this.lastViewportY&&(i=!0,this.lastViewportY=e);const l=n.x!==this.lastCursorPosition.x||n.y!==this.lastCursorPosition.y;if(l||this.cursorBlink){if(!i&&!t.isRowDirty(n.y)){const f=t.getLine(n.y);f&&this.renderLine(f,n.y,o.cols)}if(l&&!i){const f=t.getLine(this.lastCursorPosition.y);f&&this.renderLine(f,this.lastCursorPosition.y,o.cols)}}const u=this.selectionManager&&this.selectionManager.hasSelection(),d=new Set;if(this.currentSelectionCoords=u?this.selectionManager.getSelectionCoords():null,this.currentSelectionCoords){const f=this.currentSelectionCoords;for(let b=f.startRow;b<=f.endRow;b++)d.add(b)}if(this.selectionManager){const f=this.selectionManager.getDirtySelectionRows();if(f.size>0){for(const b of f)d.add(b);this.selectionManager.clearDirtySelectionRows()}}const p=new Set,m=this.hoveredHyperlinkId!==this.previousHoveredHyperlinkId,g=JSON.stringify(this.hoveredLinkRange)!==JSON.stringify(this.previousHoveredLinkRange);if(m){for(let f=0;f<o.rows;f++){let b=null;if(e>0)if(f<e&&s){const S=h-Math.floor(e)+f;b=s.getScrollbackLine(S)}else{const S=f-Math.floor(e);b=t.getLine(S)}else b=t.getLine(f);if(b){for(const S of b)if(S.hyperlink_id===this.hoveredHyperlinkId||S.hyperlink_id===this.previousHoveredHyperlinkId){p.add(f);break}}}this.previousHoveredHyperlinkId=this.hoveredHyperlinkId}if(g){if(this.previousHoveredLinkRange)for(let f=this.previousHoveredLinkRange.startY;f<=this.previousHoveredLinkRange.endY;f++)p.add(f);if(this.hoveredLinkRange)for(let f=this.hoveredLinkRange.startY;f<=this.hoveredLinkRange.endY;f++)p.add(f);this.previousHoveredLinkRange=this.hoveredLinkRange}let w=!1;const C=new Set;for(let f=0;f<o.rows;f++)(e>0?!0:i||t.isRowDirty(f)||d.has(f)||p.has(f)||this.kittyDamagedRows.has(f))&&(C.add(f),f>0&&C.add(f-1),f<o.rows-1&&C.add(f+1));for(let f=0;f<o.rows;f++){if(!C.has(f))continue;w=!0;let b=null;if(e>0)if(f<e&&s){const S=h-Math.floor(e)+f;b=s.getScrollbackLine(S)}else{const S=e>0?f-Math.floor(e):f;b=t.getLine(S)}else b=t.getLine(f);b&&this.renderLine(b,f,o.cols)}if(this.currentDirectPlacements.length>0&&w&&this.renderKittyImages(),e===0&&n.visible&&this.cursorVisible){const f=n.style??this.cursorStyle;this.renderCursor(n.x,n.y,f)}s&&r>0&&this.renderScrollbar(e,h,o.rows,r),this.lastCursorPosition={x:n.x,y:n.y},t.clearDirty()}renderLine(t,i,e){const s=i*this.metrics.height,r=e*this.metrics.width;this.ctx.clearRect(0,s,r,this.metrics.height),this.ctx.fillStyle=this.theme.background,this.ctx.fillRect(0,s,r,this.metrics.height);for(let n=0;n<t.length;n++){const o=t[n];o.width!==0&&this.renderCellBackground(o,n,i)}for(let n=0;n<t.length;n++){const o=t[n];o.width!==0&&this.renderCellText(o,n,i)}}renderCellBackground(t,i,e){const s=i*this.metrics.width,r=e*this.metrics.height,n=this.metrics.width*t.width;if(this.isInSelection(i,e)){this.ctx.fillStyle=this.theme.selectionBackground,this.ctx.fillRect(s,r,n,this.metrics.height);return}let h=t.bg_r,c=t.bg_g,l=t.bg_b;t.flags&a.CellFlags.INVERSE&&(h=t.fg_r,c=t.fg_g,l=t.fg_b),(t.flags&a.CellFlags.INVERSE?t.fgIsDefault:t.bgIsDefault)||(this.ctx.fillStyle=this.rgbToCSS(h,c,l),this.ctx.fillRect(s,r,n,this.metrics.height))}renderCellText(t,i,e,s){var C;const r=i*this.metrics.width,n=e*this.metrics.height,o=this.metrics.width*t.width;if(t.codepoint===X&&this.renderPlaceholderCell(t,i,e)||t.flags&a.CellFlags.INVISIBLE)return;const h=this.isInSelection(i,e);let c="";t.flags&a.CellFlags.ITALIC&&(c+="italic "),t.flags&a.CellFlags.BOLD&&(c+="bold "),this.ctx.font=this.buildFontString(c);let l=t.fg_r,u=t.fg_g,d=t.fg_b;if(t.flags&a.CellFlags.INVERSE&&(l=t.bg_r,u=t.bg_g,d=t.bg_b),s)this.ctx.fillStyle=s;else if(h)this.ctx.fillStyle=this.theme.selectionForeground;else{const y=t.flags&a.CellFlags.INVERSE?t.bgIsDefault:t.fgIsDefault;this.ctx.fillStyle=y?this.theme.foreground:this.rgbToCSS(l,u,d)}t.flags&a.CellFlags.FAINT&&(this.ctx.globalAlpha=.5);const p=r,m=n+this.metrics.baseline;let g;t.grapheme_len>0&&((C=this.currentBuffer)!=null&&C.getGraphemeString)?g=this.currentBuffer.getGraphemeString(e,i):g=String.fromCodePoint(t.codepoint||32);const w=t.codepoint||32;if(this.renderBlockChar(w,r,n,o)||this.renderPowerlineGlyph(w,r,n,o)||this.ctx.fillText(g,p,m),t.flags&a.CellFlags.FAINT&&(this.ctx.globalAlpha=1),t.flags&a.CellFlags.UNDERLINE){const y=n+this.metrics.baseline+2;this.ctx.strokeStyle=this.ctx.fillStyle,this.ctx.lineWidth=1,this.ctx.beginPath(),this.ctx.moveTo(r,y),this.ctx.lineTo(r+o,y),this.ctx.stroke()}if(t.flags&a.CellFlags.STRIKETHROUGH){const y=n+this.metrics.height/2;this.ctx.strokeStyle=this.ctx.fillStyle,this.ctx.lineWidth=1,this.ctx.beginPath(),this.ctx.moveTo(r,y),this.ctx.lineTo(r+o,y),this.ctx.stroke()}if(t.hyperlink_id>0&&t.hyperlink_id===this.hoveredHyperlinkId){const f=n+this.metrics.baseline+2;this.ctx.strokeStyle="#4A90E2",this.ctx.lineWidth=1,this.ctx.beginPath(),this.ctx.moveTo(r,f),this.ctx.lineTo(r+o,f),this.ctx.stroke()}if(this.hoveredLinkRange){const y=this.hoveredLinkRange;if(e===y.startY&&i>=y.startX&&(e<y.endY||i<=y.endX)||e>y.startY&&e<y.endY||e===y.endY&&i<=y.endX&&(e>y.startY||i>=y.startX)){const b=n+this.metrics.baseline+2;this.ctx.strokeStyle="#4A90E2",this.ctx.lineWidth=1,this.ctx.beginPath(),this.ctx.moveTo(r,b),this.ctx.lineTo(r+o,b),this.ctx.stroke()}}}renderBlockChar(t,i,e,s){const r=this.metrics.height;switch(t){case 9600:return this.ctx.fillRect(i,e,s,r/2),!0;case 9601:return this.ctx.fillRect(i,e+r*7/8,s,r/8),!0;case 9602:return this.ctx.fillRect(i,e+r*3/4,s,r/4),!0;case 9603:return this.ctx.fillRect(i,e+r*5/8,s,r*3/8),!0;case 9604:return this.ctx.fillRect(i,e+r/2,s,r/2),!0;case 9605:return this.ctx.fillRect(i,e+r*3/8,s,r*5/8),!0;case 9606:return this.ctx.fillRect(i,e+r/4,s,r*3/4),!0;case 9607:return this.ctx.fillRect(i,e+r/8,s,r*7/8),!0;case 9608:return this.ctx.fillRect(i,e,s,r),!0;case 9609:return this.ctx.fillRect(i,e,s*7/8,r),!0;case 9610:return this.ctx.fillRect(i,e,s*3/4,r),!0;case 9611:return this.ctx.fillRect(i,e,s*5/8,r),!0;case 9612:return this.ctx.fillRect(i,e,s/2,r),!0;case 9613:return this.ctx.fillRect(i,e,s*3/8,r),!0;case 9614:return this.ctx.fillRect(i,e,s/4,r),!0;case 9615:return this.ctx.fillRect(i,e,s/8,r),!0;case 9616:return this.ctx.fillRect(i+s/2,e,s/2,r),!0;case 9620:return this.ctx.fillRect(i,e,s,r/8),!0;case 9621:return this.ctx.fillRect(i+s*7/8,e,s/8,r),!0;default:return!1}}renderPowerlineGlyph(t,i,e,s){const r=this.metrics.height,n=this.ctx;switch(t){case 57520:return n.beginPath(),n.moveTo(i,e),n.lineTo(i+s,e+r/2),n.lineTo(i,e+r),n.closePath(),n.fill(),!0;case 57521:return n.beginPath(),n.moveTo(i,e),n.lineTo(i+s,e+r/2),n.lineTo(i,e+r),n.strokeStyle=n.fillStyle,n.lineWidth=1,n.stroke(),!0;case 57522:return n.beginPath(),n.moveTo(i+s,e),n.lineTo(i,e+r/2),n.lineTo(i+s,e+r),n.closePath(),n.fill(),!0;case 57523:return n.beginPath(),n.moveTo(i+s,e),n.lineTo(i,e+r/2),n.lineTo(i+s,e+r),n.strokeStyle=n.fillStyle,n.lineWidth=1,n.stroke(),!0;case 57524:return n.beginPath(),n.moveTo(i,e),n.ellipse(i,e+r/2,s,r/2,0,-Math.PI/2,Math.PI/2,!1),n.closePath(),n.fill(),!0;case 57525:return n.beginPath(),n.moveTo(i,e),n.ellipse(i,e+r/2,s,r/2,0,-Math.PI/2,Math.PI/2,!1),n.strokeStyle=n.fillStyle,n.lineWidth=1,n.stroke(),!0;case 57526:return n.beginPath(),n.moveTo(i+s,e),n.ellipse(i+s,e+r/2,s,r/2,0,-Math.PI/2,Math.PI/2,!0),n.closePath(),n.fill(),!0;case 57527:return n.beginPath(),n.moveTo(i+s,e),n.ellipse(i+s,e+r/2,s,r/2,0,-Math.PI/2,Math.PI/2,!0),n.strokeStyle=n.fillStyle,n.lineWidth=1,n.stroke(),!0;default:return!1}}precomputeKittyState(t,i){var n;this.kittyVirtualPlacements.clear(),this.currentDirectPlacements=[],this.kittyDamagedRows.clear(),this.currentKittyGraphics=null;const e=new Map,s=this.metrics.height,r=(o,h)=>{const c=Math.max(0,Math.floor(o)),l=Math.min(i,Math.ceil(o+h/s));for(let u=c;u<l;u++)this.kittyDamagedRows.add(u)};if(t.getKittyGraphics&&t.iterPlacements){const o=t.getKittyGraphics();if(o!==null){this.currentKittyGraphics=o;for(const h of t.iterPlacements(o,!1)){if(h.isVirtual){this.kittyVirtualPlacements.set(h.imageId,h);continue}this.currentDirectPlacements.push(h);const c=(n=t.getKittyImagePixels)==null?void 0:n.call(t,o,h.imageId),l={viewportCol:h.viewportCol,viewportRow:h.viewportRow,pixelWidth:h.pixelWidth,pixelHeight:h.pixelHeight,sourceX:h.sourceX,sourceY:h.sourceY,sourceWidth:h.sourceWidth,sourceHeight:h.sourceHeight,imgWidth:(c==null?void 0:c.width)??0,imgHeight:(c==null?void 0:c.height)??0,imgFormat:(c==null?void 0:c.format)??0,dataPtr:(c==null?void 0:c.data.byteOffset)??0,dataLen:(c==null?void 0:c.data.length)??0};e.set(h.imageId,l);const u=this.lastKittyDirectSigs.get(h.imageId);(!u||u.viewportCol!==l.viewportCol||u.viewportRow!==l.viewportRow||u.pixelWidth!==l.pixelWidth||u.pixelHeight!==l.pixelHeight||u.sourceX!==l.sourceX||u.sourceY!==l.sourceY||u.sourceWidth!==l.sourceWidth||u.sourceHeight!==l.sourceHeight||u.imgWidth!==l.imgWidth||u.imgHeight!==l.imgHeight||u.imgFormat!==l.imgFormat||u.dataPtr!==l.dataPtr||u.dataLen!==l.dataLen)&&(r(l.viewportRow,l.pixelHeight),u&&r(u.viewportRow,u.pixelHeight))}}}for(const[o,h]of this.lastKittyDirectSigs)e.has(o)||r(h.viewportRow,h.pixelHeight);this.lastKittyDirectSigs=e}getOrDecodeKittyImage(t,i,e){var o;const s=this.kittyImageCache.get(e),r=(o=t.getKittyImagePixels)==null?void 0:o.call(t,i,e);if(!r)return(s==null?void 0:s.canvas)??null;if(s&&_(s,r))return s.canvas;const n=this.decodeKittyImageToCanvas(r);return n?(this.kittyImageCache.set(e,{canvas:n,width:r.width,height:r.height,format:r.format,dataPtr:r.data.byteOffset,dataLen:r.data.length}),n):null}renderBlockElement(t,i,e,s){if(t<9600||t>9631)return!1;const r=s,n=this.metrics.height;if(t===9600)return this.ctx.fillRect(i,e,r,Math.round(n/2)),!0;if(t>=9601&&t<=9608){const g=t-9600,w=Math.round(n*g/8);return this.ctx.fillRect(i,e+n-w,r,w),!0}if(t>=9609&&t<=9615){const g=9616-t,w=Math.round(r*g/8);return this.ctx.fillRect(i,e,w,n),!0}if(t===9616){const g=Math.round(r/2);return this.ctx.fillRect(i+g,e,r-g,n),!0}if(t>=9617&&t<=9619){const g=[.25,.5,.75][t-9617],w=this.ctx.globalAlpha;return this.ctx.globalAlpha=w*g,this.ctx.fillRect(i,e,r,n),this.ctx.globalAlpha=w,!0}if(t===9620)return this.ctx.fillRect(i,e,r,Math.round(n/8)),!0;if(t===9621){const g=Math.round(r*7/8);return this.ctx.fillRect(i+g,e,r-g,n),!0}const o=8,h=4,c=2,l=1,d={9622:c,9623:l,9624:o,9625:o|c|l,9626:o|l,9627:o|h|c,9628:o|h|l,9629:h,9630:h|c,9631:h|c|l}[t];if(d===void 0)return!1;const p=Math.round(r/2),m=Math.round(n/2);return d&o&&this.ctx.fillRect(i,e,p,m),d&h&&this.ctx.fillRect(i+p,e,r-p,m),d&c&&this.ctx.fillRect(i,e+m,p,n-m),d&l&&this.ctx.fillRect(i+p,e+m,r-p,n-m),!0}renderPlaceholderCell(t,i,e){var S;const s=this.currentRenderBuffer,r=this.currentKittyGraphics;if(!s||r===null||!s.getGrapheme)return!1;const n=s.getGrapheme(e,i);if(!n||n.length<3)return!1;const o=D(n[1]),h=D(n[2]);if(o<0||h<0)return!1;const c=t.fg_r<<16|t.fg_g<<8|t.fg_b;let l=c;if(n.length>=4){const k=D(n[3]);k>=0&&(l=k<<24|c)}const u=this.kittyVirtualPlacements.get(l);if(!u)return!1;const d=(S=s.getKittyImagePixels)==null?void 0:S.call(s,r,l);if(!d)return!1;const p=this.getOrDecodeKittyImage(s,r,l);if(!p)return!1;const m=d.width/u.gridCols,g=d.height/u.gridRows,w=h*m,C=o*g,y=i*this.metrics.width,f=e*this.metrics.height,b=this.ctx.imageSmoothingEnabled;return this.ctx.imageSmoothingEnabled=!1,this.ctx.drawImage(p,w,C,m,g,y,f,this.metrics.width,this.metrics.height),this.ctx.imageSmoothingEnabled=b,!0}renderKittyImages(){const t=this.currentRenderBuffer,i=this.currentKittyGraphics;if(!(!t||i===null||!t.getKittyImagePixels))for(const e of this.currentDirectPlacements){let s=this.kittyImageCache.get(e.imageId);const r=t.getKittyImagePixels(i,e.imageId);if(r){if(!s||!_(s,r)){const n=this.decodeKittyImageToCanvas(r);if(!n)continue;s={canvas:n,width:r.width,height:r.height,format:r.format,dataPtr:r.data.byteOffset,dataLen:r.data.length},this.kittyImageCache.set(e.imageId,s)}this.ctx.drawImage(s.canvas,e.sourceX,e.sourceY,e.sourceWidth,e.sourceHeight,e.viewportCol*this.metrics.width,e.viewportRow*this.metrics.height,e.pixelWidth,e.pixelHeight)}}}decodeKittyImageToCanvas(t){const{width:i,height:e,format:s,data:r}=t;if(i===0||e===0)return null;const n=new Uint8ClampedArray(new ArrayBuffer(i*e*4));switch(s){case a.KittyImageFormat.RGBA:n.set(r);break;case a.KittyImageFormat.RGB:for(let c=0,l=0;c<r.length;c+=3,l+=4)n[l]=r[c],n[l+1]=r[c+1],n[l+2]=r[c+2],n[l+3]=255;break;case a.KittyImageFormat.GRAY:for(let c=0,l=0;c<r.length;c++,l+=4){const u=r[c];n[l]=u,n[l+1]=u,n[l+2]=u,n[l+3]=255}break;case a.KittyImageFormat.GRAY_ALPHA:for(let c=0,l=0;c<r.length;c+=2,l+=4){const u=r[c];n[l]=u,n[l+1]=u,n[l+2]=u,n[l+3]=r[c+1]}break;default:return null}const o=document.createElement("canvas");o.width=i,o.height=e;const h=o.getContext("2d");return h?(h.putImageData(new ImageData(n,i,e),0,0),o):null}renderCursor(t,i,e){var o;const s=t*this.metrics.width,r=i*this.metrics.height,n=e??this.cursorStyle;switch(this.ctx.fillStyle=this.theme.cursor,n){case"block":this.ctx.fillRect(s,r,this.metrics.width,this.metrics.height);{const l=(o=this.currentBuffer)==null?void 0:o.getLine(i);l!=null&&l[t]&&(this.ctx.save(),this.ctx.beginPath(),this.ctx.rect(s,r,this.metrics.width,this.metrics.height),this.ctx.clip(),this.renderCellText(l[t],t,i,this.theme.cursorAccent),this.ctx.restore())}break;case"underline":const h=Math.max(2,Math.floor(this.metrics.height*.15));this.ctx.fillRect(s,r+this.metrics.height-h,this.metrics.width,h);break;case"bar":const c=Math.max(2,Math.floor(this.metrics.width*.15));this.ctx.fillRect(s,r,c,this.metrics.height);break}}setOnRequestRender(t){this.onRequestRender=t}startCursorBlink(){this.cursorBlinkInterval=window.setInterval(()=>{var t;this.cursorVisible=!this.cursorVisible,(t=this.onRequestRender)==null||t.call(this)},530)}stopCursorBlink(){this.cursorBlinkInterval!==void 0&&(clearInterval(this.cursorBlinkInterval),this.cursorBlinkInterval=void 0),this.cursorVisible=!0}setTheme(t){this.theme={...T,...t},this.palette=[this.theme.black,this.theme.red,this.theme.green,this.theme.yellow,this.theme.blue,this.theme.magenta,this.theme.cyan,this.theme.white,this.theme.brightBlack,this.theme.brightRed,this.theme.brightGreen,this.theme.brightYellow,this.theme.brightBlue,this.theme.brightMagenta,this.theme.brightCyan,this.theme.brightWhite]}setFontSize(t){this.fontSize=t,this.metrics=this.measureFont()}setFontFamily(t){this.fontFamily=t,this.metrics=this.measureFont()}setCursorStyle(t){this.cursorStyle=t}setCursorBlink(t){t&&!this.cursorBlink?(this.cursorBlink=!0,this.startCursorBlink()):!t&&this.cursorBlink&&(this.cursorBlink=!1,this.stopCursorBlink())}renderScrollbar(t,i,e,s=1){const r=this.ctx,n=this.canvas.height/this.devicePixelRatio,o=this.canvas.width/this.devicePixelRatio,h=8,c=o-h-4,l=4,u=n-l*2;if(r.clearRect(c-2,0,h+6,n),r.fillStyle=this.theme.background,r.fillRect(c-2,0,h+6,n),s<=0||i===0)return;const d=i+e,p=Math.max(20,e/d*u),m=t/i,g=l+(u-p)*(1-m);r.fillStyle=`rgba(128, 128, 128, ${.1*s})`,r.fillRect(c,l,h,u);const C=t>0?.5:.3;r.fillStyle=`rgba(128, 128, 128, ${C*s})`,r.fillRect(c,g,h,p)}getMetrics(){return{...this.metrics}}getCanvas(){return this.canvas}setSelectionManager(t){this.selectionManager=t}isInSelection(t,i){const e=this.currentSelectionCoords;if(!e)return!1;const{startCol:s,startRow:r,endCol:n,endRow:o}=e;return r===o?i===r&&t>=s&&t<=n:i===r?t>=s:i===o?t<=n:i>r&&i<o}setHoveredHyperlinkId(t){var i;this.hoveredHyperlinkId!==t&&(this.hoveredHyperlinkId=t,(i=this.onRequestRender)==null||i.call(this))}setHoveredLinkRange(t){var i;this.hoveredLinkRange!==t&&(this.hoveredLinkRange=t,(i=this.onRequestRender)==null||i.call(this))}get charWidth(){return this.metrics.width}get charHeight(){return this.metrics.height}clear(){this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.ctx.fillStyle=this.theme.background,this.ctx.fillRect(0,0,this.canvas.width,this.canvas.height)}dispose(){this.stopCursorBlink()}}const M=class L{constructor(t,i,e,s){this.selectionStart=null,this.selectionEnd=null,this.isSelecting=!1,this.mouseDownX=0,this.mouseDownY=0,this.dragThresholdMet=!1,this.mouseDownTarget=null,this.dirtySelectionRows=new Set,this.selectionChangedEmitter=new a.EventEmitter,this.boundMouseUpHandler=null,this.boundContextMenuHandler=null,this.boundClickHandler=null,this.boundDocumentMouseMoveHandler=null,this.autoScrollInterval=null,this.autoScrollDirection=0,this.terminal=t,this.renderer=i,this.wasmTerm=e,this.textarea=s,this.attachEventListeners()}getViewportY(){const t=typeof this.terminal.getViewportY=="function"?this.terminal.getViewportY():this.terminal.viewportY||0;return Math.max(0,Math.floor(t))}viewportRowToAbsolute(t){const i=this.wasmTerm.getScrollbackLength(),e=this.getViewportY();return i+t-e}absoluteRowToViewport(t){const i=this.wasmTerm.getScrollbackLength(),e=this.getViewportY();return t-i+e}getSelection(){if(!this.selectionStart||!this.selectionEnd)return"";let{col:t,absoluteRow:i}=this.selectionStart,{col:e,absoluteRow:s}=this.selectionEnd;(i>s||i===s&&t>e)&&([t,e]=[e,t],[i,s]=[s,i]);const r=this.wasmTerm.getScrollbackLength();let n="";for(let o=i;o<=s;o++){let h=null;if(o<r)h=this.wasmTerm.getScrollbackLine(o);else{const p=o-r;h=this.wasmTerm.getLine(p)}if(!h)continue;let c=-1;const l=o===i?t:0,u=o===s?e:h.length-1;let d="";for(let p=l;p<=u;p++){const m=h[p];if(m&&m.codepoint!==0){let g;if(m.grapheme_len>0)if(o<r)g=this.wasmTerm.getScrollbackGraphemeString(o,p);else{const w=o-r;g=this.wasmTerm.getGraphemeString(w,p)}else g=String.fromCodePoint(m.codepoint);d+=g,g.trim()&&(c=d.length)}else(!m||m.width!==0)&&(d+=" ")}c>=0?d=d.substring(0,c):d="",n+=d,o<s&&(n+=`
|
|
2
|
+
`)}return n}hasSelection(){return!(!this.selectionStart||!this.selectionEnd||this.isSelecting&&!this.dragThresholdMet)}copySelection(){if(!this.hasSelection())return!1;const t=this.getSelection();return t?(this.copyToClipboard(t),!0):!1}clearSelection(){if(!this.hasSelection())return;const t=this.normalizeSelection();if(t)for(let i=t.startRow;i<=t.endRow;i++)this.dirtySelectionRows.add(i);this.selectionStart=null,this.selectionEnd=null,this.isSelecting=!1,this.requestRender()}selectAll(){const t=this.wasmTerm.getDimensions(),i=this.getViewportY();this.selectionStart={col:0,absoluteRow:i},this.selectionEnd={col:t.cols-1,absoluteRow:i+t.rows-1},this.requestRender(),this.selectionChangedEmitter.fire()}select(t,i,e){const s=this.wasmTerm.getDimensions();i=Math.max(0,Math.min(i,s.rows-1)),t=Math.max(0,Math.min(t,s.cols-1));let r=i,n=t+e-1;for(;n>=s.cols;)n-=s.cols,r++;r=Math.min(r,s.rows-1);const o=this.getViewportY();this.selectionStart={col:t,absoluteRow:o+i},this.selectionEnd={col:n,absoluteRow:o+r},this.requestRender(),this.selectionChangedEmitter.fire()}selectLines(t,i){const e=this.wasmTerm.getDimensions();t=Math.max(0,Math.min(t,e.rows-1)),i=Math.max(0,Math.min(i,e.rows-1)),t>i&&([t,i]=[i,t]),this.selectionStart={col:0,absoluteRow:this.viewportRowToAbsolute(t)},this.selectionEnd={col:e.cols-1,absoluteRow:this.viewportRowToAbsolute(i)},this.requestRender(),this.selectionChangedEmitter.fire()}getSelectionPosition(){const t=this.normalizeSelection();if(t)return{start:{x:t.startCol,y:t.startRow},end:{x:t.endCol,y:t.endRow}}}deselect(){this.clearSelection(),this.selectionChangedEmitter.fire()}focus(){const t=this.renderer.getCanvas();t.parentElement&&t.parentElement.focus()}getSelectionCoords(){return this.normalizeSelection()}getDirtySelectionRows(){return this.dirtySelectionRows}clearDirtySelectionRows(){this.dirtySelectionRows.clear()}get onSelectionChange(){return this.selectionChangedEmitter.event}dispose(){this.selectionChangedEmitter.dispose(),this.stopAutoScroll(),this.boundMouseUpHandler&&(document.removeEventListener("mouseup",this.boundMouseUpHandler),this.boundMouseUpHandler=null),this.boundDocumentMouseMoveHandler&&(document.removeEventListener("mousemove",this.boundDocumentMouseMoveHandler),this.boundDocumentMouseMoveHandler=null),this.boundContextMenuHandler&&(this.renderer.getCanvas().removeEventListener("contextmenu",this.boundContextMenuHandler),this.boundContextMenuHandler=null),this.boundClickHandler&&(document.removeEventListener("click",this.boundClickHandler),this.boundClickHandler=null)}attachEventListeners(){const t=this.renderer.getCanvas();t.addEventListener("mousedown",i=>{if(i.button===0){t.parentElement&&t.parentElement.focus();const e=this.pixelToCell(i.offsetX,i.offsetY);this.hasSelection()&&this.clearSelection();const r=this.viewportRowToAbsolute(e.row);this.selectionStart={col:e.col,absoluteRow:r},this.selectionEnd={col:e.col,absoluteRow:r},this.isSelecting=!0,this.mouseDownX=i.offsetX,this.mouseDownY=i.offsetY,this.dragThresholdMet=!1}}),t.addEventListener("mousemove",i=>{if(this.isSelecting){if(!this.dragThresholdMet){const r=i.offsetX-this.mouseDownX,n=i.offsetY-this.mouseDownY,o=this.renderer.getMetrics().width*.5;if(r*r+n*n<o*o)return;this.dragThresholdMet=!0}this.markCurrentSelectionDirty();const e=this.pixelToCell(i.offsetX,i.offsetY),s=this.viewportRowToAbsolute(e.row);this.selectionEnd={col:e.col,absoluteRow:s},this.requestRender(),this.updateAutoScroll(i.offsetY,t.clientHeight)}}),t.addEventListener("mouseleave",i=>{if(this.isSelecting){const e=t.getBoundingClientRect();i.clientY<e.top?this.startAutoScroll(-1):i.clientY>e.bottom&&this.startAutoScroll(1)}}),t.addEventListener("mouseenter",()=>{this.isSelecting&&this.stopAutoScroll()}),this.boundDocumentMouseMoveHandler=i=>{if(this.isSelecting){if(!this.dragThresholdMet){const h=i.clientX-(t.getBoundingClientRect().left+this.mouseDownX),c=i.clientY-(t.getBoundingClientRect().top+this.mouseDownY),l=this.renderer.getMetrics().width*.5;if(h*h+c*c<l*l)return;this.dragThresholdMet=!0}const e=t.getBoundingClientRect(),s=Math.max(e.left,Math.min(i.clientX,e.right)),r=Math.max(e.top,Math.min(i.clientY,e.bottom)),n=s-e.left,o=r-e.top;if((i.clientX<e.left||i.clientX>e.right||i.clientY<e.top||i.clientY>e.bottom)&&(i.clientY<e.top?this.startAutoScroll(-1):i.clientY>e.bottom?this.startAutoScroll(1):this.stopAutoScroll(),this.autoScrollDirection===0)){this.markCurrentSelectionDirty();const h=this.pixelToCell(n,o),c=this.viewportRowToAbsolute(h.row);this.selectionEnd={col:h.col,absoluteRow:c},this.requestRender()}}},document.addEventListener("mousemove",this.boundDocumentMouseMoveHandler),document.addEventListener("mousedown",i=>{this.mouseDownTarget=i.target}),this.boundMouseUpHandler=i=>{if(this.isSelecting){if(this.isSelecting=!1,this.stopAutoScroll(),!this.dragThresholdMet){this.clearSelection();return}if(this.hasSelection()){try{const e=this.getSelection();e&&this.copyToClipboard(e)}catch{}this.selectionChangedEmitter.fire()}}},document.addEventListener("mouseup",this.boundMouseUpHandler),t.addEventListener("click",i=>{if(i.detail===2){const e=this.pixelToCell(i.offsetX,i.offsetY),s=this.getWordAtCell(e.col,e.row);if(s){const r=this.viewportRowToAbsolute(e.row);this.selectionStart={col:s.startCol,absoluteRow:r},this.selectionEnd={col:s.endCol,absoluteRow:r},this.requestRender();try{const n=this.getSelection();n&&this.copyToClipboard(n)}catch{}this.selectionChangedEmitter.fire()}}else if(i.detail>=3){const e=this.pixelToCell(i.offsetX,i.offsetY),s=this.viewportRowToAbsolute(e.row),r=this.wasmTerm.getScrollbackLength();let n=null;if(s<r)n=this.wasmTerm.getScrollbackLine(s);else{const h=s-r;n=this.wasmTerm.getLine(h)}let o=-1;if(n){for(let h=n.length-1;h>=0;h--)if(n[h]&&n[h].codepoint!==0&&n[h].codepoint!==32){o=h;break}}if(o>=0){this.selectionStart={col:0,absoluteRow:s},this.selectionEnd={col:o,absoluteRow:s},this.requestRender();try{const h=this.getSelection();h&&this.copyToClipboard(h)}catch{}this.selectionChangedEmitter.fire()}}}),this.boundContextMenuHandler=i=>{if(this.renderer.getCanvas().getBoundingClientRect(),this.textarea.style.position="fixed",this.textarea.style.left=`${i.clientX}px`,this.textarea.style.top=`${i.clientY}px`,this.textarea.style.width="1px",this.textarea.style.height="1px",this.textarea.style.zIndex="1000",this.textarea.style.opacity="0",this.textarea.style.pointerEvents="auto",this.hasSelection()){const s=this.getSelection();this.textarea.value=s,this.textarea.select(),this.textarea.setSelectionRange(0,s.length)}else this.textarea.value="";this.textarea.focus(),setTimeout(()=>{const s=()=>{this.textarea.style.pointerEvents="none",this.textarea.style.zIndex="-10",this.textarea.style.width="0",this.textarea.style.height="0",this.textarea.style.left="0",this.textarea.style.top="0",this.textarea.value="",document.removeEventListener("click",s),document.removeEventListener("contextmenu",s),this.textarea.removeEventListener("blur",s)};document.addEventListener("click",s,{once:!0}),document.addEventListener("contextmenu",s,{once:!0}),this.textarea.addEventListener("blur",s,{once:!0})},10)},t.addEventListener("contextmenu",this.boundContextMenuHandler),this.boundClickHandler=i=>{if(this.isSelecting||this.mouseDownTarget&&t.contains(this.mouseDownTarget))return;const s=i.target;t.contains(s)||this.hasSelection()&&this.clearSelection()},document.addEventListener("click",this.boundClickHandler)}markCurrentSelectionDirty(){const t=this.normalizeSelection();if(t)for(let i=t.startRow;i<=t.endRow;i++)this.dirtySelectionRows.add(i)}updateAutoScroll(t,i){const e=L.AUTO_SCROLL_EDGE_SIZE;t<e?this.startAutoScroll(-1):t>i-e?this.startAutoScroll(1):this.stopAutoScroll()}startAutoScroll(t){this.autoScrollInterval!==null&&this.autoScrollDirection===t||(this.stopAutoScroll(),this.autoScrollDirection=t,this.autoScrollInterval=setInterval(()=>{if(!this.isSelecting){this.stopAutoScroll();return}const i=L.AUTO_SCROLL_SPEED*this.autoScrollDirection;if(this.terminal.scrollLines(i),this.selectionEnd){const e=this.wasmTerm.getDimensions();if(this.autoScrollDirection<0){const s=this.viewportRowToAbsolute(0);s<this.selectionEnd.absoluteRow&&(this.selectionEnd={col:0,absoluteRow:s})}else{const s=this.viewportRowToAbsolute(e.rows-1);s>this.selectionEnd.absoluteRow&&(this.selectionEnd={col:e.cols-1,absoluteRow:s})}}this.requestRender()},L.AUTO_SCROLL_INTERVAL))}stopAutoScroll(){this.autoScrollInterval!==null&&(clearInterval(this.autoScrollInterval),this.autoScrollInterval=null),this.autoScrollDirection=0}pixelToCell(t,i){const e=this.renderer.getMetrics(),s=Math.floor(t/e.width),r=Math.floor(i/e.height);return{col:Math.max(0,Math.min(s,this.terminal.cols-1)),row:Math.max(0,Math.min(r,this.terminal.rows-1))}}normalizeSelection(){if(!this.selectionStart||!this.selectionEnd)return null;let{col:t,absoluteRow:i}=this.selectionStart,{col:e,absoluteRow:s}=this.selectionEnd;(i>s||i===s&&t>e)&&([t,e]=[e,t],[i,s]=[s,i]);let r=this.absoluteRowToViewport(i),n=this.absoluteRowToViewport(s);const o=this.wasmTerm.getDimensions(),h=o.rows-1;return n<0||r>h?null:(r<0&&(r=0,t=0),n>h&&(n=h,e=o.cols-1),{startCol:t,startRow:r,endCol:e,endRow:n})}getWordAtCell(t,i){const e=this.viewportRowToAbsolute(i),s=this.wasmTerm.getScrollbackLength();let r;try{if(e<s)r=this.wasmTerm.getScrollbackLine(e);else{const c=e-s;r=this.wasmTerm.getLine(c)}}catch{return null}if(!r)return null;const n=c=>{if(!c||c.codepoint===0)return!1;const l=String.fromCodePoint(c.codepoint);return/[\w\-./~@+]/.test(l)};if(!n(r[t]))return null;let o=t;for(;o>0&&n(r[o-1]);)o--;let h=t;for(;h<r.length-1&&n(r[h+1]);)h++;return{startCol:o,endCol:h}}copyToClipboard(t){if(navigator.clipboard&&typeof ClipboardItem<"u")try{const i=new Blob([t],{type:"text/plain"}),e=new ClipboardItem({"text/plain":i});navigator.clipboard.write([e]).catch(s=>{console.warn("ClipboardItem write failed, trying writeText:",s),this.copyWithWriteText(t)});return}catch{}if(navigator.clipboard&&navigator.clipboard.writeText){navigator.clipboard.writeText(t).catch(i=>{console.warn("Clipboard writeText failed, trying execCommand:",i),this.copyWithExecCommand(t)});return}this.copyWithExecCommand(t)}copyWithWriteText(t){navigator.clipboard&&navigator.clipboard.writeText?navigator.clipboard.writeText(t).catch(i=>{console.warn("Clipboard writeText failed, trying execCommand:",i),this.copyWithExecCommand(t)}):this.copyWithExecCommand(t)}copyWithExecCommand(t){const i=document.activeElement;try{const e=this.textarea;e.value=t,e.style.position="fixed",e.style.left="-9999px",e.style.top="0",e.style.width="1px",e.style.height="1px",e.style.opacity="0",e.focus(),e.select(),e.setSelectionRange(0,t.length);const s=document.execCommand("copy");i&&i.focus(),s||console.warn("execCommand copy failed")}catch(e){console.warn("execCommand copy threw:",e),i&&i.focus()}}requestRender(){}};M.AUTO_SCROLL_EDGE_SIZE=30;M.AUTO_SCROLL_SPEED=3;M.AUTO_SCROLL_INTERVAL=50;let V=M;function H(v,t){const i=String(v||"").trim();if(!i)return t;if(i.startsWith("#")){const s=i.slice(1),r=s.length===3?s.split("").map(n=>n+n).join(""):s;if(/^[0-9a-fA-F]{6}$/.test(r)){const n=Number.parseInt(r,16);return{r:n>>16&255,g:n>>8&255,b:n&255}}}const e=i.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/i);return e?{r:Number.parseInt(e[1],10),g:Number.parseInt(e[2],10),b:Number.parseInt(e[3],10)}:t}function J(v,t,i){const e=H(i.foreground,{r:212,g:212,b:212}),s=H(i.background,{r:30,g:30,b:30}),r={codepoint:32,fg_r:e.r,fg_g:e.g,fg_b:e.b,bg_r:s.r,bg_g:s.g,bg_b:s.b,fgIsDefault:!1,bgIsDefault:!1,flags:0,width:1,hyperlink_id:0,grapheme_len:0};return Array.from({length:t},()=>Array.from({length:v},()=>({...r})))}const W=class z extends a.TerminalCore{constructor(t={}){const i=t.ghostty??G();super(i,t),this.unicode={get activeVersion(){return"15.1"}},this.selectionChangeEmitter=new a.EventEmitter,this.keyEmitter=new a.EventEmitter,this.renderEmitter=new a.EventEmitter,this.mouseCursorChangeEmitter=new a.EventEmitter,this.onSelectionChange=this.selectionChangeEmitter.event,this.onKey=this.keyEmitter.event,this.onRender=this.renderEmitter.event,this.onMouseCursorChange=this.mouseCursorChangeEmitter.event,this.isOpen=!1,this.writeQueue=[],this.awaitingEcho=!1,this.syncOutputStartTime=void 0,this.currentTheme={...T},this.targetViewportY=0,this.isDraggingScrollbar=!1,this.scrollbarDragStart=null,this.scrollbarDragStartViewportY=0,this.scrollbarVisible=!1,this.scrollbarOpacity=0,this.SCROLLBAR_HIDE_DELAY_MS=1500,this.SCROLLBAR_FADE_DURATION_MS=200,this.bootstrapCells=null,this.bootstrapDirty=!1,this.renderTick=()=>{if(this.animationFrameId=void 0,this.isDisposed||!this.isOpen)return;if(this.wasmTerm.getMode(2026,!1)){const s=performance.now();if(this.syncOutputStartTime===void 0&&(this.syncOutputStartTime=s),s-this.syncOutputStartTime<z.SYNC_OUTPUT_TIMEOUT_MS){this.requestRender();return}}this.syncOutputStartTime=void 0,this.renderer.render(this.wasmTerm,!1,this.viewportY,this,this.scrollbarOpacity),this.renderEmitter.fire({start:0,end:this.rows-1});const e=this.wasmTerm.getCursor();(e.x!==this.lastCursorX||e.y!==this.lastCursorY)&&(this.lastCursorX=e.x,this.lastCursorY=e.y,this.cursorMoveEmitter.fire()),this.syncTextareaToCursor(e.x,e.y)},this.lastOsc22Cursor="",this.animateScroll=()=>{if(!this.wasmTerm||this.scrollAnimationStartTime===void 0)return;const e=this.options.smoothScrollDuration??100,s=this.targetViewportY-this.viewportY;if(Math.abs(s)<.01){this.viewportY=this.targetViewportY,this.scrollEmitter.fire(Math.floor(this.viewportY)),this.getScrollbackLength()>0&&this.showScrollbar(),this.scrollAnimationFrame=void 0,this.scrollAnimationStartTime=void 0,this.scrollAnimationStartY=void 0,this.requestRender();return}const o=1-(1/(e/1e3*60))**2;this.viewportY+=s*o;const h=Math.floor(this.viewportY);this.scrollEmitter.fire(h),this.getScrollbackLength()>0&&this.showScrollbar(),this.requestRender(),this.scrollAnimationFrame=requestAnimationFrame(this.animateScroll)},this.handleMouseMove=e=>{if(!(!this.canvas||!this.renderer||!this.wasmTerm)){if(this.isDraggingScrollbar){this.processScrollbarDrag(e);return}if(this.linkDetector){if(this.mouseMoveThrottleTimeout){this.pendingMouseMove=e;return}this.processMouseMove(e),this.mouseMoveThrottleTimeout=window.setTimeout(()=>{if(this.mouseMoveThrottleTimeout=void 0,this.pendingMouseMove){const s=this.pendingMouseMove;this.pendingMouseMove=void 0,this.processMouseMove(s)}},16)}}},this.handleMouseLeave=()=>{var e,s;this.renderer&&this.wasmTerm&&((this.renderer.hoveredHyperlinkId||0)>0&&this.renderer.setHoveredHyperlinkId(0),this.renderer.setHoveredLinkRange(null)),this.currentHoveredLink&&((s=(e=this.currentHoveredLink).hover)==null||s.call(e,!1),this.currentHoveredLink=void 0,this.element&&(this.element.style.cursor="text",this.canvas&&(this.canvas.style.cursor="text")))},this.handleClick=async e=>{if(!this.canvas||!this.renderer||!this.linkDetector||!this.wasmTerm)return;const s=this.canvas.getBoundingClientRect(),r=Math.floor((e.clientX-s.left)/this.renderer.charWidth),o=Math.floor((e.clientY-s.top)/this.renderer.charHeight),h=this.wasmTerm.getScrollbackLength();let c;const l=this.getViewportY(),u=Math.max(0,Math.floor(l));if(u>0)if(o<u)c=h-u+o;else{const p=o-u;c=h+p}else c=h+o;const d=await this.linkDetector.getLinkAt(r,c);d&&(d.activate(e),(e.ctrlKey||e.metaKey)&&e.preventDefault())},this.handleWheel=e=>{var r,n,o,h,c,l,u;if(e.preventDefault(),e.stopPropagation(),this.customWheelEventHandler&&this.customWheelEventHandler(e))return;if((r=this.wasmTerm)!=null&&r.hasMouseTracking()){(n=this.inputHandler)==null||n.handleWheelEvent(e);return}if(((o=this.wasmTerm)==null?void 0:o.isAlternateScreen())??!1){if((h=this.wasmTerm)!=null&&h.hasMouseTracking()){const m=(c=this.renderer)==null?void 0:c.getMetrics(),g=this.canvas;if(m&&g){const w=g.getBoundingClientRect(),C=Math.max(1,Math.floor((e.clientX-w.left)/m.width)+1),y=Math.max(1,Math.floor((e.clientY-w.top)/m.height)+1),f=e.deltaY<0?64:65;this.dataEmitter.fire(`\x1B[<${f};${C};${y}M`)}return}const d=e.deltaY>0?"down":"up",p=Math.min(Math.abs(Math.round(e.deltaY/33)),5);for(let m=0;m<p;m++)this.dataEmitter.fire(d==="up"?"\x1B[A":"\x1B[B")}else{let d;if(e.deltaMode===WheelEvent.DOM_DELTA_PIXEL){const p=((u=(l=this.renderer)==null?void 0:l.getMetrics())==null?void 0:u.height)??20;d=e.deltaY/p}else e.deltaMode===WheelEvent.DOM_DELTA_LINE?d=e.deltaY:e.deltaMode===WheelEvent.DOM_DELTA_PAGE?d=e.deltaY*this.rows:d=e.deltaY/33;if(d!==0){const p=this.viewportY-d;this.smoothScrollTo(p)}}},this.handleMouseDown=e=>{if(!this.canvas||!this.renderer||!this.wasmTerm)return;const s=this.wasmTerm.getScrollbackLength();if(s===0)return;const r=this.canvas.getBoundingClientRect(),n=e.clientX-r.left,o=e.clientY-r.top,h=r.width,c=r.height,l=8,u=h-l-4,d=4;if(n>=u&&n<=u+l){e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation();const p=c-d*2,m=this.rows,g=s+m,w=Math.max(20,m/g*p),C=this.viewportY/s,y=d+(p-w)*(1-C);if(o>=y&&o<=y+w)this.isDraggingScrollbar=!0,this.scrollbarDragStart=o,this.scrollbarDragStartViewportY=this.viewportY,this.canvas&&(this.canvas.style.userSelect="none",this.canvas.style.webkitUserSelect="none");else{const b=1-(o-d)/p,S=Math.round(b*s);this.scrollToLine(Math.max(0,Math.min(s,S)))}}},this.handleMouseUp=()=>{this.isDraggingScrollbar&&(this.isDraggingScrollbar=!1,this.scrollbarDragStart=null,this.canvas&&(this.canvas.style.userSelect="",this.canvas.style.webkitUserSelect=""),this.scrollbarVisible&&this.getScrollbackLength()>0&&this.showScrollbar())},this.currentTheme={...T,...t.theme},this.bootstrapBuffer={getLine:e=>{var s;return this.bootstrapCells&&e>=0&&e<this.bootstrapCells.length?this.bootstrapCells[e]:((s=this.wasmTerm)==null?void 0:s.getLine(e))??null},getCursor:()=>{var e;return this.bootstrapCells?{x:0,y:0,visible:!0}:((e=this.wasmTerm)==null?void 0:e.getCursor())??{x:0,y:0,visible:!0}},getDimensions:()=>({cols:this.cols,rows:this.rows}),isRowDirty:e=>{var s;return this.bootstrapDirty?!0:this.bootstrapCells?!1:((s=this.wasmTerm)==null?void 0:s.isRowDirty(e))??!1},needsFullRedraw:()=>{var s;if(this.bootstrapDirty)return!0;if(this.bootstrapCells)return!1;const e=this.wasmTerm;return((s=e==null?void 0:e.needsFullRedraw)==null?void 0:s.call(e))??!1},clearDirty:()=>{var e;this.bootstrapDirty=!1,(e=this.wasmTerm)==null||e.clearDirty()},getGraphemeString:(e,s)=>{var n,o;if(this.bootstrapCells&&e>=0&&e<this.bootstrapCells.length){const h=(n=this.bootstrapCells[e])==null?void 0:n[s];return h?String.fromCodePoint(h.codepoint||32):" "}const r=this.wasmTerm;return((o=r==null?void 0:r.getGraphemeString)==null?void 0:o.call(r,e,s))??" "}}}get viewportY(){return this._viewportY}set viewportY(t){this._viewportY=t}handleOptionChange(t,i,e){if(i!==e)switch(t){case"disableStdin":break;case"cursorBlink":case"cursorStyle":this.renderer&&(this.renderer.setCursorStyle(this.options.cursorStyle),this.renderer.setCursorBlink(this.options.cursorBlink));break;case"theme":if(this.renderer&&this.wasmTerm){const s=i&&typeof i=="object"?i:{},r=Object.keys(s).length>0;this.currentTheme=r?{...this.currentTheme,...s}:{...T},this.renderer.setTheme(this.currentTheme),this.wasmTerm.setColors(this.buildThemeColorsConfig(this.currentTheme))}break;case"fontSize":this.renderer&&(this.renderer.setFontSize(this.options.fontSize),this.handleFontChange());break;case"fontFamily":this.renderer&&(this.renderer.setFontFamily(this.options.fontFamily),this.handleFontChange());break;case"cols":case"rows":this.resize(this.options.cols,this.options.rows);break}}handleFontChange(){if(!this.renderer||!this.wasmTerm||!this.canvas)return;this.selectionManager&&this.selectionManager.clearSelection(),this.renderer.resize(this.cols,this.rows);const t=this.renderer.getMetrics();this.canvas.width=t.width*this.cols,this.canvas.height=t.height*this.rows,this.canvas.style.width=`${t.width*this.cols}px`,this.canvas.style.height=`${t.height*this.rows}px`,this.updateWasmPixelSize(),this.renderer.render(this.wasmTerm,!0,this.viewportY,this)}buildThemeColorsConfig(t){return{fgColor:this.parseColorToHex(t.foreground),bgColor:this.parseColorToHex(t.background),cursorColor:this.parseColorToHex(t.cursor),palette:[this.parseColorToHex(t.black),this.parseColorToHex(t.red),this.parseColorToHex(t.green),this.parseColorToHex(t.yellow),this.parseColorToHex(t.blue),this.parseColorToHex(t.magenta),this.parseColorToHex(t.cyan),this.parseColorToHex(t.white),this.parseColorToHex(t.brightBlack),this.parseColorToHex(t.brightRed),this.parseColorToHex(t.brightGreen),this.parseColorToHex(t.brightYellow),this.parseColorToHex(t.brightBlue),this.parseColorToHex(t.brightMagenta),this.parseColorToHex(t.brightCyan),this.parseColorToHex(t.brightWhite)]}}open(t){if(this.isOpen)throw new Error("Terminal is already open");if(this.isDisposed)throw new Error("Terminal has been disposed");this.element=t,this.isOpen=!0;try{t.setAttribute("tabindex","-1"),t.setAttribute("role","textbox"),t.setAttribute("aria-label","Terminal input"),t.setAttribute("aria-multiline","true"),this.canvas=document.createElement("canvas"),this.canvas.style.display="block",this.canvas.style.cursor="text",t.appendChild(this.canvas),this.textarea=document.createElement("textarea"),this.textarea.setAttribute("autocorrect","off"),this.textarea.setAttribute("autocapitalize","off"),this.textarea.setAttribute("spellcheck","false"),this.textarea.setAttribute("tabindex","0"),this.textarea.setAttribute("aria-label","Terminal input"),this.textarea.style.position="absolute",this.textarea.style.left="0",this.textarea.style.top="0",this.textarea.style.width="1px",this.textarea.style.height="1px",this.textarea.style.padding="0",this.textarea.style.border="none",this.textarea.style.margin="0",this.textarea.style.opacity="0",this.textarea.style.clipPath="inset(50%)",this.textarea.style.overflow="hidden",this.textarea.style.whiteSpace="nowrap",this.textarea.style.resize="none",t.appendChild(this.textarea);const i=this.textarea;this.canvas.addEventListener("mousedown",o=>{o.preventDefault(),i.focus()}),this.canvas.addEventListener("touchend",o=>{o.preventDefault(),i.focus()}),t.addEventListener("mousedown",o=>{o.target===t&&(o.preventDefault(),i.focus())}),t.addEventListener("focus",()=>{var o;i.focus(),(o=this.wasmTerm)!=null&&o.hasFocusEvents()&&this.dataEmitter.fire("\x1B[I")}),t.addEventListener("blur",()=>{var o;(o=this.wasmTerm)!=null&&o.hasFocusEvents()&&this.dataEmitter.fire("\x1B[O")}),this.renderer=new U(this.canvas,{fontSize:this.options.fontSize,fontFamily:this.options.fontFamily,cursorStyle:this.options.cursorStyle,cursorBlink:this.options.cursorBlink,theme:this.options.theme}),this.renderer.resize(this.cols,this.rows),this.updateWasmPixelSize();const e=this.canvas,s=this.renderer,r=this.wasmTerm,n={hasMouseTracking:()=>(r==null?void 0:r.hasMouseTracking())??!1,hasSgrMouseMode:()=>(r==null?void 0:r.getMode(1006,!1))??!0,getCellDimensions:()=>({width:s.charWidth,height:s.charHeight}),getCanvasOffset:()=>{const o=e.getBoundingClientRect();return{left:o.left,top:o.top}}};this.inputHandler=new F(this.ghostty,t,o=>{var h;this.options.disableStdin||((h=this.selectionManager)==null||h.clearSelection(),this.awaitingEcho=!0,this.dataEmitter.fire(o))},()=>{this.bellEmitter.fire()},o=>{this.keyEmitter.fire(o)},this.customKeyEventHandler,o=>{var h;return((h=this.wasmTerm)==null?void 0:h.getMode(o,!1))??!1},()=>this.copySelection(),this.textarea,n),this.selectionManager=new V(this,this.renderer,this.wasmTerm,this.textarea),this.renderer.setSelectionManager(this.selectionManager),this.selectionManager.onSelectionChange(()=>{this.selectionChangeEmitter.fire(),this.requestRender()}),this.linkDetector=new O(this),this.linkDetector.registerProvider(new Y(this)),this.linkDetector.registerProvider(new N(this)),t.addEventListener("mousedown",this.handleMouseDown,{capture:!0}),t.addEventListener("mousemove",this.handleMouseMove),t.addEventListener("mouseleave",this.handleMouseLeave),t.addEventListener("click",this.handleClick),document.addEventListener("mouseup",this.handleMouseUp),t.addEventListener("wheel",this.handleWheel,{passive:!1,capture:!0}),this.armBootstrapBlank(),this.renderer.render(this.bootstrapBuffer,!0,this.viewportY,this,this.scrollbarOpacity),this.renderer.setOnRequestRender(()=>this.requestRender()),this.renderTick(),this.options.focusOnOpen!==!1&&this.focus()}catch(i){throw this.isOpen=!1,this.cleanupComponents(),new Error(`Failed to open terminal: ${i}`)}}write(t,i){this.assertOpen(),this.options.convertEol&&typeof t=="string"&&(t=t.replace(/\n/g,`\r
|
|
3
|
+
`)),typeof t=="string"&&t.includes("\x1B]22;")&&this.interceptOsc22(t),this.writeInternal(t,i)}stripUnimplementedTitleSequences(t){if(typeof t=="string")return t.replace(/\x1bk[^\x1b\x07]*(?:\x1b\\|\x07)/g,"");let i=0,e=-1,s=null;for(;i<t.length;){if(t[i]===27&&i+1<t.length&&t[i+1]===107){let r=i+2;for(;r<t.length;){if(t[r]===7){r++;break}if(t[r]===27&&r+1<t.length&&t[r+1]===92){r+=2;break}r++}s===null&&(s=new Uint8Array(t.length),s.set(t.subarray(0,i)),e=i),i=r;continue}s!==null&&(s[e++]=t[i]),i++}return s===null?t:s.subarray(0,e)}writeInternal(t,i){var o;this.disarmBootstrapBlank();const e=this.stripUnimplementedTitleSequences(t),s=this.options.preserveScrollOnWrite===!0,r=s?this.viewportY:0,n=s&&r>0?this.wasmTerm.getScrollbackLength():0;if(this.wasmTerm.write(e),this.options.emitTerminalResponses&&this.processTerminalResponses(),typeof t=="string"&&t.includes("\x07")?this.bellEmitter.fire():t instanceof Uint8Array&&t.includes(7)&&this.bellEmitter.fire(),(o=this.linkDetector)==null||o.invalidateCache(),s){if(r>0){const h=this.wasmTerm.getScrollbackLength(),c=h-n,l=Math.max(0,Math.min(r+c,h));l!==r&&(this.viewportY=l,this.scrollEmitter.fire(this.viewportY),h>0&&this.showScrollbar())}}else this.viewportY!==0&&this.scrollToBottom();typeof t=="string"&&t.includes("\x1B]")&&(this.checkForTitleChange(t),this.checkForShellIntegration(t)),typeof t=="string"&&(t.includes(`
|
|
4
|
+
`)||t.includes(`\r
|
|
5
|
+
`))?this.lineFeedEmitter.fire():t instanceof Uint8Array&&t.includes(10)&&this.lineFeedEmitter.fire(),this.checkCursorMove(),i?requestAnimationFrame(()=>{i(),this.writeParsedEmitter.fire()}):this.writeParsedEmitter.fire(),this.awaitingEcho&&this.renderer&&this.wasmTerm&&(this.awaitingEcho=!1,this.renderer.render(this.wasmTerm,!1,this.viewportY,this,this.scrollbarOpacity)),this.requestRender()}writeln(t,i){if(typeof t=="string")this.write(t+`\r
|
|
6
|
+
`,i);else{const e=new Uint8Array(t.length+2);e.set(t),e[t.length]=13,e[t.length+1]=10,this.write(e,i)}}paste(t){this.assertOpen(),!this.options.disableStdin&&(this.awaitingEcho=!0,this.wasmTerm.hasBracketedPaste()?this.dataEmitter.fire("\x1B[200~"+t+"\x1B[201~"):this.dataEmitter.fire(t))}input(t,i=!1){this.assertOpen(),!this.options.disableStdin&&(i?(this.awaitingEcho=!0,this.dataEmitter.fire(t)):this.write(t))}resize(t,i){if(this.isDisposed)throw new Error("Terminal has been disposed");if(!this.wasmTerm)throw new Error("Terminal not initialized");if(!(t===this.cols&&i===this.rows)){this.isOpen&&this.cancelRenderLoop();try{if(this.cols=t,this.rows=i,this.wasmTerm.resize(t,i),this.renderer&&this.canvas){this.renderer.resize(t,i);const e=this.renderer.getMetrics();this.canvas.width=e.width*t,this.canvas.height=e.height*i,this.canvas.style.width=`${e.width*t}px`,this.canvas.style.height=`${e.height*i}px`,this.updateWasmPixelSize(),this.renderer.render(this.wasmTerm,!0,this.viewportY,this)}this.resizeEmitter.fire({cols:t,rows:i})}catch(e){console.error("Terminal resize failed:",e)}this.isOpen&&(this.flushWriteQueue(),this.requestRender())}}reset(){this.assertOpen(),this.wasmTerm&&this.wasmTerm.free();const t=this.buildWasmConfig();this.wasmTerm=this.ghostty.createTerminal(this.cols,this.rows,t),this.updateWasmPixelSize(),this.armBootstrapBlank(),this.renderer.clear(),this.renderer.render(this.bootstrapBuffer,!0,this.viewportY,this,this.scrollbarOpacity),this.currentTitle=""}clear(){this.assertOpen(),this.wasmTerm.write("\x1B[2J\x1B[H")}focus(){if(this.isOpen){const t=this.textarea||this.element;t&&(t.focus(),setTimeout(()=>t==null?void 0:t.focus(),0))}}blur(){this.isOpen&&this.element&&this.element.blur()}loadAddon(t){t.activate(this),this.addons.push(t)}getMode(t,i=!1){return this.wasmTerm?this.wasmTerm.getMode(t,i):!1}hasBracketedPaste(){return this.wasmTerm?this.wasmTerm.hasBracketedPaste():!1}hasFocusEvents(){return this.wasmTerm?this.wasmTerm.hasFocusEvents():!1}hasMouseTracking(){return this.wasmTerm?this.wasmTerm.hasMouseTracking():!1}getSelection(){var t;return((t=this.selectionManager)==null?void 0:t.getSelection())||""}hasSelection(){var t;return((t=this.selectionManager)==null?void 0:t.hasSelection())||!1}clearSelection(){var t;(t=this.selectionManager)==null||t.clearSelection()}copySelection(){var t;return((t=this.selectionManager)==null?void 0:t.copySelection())||!1}selectAll(){var t;(t=this.selectionManager)==null||t.selectAll()}select(t,i,e){var s;(s=this.selectionManager)==null||s.select(t,i,e)}selectLines(t,i){var e;(e=this.selectionManager)==null||e.selectLines(t,i)}getSelectionPosition(){var t;return(t=this.selectionManager)==null?void 0:t.getSelectionPosition()}attachCustomKeyEventHandler(t){this.customKeyEventHandler=t,this.inputHandler&&this.inputHandler.setCustomKeyEventHandler(t)}attachCustomWheelEventHandler(t){this.customWheelEventHandler=t}registerLinkProvider(t){if(!this.linkDetector)throw new Error("Terminal must be opened before registering link providers");this.linkDetector.registerProvider(t)}scrollLines(t){if(!this.wasmTerm)throw new Error("Terminal not open");const i=this.getScrollbackLength(),e=Math.max(0,Math.min(i,this.viewportY-t));e!==this.viewportY&&(this.viewportY=e,this.scrollEmitter.fire(this.viewportY),i>0&&this.showScrollbar(),this.requestRender())}scrollPages(t){this.scrollLines(t*this.rows)}scrollToTop(){const t=this.getScrollbackLength();t>0&&this.viewportY!==t&&(this.viewportY=t,this.scrollEmitter.fire(this.viewportY),this.showScrollbar(),this.requestRender())}scrollToBottom(){this.viewportY!==0&&(this.viewportY=0,this.scrollEmitter.fire(this.viewportY),this.getScrollbackLength()>0&&this.showScrollbar(),this.requestRender())}scrollToLine(t){const i=this.getScrollbackLength(),e=Math.max(0,Math.min(i,t));e!==this.viewportY&&(this.viewportY=e,this.scrollEmitter.fire(this.viewportY),i>0&&this.showScrollbar(),this.requestRender())}dispose(){this.isDisposed||(this.isOpen=!1,this.cancelRenderLoop(),this.writeQueue.length=0,this.scrollAnimationFrame&&(cancelAnimationFrame(this.scrollAnimationFrame),this.scrollAnimationFrame=void 0),this.mouseMoveThrottleTimeout&&(clearTimeout(this.mouseMoveThrottleTimeout),this.mouseMoveThrottleTimeout=void 0),this.pendingMouseMove=void 0,this.cleanupComponents(),this.selectionChangeEmitter.dispose(),this.keyEmitter.dispose(),this.renderEmitter.dispose(),this.mouseCursorChangeEmitter.dispose(),super.dispose())}processTerminalResponses(){if(this.wasmTerm)for(;;){const t=this.wasmTerm.readResponse();if(t===null)break;this.dataEmitter.fire(t)}}updateWasmPixelSize(){if(!this.renderer||!this.wasmTerm)return;const t=this.renderer.getMetrics();this.wasmTerm.setCellPixelSize(t.width,t.height)}cancelRenderLoop(){this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}flushWriteQueue(){for(;this.writeQueue.length>0;){const t=this.writeQueue.shift();this.wasmTerm.write(t)}}requestRender(){this.animationFrameId===void 0&&(this.isDisposed||!this.isOpen||(this.animationFrameId=requestAnimationFrame(this.renderTick)))}syncTextareaToCursor(t,i){if(!this.textarea||!this.renderer)return;const e=this.renderer.charWidth,s=this.renderer.charHeight;!e||!s||(this.textarea.style.left=`${t*e}px`,this.textarea.style.top=`${i*s}px`)}interceptOsc22(t){const i=/\x1b\]22;([^\x07\x1b]*)(?:\x07|\x1b\\)/g;let e;for(;(e=i.exec(t))!==null;){const s=e[1].replace(/_/g,"-")||"default";s!==this.lastOsc22Cursor&&(this.lastOsc22Cursor=s,this.canvas&&(this.canvas.style.cursor=s),this.element&&(this.element.style.cursor=s),this.mouseCursorChangeEmitter.fire(s))}}armBootstrapBlank(){const t={...T,...this.options.theme};this.bootstrapCells=J(this.cols,this.rows,{foreground:t.foreground,background:t.background}),this.bootstrapDirty=!0}disarmBootstrapBlank(){this.bootstrapCells&&(this.bootstrapCells=null,this.bootstrapDirty=!0)}cleanupComponents(){this.selectionManager&&(this.selectionManager.dispose(),this.selectionManager=void 0),this.inputHandler&&(this.inputHandler.dispose(),this.inputHandler=void 0),this.renderer&&(this.renderer.dispose(),this.renderer=void 0),this.canvas&&this.canvas.parentNode&&(this.canvas.parentNode.removeChild(this.canvas),this.canvas=void 0),this.textarea&&this.textarea.parentNode&&(this.textarea.parentNode.removeChild(this.textarea),this.textarea=void 0),this.element&&(this.element.removeEventListener("wheel",this.handleWheel),this.element.removeEventListener("mousedown",this.handleMouseDown,{capture:!0}),this.element.removeEventListener("mousemove",this.handleMouseMove),this.element.removeEventListener("mouseleave",this.handleMouseLeave),this.element.removeEventListener("click",this.handleClick),this.element.removeAttribute("role"),this.element.removeAttribute("aria-label"),this.element.removeAttribute("aria-multiline")),this.isOpen&&typeof document<"u"&&document.removeEventListener("mouseup",this.handleMouseUp),this.scrollbarHideTimeout&&(window.clearTimeout(this.scrollbarHideTimeout),this.scrollbarHideTimeout=void 0),this.linkDetector&&(this.linkDetector.dispose(),this.linkDetector=void 0),this.element=void 0,this.textarea=void 0}assertOpen(){if(this.isDisposed)throw new Error("Terminal has been disposed");if(!this.isOpen)throw new Error("Terminal must be opened before use. Call terminal.open(parent) first.")}smoothScrollTo(t){if(!this.wasmTerm)return;const i=this.getScrollbackLength(),e=Math.max(0,Math.min(i,t));if((this.options.smoothScrollDuration??100)===0){this.viewportY=e,this.targetViewportY=e,this.scrollEmitter.fire(Math.floor(this.viewportY)),i>0&&this.showScrollbar(),this.requestRender();return}this.targetViewportY=e,!this.scrollAnimationFrame&&(this.scrollAnimationStartTime=Date.now(),this.scrollAnimationStartY=this.viewportY,this.animateScroll())}showScrollbar(){this.scrollbarHideTimeout&&(window.clearTimeout(this.scrollbarHideTimeout),this.scrollbarHideTimeout=void 0),this.scrollbarVisible?this.scrollbarOpacity=1:(this.scrollbarVisible=!0,this.scrollbarOpacity=0,this.fadeInScrollbar()),this.isDraggingScrollbar||(this.scrollbarHideTimeout=window.setTimeout(()=>{this.hideScrollbar()},this.SCROLLBAR_HIDE_DELAY_MS))}hideScrollbar(){this.scrollbarHideTimeout&&(window.clearTimeout(this.scrollbarHideTimeout),this.scrollbarHideTimeout=void 0),this.scrollbarVisible&&this.fadeOutScrollbar()}fadeInScrollbar(){const t=Date.now(),i=()=>{const e=Date.now()-t,s=Math.min(e/this.SCROLLBAR_FADE_DURATION_MS,1);this.scrollbarOpacity=s,this.renderer&&this.wasmTerm&&this.renderer.render(this.wasmTerm,!1,this.viewportY,this,this.scrollbarOpacity),s<1&&requestAnimationFrame(i)};i()}fadeOutScrollbar(){const t=Date.now(),i=this.scrollbarOpacity,e=()=>{const s=Date.now()-t,r=Math.min(s/this.SCROLLBAR_FADE_DURATION_MS,1);this.scrollbarOpacity=i*(1-r),this.renderer&&this.wasmTerm&&this.renderer.render(this.wasmTerm,!1,this.viewportY,this,this.scrollbarOpacity),r<1?requestAnimationFrame(e):(this.scrollbarVisible=!1,this.scrollbarOpacity=0,this.renderer&&this.wasmTerm&&this.renderer.render(this.wasmTerm,!1,this.viewportY,this,0))};e()}processMouseMove(t){if(!this.canvas||!this.renderer||!this.linkDetector||!this.wasmTerm)return;const i=this.canvas.getBoundingClientRect(),e=Math.floor((t.clientX-i.left)/this.renderer.charWidth),r=Math.floor((t.clientY-i.top)/this.renderer.charHeight);let n=0,o=null;const h=this.getViewportY(),c=Math.max(0,Math.floor(h));if(c>0){const g=this.wasmTerm.getScrollbackLength();if(r<c){const w=g-c+r;o=this.wasmTerm.getScrollbackLine(w)}else{const w=r-c;o=this.wasmTerm.getLine(w)}}else o=this.wasmTerm.getLine(r);o&&e>=0&&e<o.length&&(n=o[e].hyperlink_id);const l=this.renderer.hoveredHyperlinkId||0;n!==l&&this.renderer.setHoveredHyperlinkId(n);const u=this.wasmTerm.getScrollbackLength();let d;const p=this.getViewportY(),m=Math.max(0,Math.floor(p));if(m>0)if(r<m)d=u-m+r;else{const g=r-m;d=u+g}else d=u+r;this.linkDetector.getLinkAt(e,d).then(g=>{var w,C,y,f;if(g!==this.currentHoveredLink){(C=(w=this.currentHoveredLink)==null?void 0:w.hover)==null||C.call(w,!1),this.currentHoveredLink=g,(y=g==null?void 0:g.hover)==null||y.call(g,!0);const b=g?"pointer":"text";if(this.element&&(this.element.style.cursor=b),this.canvas&&(this.canvas.style.cursor=b),this.renderer)if(g){const S=((f=this.wasmTerm)==null?void 0:f.getScrollbackLength())||0,k=this.getViewportY(),I=Math.max(0,Math.floor(k)),P=g.range.start.y-S+I,A=g.range.end.y-S+I;P<this.rows&&A>=0?this.renderer.setHoveredLinkRange({startX:g.range.start.x,startY:Math.max(0,P),endX:g.range.end.x,endY:Math.min(this.rows-1,A)}):this.renderer.setHoveredLinkRange(null)}else this.renderer.setHoveredLinkRange(null)}}).catch(g=>{console.warn("Link detection error:",g)})}processScrollbarDrag(t){if(!this.canvas||!this.renderer||!this.wasmTerm||this.scrollbarDragStart===null)return;const i=this.wasmTerm.getScrollbackLength();if(i===0)return;const e=this.canvas.getBoundingClientRect(),r=t.clientY-e.top-this.scrollbarDragStart,h=e.height-4*2,c=this.rows,l=i+c,u=Math.max(20,c/l*h),d=-r/(h-u),p=Math.round(d*i),m=this.scrollbarDragStartViewportY+p;this.scrollToLine(Math.max(0,Math.min(i,m)))}};W.SYNC_OUTPUT_TIMEOUT_MS=500;let j=W;const Z=2,tt=1,et=15,it=100;class st{constructor(){this._isResizing=!1}activate(t){this._terminal=t}dispose(){this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=void 0),this._resizeDebounceTimer&&(clearTimeout(this._resizeDebounceTimer),this._resizeDebounceTimer=void 0),this._lastCols=void 0,this._lastRows=void 0,this._terminal=void 0}fit(){if(this._isResizing)return;const t=this.proposeDimensions();if(!t||!this._terminal)return;const i=this._terminal,e=i.cols,s=i.rows;if(!(t.cols===this._lastCols&&t.rows===this._lastRows||t.cols===e&&t.rows===s)){this._lastCols=t.cols,this._lastRows=t.rows,this._isResizing=!0;try{i.resize&&typeof i.resize=="function"&&i.resize(t.cols,t.rows)}finally{setTimeout(()=>{this._isResizing=!1},50)}}}proposeDimensions(){var w;if(!((w=this._terminal)!=null&&w.element))return;const i=this._terminal.renderer;if(!i||typeof i.getMetrics!="function")return;const e=i.getMetrics();if(!e||e.width===0||e.height===0)return;const s=this._terminal.element;if(typeof s.clientWidth>"u")return;const r=window.getComputedStyle(s),n=Number.parseInt(r.getPropertyValue("padding-top"))||0,o=Number.parseInt(r.getPropertyValue("padding-bottom"))||0,h=Number.parseInt(r.getPropertyValue("padding-left"))||0,c=Number.parseInt(r.getPropertyValue("padding-right"))||0,l=s.clientWidth,u=s.clientHeight;if(l===0||u===0)return;const d=l-h-c-et,p=u-n-o,m=Math.max(Z,Math.floor(d/e.width)),g=Math.max(tt,Math.floor(p/e.height));return{cols:m,rows:g}}observeResize(){var t;(t=this._terminal)!=null&&t.element&&(this._resizeObserver||(this._resizeObserver=new ResizeObserver(i=>{this._isResizing||!i[0]||(this._resizeDebounceTimer&&clearTimeout(this._resizeDebounceTimer),this._resizeDebounceTimer=setTimeout(()=>{this.fit()},it))}),this._resizeObserver.observe(this._terminal.element)))}}class rt{constructor(){this._pasteListener=null,this._emitter=new a.EventEmitter,this.onImagePaste=this._emitter.event}activate(t){this._terminal=t;const i=t.element;i&&this._attachListener(i)}dispose(){this._detachListener(),this._emitter.dispose(),this._terminal=void 0}_attachListener(t){this._pasteListener=i=>{const e=i.clipboardData;if(e!=null&&e.items){for(const s of Array.from(e.items))if(s.kind==="file"&&s.type.startsWith("image/")){const r=s.getAsFile();if(r){i.preventDefault(),i.stopPropagation();const n=new FileReader;n.onload=()=>{const h=n.result.split(",")[1];if(h){const c=r.type.split("/")[1]||"png";this._emitter.fire({name:`clipboard_${Date.now()}.${c}`,dataBase64:h})}},n.readAsDataURL(r);return}}}},t.addEventListener("paste",this._pasteListener)}_detachListener(){var t;this._pasteListener&&((t=this._terminal)!=null&&t.element)&&this._terminal.element.removeEventListener("paste",this._pasteListener),this._pasteListener=null}}let R=null;async function nt(){R||(R=await a.Ghostty.load())}function G(){if(!R)throw new Error(`ghostty-web not initialized. Call init() before creating Terminal instances.
|
|
7
|
+
Example:
|
|
8
|
+
import { init, Terminal } from "ghostty-web";
|
|
9
|
+
await init();
|
|
10
|
+
const term = new Terminal();
|
|
11
|
+
|
|
12
|
+
For tests, pass a Ghostty instance directly:
|
|
13
|
+
import { Ghostty, Terminal } from "ghostty-web";
|
|
14
|
+
const ghostty = await Ghostty.load();
|
|
15
|
+
const term = new Terminal({ ghostty });`);return R}exports.CellFlags=a.CellFlags;exports.DirtyState=a.DirtyState;exports.EventEmitter=a.EventEmitter;exports.Ghostty=a.Ghostty;exports.GhosttyTerminal=a.GhosttyTerminal;exports.Key=a.Key;exports.KeyAction=a.KeyAction;exports.KeyEncoder=a.KeyEncoder;exports.KeyEncoderOption=a.KeyEncoderOption;exports.Mods=a.Mods;exports.TerminalCore=a.TerminalCore;exports.CanvasRenderer=U;exports.FitAddon=st;exports.ImagePasteAddon=rt;exports.InputHandler=F;exports.LinkDetector=O;exports.OSC8LinkProvider=Y;exports.SelectionManager=V;exports.Terminal=j;exports.UrlRegexProvider=N;exports.getGhostty=G;exports.init=nt;
|