@gkoreli/ghostty-vt-js 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +89 -0
- package/THIRD_PARTY_NOTICES.md +45 -0
- package/dist/browser-terminal/buffer.d.ts +93 -0
- package/dist/browser-terminal/buffer.d.ts.map +1 -0
- package/dist/browser-terminal/buffer.js +337 -0
- package/dist/browser-terminal/buffer.js.map +1 -0
- package/dist/browser-terminal/encoding.d.ts +17 -0
- package/dist/browser-terminal/encoding.d.ts.map +1 -0
- package/dist/browser-terminal/encoding.js +22 -0
- package/dist/browser-terminal/encoding.js.map +1 -0
- package/dist/browser-terminal/event-emitter.d.ts +8 -0
- package/dist/browser-terminal/event-emitter.d.ts.map +1 -0
- package/dist/browser-terminal/event-emitter.js +27 -0
- package/dist/browser-terminal/event-emitter.js.map +1 -0
- package/dist/browser-terminal/frame-hold.d.ts +13 -0
- package/dist/browser-terminal/frame-hold.d.ts.map +1 -0
- package/dist/browser-terminal/frame-hold.js +17 -0
- package/dist/browser-terminal/frame-hold.js.map +1 -0
- package/dist/browser-terminal/geometry.d.ts +229 -0
- package/dist/browser-terminal/geometry.d.ts.map +1 -0
- package/dist/browser-terminal/geometry.js +299 -0
- package/dist/browser-terminal/geometry.js.map +1 -0
- package/dist/browser-terminal/ghostty.d.ts +478 -0
- package/dist/browser-terminal/ghostty.d.ts.map +1 -0
- package/dist/browser-terminal/ghostty.js +1212 -0
- package/dist/browser-terminal/ghostty.js.map +1 -0
- package/dist/browser-terminal/gpu/adapter.d.ts +70 -0
- package/dist/browser-terminal/gpu/adapter.d.ts.map +1 -0
- package/dist/browser-terminal/gpu/adapter.js +260 -0
- package/dist/browser-terminal/gpu/adapter.js.map +1 -0
- package/dist/browser-terminal/gpu/core/canvas-glyph-rasterizer.d.ts +33 -0
- package/dist/browser-terminal/gpu/core/canvas-glyph-rasterizer.d.ts.map +1 -0
- package/dist/browser-terminal/gpu/core/canvas-glyph-rasterizer.js +159 -0
- package/dist/browser-terminal/gpu/core/canvas-glyph-rasterizer.js.map +1 -0
- package/dist/browser-terminal/gpu/core/context-loss-watchdog.d.ts +35 -0
- package/dist/browser-terminal/gpu/core/context-loss-watchdog.d.ts.map +1 -0
- package/dist/browser-terminal/gpu/core/context-loss-watchdog.js +73 -0
- package/dist/browser-terminal/gpu/core/context-loss-watchdog.js.map +1 -0
- package/dist/browser-terminal/gpu/core/frame.d.ts +68 -0
- package/dist/browser-terminal/gpu/core/frame.d.ts.map +1 -0
- package/dist/browser-terminal/gpu/core/frame.js +167 -0
- package/dist/browser-terminal/gpu/core/frame.js.map +1 -0
- package/dist/browser-terminal/gpu/core/glyph-atlas.d.ts +136 -0
- package/dist/browser-terminal/gpu/core/glyph-atlas.d.ts.map +1 -0
- package/dist/browser-terminal/gpu/core/glyph-atlas.js +281 -0
- package/dist/browser-terminal/gpu/core/glyph-atlas.js.map +1 -0
- package/dist/browser-terminal/gpu/core/procedural-shapes.d.ts +24 -0
- package/dist/browser-terminal/gpu/core/procedural-shapes.d.ts.map +1 -0
- package/dist/browser-terminal/gpu/core/procedural-shapes.js +316 -0
- package/dist/browser-terminal/gpu/core/procedural-shapes.js.map +1 -0
- package/dist/browser-terminal/gpu/core/webgl2-renderer.d.ts +107 -0
- package/dist/browser-terminal/gpu/core/webgl2-renderer.d.ts.map +1 -0
- package/dist/browser-terminal/gpu/core/webgl2-renderer.js +698 -0
- package/dist/browser-terminal/gpu/core/webgl2-renderer.js.map +1 -0
- package/dist/browser-terminal/gpu/create-renderer.d.ts +15 -0
- package/dist/browser-terminal/gpu/create-renderer.d.ts.map +1 -0
- package/dist/browser-terminal/gpu/create-renderer.js +33 -0
- package/dist/browser-terminal/gpu/create-renderer.js.map +1 -0
- package/dist/browser-terminal/index.d.ts +47 -0
- package/dist/browser-terminal/index.d.ts.map +1 -0
- package/dist/browser-terminal/index.js +75 -0
- package/dist/browser-terminal/index.js.map +1 -0
- package/dist/browser-terminal/input-handler.d.ts +262 -0
- package/dist/browser-terminal/input-handler.d.ts.map +1 -0
- package/dist/browser-terminal/input-handler.js +978 -0
- package/dist/browser-terminal/input-handler.js.map +1 -0
- package/dist/browser-terminal/interfaces.d.ts +230 -0
- package/dist/browser-terminal/interfaces.d.ts.map +1 -0
- package/dist/browser-terminal/interfaces.js +5 -0
- package/dist/browser-terminal/interfaces.js.map +1 -0
- package/dist/browser-terminal/link-detector.d.ts +76 -0
- package/dist/browser-terminal/link-detector.d.ts.map +1 -0
- package/dist/browser-terminal/link-detector.js +165 -0
- package/dist/browser-terminal/link-detector.js.map +1 -0
- package/dist/browser-terminal/providers/osc8-link-provider.d.ts +56 -0
- package/dist/browser-terminal/providers/osc8-link-provider.d.ts.map +1 -0
- package/dist/browser-terminal/providers/osc8-link-provider.js +204 -0
- package/dist/browser-terminal/providers/osc8-link-provider.js.map +1 -0
- package/dist/browser-terminal/providers/url-regex-provider.d.ts +68 -0
- package/dist/browser-terminal/providers/url-regex-provider.d.ts.map +1 -0
- package/dist/browser-terminal/providers/url-regex-provider.js +107 -0
- package/dist/browser-terminal/providers/url-regex-provider.js.map +1 -0
- package/dist/browser-terminal/renderer-interface.d.ts +59 -0
- package/dist/browser-terminal/renderer-interface.d.ts.map +1 -0
- package/dist/browser-terminal/renderer-interface.js +2 -0
- package/dist/browser-terminal/renderer-interface.js.map +1 -0
- package/dist/browser-terminal/renderer.d.ts +254 -0
- package/dist/browser-terminal/renderer.d.ts.map +1 -0
- package/dist/browser-terminal/renderer.js +905 -0
- package/dist/browser-terminal/renderer.js.map +1 -0
- package/dist/browser-terminal/scrollbar-overlay.d.ts +45 -0
- package/dist/browser-terminal/scrollbar-overlay.d.ts.map +1 -0
- package/dist/browser-terminal/scrollbar-overlay.js +89 -0
- package/dist/browser-terminal/scrollbar-overlay.js.map +1 -0
- package/dist/browser-terminal/selection-manager.d.ts +180 -0
- package/dist/browser-terminal/selection-manager.d.ts.map +1 -0
- package/dist/browser-terminal/selection-manager.js +913 -0
- package/dist/browser-terminal/selection-manager.js.map +1 -0
- package/dist/browser-terminal/terminal.d.ts +423 -0
- package/dist/browser-terminal/terminal.d.ts.map +1 -0
- package/dist/browser-terminal/terminal.js +1754 -0
- package/dist/browser-terminal/terminal.js.map +1 -0
- package/dist/browser-terminal/types.d.ts +595 -0
- package/dist/browser-terminal/types.d.ts.map +1 -0
- package/dist/browser-terminal/types.js +467 -0
- package/dist/browser-terminal/types.js.map +1 -0
- package/dist/browser-terminal/viewport-scroller.d.ts +94 -0
- package/dist/browser-terminal/viewport-scroller.d.ts.map +1 -0
- package/dist/browser-terminal/viewport-scroller.js +159 -0
- package/dist/browser-terminal/viewport-scroller.js.map +1 -0
- package/dist/browser-terminal/vt/effects.d.ts +114 -0
- package/dist/browser-terminal/vt/effects.d.ts.map +1 -0
- package/dist/browser-terminal/vt/effects.js +143 -0
- package/dist/browser-terminal/vt/effects.js.map +1 -0
- package/dist/browser-terminal/vt/enums.d.ts +155 -0
- package/dist/browser-terminal/vt/enums.d.ts.map +1 -0
- package/dist/browser-terminal/vt/enums.js +161 -0
- package/dist/browser-terminal/vt/enums.js.map +1 -0
- package/dist/browser-terminal/vt/mouse.d.ts +166 -0
- package/dist/browser-terminal/vt/mouse.d.ts.map +1 -0
- package/dist/browser-terminal/vt/mouse.js +259 -0
- package/dist/browser-terminal/vt/mouse.js.map +1 -0
- package/dist/browser-terminal/vt/paste.d.ts +53 -0
- package/dist/browser-terminal/vt/paste.d.ts.map +1 -0
- package/dist/browser-terminal/vt/paste.js +89 -0
- package/dist/browser-terminal/vt/paste.js.map +1 -0
- package/dist/browser-terminal/vt/render-state.d.ts +208 -0
- package/dist/browser-terminal/vt/render-state.d.ts.map +1 -0
- package/dist/browser-terminal/vt/render-state.js +776 -0
- package/dist/browser-terminal/vt/render-state.js.map +1 -0
- package/dist/browser-terminal/vt/style.d.ts +54 -0
- package/dist/browser-terminal/vt/style.d.ts.map +1 -0
- package/dist/browser-terminal/vt/style.js +92 -0
- package/dist/browser-terminal/vt/style.js.map +1 -0
- package/dist/browser-terminal/wasm-loader.d.ts +39 -0
- package/dist/browser-terminal/wasm-loader.d.ts.map +1 -0
- package/dist/browser-terminal/wasm-loader.js +73 -0
- package/dist/browser-terminal/wasm-loader.js.map +1 -0
- package/dist/browser-terminal/write-buffer.d.ts +40 -0
- package/dist/browser-terminal/write-buffer.d.ts.map +1 -0
- package/dist/browser-terminal/write-buffer.js +144 -0
- package/dist/browser-terminal/write-buffer.js.map +1 -0
- package/dist/protocol/index.d.ts +135 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/index.js +76 -0
- package/dist/protocol/index.js.map +1 -0
- package/dist/react/index.d.ts +59 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +146 -0
- package/dist/react/index.js.map +1 -0
- package/dist/server/index.d.ts +130 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +191 -0
- package/dist/server/index.js.map +1 -0
- package/dist/terminal-screen-emulator/emulator.d.ts +66 -0
- package/dist/terminal-screen-emulator/emulator.d.ts.map +1 -0
- package/dist/terminal-screen-emulator/emulator.js +286 -0
- package/dist/terminal-screen-emulator/emulator.js.map +1 -0
- package/dist/terminal-screen-emulator/index.d.ts +82 -0
- package/dist/terminal-screen-emulator/index.d.ts.map +1 -0
- package/dist/terminal-screen-emulator/index.js +92 -0
- package/dist/terminal-screen-emulator/index.js.map +1 -0
- package/dist/terminal-screen-emulator/types.d.ts +382 -0
- package/dist/terminal-screen-emulator/types.d.ts.map +1 -0
- package/dist/terminal-screen-emulator/types.js +91 -0
- package/dist/terminal-screen-emulator/types.js.map +1 -0
- package/dist/terminal-screen-emulator/wasm-loader.d.ts +71 -0
- package/dist/terminal-screen-emulator/wasm-loader.d.ts.map +1 -0
- package/dist/terminal-screen-emulator/wasm-loader.js +162 -0
- package/dist/terminal-screen-emulator/wasm-loader.js.map +1 -0
- package/dist/themes/index.d.ts +6 -0
- package/dist/themes/index.d.ts.map +1 -0
- package/dist/themes/index.js +51 -0
- package/dist/themes/index.js.map +1 -0
- package/dist/wasm/alloc.d.ts +170 -0
- package/dist/wasm/alloc.d.ts.map +1 -0
- package/dist/wasm/alloc.js +307 -0
- package/dist/wasm/alloc.js.map +1 -0
- package/dist/wasm/compile.d.ts +73 -0
- package/dist/wasm/compile.d.ts.map +1 -0
- package/dist/wasm/compile.js +82 -0
- package/dist/wasm/compile.js.map +1 -0
- package/dist/wasm/exports.d.ts +234 -0
- package/dist/wasm/exports.d.ts.map +1 -0
- package/dist/wasm/exports.js +15 -0
- package/dist/wasm/exports.js.map +1 -0
- package/dist/wasm/fn-table.d.ts +119 -0
- package/dist/wasm/fn-table.d.ts.map +1 -0
- package/dist/wasm/fn-table.js +168 -0
- package/dist/wasm/fn-table.js.map +1 -0
- package/dist/wasm/memory.d.ts +59 -0
- package/dist/wasm/memory.d.ts.map +1 -0
- package/dist/wasm/memory.js +89 -0
- package/dist/wasm/memory.js.map +1 -0
- package/dist/wasm/type-layouts.d.ts +61 -0
- package/dist/wasm/type-layouts.d.ts.map +1 -0
- package/dist/wasm/type-layouts.js +32 -0
- package/dist/wasm/type-layouts.js.map +1 -0
- package/package.json +94 -0
- package/wasm/ghostty-vt.wasm +0 -0
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module wasm/exports
|
|
3
|
+
*
|
|
4
|
+
* Type definition for the raw functions exported by the ghostty-vt.wasm
|
|
5
|
+
* binary. Shared between every consumer of the WASM module (e.g. the
|
|
6
|
+
* Node-side `terminal-screen-emulator` and the browser-side terminal
|
|
7
|
+
* surface), since the binary is identical in both environments.
|
|
8
|
+
*
|
|
9
|
+
* Each entry maps 1:1 to a C ABI function in `vendor/ghostty/include/ghostty/vt/*.h`.
|
|
10
|
+
* The header citation lives in JSDoc on the entry.
|
|
11
|
+
*
|
|
12
|
+
* @internal This module is not part of the public API.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* The complete set of functions exported by the ghostty-vt.wasm binary.
|
|
16
|
+
*
|
|
17
|
+
* These map 1:1 to the C API defined in `include/ghostty/vt/*.h`.
|
|
18
|
+
* The TypeScript wrapper never exposes these directly — they're an
|
|
19
|
+
* implementation detail of the WASM bridge.
|
|
20
|
+
*
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export interface GhosttyWasmExports {
|
|
24
|
+
/** Linear memory shared between JS and WASM. */
|
|
25
|
+
memory: WebAssembly.Memory;
|
|
26
|
+
/**
|
|
27
|
+
* The module's indirect function table — how C function pointers are
|
|
28
|
+
* represented in WASM. Exported by our `-Demit-lib-vt` build. Used by
|
|
29
|
+
* `fn-table.ts` to install JS effect callbacks (grow + set, then pass the
|
|
30
|
+
* index to `ghostty_terminal_set` as the "function pointer" value).
|
|
31
|
+
*/
|
|
32
|
+
__indirect_function_table: WebAssembly.Table;
|
|
33
|
+
/**
|
|
34
|
+
* Returns a pointer to a null-terminated JSON string describing all
|
|
35
|
+
* struct layouts (field names, offsets, sizes, types). This makes the
|
|
36
|
+
* wrapper self-describing — it adapts to future Ghostty versions without
|
|
37
|
+
* code changes.
|
|
38
|
+
*/
|
|
39
|
+
ghostty_type_json(): number;
|
|
40
|
+
/** `ghostty_terminal_new` — create a new terminal instance. terminal.h. */
|
|
41
|
+
/**
|
|
42
|
+
* `ghostty_terminal_new(allocator, &handle, uint16 cols, uint16 rows)`.
|
|
43
|
+
* VT_NOTE: the `GhosttyTerminalOptions` struct parameter was removed upstream
|
|
44
|
+
* in vendor/ghostty@6ad1fe7d8; scrollback moved to
|
|
45
|
+
* `ghostty_terminal_set(OPT_SCROLLBACK_MAX_LINES)`. terminal.h.
|
|
46
|
+
*/
|
|
47
|
+
ghostty_terminal_new(allocator: number, outPtr: number, cols: number, rows: number): number;
|
|
48
|
+
/** `ghostty_terminal_free` — destroy a terminal instance. terminal.h. */
|
|
49
|
+
ghostty_terminal_free(terminal: number): void;
|
|
50
|
+
/** `ghostty_terminal_reset` — reset terminal to initial state. terminal.h. */
|
|
51
|
+
ghostty_terminal_reset(terminal: number): void;
|
|
52
|
+
/**
|
|
53
|
+
* `ghostty_terminal_resize` — resize terminal. terminal.h.
|
|
54
|
+
*
|
|
55
|
+
* The C signature is (terminal, cols, rows, cell_width_px, cell_height_px).
|
|
56
|
+
* Browser-terminal pixel sizing is done via the JS-side renderer and is
|
|
57
|
+
* not surfaced through the WASM call, so callers pass `0` for both pixel
|
|
58
|
+
* fields. Trailing args are ignored by WASM if not declared in the import
|
|
59
|
+
* type, but we declare them for correctness against the header.
|
|
60
|
+
*/
|
|
61
|
+
ghostty_terminal_resize(terminal: number, columns: number, rows: number, cellWidthPx?: number, cellHeightPx?: number): number;
|
|
62
|
+
/** `ghostty_terminal_vt_write` — feed VT bytes. terminal.h. */
|
|
63
|
+
ghostty_terminal_vt_write(terminal: number, dataPtr: number, length: number): void;
|
|
64
|
+
/** `ghostty_terminal_get` — keyed data extraction. terminal.h. */
|
|
65
|
+
ghostty_terminal_get(terminal: number, dataKind: number, outPtr: number): number;
|
|
66
|
+
/** `ghostty_terminal_get_multi` — batched keyed data extraction. terminal.h. */
|
|
67
|
+
ghostty_terminal_get_multi(terminal: number, count: number, keysPtr: number, valuesPtr: number, outWrittenPtr: number): number;
|
|
68
|
+
/** `ghostty_terminal_set` — install effects/options on the terminal. terminal.h. */
|
|
69
|
+
ghostty_terminal_set(terminal: number, option: number, valuePtr: number): number;
|
|
70
|
+
/** `ghostty_terminal_mode_get` — read a mode bit. terminal.h + modes.h. */
|
|
71
|
+
ghostty_terminal_mode_get(terminal: number, mode: number, outPtr: number): number;
|
|
72
|
+
/** `ghostty_terminal_mode_set` — set a mode bit. terminal.h + modes.h. */
|
|
73
|
+
ghostty_terminal_mode_set(terminal: number, mode: number, value: number): number;
|
|
74
|
+
/** `ghostty_terminal_scroll_viewport` — scroll the viewport. terminal.h. */
|
|
75
|
+
ghostty_terminal_scroll_viewport(terminal: number, behaviorPtr: number): void;
|
|
76
|
+
/**
|
|
77
|
+
* `ghostty_terminal_grid_ref` — resolve a point to a grid reference. terminal.h.
|
|
78
|
+
*
|
|
79
|
+
* Caller fills a sized GhosttyGridRef struct (with `size` and `node`/`x`/`y`
|
|
80
|
+
* defaulted to zero) and passes it as `outRefPtr`. On success, the struct
|
|
81
|
+
* is populated and can be used with `ghostty_grid_ref_*` accessors.
|
|
82
|
+
*/
|
|
83
|
+
ghostty_terminal_grid_ref(terminal: number, pointPtr: number, outRefPtr: number): number;
|
|
84
|
+
/** `ghostty_grid_ref_cell` — get the cell at a grid ref. grid_ref.h. */
|
|
85
|
+
ghostty_grid_ref_cell(refPtr: number, outCellPtr: number): number;
|
|
86
|
+
/** `ghostty_grid_ref_row` — get the row at a grid ref. grid_ref.h. */
|
|
87
|
+
ghostty_grid_ref_row(refPtr: number, outRowPtr: number): number;
|
|
88
|
+
/** `ghostty_grid_ref_graphemes` — write grapheme codepoints into a buffer. grid_ref.h. */
|
|
89
|
+
ghostty_grid_ref_graphemes(refPtr: number, bufPtr: number, bufLen: number, outLenPtr: number): number;
|
|
90
|
+
/** `ghostty_grid_ref_hyperlink_uri` — write hyperlink URI bytes into a buffer. grid_ref.h. */
|
|
91
|
+
ghostty_grid_ref_hyperlink_uri(refPtr: number, bufPtr: number, bufLen: number, outLenPtr: number): number;
|
|
92
|
+
/** `ghostty_grid_ref_style` — fill a sized GhosttyStyle for the cell. grid_ref.h. */
|
|
93
|
+
ghostty_grid_ref_style(refPtr: number, outStylePtr: number): number;
|
|
94
|
+
/** `ghostty_cell_get` — keyed cell data extraction. screen.h. */
|
|
95
|
+
ghostty_cell_get(cell: bigint, dataKind: number, outPtr: number): number;
|
|
96
|
+
/** `ghostty_cell_get_multi` — batched keyed cell data extraction. screen.h. */
|
|
97
|
+
ghostty_cell_get_multi(cell: bigint, count: number, keysPtr: number, valuesPtr: number, outWrittenPtr: number): number;
|
|
98
|
+
/** `ghostty_row_get` — keyed row data extraction. screen.h. */
|
|
99
|
+
ghostty_row_get(row: bigint, dataKind: number, outPtr: number): number;
|
|
100
|
+
/** `ghostty_render_state_new` — create a render state. render.h. */
|
|
101
|
+
ghostty_render_state_new(allocator: number, outPtr: number): number;
|
|
102
|
+
/** `ghostty_render_state_free` — destroy a render state. render.h. */
|
|
103
|
+
ghostty_render_state_free(state: number): void;
|
|
104
|
+
/** `ghostty_render_state_update` — sync render state from terminal. render.h. */
|
|
105
|
+
ghostty_render_state_update(state: number, terminal: number): number;
|
|
106
|
+
/** `ghostty_render_state_get` — keyed render-state data. render.h. */
|
|
107
|
+
ghostty_render_state_get(state: number, dataKind: number, outPtr: number): number;
|
|
108
|
+
/** `ghostty_render_state_get_multi` — batched render-state data. render.h. */
|
|
109
|
+
ghostty_render_state_get_multi(state: number, count: number, keysPtr: number, valuesPtr: number, outWrittenPtr: number): number;
|
|
110
|
+
/** `ghostty_render_state_set` — set a render-state option (e.g. clear dirty). render.h. */
|
|
111
|
+
ghostty_render_state_set(state: number, option: number, valuePtr: number): number;
|
|
112
|
+
/** `ghostty_render_state_colors_get` — sized struct fill of effective colors. render.h. */
|
|
113
|
+
ghostty_render_state_colors_get(state: number, outColorsPtr: number): number;
|
|
114
|
+
/** `ghostty_render_state_row_iterator_new` — allocate a row iterator. render.h. */
|
|
115
|
+
ghostty_render_state_row_iterator_new(allocator: number, outIterPtr: number): number;
|
|
116
|
+
/** `ghostty_render_state_row_iterator_free` — free a row iterator. render.h. */
|
|
117
|
+
ghostty_render_state_row_iterator_free(iter: number): void;
|
|
118
|
+
/** `ghostty_render_state_row_iterator_next` — advance to next row. render.h. */
|
|
119
|
+
ghostty_render_state_row_iterator_next(iter: number): number;
|
|
120
|
+
/** `ghostty_render_state_row_get` — keyed row data from iterator's current row. render.h. */
|
|
121
|
+
ghostty_render_state_row_get(iter: number, dataKind: number, outPtr: number): number;
|
|
122
|
+
/** `ghostty_render_state_row_get_multi` — batched row data. render.h. */
|
|
123
|
+
ghostty_render_state_row_get_multi(iter: number, count: number, keysPtr: number, valuesPtr: number, outWrittenPtr: number): number;
|
|
124
|
+
/** `ghostty_render_state_row_set` — set option on current iterator row. render.h. */
|
|
125
|
+
ghostty_render_state_row_set(iter: number, option: number, valuePtr: number): number;
|
|
126
|
+
/** `ghostty_render_state_row_cells_new` — allocate a row cells iterator. render.h. */
|
|
127
|
+
ghostty_render_state_row_cells_new(allocator: number, outCellsPtr: number): number;
|
|
128
|
+
/** `ghostty_render_state_row_cells_free` — free a row cells iterator. render.h. */
|
|
129
|
+
ghostty_render_state_row_cells_free(cells: number): void;
|
|
130
|
+
/** `ghostty_render_state_row_cells_next` — advance to next cell in row. render.h. */
|
|
131
|
+
ghostty_render_state_row_cells_next(cells: number): number;
|
|
132
|
+
/** `ghostty_render_state_row_cells_select` — jump iterator to column x. render.h. */
|
|
133
|
+
ghostty_render_state_row_cells_select(cells: number, x: number): number;
|
|
134
|
+
/** `ghostty_render_state_row_cells_get` — keyed cell data from iterator. render.h. */
|
|
135
|
+
ghostty_render_state_row_cells_get(cells: number, dataKind: number, outPtr: number): number;
|
|
136
|
+
/** `ghostty_render_state_row_cells_get_multi` — batched current-cell data. render.h. */
|
|
137
|
+
ghostty_render_state_row_cells_get_multi(cells: number, count: number, keysPtr: number, valuesPtr: number, outWrittenPtr: number): number;
|
|
138
|
+
/** `ghostty_style_default` — initialize a sized GhosttyStyle to defaults. style.h. */
|
|
139
|
+
ghostty_style_default(stylePtr: number): void;
|
|
140
|
+
/** `ghostty_key_encoder_new` — create a key encoder. key/encoder.h. */
|
|
141
|
+
ghostty_key_encoder_new(allocator: number, outPtr: number): number;
|
|
142
|
+
/** `ghostty_key_encoder_free` — destroy a key encoder. key/encoder.h. */
|
|
143
|
+
ghostty_key_encoder_free(encoder: number): void;
|
|
144
|
+
/** `ghostty_key_encoder_setopt` — set encoder option. key/encoder.h. */
|
|
145
|
+
ghostty_key_encoder_setopt(encoder: number, option: number, valuePtr: number): void;
|
|
146
|
+
/** `ghostty_key_encoder_setopt_from_terminal` — sync encoder modes from a terminal. key/encoder.h. */
|
|
147
|
+
ghostty_key_encoder_setopt_from_terminal(encoder: number, terminal: number): void;
|
|
148
|
+
/** `ghostty_key_encoder_encode` — encode a key event into bytes. key/encoder.h. */
|
|
149
|
+
ghostty_key_encoder_encode(encoder: number, event: number, bufPtr: number, bufLen: number, outWrittenPtr: number): number;
|
|
150
|
+
/** `ghostty_key_event_new` — create a key event. key/event.h. */
|
|
151
|
+
ghostty_key_event_new(allocator: number, outPtr: number): number;
|
|
152
|
+
/** `ghostty_key_event_free` — destroy a key event. key/event.h. */
|
|
153
|
+
ghostty_key_event_free(event: number): void;
|
|
154
|
+
/** `ghostty_key_event_set_action` — set action (press/release/repeat). key/event.h. */
|
|
155
|
+
ghostty_key_event_set_action(event: number, action: number): void;
|
|
156
|
+
/** `ghostty_key_event_set_key` — set physical key code. key/event.h. */
|
|
157
|
+
ghostty_key_event_set_key(event: number, key: number): void;
|
|
158
|
+
/** `ghostty_key_event_set_mods` — set modifier mask. key/event.h. */
|
|
159
|
+
ghostty_key_event_set_mods(event: number, mods: number): void;
|
|
160
|
+
/** `ghostty_key_event_set_consumed_mods` — set consumed-modifier mask. key/event.h. */
|
|
161
|
+
ghostty_key_event_set_consumed_mods(event: number, mods: number): void;
|
|
162
|
+
/** `ghostty_key_event_set_composing` — set composing flag. key/event.h. */
|
|
163
|
+
ghostty_key_event_set_composing(event: number, composing: number): void;
|
|
164
|
+
/** `ghostty_key_event_set_utf8` — attach UTF-8 text for the key. key/event.h. */
|
|
165
|
+
ghostty_key_event_set_utf8(event: number, ptr: number, len: number): void;
|
|
166
|
+
/** `ghostty_key_event_set_unshifted_codepoint` — set unshifted codepoint. key/event.h. */
|
|
167
|
+
ghostty_key_event_set_unshifted_codepoint(event: number, codepoint: number): void;
|
|
168
|
+
/** `ghostty_paste_is_safe` — conservative check: newlines / `ESC[201~` ⇒ unsafe. paste.h. */
|
|
169
|
+
ghostty_paste_is_safe(dataPtr: number, len: number): number;
|
|
170
|
+
/**
|
|
171
|
+
* `ghostty_paste_encode` — strip unsafe control bytes, bracket-wrap (mode
|
|
172
|
+
* 2004) or convert `\n`→`\r`. Mutates the input buffer in place; returns
|
|
173
|
+
* `OUT_OF_SPACE` with the required size in `outWrittenPtr` when `bufLen`
|
|
174
|
+
* is too small. paste.h.
|
|
175
|
+
*/
|
|
176
|
+
ghostty_paste_encode(dataPtr: number, dataLen: number, bracketed: number, bufPtr: number, bufLen: number, outWrittenPtr: number): number;
|
|
177
|
+
/** `ghostty_mouse_encoder_new` — create an encoder. mouse/encoder.h. */
|
|
178
|
+
ghostty_mouse_encoder_new(allocator: number, outPtr: number): number;
|
|
179
|
+
/** `ghostty_mouse_encoder_free`. mouse/encoder.h. */
|
|
180
|
+
ghostty_mouse_encoder_free(encoder: number): void;
|
|
181
|
+
/** `ghostty_mouse_encoder_setopt` — value semantics depend on the option enum. mouse/encoder.h. */
|
|
182
|
+
ghostty_mouse_encoder_setopt(encoder: number, option: number, valuePtr: number): void;
|
|
183
|
+
/** `ghostty_mouse_encoder_setopt_from_terminal` — sync tracking mode + format from live terminal state. mouse/encoder.h. */
|
|
184
|
+
ghostty_mouse_encoder_setopt_from_terminal(encoder: number, terminal: number): void;
|
|
185
|
+
/** `ghostty_mouse_encoder_reset` — clear internal state (last-cell dedup etc.). mouse/encoder.h. */
|
|
186
|
+
ghostty_mouse_encoder_reset(encoder: number): void;
|
|
187
|
+
/** `ghostty_mouse_encoder_encode` — 0 bytes written ⇒ event not reported. mouse/encoder.h. */
|
|
188
|
+
ghostty_mouse_encoder_encode(encoder: number, event: number, bufPtr: number, bufLen: number, outWrittenPtr: number): number;
|
|
189
|
+
/** `ghostty_mouse_event_new`. mouse/event.h. */
|
|
190
|
+
ghostty_mouse_event_new(allocator: number, outPtr: number): number;
|
|
191
|
+
/** `ghostty_mouse_event_free`. mouse/event.h. */
|
|
192
|
+
ghostty_mouse_event_free(event: number): void;
|
|
193
|
+
/** `ghostty_mouse_event_set_action` — press/release/motion. mouse/event.h. */
|
|
194
|
+
ghostty_mouse_event_set_action(event: number, action: number): void;
|
|
195
|
+
/** `ghostty_mouse_event_set_button`. mouse/event.h. */
|
|
196
|
+
ghostty_mouse_event_set_button(event: number, button: number): void;
|
|
197
|
+
/** `ghostty_mouse_event_clear_button` — motion with no pressed button. mouse/event.h. */
|
|
198
|
+
ghostty_mouse_event_clear_button(event: number): void;
|
|
199
|
+
/** `ghostty_mouse_event_set_mods` — GhosttyMods bitmask (key.h layout). mouse/event.h. */
|
|
200
|
+
ghostty_mouse_event_set_mods(event: number, mods: number): void;
|
|
201
|
+
/** `ghostty_mouse_event_set_position` — {f32 x, f32 y} surface-space pixels, struct passed by pointer on wasm32. mouse/event.h. */
|
|
202
|
+
ghostty_mouse_event_set_position(event: number, positionPtr: number): void;
|
|
203
|
+
/** `ghostty_color_rgb_get` — extract r/g/b from a passed-by-value RGB. color.h. */
|
|
204
|
+
ghostty_color_rgb_get(rgbLowOrPacked: number, outRPtr: number, outGPtr: number, outBPtr: number): void;
|
|
205
|
+
/** Create a formatter for a terminal. Returns 0 on success. */
|
|
206
|
+
ghostty_formatter_terminal_new(allocator: number, outPtr: number, terminal: number, optionsPtr: number): number;
|
|
207
|
+
/** Execute the formatter, writing output to an allocated buffer. Returns 0 on success. */
|
|
208
|
+
ghostty_formatter_format_alloc(formatter: number, allocator: number, outPtrPtr: number, outLenPtr: number): number;
|
|
209
|
+
/** Destroy a formatter instance. */
|
|
210
|
+
ghostty_formatter_free(formatter: number): void;
|
|
211
|
+
/** Free a buffer previously allocated by the WASM allocator. */
|
|
212
|
+
ghostty_free(allocator: number, ptr: number, length: number): void;
|
|
213
|
+
/** Allocate an opaque pointer slot (for out-parameters). */
|
|
214
|
+
ghostty_wasm_alloc_opaque(): number;
|
|
215
|
+
/** Free an opaque pointer slot. */
|
|
216
|
+
ghostty_wasm_free_opaque(ptr: number): void;
|
|
217
|
+
/** Allocate a single-byte slot. */
|
|
218
|
+
ghostty_wasm_alloc_u8(): number;
|
|
219
|
+
/** Free a single-byte slot. */
|
|
220
|
+
ghostty_wasm_free_u8(ptr: number): void;
|
|
221
|
+
/** Allocate a byte array in WASM memory. */
|
|
222
|
+
ghostty_wasm_alloc_u8_array(length: number): number;
|
|
223
|
+
/** Free a byte array in WASM memory. */
|
|
224
|
+
ghostty_wasm_free_u8_array(ptr: number, length: number): void;
|
|
225
|
+
/** Allocate a u16 array. */
|
|
226
|
+
ghostty_wasm_alloc_u16_array(length: number): number;
|
|
227
|
+
/** Free a u16 array. */
|
|
228
|
+
ghostty_wasm_free_u16_array(ptr: number, length: number): void;
|
|
229
|
+
/** Allocate a usize slot (for length out-parameters). */
|
|
230
|
+
ghostty_wasm_alloc_usize(): number;
|
|
231
|
+
/** Free a usize slot. */
|
|
232
|
+
ghostty_wasm_free_usize(ptr: number): void;
|
|
233
|
+
}
|
|
234
|
+
//# sourceMappingURL=exports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exports.d.ts","sourceRoot":"","sources":["../../src/wasm/exports.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH;;;;;;;;GAQG;AACH,MAAM,WAAW,kBAAkB;IACjC,gDAAgD;IAChD,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC;IAE3B;;;;;OAKG;IACH,yBAAyB,EAAE,WAAW,CAAC,KAAK,CAAC;IAG7C;;;;;OAKG;IACH,iBAAiB,IAAI,MAAM,CAAC;IAG5B,2EAA2E;IAC3E;;;;;OAKG;IACH,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5F,yEAAyE;IACzE,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9C,8EAA8E;IAC9E,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/C;;;;;;;;OAQG;IACH,uBAAu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* binary. Shared between every consumer of the WASM module (e.g. the
|
|
6
|
+
* Node-side `terminal-screen-emulator` and the browser-side terminal
|
|
7
|
+
* surface), since the binary is identical in both environments.
|
|
8
|
+
*
|
|
9
|
+
* Each entry maps 1:1 to a C ABI function in `vendor/ghostty/include/ghostty/vt/*.h`.
|
|
10
|
+
* The header citation lives in JSDoc on the entry.
|
|
11
|
+
*
|
|
12
|
+
* @internal This module is not part of the public API.
|
|
13
|
+
*/
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=exports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exports.js","sourceRoot":"","sources":["../../src/wasm/exports.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JS → WASM function-pointer installation (the "synthetic module" trick).
|
|
3
|
+
*
|
|
4
|
+
* # Why this file exists
|
|
5
|
+
*
|
|
6
|
+
* libghostty-vt's effect callbacks (`GHOSTTY_TERMINAL_OPT_WRITE_PTY`, `_BELL`,
|
|
7
|
+
* `_TITLE_CHANGED`, ... — `terminal.h:60-95`) are C function pointers. In WASM,
|
|
8
|
+
* a "C function pointer" is an index into the module's indirect function table
|
|
9
|
+
* (`__indirect_function_table`, exported by our `ghostty-vt.wasm` build).
|
|
10
|
+
*
|
|
11
|
+
* The naive way to put a JS function into that table is `WebAssembly.Function`
|
|
12
|
+
* (the js-types / Type Reflection proposal), which as of 2026-07 is still NOT
|
|
13
|
+
* shipped by default in stable Chrome or Bun (V8 gates it behind
|
|
14
|
+
* `--experimental-wasm-type-reflection`; JSC doesn't expose it). Wasm 3.0
|
|
15
|
+
* (2025-09) did not change this — typed function references are a *core spec*
|
|
16
|
+
* feature; synthesizing a typed wasm function from JS lives in the separate
|
|
17
|
+
* JS-API proposal.
|
|
18
|
+
*
|
|
19
|
+
* # The trick (works in every runtime, today)
|
|
20
|
+
*
|
|
21
|
+
* `WebAssembly.Function`'s only job is to give a JS function a wasm type. But a
|
|
22
|
+
* ~50-byte synthetic module that IMPORTS a JS function and immediately
|
|
23
|
+
* RE-EXPORTS it produces an "Exported Function" — which carries a declared wasm
|
|
24
|
+
* type and is therefore legal to store in a `funcref` table in every engine:
|
|
25
|
+
*
|
|
26
|
+
* ```
|
|
27
|
+
* (module
|
|
28
|
+
* (import "e" "f" (func $f (param i32 i32 ...) (result ...)))
|
|
29
|
+
* (export "f" (func $f)))
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* We assemble that module's binary by hand (it has no code section — just
|
|
33
|
+
* type/import/export), instantiate it with the JS function as the import, grow
|
|
34
|
+
* `__indirect_function_table`, store the export, and hand the index to
|
|
35
|
+
* `ghostty_terminal_set()` as the "function pointer".
|
|
36
|
+
*
|
|
37
|
+
* # Rules (violate these and you get engine traps or corrupted state)
|
|
38
|
+
*
|
|
39
|
+
* 1. **The wasm signature must match the C typedef exactly.** Pointers,
|
|
40
|
+
* lengths, handles and `void*` are all `i32` on wasm32; `size_t` is `i32`;
|
|
41
|
+
* a C `bool` return is `i32`. A mismatch traps with "indirect call type
|
|
42
|
+
* mismatch" at *call* time (i.e. mid-`vt_write`), not at install time.
|
|
43
|
+
* 2. **Table indices are per-instance.** An index acquired from one WASM
|
|
44
|
+
* instance's table means nothing to another instance. Never cache indices
|
|
45
|
+
* across instances.
|
|
46
|
+
* 3. **Indices must outlive the consumer.** If a table slot is released (or
|
|
47
|
+
* overwritten) while a terminal still has it registered as a callback, the
|
|
48
|
+
* next triggering VT sequence traps. Release slots only after clearing the
|
|
49
|
+
* registration (`ghostty_terminal_set(term, OPT, 0)`) or freeing the
|
|
50
|
+
* terminal.
|
|
51
|
+
* 4. **Slots are recycled, not shrunk.** `WebAssembly.Table` cannot shrink.
|
|
52
|
+
* {@link FnTable} keeps a free-list so long-lived hosts (a browser tab
|
|
53
|
+
* opening many terminals) don't leak table slots.
|
|
54
|
+
* 5. **What the callback may do is governed by the *callee's* contract**, not
|
|
55
|
+
* by this file. For libghostty-vt effects see `../browser-terminal/vt/effects.ts`
|
|
56
|
+
* — most importantly: never re-enter `ghostty_terminal_vt_write` from
|
|
57
|
+
* inside a callback.
|
|
58
|
+
*
|
|
59
|
+
* This file is platform-agnostic (no DOM, no Node APIs) — it works identically
|
|
60
|
+
* in browsers, Node, and Bun.
|
|
61
|
+
*/
|
|
62
|
+
/** WASM value type byte codes (binary format §5.3.1). */
|
|
63
|
+
export declare const WasmValType: {
|
|
64
|
+
readonly I32: 127;
|
|
65
|
+
readonly I64: 126;
|
|
66
|
+
readonly F32: 125;
|
|
67
|
+
readonly F64: 124;
|
|
68
|
+
};
|
|
69
|
+
export type WasmValTypeCode = (typeof WasmValType)[keyof typeof WasmValType];
|
|
70
|
+
/**
|
|
71
|
+
* Wrap a JS function as a *typed wasm exported function* — the
|
|
72
|
+
* `WebAssembly.Function` substitute described in the file header.
|
|
73
|
+
*
|
|
74
|
+
* Synchronous by design: the synthetic module is tiny and
|
|
75
|
+
* `new WebAssembly.Module` on <100 bytes is microseconds. (Some engines warn
|
|
76
|
+
* about sync compilation of *large* modules on the main thread; this is 50
|
|
77
|
+
* bytes.)
|
|
78
|
+
*
|
|
79
|
+
* @param jsFn - The JS function to wrap. It receives the raw wasm values
|
|
80
|
+
* (numbers) — pointer arguments must be dereferenced against the target
|
|
81
|
+
* instance's `memory` by the caller.
|
|
82
|
+
* @param params - Parameter types matching the C typedef (rule 1 above).
|
|
83
|
+
* @param results - Result types (empty for `void`).
|
|
84
|
+
*/
|
|
85
|
+
export declare function wrapAsWasmFunction(jsFn: (...args: number[]) => number | void, params: readonly WasmValTypeCode[], results?: readonly WasmValTypeCode[]): WebAssembly.ExportValue & CallableFunction;
|
|
86
|
+
/** A table slot holding an installed JS callback. See {@link FnTable.install}. */
|
|
87
|
+
export interface InstalledFn {
|
|
88
|
+
/**
|
|
89
|
+
* The table index — pass this as the C "function pointer" value (e.g. the
|
|
90
|
+
* `value` argument of `ghostty_terminal_set`).
|
|
91
|
+
*/
|
|
92
|
+
readonly index: number;
|
|
93
|
+
/**
|
|
94
|
+
* Return the slot to the free-list. Only call after no C-side consumer can
|
|
95
|
+
* invoke the pointer anymore (rule 3 in the file header).
|
|
96
|
+
*/
|
|
97
|
+
release(): void;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Slot allocator over a module's `__indirect_function_table`.
|
|
101
|
+
*
|
|
102
|
+
* One `FnTable` per WASM instance (rule 2). Grows the table on demand and
|
|
103
|
+
* recycles released slots (rule 4). Create it once next to the instance and
|
|
104
|
+
* share it among all consumers of that instance.
|
|
105
|
+
*/
|
|
106
|
+
export declare class FnTable {
|
|
107
|
+
private readonly table;
|
|
108
|
+
private readonly freeSlots;
|
|
109
|
+
constructor(table: WebAssembly.Table);
|
|
110
|
+
/**
|
|
111
|
+
* Install a JS function into the table and return its index.
|
|
112
|
+
*
|
|
113
|
+
* @param jsFn - JS callback receiving raw wasm values (numbers).
|
|
114
|
+
* @param params - Wasm parameter types matching the C typedef exactly.
|
|
115
|
+
* @param results - Wasm result types (empty for `void`).
|
|
116
|
+
*/
|
|
117
|
+
install(jsFn: (...args: number[]) => number | void, params: readonly WasmValTypeCode[], results?: readonly WasmValTypeCode[]): InstalledFn;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=fn-table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fn-table.d.ts","sourceRoot":"","sources":["../../src/wasm/fn-table.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AAEH,yDAAyD;AACzD,eAAO,MAAM,WAAW;;;;;CAKd,CAAC;AAEX,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC;AA8C7E;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,KAAK,MAAM,GAAG,IAAI,EAC1C,MAAM,EAAE,SAAS,eAAe,EAAE,EAClC,OAAO,GAAE,SAAS,eAAe,EAAO,GACvC,WAAW,CAAC,WAAW,GAAG,gBAAgB,CAI5C;AAED,kFAAkF;AAClF,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,OAAO,IAAI,IAAI,CAAC;CACjB;AAED;;;;;;GAMG;AACH,qBAAa,OAAO;IAClB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAoB;IAC1C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAgB;gBAE9B,KAAK,EAAE,WAAW,CAAC,KAAK;IAIpC;;;;;;OAMG;IACH,OAAO,CACL,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,KAAK,MAAM,GAAG,IAAI,EAC1C,MAAM,EAAE,SAAS,eAAe,EAAE,EAClC,OAAO,GAAE,SAAS,eAAe,EAAO,GACvC,WAAW;CAgBf"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JS → WASM function-pointer installation (the "synthetic module" trick).
|
|
3
|
+
*
|
|
4
|
+
* # Why this file exists
|
|
5
|
+
*
|
|
6
|
+
* libghostty-vt's effect callbacks (`GHOSTTY_TERMINAL_OPT_WRITE_PTY`, `_BELL`,
|
|
7
|
+
* `_TITLE_CHANGED`, ... — `terminal.h:60-95`) are C function pointers. In WASM,
|
|
8
|
+
* a "C function pointer" is an index into the module's indirect function table
|
|
9
|
+
* (`__indirect_function_table`, exported by our `ghostty-vt.wasm` build).
|
|
10
|
+
*
|
|
11
|
+
* The naive way to put a JS function into that table is `WebAssembly.Function`
|
|
12
|
+
* (the js-types / Type Reflection proposal), which as of 2026-07 is still NOT
|
|
13
|
+
* shipped by default in stable Chrome or Bun (V8 gates it behind
|
|
14
|
+
* `--experimental-wasm-type-reflection`; JSC doesn't expose it). Wasm 3.0
|
|
15
|
+
* (2025-09) did not change this — typed function references are a *core spec*
|
|
16
|
+
* feature; synthesizing a typed wasm function from JS lives in the separate
|
|
17
|
+
* JS-API proposal.
|
|
18
|
+
*
|
|
19
|
+
* # The trick (works in every runtime, today)
|
|
20
|
+
*
|
|
21
|
+
* `WebAssembly.Function`'s only job is to give a JS function a wasm type. But a
|
|
22
|
+
* ~50-byte synthetic module that IMPORTS a JS function and immediately
|
|
23
|
+
* RE-EXPORTS it produces an "Exported Function" — which carries a declared wasm
|
|
24
|
+
* type and is therefore legal to store in a `funcref` table in every engine:
|
|
25
|
+
*
|
|
26
|
+
* ```
|
|
27
|
+
* (module
|
|
28
|
+
* (import "e" "f" (func $f (param i32 i32 ...) (result ...)))
|
|
29
|
+
* (export "f" (func $f)))
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* We assemble that module's binary by hand (it has no code section — just
|
|
33
|
+
* type/import/export), instantiate it with the JS function as the import, grow
|
|
34
|
+
* `__indirect_function_table`, store the export, and hand the index to
|
|
35
|
+
* `ghostty_terminal_set()` as the "function pointer".
|
|
36
|
+
*
|
|
37
|
+
* # Rules (violate these and you get engine traps or corrupted state)
|
|
38
|
+
*
|
|
39
|
+
* 1. **The wasm signature must match the C typedef exactly.** Pointers,
|
|
40
|
+
* lengths, handles and `void*` are all `i32` on wasm32; `size_t` is `i32`;
|
|
41
|
+
* a C `bool` return is `i32`. A mismatch traps with "indirect call type
|
|
42
|
+
* mismatch" at *call* time (i.e. mid-`vt_write`), not at install time.
|
|
43
|
+
* 2. **Table indices are per-instance.** An index acquired from one WASM
|
|
44
|
+
* instance's table means nothing to another instance. Never cache indices
|
|
45
|
+
* across instances.
|
|
46
|
+
* 3. **Indices must outlive the consumer.** If a table slot is released (or
|
|
47
|
+
* overwritten) while a terminal still has it registered as a callback, the
|
|
48
|
+
* next triggering VT sequence traps. Release slots only after clearing the
|
|
49
|
+
* registration (`ghostty_terminal_set(term, OPT, 0)`) or freeing the
|
|
50
|
+
* terminal.
|
|
51
|
+
* 4. **Slots are recycled, not shrunk.** `WebAssembly.Table` cannot shrink.
|
|
52
|
+
* {@link FnTable} keeps a free-list so long-lived hosts (a browser tab
|
|
53
|
+
* opening many terminals) don't leak table slots.
|
|
54
|
+
* 5. **What the callback may do is governed by the *callee's* contract**, not
|
|
55
|
+
* by this file. For libghostty-vt effects see `../browser-terminal/vt/effects.ts`
|
|
56
|
+
* — most importantly: never re-enter `ghostty_terminal_vt_write` from
|
|
57
|
+
* inside a callback.
|
|
58
|
+
*
|
|
59
|
+
* This file is platform-agnostic (no DOM, no Node APIs) — it works identically
|
|
60
|
+
* in browsers, Node, and Bun.
|
|
61
|
+
*/
|
|
62
|
+
/** WASM value type byte codes (binary format §5.3.1). */
|
|
63
|
+
export const WasmValType = {
|
|
64
|
+
I32: 0x7f,
|
|
65
|
+
I64: 0x7e,
|
|
66
|
+
F32: 0x7d,
|
|
67
|
+
F64: 0x7c,
|
|
68
|
+
};
|
|
69
|
+
/** Unsigned LEB128 encoding (wasm binary format integers). */
|
|
70
|
+
function uleb(n) {
|
|
71
|
+
const bytes = [];
|
|
72
|
+
do {
|
|
73
|
+
let b = n & 0x7f;
|
|
74
|
+
n >>>= 7;
|
|
75
|
+
if (n !== 0)
|
|
76
|
+
b |= 0x80;
|
|
77
|
+
bytes.push(b);
|
|
78
|
+
} while (n !== 0);
|
|
79
|
+
return bytes;
|
|
80
|
+
}
|
|
81
|
+
function section(id, body) {
|
|
82
|
+
return [id, ...uleb(body.length), ...body];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Assemble the binary for `(module (import "e" "f" (func <sig>)) (export "f" (func 0)))`.
|
|
86
|
+
*
|
|
87
|
+
* Sections: type (id 1), import (id 2), export (id 7). No code section — the
|
|
88
|
+
* one function is the import itself, re-exported.
|
|
89
|
+
*/
|
|
90
|
+
function buildReExportModule(params, results) {
|
|
91
|
+
const typeSection = section(1, [
|
|
92
|
+
0x01, // one type entry
|
|
93
|
+
0x60, // func type
|
|
94
|
+
...uleb(params.length),
|
|
95
|
+
...params,
|
|
96
|
+
...uleb(results.length),
|
|
97
|
+
...results,
|
|
98
|
+
]);
|
|
99
|
+
// import "e" "f" (func, type index 0)
|
|
100
|
+
const importSection = section(2, [0x01, 0x01, 0x65, 0x01, 0x66, 0x00, 0x00]);
|
|
101
|
+
// export "f" = func index 0
|
|
102
|
+
const exportSection = section(7, [0x01, 0x01, 0x66, 0x00, 0x00]);
|
|
103
|
+
return new Uint8Array([
|
|
104
|
+
0x00, 0x61, 0x73, 0x6d, // magic "\0asm"
|
|
105
|
+
0x01, 0x00, 0x00, 0x00, // version 1
|
|
106
|
+
...typeSection,
|
|
107
|
+
...importSection,
|
|
108
|
+
...exportSection,
|
|
109
|
+
]);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Wrap a JS function as a *typed wasm exported function* — the
|
|
113
|
+
* `WebAssembly.Function` substitute described in the file header.
|
|
114
|
+
*
|
|
115
|
+
* Synchronous by design: the synthetic module is tiny and
|
|
116
|
+
* `new WebAssembly.Module` on <100 bytes is microseconds. (Some engines warn
|
|
117
|
+
* about sync compilation of *large* modules on the main thread; this is 50
|
|
118
|
+
* bytes.)
|
|
119
|
+
*
|
|
120
|
+
* @param jsFn - The JS function to wrap. It receives the raw wasm values
|
|
121
|
+
* (numbers) — pointer arguments must be dereferenced against the target
|
|
122
|
+
* instance's `memory` by the caller.
|
|
123
|
+
* @param params - Parameter types matching the C typedef (rule 1 above).
|
|
124
|
+
* @param results - Result types (empty for `void`).
|
|
125
|
+
*/
|
|
126
|
+
export function wrapAsWasmFunction(jsFn, params, results = []) {
|
|
127
|
+
const module = new WebAssembly.Module(buildReExportModule(params, results));
|
|
128
|
+
const instance = new WebAssembly.Instance(module, { e: { f: jsFn } });
|
|
129
|
+
return instance.exports.f;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Slot allocator over a module's `__indirect_function_table`.
|
|
133
|
+
*
|
|
134
|
+
* One `FnTable` per WASM instance (rule 2). Grows the table on demand and
|
|
135
|
+
* recycles released slots (rule 4). Create it once next to the instance and
|
|
136
|
+
* share it among all consumers of that instance.
|
|
137
|
+
*/
|
|
138
|
+
export class FnTable {
|
|
139
|
+
table;
|
|
140
|
+
freeSlots = [];
|
|
141
|
+
constructor(table) {
|
|
142
|
+
this.table = table;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Install a JS function into the table and return its index.
|
|
146
|
+
*
|
|
147
|
+
* @param jsFn - JS callback receiving raw wasm values (numbers).
|
|
148
|
+
* @param params - Wasm parameter types matching the C typedef exactly.
|
|
149
|
+
* @param results - Wasm result types (empty for `void`).
|
|
150
|
+
*/
|
|
151
|
+
install(jsFn, params, results = []) {
|
|
152
|
+
const wrapped = wrapAsWasmFunction(jsFn, params, results);
|
|
153
|
+
const index = this.freeSlots.pop() ?? this.table.grow(1);
|
|
154
|
+
this.table.set(index, wrapped);
|
|
155
|
+
let released = false;
|
|
156
|
+
return {
|
|
157
|
+
index,
|
|
158
|
+
release: () => {
|
|
159
|
+
if (released)
|
|
160
|
+
return;
|
|
161
|
+
released = true;
|
|
162
|
+
this.table.set(index, null);
|
|
163
|
+
this.freeSlots.push(index);
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=fn-table.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fn-table.js","sourceRoot":"","sources":["../../src/wasm/fn-table.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AAEH,yDAAyD;AACzD,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,GAAG,E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;gBAChB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;gBAC5B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC7B,CAAC;SACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module wasm/memory
|
|
3
|
+
*
|
|
4
|
+
* Low-level helpers for reading from / writing to a `WebAssembly.Memory`
|
|
5
|
+
* buffer at numeric pointers.
|
|
6
|
+
*
|
|
7
|
+
* VT_NOTE (audit B6): every helper here re-derives `DataView` / typed arrays
|
|
8
|
+
* from `memory.buffer` at use time. Caching them across WASM calls is unsafe —
|
|
9
|
+
* `WebAssembly.Memory.grow()` invalidates all existing views on the buffer.
|
|
10
|
+
*
|
|
11
|
+
* Mirrors the C ABI's expectation that callers know the byte layout of their
|
|
12
|
+
* output struct (which we get from `ghostty_type_json()` via
|
|
13
|
+
* {@link ./type-layouts}). Nothing here invents shapes — it's all primitive
|
|
14
|
+
* reads/writes plus a thin lookup helper for self-describing struct fields.
|
|
15
|
+
*/
|
|
16
|
+
import type { WasmTypeLayouts } from "./type-layouts.js";
|
|
17
|
+
/** Read a little-endian u8 at `ptr`. */
|
|
18
|
+
export declare function readU8(memory: WebAssembly.Memory, ptr: number): number;
|
|
19
|
+
/** Read a little-endian u16 at `ptr`. */
|
|
20
|
+
export declare function readU16(memory: WebAssembly.Memory, ptr: number): number;
|
|
21
|
+
/** Read a little-endian u32 at `ptr`. Used for opaque-handle out-parameters (WASM ptrs are 32-bit). */
|
|
22
|
+
export declare function readU32(memory: WebAssembly.Memory, ptr: number): number;
|
|
23
|
+
/** Read a little-endian i32 at `ptr`. */
|
|
24
|
+
export declare function readI32(memory: WebAssembly.Memory, ptr: number): number;
|
|
25
|
+
/** Read a little-endian u64 at `ptr`. Returned as a `bigint`. */
|
|
26
|
+
export declare function readU64(memory: WebAssembly.Memory, ptr: number): bigint;
|
|
27
|
+
/** Write a u32 at `ptr`. */
|
|
28
|
+
export declare function writeU32(memory: WebAssembly.Memory, ptr: number, value: number): void;
|
|
29
|
+
/** Write an i32 at `ptr`. */
|
|
30
|
+
export declare function writeI32(memory: WebAssembly.Memory, ptr: number, value: number): void;
|
|
31
|
+
/** RGB triple, mirrors `GhosttyColorRgb` from `color.h`. */
|
|
32
|
+
export interface RgbBytes {
|
|
33
|
+
r: number;
|
|
34
|
+
g: number;
|
|
35
|
+
b: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Read a `GhosttyColorRgb` (3 packed bytes) at `ptr`.
|
|
39
|
+
*
|
|
40
|
+
* Mirrors the layout from `color.h`: `{ uint8_t r, g, b }`.
|
|
41
|
+
*/
|
|
42
|
+
export declare function readRgb(memory: WebAssembly.Memory, ptr: number): RgbBytes;
|
|
43
|
+
/**
|
|
44
|
+
* Look up a field offset inside a struct described by {@link WasmTypeLayouts}
|
|
45
|
+
* (parsed from `ghostty_type_json()`).
|
|
46
|
+
*
|
|
47
|
+
* Throws if the struct or field is unknown — the layouts are self-describing
|
|
48
|
+
* and guaranteed to match the WASM build, so any miss is a programmer error
|
|
49
|
+
* worth surfacing loudly.
|
|
50
|
+
*/
|
|
51
|
+
export declare function fieldOffset(layouts: WasmTypeLayouts, structName: string, fieldName: string): number;
|
|
52
|
+
/**
|
|
53
|
+
* Read a struct's reported size from {@link WasmTypeLayouts}.
|
|
54
|
+
*
|
|
55
|
+
* Use this for every WASM struct allocation — sizes can drift between
|
|
56
|
+
* Ghostty versions, and `ghostty_type_json()` is the canonical source.
|
|
57
|
+
*/
|
|
58
|
+
export declare function structSize(layouts: WasmTypeLayouts, structName: string): number;
|
|
59
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/wasm/memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;A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