ink.ts
1 import { createElement, type ReactNode } from 'react' 2 import { ThemeProvider } from './components/design-system/ThemeProvider.js' 3 import inkRender, { 4 type Instance, 5 createRoot as inkCreateRoot, 6 type RenderOptions, 7 type Root, 8 } from './ink/root.js' 9 10 export type { RenderOptions, Instance, Root } 11 12 // Wrap all CC render calls with ThemeProvider so ThemedBox/ThemedText work 13 // without every call site having to mount it. Ink itself is theme-agnostic. 14 function withTheme(node: ReactNode): ReactNode { 15 return createElement(ThemeProvider, null, node) 16 } 17 18 export async function render( 19 node: ReactNode, 20 options?: NodeJS.WriteStream | RenderOptions, 21 ): Promise<Instance> { 22 return inkRender(withTheme(node), options) 23 } 24 25 export async function createRoot(options?: RenderOptions): Promise<Root> { 26 const root = await inkCreateRoot(options) 27 return { 28 ...root, 29 render: node => root.render(withTheme(node)), 30 } 31 } 32 33 export { color } from './components/design-system/color.js' 34 export type { Props as BoxProps } from './components/design-system/ThemedBox.js' 35 export { default as Box } from './components/design-system/ThemedBox.js' 36 export type { Props as TextProps } from './components/design-system/ThemedText.js' 37 export { default as Text } from './components/design-system/ThemedText.js' 38 export { 39 ThemeProvider, 40 usePreviewTheme, 41 useTheme, 42 useThemeSetting, 43 } from './components/design-system/ThemeProvider.js' 44 export { Ansi } from './ink/Ansi.js' 45 export type { Props as AppProps } from './ink/components/AppContext.js' 46 export type { Props as BaseBoxProps } from './ink/components/Box.js' 47 export { default as BaseBox } from './ink/components/Box.js' 48 export type { 49 ButtonState, 50 Props as ButtonProps, 51 } from './ink/components/Button.js' 52 export { default as Button } from './ink/components/Button.js' 53 export type { Props as LinkProps } from './ink/components/Link.js' 54 export { default as Link } from './ink/components/Link.js' 55 export type { Props as NewlineProps } from './ink/components/Newline.js' 56 export { default as Newline } from './ink/components/Newline.js' 57 export { NoSelect } from './ink/components/NoSelect.js' 58 export { RawAnsi } from './ink/components/RawAnsi.js' 59 export { default as Spacer } from './ink/components/Spacer.js' 60 export type { Props as StdinProps } from './ink/components/StdinContext.js' 61 export type { Props as BaseTextProps } from './ink/components/Text.js' 62 export { default as BaseText } from './ink/components/Text.js' 63 export type { DOMElement } from './ink/dom.js' 64 export { ClickEvent } from './ink/events/click-event.js' 65 export { EventEmitter } from './ink/events/emitter.js' 66 export { Event } from './ink/events/event.js' 67 export type { Key } from './ink/events/input-event.js' 68 export { InputEvent } from './ink/events/input-event.js' 69 export type { TerminalFocusEventType } from './ink/events/terminal-focus-event.js' 70 export { TerminalFocusEvent } from './ink/events/terminal-focus-event.js' 71 export { FocusManager } from './ink/focus.js' 72 export type { FlickerReason } from './ink/frame.js' 73 export { useAnimationFrame } from './ink/hooks/use-animation-frame.js' 74 export { default as useApp } from './ink/hooks/use-app.js' 75 export { default as useInput } from './ink/hooks/use-input.js' 76 export { useAnimationTimer, useInterval } from './ink/hooks/use-interval.js' 77 export { useSelection } from './ink/hooks/use-selection.js' 78 export { default as useStdin } from './ink/hooks/use-stdin.js' 79 export { useTabStatus } from './ink/hooks/use-tab-status.js' 80 export { useTerminalFocus } from './ink/hooks/use-terminal-focus.js' 81 export { useTerminalTitle } from './ink/hooks/use-terminal-title.js' 82 export { useTerminalViewport } from './ink/hooks/use-terminal-viewport.js' 83 export { default as measureElement } from './ink/measure-element.js' 84 export { supportsTabStatus } from './ink/termio/osc.js' 85 export { default as wrapText } from './ink/wrap-text.js'