ink.ts 3.8 KB

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