@bigpixelrocket/uiok 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (280) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/LICENSE +21 -0
  3. package/NOTICE +569 -0
  4. package/README.md +44 -2
  5. package/dist/VisuallyHidden.d.ts +13 -0
  6. package/dist/VisuallyHidden.js +13 -0
  7. package/dist/activity/ActivityBar.d.ts +29 -0
  8. package/dist/activity/ActivityBar.js +21 -0
  9. package/dist/activity/activity.css +43 -0
  10. package/dist/activity/index.d.ts +2 -0
  11. package/dist/activity/index.js +2 -0
  12. package/dist/button/Button.d.ts +26 -0
  13. package/dist/button/Button.js +14 -0
  14. package/dist/button/IconButton.d.ts +18 -0
  15. package/dist/button/IconButton.js +14 -0
  16. package/dist/button/button.css +95 -0
  17. package/dist/button/index.d.ts +3 -0
  18. package/dist/button/index.js +3 -0
  19. package/dist/charts/Drawing.d.ts +27 -0
  20. package/dist/charts/Drawing.js +117 -0
  21. package/dist/charts/Drawing.logic.d.ts +2 -0
  22. package/dist/charts/Drawing.logic.js +22 -0
  23. package/dist/charts/Line.logic.d.ts +33 -0
  24. package/dist/charts/Line.logic.js +72 -0
  25. package/dist/charts/LineChart.d.ts +34 -0
  26. package/dist/charts/LineChart.js +100 -0
  27. package/dist/charts/Pie.logic.d.ts +16 -0
  28. package/dist/charts/Pie.logic.js +28 -0
  29. package/dist/charts/PieChart.d.ts +20 -0
  30. package/dist/charts/PieChart.js +16 -0
  31. package/dist/charts/ResultChart.d.ts +47 -0
  32. package/dist/charts/ResultChart.js +175 -0
  33. package/dist/charts/ResultChart.logic.d.ts +42 -0
  34. package/dist/charts/ResultChart.logic.js +165 -0
  35. package/dist/charts/Scatter.logic.d.ts +55 -0
  36. package/dist/charts/Scatter.logic.js +134 -0
  37. package/dist/charts/ScatterChart.d.ts +36 -0
  38. package/dist/charts/ScatterChart.js +99 -0
  39. package/dist/charts/charts.css +310 -0
  40. package/dist/charts/index.d.ts +14 -0
  41. package/dist/charts/index.js +11 -0
  42. package/dist/charts/seriesColour.d.ts +2 -0
  43. package/dist/charts/seriesColour.js +8 -0
  44. package/dist/clock/index.d.ts +2 -0
  45. package/dist/clock/index.js +2 -0
  46. package/dist/clock/useClock.d.ts +14 -0
  47. package/dist/clock/useClock.js +57 -0
  48. package/dist/datetime/DateTimePicker.d.ts +50 -0
  49. package/dist/datetime/DateTimePicker.js +98 -0
  50. package/dist/datetime/DateTimePicker.logic.d.ts +59 -0
  51. package/dist/datetime/DateTimePicker.logic.js +103 -0
  52. package/dist/datetime/datetime.css +115 -0
  53. package/dist/datetime/index.d.ts +7 -0
  54. package/dist/datetime/index.js +7 -0
  55. package/dist/dialog/ConfirmDialog.d.ts +73 -0
  56. package/dist/dialog/ConfirmDialog.js +30 -0
  57. package/dist/dialog/DialogLegend.d.ts +21 -0
  58. package/dist/dialog/DialogLegend.js +28 -0
  59. package/dist/dialog/DialogLegend.logic.d.ts +145 -0
  60. package/dist/dialog/DialogLegend.logic.js +71 -0
  61. package/dist/dialog/ModalDialog.d.ts +101 -0
  62. package/dist/dialog/ModalDialog.js +184 -0
  63. package/dist/dialog/dialog.css +283 -0
  64. package/dist/dialog/index.d.ts +8 -0
  65. package/dist/dialog/index.js +8 -0
  66. package/dist/filter/FilterEscape.d.ts +16 -0
  67. package/dist/filter/FilterEscape.js +15 -0
  68. package/dist/filter/FilterIcon.d.ts +8 -0
  69. package/dist/filter/FilterIcon.js +11 -0
  70. package/dist/filter/filter.css +42 -0
  71. package/dist/filter/index.d.ts +3 -0
  72. package/dist/filter/index.js +3 -0
  73. package/dist/grid/DataGrid.d.ts +149 -0
  74. package/dist/grid/DataGrid.js +373 -0
  75. package/dist/grid/DataGrid.logic.d.ts +57 -0
  76. package/dist/grid/DataGrid.logic.js +121 -0
  77. package/dist/grid/grid.css +206 -0
  78. package/dist/grid/index.d.ts +7 -0
  79. package/dist/grid/index.js +7 -0
  80. package/dist/index.d.ts +32 -0
  81. package/dist/index.js +32 -0
  82. package/dist/keyboard/BrowserKeys.d.ts +15 -0
  83. package/dist/keyboard/BrowserKeys.js +28 -0
  84. package/dist/keyboard/KeyChord.logic.d.ts +25 -0
  85. package/dist/keyboard/KeyChord.logic.js +50 -0
  86. package/dist/keyboard/Keyboard.logic.d.ts +84 -0
  87. package/dist/keyboard/Keyboard.logic.js +137 -0
  88. package/dist/keyboard/OverlayWatch.d.ts +28 -0
  89. package/dist/keyboard/OverlayWatch.js +119 -0
  90. package/dist/keyboard/PageSelectAll.d.ts +14 -0
  91. package/dist/keyboard/PageSelectAll.js +22 -0
  92. package/dist/keyboard/index.d.ts +9 -0
  93. package/dist/keyboard/index.js +9 -0
  94. package/dist/keychord/KeyChord.d.ts +16 -0
  95. package/dist/keychord/KeyChord.js +55 -0
  96. package/dist/keychord/index.d.ts +2 -0
  97. package/dist/keychord/index.js +2 -0
  98. package/dist/keychord/keychord.css +41 -0
  99. package/dist/labels/UiokLabels.d.ts +41 -0
  100. package/dist/labels/UiokLabels.js +31 -0
  101. package/dist/labels/UiokProvider.d.ts +44 -0
  102. package/dist/labels/UiokProvider.js +54 -0
  103. package/dist/labels/charts.d.ts +34 -0
  104. package/dist/labels/charts.js +15 -0
  105. package/dist/labels/dateTime.d.ts +32 -0
  106. package/dist/labels/dateTime.js +14 -0
  107. package/dist/labels/dialog.d.ts +18 -0
  108. package/dist/labels/dialog.js +6 -0
  109. package/dist/labels/index.d.ts +13 -0
  110. package/dist/labels/index.js +13 -0
  111. package/dist/labels/keys.d.ts +28 -0
  112. package/dist/labels/keys.js +53 -0
  113. package/dist/labels/legend.d.ts +21 -0
  114. package/dist/labels/legend.js +7 -0
  115. package/dist/labels/listing.d.ts +16 -0
  116. package/dist/labels/listing.js +8 -0
  117. package/dist/labels/pager.d.ts +32 -0
  118. package/dist/labels/pager.js +20 -0
  119. package/dist/labels/palette.d.ts +17 -0
  120. package/dist/labels/palette.js +6 -0
  121. package/dist/labels/selectAll.d.ts +15 -0
  122. package/dist/labels/selectAll.js +6 -0
  123. package/dist/labels/terminal.d.ts +25 -0
  124. package/dist/labels/terminal.js +9 -0
  125. package/dist/legend/KeyLegend.logic.d.ts +84 -0
  126. package/dist/legend/KeyLegend.logic.js +109 -0
  127. package/dist/legend/KeyLegendStrip.d.ts +36 -0
  128. package/dist/legend/KeyLegendStrip.js +82 -0
  129. package/dist/legend/index.d.ts +3 -0
  130. package/dist/legend/index.js +3 -0
  131. package/dist/legend/legend.css +148 -0
  132. package/dist/listing/CurrentDot.d.ts +15 -0
  133. package/dist/listing/CurrentDot.js +13 -0
  134. package/dist/listing/Listing.d.ts +230 -0
  135. package/dist/listing/Listing.js +265 -0
  136. package/dist/listing/PathParts.logic.d.ts +17 -0
  137. package/dist/listing/PathParts.logic.js +18 -0
  138. package/dist/listing/index.d.ts +10 -0
  139. package/dist/listing/index.js +10 -0
  140. package/dist/listing/listing.css +867 -0
  141. package/dist/menu/MenuQuery.logic.d.ts +69 -0
  142. package/dist/menu/MenuQuery.logic.js +75 -0
  143. package/dist/menu/fuzzyMatch.d.ts +31 -0
  144. package/dist/menu/fuzzyMatch.js +296 -0
  145. package/dist/menu/index.d.ts +9 -0
  146. package/dist/menu/index.js +9 -0
  147. package/dist/menu/menu.css +203 -0
  148. package/dist/menu/useBellBeat.d.ts +8 -0
  149. package/dist/menu/useBellBeat.js +26 -0
  150. package/dist/namecut/NameCut.d.ts +22 -0
  151. package/dist/namecut/NameCut.js +28 -0
  152. package/dist/namecut/NameCut.logic.d.ts +51 -0
  153. package/dist/namecut/NameCut.logic.js +120 -0
  154. package/dist/namecut/index.d.ts +3 -0
  155. package/dist/namecut/index.js +3 -0
  156. package/dist/namecut/namecut.css +67 -0
  157. package/dist/pager/Pager.d.ts +37 -0
  158. package/dist/pager/Pager.js +38 -0
  159. package/dist/pager/Pager.logic.d.ts +13 -0
  160. package/dist/pager/Pager.logic.js +63 -0
  161. package/dist/pager/index.d.ts +7 -0
  162. package/dist/pager/index.js +7 -0
  163. package/dist/pager/pager.css +62 -0
  164. package/dist/palette/Palette.d.ts +79 -0
  165. package/dist/palette/Palette.js +60 -0
  166. package/dist/palette/index.d.ts +6 -0
  167. package/dist/palette/index.js +6 -0
  168. package/dist/palette/palette.css +159 -0
  169. package/dist/pane/PaneActions.d.ts +104 -0
  170. package/dist/pane/PaneActions.js +62 -0
  171. package/dist/pane/PaneFrame.d.ts +51 -0
  172. package/dist/pane/PaneFrame.js +28 -0
  173. package/dist/pane/PaneKeys.d.ts +41 -0
  174. package/dist/pane/PaneKeys.js +104 -0
  175. package/dist/pane/PaneKeys.logic.d.ts +95 -0
  176. package/dist/pane/PaneKeys.logic.js +109 -0
  177. package/dist/pane/index.d.ts +11 -0
  178. package/dist/pane/index.js +11 -0
  179. package/dist/pane/usePaneKeys.d.ts +141 -0
  180. package/dist/pane/usePaneKeys.js +313 -0
  181. package/dist/run/RunHeader.d.ts +50 -0
  182. package/dist/run/RunHeader.js +31 -0
  183. package/dist/run/RunProgress.logic.d.ts +29 -0
  184. package/dist/run/RunProgress.logic.js +34 -0
  185. package/dist/run/index.d.ts +3 -0
  186. package/dist/run/index.js +3 -0
  187. package/dist/run/run.css +190 -0
  188. package/dist/segmented/SegmentedChoice.d.ts +22 -0
  189. package/dist/segmented/SegmentedChoice.js +31 -0
  190. package/dist/segmented/index.d.ts +2 -0
  191. package/dist/segmented/index.js +2 -0
  192. package/dist/segmented/segmented.css +49 -0
  193. package/dist/selectall/CheckRange.logic.d.ts +8 -0
  194. package/dist/selectall/CheckRange.logic.js +23 -0
  195. package/dist/selectall/SelectAllBar.d.ts +25 -0
  196. package/dist/selectall/SelectAllBar.js +24 -0
  197. package/dist/selectall/index.d.ts +7 -0
  198. package/dist/selectall/index.js +7 -0
  199. package/dist/selectall/selectall.css +31 -0
  200. package/dist/store/KeepUnchanged.logic.d.ts +19 -0
  201. package/dist/store/KeepUnchanged.logic.js +33 -0
  202. package/dist/store/SameProps.d.ts +15 -0
  203. package/dist/store/SameProps.js +46 -0
  204. package/dist/store/ValueStore.d.ts +17 -0
  205. package/dist/store/ValueStore.js +23 -0
  206. package/dist/store/index.d.ts +8 -0
  207. package/dist/store/index.js +8 -0
  208. package/dist/store/useStableHandlers.d.ts +13 -0
  209. package/dist/store/useStableHandlers.js +22 -0
  210. package/dist/styles.css +85 -0
  211. package/dist/tabs/PageTabs.d.ts +38 -0
  212. package/dist/tabs/PageTabs.js +33 -0
  213. package/dist/tabs/index.d.ts +2 -0
  214. package/dist/tabs/index.js +2 -0
  215. package/dist/tabs/tabs.css +64 -0
  216. package/dist/terminal/Terminal.d.ts +104 -0
  217. package/dist/terminal/Terminal.js +309 -0
  218. package/dist/terminal/Terminal.logic.d.ts +66 -0
  219. package/dist/terminal/Terminal.logic.js +156 -0
  220. package/dist/terminal/TerminalMenu.d.ts +36 -0
  221. package/dist/terminal/TerminalMenu.js +87 -0
  222. package/dist/terminal/TerminalMenu.logic.d.ts +78 -0
  223. package/dist/terminal/TerminalMenu.logic.js +68 -0
  224. package/dist/terminal/TerminalScrollback.d.ts +10 -0
  225. package/dist/terminal/TerminalScrollback.js +11 -0
  226. package/dist/terminal/ghostty/LICENSE +21 -0
  227. package/dist/terminal/ghostty/core.d.ts +315 -0
  228. package/dist/terminal/ghostty/core.js +1189 -0
  229. package/dist/terminal/ghostty/fallbackColors.d.ts +12 -0
  230. package/dist/terminal/ghostty/fallbackColors.js +23 -0
  231. package/dist/terminal/ghostty/fonts/LICENSE +21 -0
  232. package/dist/terminal/ghostty/fonts/SymbolsNerdFontMono-Regular.woff2 +0 -0
  233. package/dist/terminal/ghostty/keyCodes.logic.d.ts +20 -0
  234. package/dist/terminal/ghostty/keyCodes.logic.js +249 -0
  235. package/dist/terminal/ghostty/links.logic.d.ts +39 -0
  236. package/dist/terminal/ghostty/links.logic.js +84 -0
  237. package/dist/terminal/ghostty/renderer.d.ts +98 -0
  238. package/dist/terminal/ghostty/renderer.js +481 -0
  239. package/dist/terminal/ghostty/runtime.d.ts +126 -0
  240. package/dist/terminal/ghostty/runtime.js +346 -0
  241. package/dist/terminal/ghostty/spriteGlyphs.logic.d.ts +64 -0
  242. package/dist/terminal/ghostty/spriteGlyphs.logic.js +546 -0
  243. package/dist/terminal/ghostty/surface.d.ts +285 -0
  244. package/dist/terminal/ghostty/surface.js +1565 -0
  245. package/dist/terminal/ghostty/surface.logic.d.ts +181 -0
  246. package/dist/terminal/ghostty/surface.logic.js +392 -0
  247. package/dist/terminal/ghostty/vendor/LICENSE +21 -0
  248. package/dist/terminal/ghostty/vendor/ghostty-effects.wasm +0 -0
  249. package/dist/terminal/ghostty/vendor/ghostty-vt.wasm +0 -0
  250. package/dist/terminal/index.d.ts +12 -0
  251. package/dist/terminal/index.js +12 -0
  252. package/dist/terminal/terminal.css +169 -0
  253. package/dist/text/MarkedText.d.ts +14 -0
  254. package/dist/text/MarkedText.js +11 -0
  255. package/dist/text/highlightSegments.d.ts +13 -0
  256. package/dist/text/highlightSegments.js +29 -0
  257. package/dist/text/index.d.ts +3 -0
  258. package/dist/text/index.js +3 -0
  259. package/dist/text/text.css +11 -0
  260. package/dist/themes/attributes.d.ts +21 -0
  261. package/dist/themes/attributes.js +41 -0
  262. package/dist/themes/catalog.d.ts +125 -0
  263. package/dist/themes/catalog.js +940 -0
  264. package/dist/themes/color.d.ts +29 -0
  265. package/dist/themes/color.js +52 -0
  266. package/dist/themes/ids.d.ts +139 -0
  267. package/dist/themes/ids.js +59 -0
  268. package/dist/themes/index.d.ts +12 -0
  269. package/dist/themes/index.js +12 -0
  270. package/dist/themes/themes.generated.css +1830 -0
  271. package/dist/themes/tokens.d.ts +189 -0
  272. package/dist/themes/tokens.js +462 -0
  273. package/dist/tooltip/Tooltip.d.ts +21 -0
  274. package/dist/tooltip/Tooltip.js +105 -0
  275. package/dist/tooltip/Tooltip.logic.d.ts +49 -0
  276. package/dist/tooltip/Tooltip.logic.js +50 -0
  277. package/dist/tooltip/index.d.ts +3 -0
  278. package/dist/tooltip/index.js +3 -0
  279. package/dist/tooltip/tooltip.css +45 -0
  280. package/package.json +91 -4
@@ -0,0 +1,346 @@
1
+ /**
2
+ * The page's single libghostty-vt WebAssembly instance and its C ABI helpers:
3
+ * export calls, allocation, struct layouts read from the module's own type
4
+ * manifest, and the callback trampolines for a terminal's effects (its
5
+ * replies, its bell, and its color scheme). Every terminal shares this
6
+ * instance and owns (and frees) its own handles inside it.
7
+ */
8
+ // Each asset is a URL built from a relative string literal and the module's
9
+ // own URL (import.meta.url): the standard form Vite emits as files (tested by
10
+ // npm run smoke:terminal; webpack 5 and Parcel document it too, untested) and
11
+ // native ESM resolves beside this module, so the path must stay a literal
12
+ // (docs/components/terminal.md, Assets).
13
+ const GHOSTTY_WASM_URL = new URL('./vendor/ghostty-vt.wasm', import.meta.url);
14
+ const GHOSTTY_EFFECTS_WASM_URL = new URL('./vendor/ghostty-effects.wasm', import.meta.url);
15
+ const TYPE_MANIFEST_SCHEMA = 1;
16
+ const textDecoder = new TextDecoder();
17
+ /** `GHOSTTY_TERMINAL_OPT_USERDATA`: the value every effect callback receives. */
18
+ const OPTION_USERDATA = 0;
19
+ /** `GHOSTTY_TERMINAL_OPT_WRITE_PTY`: the callback for the terminal's replies. */
20
+ const OPTION_WRITE_PTY = 1;
21
+ /** `GHOSTTY_TERMINAL_OPT_BELL`: the callback for a BEL the parser executes. */
22
+ const OPTION_BELL = 2;
23
+ /** `GHOSTTY_TERMINAL_OPT_COLOR_SCHEME`: the callback that answers `CSI ? 996 n`. */
24
+ const OPTION_COLOR_SCHEME = 7;
25
+ /** `GhosttyColorScheme`, which the color scheme callback writes as an `i32`. */
26
+ const COLOR_SCHEME_VALUE = { light: 0, dark: 1 };
27
+ /**
28
+ * A wasm32 address as JavaScript must index memory with it. The module's
29
+ * pointer results and callback arguments are `i32`, which JavaScript reads as
30
+ * signed, so an address past 2 GiB (several full histories) would come back
31
+ * negative; addresses passed into the module wrap back to the same bits.
32
+ */
33
+ function wasmPointer(value) {
34
+ return value >>> 0;
35
+ }
36
+ /**
37
+ * The bytes of a base64 `data:` URL, or null for any other URL. A bundler
38
+ * may inline a small asset (the 244-byte trampoline module) as one, and a
39
+ * page's Content Security Policy rarely lets `fetch` read `data:`, so the
40
+ * bytes are decoded here instead of fetched.
41
+ */
42
+ export function wasmDataUrlBytes(url) {
43
+ if (url.protocol !== 'data:')
44
+ return null;
45
+ const comma = url.href.indexOf(',');
46
+ if (comma < 0 || !url.href.slice(0, comma).endsWith(';base64')) {
47
+ throw new Error('A WebAssembly data: URL must be base64');
48
+ }
49
+ return Uint8Array.from(atob(url.href.slice(comma + 1)), (character) => character.charCodeAt(0));
50
+ }
51
+ /**
52
+ * Compiles a module from its URL, streaming when the response allows it.
53
+ * Streaming compilation requires the server to send `.wasm` as
54
+ * `application/wasm`; any other response falls back to buffering.
55
+ */
56
+ async function instantiateWasm(url, imports, failure) {
57
+ const inline = wasmDataUrlBytes(url);
58
+ if (inline !== null)
59
+ return (await WebAssembly.instantiate(inline, imports)).instance;
60
+ const response = await fetch(url);
61
+ if (!response.ok)
62
+ throw new Error(`${failure} (${response.status})`);
63
+ if (typeof WebAssembly.instantiateStreaming === 'function' &&
64
+ response.headers.get('content-type')?.startsWith('application/wasm') === true) {
65
+ return (await WebAssembly.instantiateStreaming(response, imports)).instance;
66
+ }
67
+ return (await WebAssembly.instantiate(await response.arrayBuffer(), imports)).instance;
68
+ }
69
+ /** The loaded libghostty-vt module; obtain it through `loadGhosttyRuntime`. */
70
+ export class GhosttyRuntime {
71
+ memory;
72
+ types;
73
+ exports;
74
+ memoryView;
75
+ heap;
76
+ effects = new Map();
77
+ nextEffectsId = 1;
78
+ writePtyFunctionIndex = 0;
79
+ bellFunctionIndex = 0;
80
+ colorSchemeFunctionIndex = 0;
81
+ constructor(instance) {
82
+ this.exports = instance.exports;
83
+ const memory = instance.exports['memory'];
84
+ if (!(memory instanceof WebAssembly.Memory)) {
85
+ throw new Error('libghostty-vt did not export WebAssembly memory');
86
+ }
87
+ // Growing an unshared memory detaches its old buffer, which is how `heapBytes`
88
+ // notices a grow without reading `memory.buffer` on every call.
89
+ if (Object.prototype.toString.call(memory.buffer) === '[object SharedArrayBuffer]') {
90
+ throw new Error('libghostty-vt memory must not be shared');
91
+ }
92
+ this.memory = memory;
93
+ this.memoryView = new DataView(memory.buffer);
94
+ this.heap = new Uint8Array(memory.buffer);
95
+ const jsonPointer = this.callPointer('ghostty_type_json');
96
+ const bytes = new Uint8Array(memory.buffer);
97
+ let end = jsonPointer;
98
+ while (end < bytes.length && bytes[end] !== 0)
99
+ end += 1;
100
+ const manifest = JSON.parse(textDecoder.decode(bytes.subarray(jsonPointer, end)));
101
+ // Every offset, size, and pointer read below assumes this manifest
102
+ // version on wasm32; another build fails here, not with corrupt memory.
103
+ if (manifest.schema !== TYPE_MANIFEST_SCHEMA ||
104
+ manifest.abi.pointer_size !== 4 ||
105
+ manifest.abi.usize_size !== 4) {
106
+ throw new Error(`Unsupported libghostty-vt type manifest (schema ${manifest.schema})`);
107
+ }
108
+ this.types = manifest.types;
109
+ }
110
+ /** Fetches and instantiates both modules; prefer the memoized `loadGhosttyRuntime`. */
111
+ static async load() {
112
+ const instance = await instantiateWasm(GHOSTTY_WASM_URL, {}, 'Unable to load libghostty-vt');
113
+ const runtime = new GhosttyRuntime(instance);
114
+ await runtime.installEffectTrampolines();
115
+ return runtime;
116
+ }
117
+ /** Calls a libghostty-vt export by name. */
118
+ call(name, ...args) {
119
+ const fn = this.exports[name];
120
+ if (typeof fn !== 'function') {
121
+ throw new Error(`libghostty-vt export is unavailable: ${name}`);
122
+ }
123
+ return fn(...args);
124
+ }
125
+ /**
126
+ * A libghostty-vt export by name, for a loop that calls it per cell without
127
+ * `call`'s lookup and argument array.
128
+ */
129
+ exportedFunction(name) {
130
+ const fn = this.exports[name];
131
+ if (typeof fn !== 'function') {
132
+ throw new Error(`libghostty-vt export is unavailable: ${name}`);
133
+ }
134
+ return fn;
135
+ }
136
+ /** Calls a libghostty-vt export that returns a pointer, as an unsigned address. */
137
+ callPointer(name, ...args) {
138
+ return wasmPointer(this.call(name, ...args));
139
+ }
140
+ /** The layout of a named C struct. */
141
+ layout(name) {
142
+ const type = this.types[name];
143
+ if (type?.kind !== 'struct' || type.size === undefined || type.fields === undefined) {
144
+ throw new Error(`libghostty-vt type layout is unavailable: ${name}`);
145
+ }
146
+ return type;
147
+ }
148
+ /** Allocates `size` zeroed bytes inside the module's memory; `size` must be positive. */
149
+ alloc(size) {
150
+ const pointer = this.callPointer('ghostty_wasm_alloc', size);
151
+ if (pointer === 0)
152
+ throw new Error(`libghostty-vt failed to allocate ${size} bytes`);
153
+ new Uint8Array(this.memory.buffer, pointer, size).fill(0);
154
+ return pointer;
155
+ }
156
+ /** Frees an `alloc` allocation; a null pointer is ignored. */
157
+ free(pointer, size) {
158
+ if (pointer !== 0)
159
+ this.call('ghostty_wasm_free', pointer, size);
160
+ }
161
+ /**
162
+ * Allocates a pointer slot for a `*_new` call to fill. The engine starts it
163
+ * null, so dispose paths that run after a partial initialization never free
164
+ * a garbage pointer.
165
+ */
166
+ allocOpaque() {
167
+ const pointer = this.callPointer('ghostty_wasm_alloc_opaque');
168
+ if (pointer === 0)
169
+ throw new Error('libghostty-vt failed to allocate an opaque pointer');
170
+ return pointer;
171
+ }
172
+ /** Frees an `allocOpaque` slot; a null pointer is ignored. */
173
+ freeOpaque(pointer) {
174
+ if (pointer !== 0)
175
+ this.call('ghostty_wasm_free_opaque', pointer);
176
+ }
177
+ /** Reads the pointer stored in a slot. */
178
+ readPointer(slot) {
179
+ return this.currentMemoryView().getUint32(slot, true);
180
+ }
181
+ /**
182
+ * Routes a terminal's replies, its bell, and its color scheme queries to
183
+ * `effects`; returns the id that detaches them. The engine passes every
184
+ * callback the same userdata, so one id carries them all.
185
+ */
186
+ attachEffects(terminal, effects) {
187
+ if (this.writePtyFunctionIndex === 0 ||
188
+ this.bellFunctionIndex === 0 ||
189
+ this.colorSchemeFunctionIndex === 0) {
190
+ throw new Error('libghostty-vt callback trampolines are unavailable');
191
+ }
192
+ const id = this.nextEffectsId++;
193
+ this.effects.set(id, effects);
194
+ this.call('ghostty_terminal_set', terminal, OPTION_USERDATA, id);
195
+ this.call('ghostty_terminal_set', terminal, OPTION_WRITE_PTY, this.writePtyFunctionIndex);
196
+ this.call('ghostty_terminal_set', terminal, OPTION_BELL, this.bellFunctionIndex);
197
+ this.call('ghostty_terminal_set', terminal, OPTION_COLOR_SCHEME, this.colorSchemeFunctionIndex);
198
+ return id;
199
+ }
200
+ /** Stops routing a terminal's effects. */
201
+ detachEffects(terminal, id) {
202
+ this.call('ghostty_terminal_set', terminal, OPTION_COLOR_SCHEME, 0);
203
+ this.call('ghostty_terminal_set', terminal, OPTION_BELL, 0);
204
+ this.call('ghostty_terminal_set', terminal, OPTION_WRITE_PTY, 0);
205
+ this.call('ghostty_terminal_set', terminal, OPTION_USERDATA, 0);
206
+ this.effects.delete(id);
207
+ }
208
+ /** A DataView over module memory; recreate it after any call that can grow memory. */
209
+ view(pointer, size) {
210
+ return new DataView(this.memory.buffer, pointer, size);
211
+ }
212
+ /** A byte view over module memory; recreate it after any call that can grow memory. */
213
+ bytes(pointer, size) {
214
+ return new Uint8Array(this.memory.buffer, pointer, size);
215
+ }
216
+ /**
217
+ * Every byte of module memory as one view, kept until a grow detaches it,
218
+ * for loops that read many small values. Fetch it again after any call that
219
+ * can grow memory.
220
+ */
221
+ heapBytes() {
222
+ if (this.heap.length === 0)
223
+ this.heap = new Uint8Array(this.memory.buffer);
224
+ return this.heap;
225
+ }
226
+ /** Reuse scalar reads across cells, refreshing after any terminal grows shared WASM memory. */
227
+ currentMemoryView() {
228
+ if (this.memoryView.buffer !== this.memory.buffer) {
229
+ this.memoryView = new DataView(this.memory.buffer);
230
+ }
231
+ return this.memoryView;
232
+ }
233
+ /** Writes a scalar struct field by name. */
234
+ setField(pointer, structName, fieldName, value) {
235
+ const field = this.layout(structName).fields[fieldName];
236
+ if (!field)
237
+ throw new Error(`libghostty-vt field is unavailable: ${structName}.${fieldName}`);
238
+ const view = this.currentMemoryView();
239
+ const offset = pointer + field.offset;
240
+ switch (this.scalarType(field)) {
241
+ case 'bool':
242
+ case 'u8':
243
+ view.setUint8(offset, value);
244
+ return;
245
+ case 'u16':
246
+ view.setUint16(offset, value, true);
247
+ return;
248
+ case 'i32':
249
+ view.setInt32(offset, value, true);
250
+ return;
251
+ case 'u32':
252
+ view.setUint32(offset, value, true);
253
+ return;
254
+ case 'u64':
255
+ view.setBigUint64(offset, BigInt(value), true);
256
+ return;
257
+ default:
258
+ throw new Error(`Unsupported libghostty-vt field type: ${field.type}`);
259
+ }
260
+ }
261
+ /** Reads a scalar struct field by name. */
262
+ readField(pointer, structName, fieldName) {
263
+ const field = this.layout(structName).fields[fieldName];
264
+ if (!field)
265
+ throw new Error(`libghostty-vt field is unavailable: ${structName}.${fieldName}`);
266
+ const view = this.currentMemoryView();
267
+ const offset = pointer + field.offset;
268
+ switch (this.scalarType(field)) {
269
+ case 'bool':
270
+ case 'u8':
271
+ return view.getUint8(offset);
272
+ case 'u16':
273
+ return view.getUint16(offset, true);
274
+ case 'i32':
275
+ return view.getInt32(offset, true);
276
+ case 'u32':
277
+ return view.getUint32(offset, true);
278
+ case 'u64':
279
+ return Number(view.getBigUint64(offset, true));
280
+ default:
281
+ throw new Error(`Unsupported libghostty-vt field type: ${field.type}`);
282
+ }
283
+ }
284
+ /**
285
+ * A field's scalar type: an enum reads as its backing integer, an alias as
286
+ * the type it names, and a pointer as `u32`.
287
+ */
288
+ scalarType(field) {
289
+ if (field.type === 'pointer')
290
+ return 'u32';
291
+ const named = this.types[field.type];
292
+ if (named?.kind === 'enum' && named.underlying !== undefined)
293
+ return named.underlying;
294
+ if (named?.kind === 'alias' && named.type !== undefined)
295
+ return named.type;
296
+ return field.type;
297
+ }
298
+ async installEffectTrampolines() {
299
+ // The import names are compiled into the trampoline module from
300
+ // `scripts/ghostty-effects.zig`; change both together.
301
+ const trampolines = await instantiateWasm(GHOSTTY_EFFECTS_WASM_URL, {
302
+ env: {
303
+ write_pty: (_terminal, userdata, pointer, length) => {
304
+ const effects = this.effects.get(userdata);
305
+ if (!effects || length === 0)
306
+ return;
307
+ effects.writePty(textDecoder.decode(new Uint8Array(this.memory.buffer, wasmPointer(pointer), length)));
308
+ },
309
+ bell: (_terminal, userdata) => this.effects.get(userdata)?.bell(),
310
+ color_scheme: (_terminal, userdata, out) => {
311
+ const effects = this.effects.get(userdata);
312
+ if (!effects)
313
+ return false;
314
+ this.currentMemoryView().setInt32(wasmPointer(out), COLOR_SCHEME_VALUE[effects.colorScheme()], true);
315
+ return true;
316
+ }
317
+ }
318
+ }, 'Unable to load the libghostty-vt callback trampolines');
319
+ this.writePtyFunctionIndex = this.addCallback(trampolines.exports['ghostty_write_pty']);
320
+ this.bellFunctionIndex = this.addCallback(trampolines.exports['ghostty_bell']);
321
+ this.colorSchemeFunctionIndex = this.addCallback(trampolines.exports['ghostty_color_scheme']);
322
+ }
323
+ /** Adds a trampoline to the module's callback table; returns its index for `ghostty_terminal_set`. */
324
+ addCallback(trampoline) {
325
+ const table = this.exports['__indirect_function_table'];
326
+ if (typeof trampoline !== 'function' || !(table instanceof WebAssembly.Table)) {
327
+ throw new Error('libghostty-vt did not expose its callback table');
328
+ }
329
+ const index = table.length;
330
+ // grow-then-set instead of grow(1, fn): WebKit stores a grow init value
331
+ // with broken type information and every later call_indirect through the
332
+ // entry traps with a signature mismatch. table.set canonicalizes correctly.
333
+ table.grow(1);
334
+ table.set(index, trampoline);
335
+ return index;
336
+ }
337
+ }
338
+ let runtimePromise = null;
339
+ /** The page's shared runtime, loaded on first use; a failed load is retried by the next call. */
340
+ export function loadGhosttyRuntime() {
341
+ runtimePromise ??= GhosttyRuntime.load().catch((error) => {
342
+ runtimePromise = null;
343
+ throw error;
344
+ });
345
+ return runtimePromise;
346
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Block elements and box drawing as shapes computed from the cell box, the way
3
+ * Ghostty's sprite font draws them (`src/font/sprite/draw/block.zig` and
4
+ * `box.zig` upstream). A font's glyphs for these characters rarely fill the
5
+ * cell, so text drawn with `fillText` leaves seams between neighbours; shapes
6
+ * that reach the cell's edges exactly tile into solid art and joined lines.
7
+ *
8
+ * Every size here is in whole device pixels: the renderer rounds each cell's
9
+ * edges to device pixels before asking, so neighbouring cells share an edge.
10
+ */
11
+ /** A filled rectangle by its edges, in device pixels from the cell's top-left corner. */
12
+ export interface GhosttySpriteRect {
13
+ readonly left: number;
14
+ readonly top: number;
15
+ readonly right: number;
16
+ readonly bottom: number;
17
+ }
18
+ /**
19
+ * A rounded corner stroked with butt caps along one path: a straight line in
20
+ * from a cell edge (`start` to `bendStart`), a cubic Bézier through two
21
+ * control points, and a straight line out to another edge (`bendEnd` to
22
+ * `end`). Points are in device pixels from the cell's top-left corner.
23
+ */
24
+ export interface GhosttySpriteArc {
25
+ readonly lineWidth: number;
26
+ readonly startX: number;
27
+ readonly startY: number;
28
+ readonly bendStartX: number;
29
+ readonly bendStartY: number;
30
+ readonly control1X: number;
31
+ readonly control1Y: number;
32
+ readonly control2X: number;
33
+ readonly control2Y: number;
34
+ readonly bendEndX: number;
35
+ readonly bendEndY: number;
36
+ readonly endX: number;
37
+ readonly endY: number;
38
+ }
39
+ /** One character's shapes, all filled or stroked in the cell's foreground colour. */
40
+ export interface GhosttySpriteGlyph {
41
+ /** The opacity the shapes are painted at: 1, or a shade's coverage. */
42
+ readonly alpha: number;
43
+ readonly rects: readonly GhosttySpriteRect[];
44
+ readonly arc: GhosttySpriteArc | null;
45
+ }
46
+ /**
47
+ * The light line thickness in device pixels for a font size and pixel ratio.
48
+ * Ghostty uses the face's underline thickness rounded up to a whole pixel;
49
+ * heavy lines are twice this.
50
+ */
51
+ export declare function ghosttySpriteThickness(fontSize: number, pixelRatio: number): number;
52
+ /**
53
+ * The codepoint a cell's text is drawn procedurally as, or -1 when it stays on
54
+ * the font path: anything but a single character in Box Drawing or Block
55
+ * Elements, and the three diagonals, which need clipping to the cell.
56
+ */
57
+ export declare function ghosttySpriteCodepoint(text: string): number;
58
+ /**
59
+ * The shapes for a Box Drawing or Block Elements codepoint in a cell `width`
60
+ * by `height` device pixels, with light lines `thickness` pixels thick; null
61
+ * for a codepoint left to the font (see `ghosttySpriteCodepoint`). All three
62
+ * sizes must be whole pixels.
63
+ */
64
+ export declare function ghosttySpriteGlyph(codepoint: number, width: number, height: number, thickness: number): GhosttySpriteGlyph | null;