| 1 | // htm bound to React's createElement, so components can be written as tagged |
| 2 | // templates instead of nested createElement calls. This buys us JSX-like markup |
| 3 | // with no build step — which matters twice over here: the Node TUI runs straight |
| 4 | // off `node` with no Vite in the loop, and Node's native TypeScript support |
| 5 | // strips types but does *not* understand JSX, so .tsx would need a bundler. |
| 6 | import { createElement } from 'react'; |
| 7 | import type { ReactElement } from 'react'; |
| 8 | import htm from 'htm'; |
| 9 | |
| 10 | // htm's own types describe it as a namespace with a call signature, which |
| 11 | // doesn't carry `bind` through. The bound result is what we actually care about, |
| 12 | // so the shape is declared here rather than fought upstream. |
| 13 | type Html = (strings: TemplateStringsArray, ...values: unknown[]) => ReactElement; |
| 14 | |
| 15 | export const html = (htm as unknown as { bind(fn: typeof createElement): Html }).bind( |
| 16 | createElement, |
| 17 | ); |