@kingkoo1985/ink 6.6.6

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 (225) hide show
  1. package/build/colorize.d.ts +4 -0
  2. package/build/colorize.js +59 -0
  3. package/build/colorize.js.map +1 -0
  4. package/build/components/AccessibilityContext.d.ts +3 -0
  5. package/build/components/AccessibilityContext.js +5 -0
  6. package/build/components/AccessibilityContext.js.map +1 -0
  7. package/build/components/App.d.ts +68 -0
  8. package/build/components/App.js +290 -0
  9. package/build/components/App.js.map +1 -0
  10. package/build/components/AppContext.d.ts +52 -0
  11. package/build/components/AppContext.js +16 -0
  12. package/build/components/AppContext.js.map +1 -0
  13. package/build/components/BackgroundContext.d.ts +4 -0
  14. package/build/components/BackgroundContext.js +3 -0
  15. package/build/components/BackgroundContext.js.map +1 -0
  16. package/build/components/Box.d.ts +171 -0
  17. package/build/components/Box.js +40 -0
  18. package/build/components/Box.js.map +1 -0
  19. package/build/components/ErrorOverview.d.ts +6 -0
  20. package/build/components/ErrorOverview.js +84 -0
  21. package/build/components/ErrorOverview.js.map +1 -0
  22. package/build/components/FocusContext.d.ts +16 -0
  23. package/build/components/FocusContext.js +16 -0
  24. package/build/components/FocusContext.js.map +1 -0
  25. package/build/components/Newline.d.ts +13 -0
  26. package/build/components/Newline.js +8 -0
  27. package/build/components/Newline.js.map +1 -0
  28. package/build/components/Spacer.d.ts +7 -0
  29. package/build/components/Spacer.js +11 -0
  30. package/build/components/Spacer.js.map +1 -0
  31. package/build/components/Static.d.ts +24 -0
  32. package/build/components/Static.js +29 -0
  33. package/build/components/Static.js.map +1 -0
  34. package/build/components/StaticRender.d.ts +8 -0
  35. package/build/components/StaticRender.js +19 -0
  36. package/build/components/StaticRender.js.map +1 -0
  37. package/build/components/StderrContext.d.ts +15 -0
  38. package/build/components/StderrContext.js +12 -0
  39. package/build/components/StderrContext.js.map +1 -0
  40. package/build/components/StdinContext.d.ts +22 -0
  41. package/build/components/StdinContext.js +16 -0
  42. package/build/components/StdinContext.js.map +1 -0
  43. package/build/components/StdoutContext.d.ts +15 -0
  44. package/build/components/StdoutContext.js +12 -0
  45. package/build/components/StdoutContext.js.map +1 -0
  46. package/build/components/Text.d.ts +63 -0
  47. package/build/components/Text.js +50 -0
  48. package/build/components/Text.js.map +1 -0
  49. package/build/components/Transform.d.ts +16 -0
  50. package/build/components/Transform.js +15 -0
  51. package/build/components/Transform.js.map +1 -0
  52. package/build/data-limited-lru-map.d.ts +20 -0
  53. package/build/data-limited-lru-map.js +65 -0
  54. package/build/data-limited-lru-map.js.map +1 -0
  55. package/build/debug-log.d.ts +2 -0
  56. package/build/debug-log.js +44 -0
  57. package/build/debug-log.js.map +1 -0
  58. package/build/devtools-window-polyfill.d.ts +1 -0
  59. package/build/devtools-window-polyfill.js +65 -0
  60. package/build/devtools-window-polyfill.js.map +1 -0
  61. package/build/devtools.d.ts +1 -0
  62. package/build/devtools.js +8 -0
  63. package/build/devtools.js.map +1 -0
  64. package/build/dom.d.ts +114 -0
  65. package/build/dom.js +169 -0
  66. package/build/dom.js.map +1 -0
  67. package/build/get-max-width.d.ts +3 -0
  68. package/build/get-max-width.js +10 -0
  69. package/build/get-max-width.js.map +1 -0
  70. package/build/hooks/use-app.d.ts +5 -0
  71. package/build/hooks/use-app.js +8 -0
  72. package/build/hooks/use-app.js.map +1 -0
  73. package/build/hooks/use-focus-manager.d.ts +28 -0
  74. package/build/hooks/use-focus-manager.js +17 -0
  75. package/build/hooks/use-focus-manager.js.map +1 -0
  76. package/build/hooks/use-focus.d.ts +29 -0
  77. package/build/hooks/use-focus.js +42 -0
  78. package/build/hooks/use-focus.js.map +1 -0
  79. package/build/hooks/use-input.d.ts +93 -0
  80. package/build/hooks/use-input.js +92 -0
  81. package/build/hooks/use-input.js.map +1 -0
  82. package/build/hooks/use-is-screen-reader-enabled.d.ts +5 -0
  83. package/build/hooks/use-is-screen-reader-enabled.js +11 -0
  84. package/build/hooks/use-is-screen-reader-enabled.js.map +1 -0
  85. package/build/hooks/use-stderr.d.ts +5 -0
  86. package/build/hooks/use-stderr.js +8 -0
  87. package/build/hooks/use-stderr.js.map +1 -0
  88. package/build/hooks/use-stdin.d.ts +5 -0
  89. package/build/hooks/use-stdin.js +8 -0
  90. package/build/hooks/use-stdin.js.map +1 -0
  91. package/build/hooks/use-stdout.d.ts +5 -0
  92. package/build/hooks/use-stdout.js +8 -0
  93. package/build/hooks/use-stdout.js.map +1 -0
  94. package/build/index.d.ts +38 -0
  95. package/build/index.js +27 -0
  96. package/build/index.js.map +1 -0
  97. package/build/ink.d.ts +110 -0
  98. package/build/ink.js +576 -0
  99. package/build/ink.js.map +1 -0
  100. package/build/instances.d.ts +3 -0
  101. package/build/instances.js +8 -0
  102. package/build/instances.js.map +1 -0
  103. package/build/layout.d.ts +18 -0
  104. package/build/layout.js +54 -0
  105. package/build/layout.js.map +1 -0
  106. package/build/log-update.d.ts +28 -0
  107. package/build/log-update.js +529 -0
  108. package/build/log-update.js.map +1 -0
  109. package/build/measure-element.d.ts +119 -0
  110. package/build/measure-element.js +825 -0
  111. package/build/measure-element.js.map +1 -0
  112. package/build/measure-text.d.ts +50 -0
  113. package/build/measure-text.js +237 -0
  114. package/build/measure-text.js.map +1 -0
  115. package/build/output.d.ts +242 -0
  116. package/build/output.js +607 -0
  117. package/build/output.js.map +1 -0
  118. package/build/parse-keypress.d.ts +14 -0
  119. package/build/parse-keypress.js +225 -0
  120. package/build/parse-keypress.js.map +1 -0
  121. package/build/reconciler.d.ts +4 -0
  122. package/build/reconciler.js +326 -0
  123. package/build/reconciler.js.map +1 -0
  124. package/build/render-background.d.ts +4 -0
  125. package/build/render-background.js +37 -0
  126. package/build/render-background.js.map +1 -0
  127. package/build/render-border.d.ts +4 -0
  128. package/build/render-border.js +81 -0
  129. package/build/render-border.js.map +1 -0
  130. package/build/render-cached.d.ts +18 -0
  131. package/build/render-cached.js +66 -0
  132. package/build/render-cached.js.map +1 -0
  133. package/build/render-container.d.ts +27 -0
  134. package/build/render-container.js +169 -0
  135. package/build/render-container.js.map +1 -0
  136. package/build/render-node-to-output.d.ts +32 -0
  137. package/build/render-node-to-output.js +177 -0
  138. package/build/render-node-to-output.js.map +1 -0
  139. package/build/render-screen-reader.d.ts +5 -0
  140. package/build/render-screen-reader.js +54 -0
  141. package/build/render-screen-reader.js.map +1 -0
  142. package/build/render-scrollbar.d.ts +23 -0
  143. package/build/render-scrollbar.js +70 -0
  144. package/build/render-scrollbar.js.map +1 -0
  145. package/build/render-sticky.d.ts +53 -0
  146. package/build/render-sticky.js +317 -0
  147. package/build/render-sticky.js.map +1 -0
  148. package/build/render-text-node.d.ts +20 -0
  149. package/build/render-text-node.js +155 -0
  150. package/build/render-text-node.js.map +1 -0
  151. package/build/render.d.ts +165 -0
  152. package/build/render.js +60 -0
  153. package/build/render.js.map +1 -0
  154. package/build/renderer.d.ts +24 -0
  155. package/build/renderer.js +292 -0
  156. package/build/renderer.js.map +1 -0
  157. package/build/replay.d.ts +59 -0
  158. package/build/replay.js +128 -0
  159. package/build/replay.js.map +1 -0
  160. package/build/resize-observer.d.ts +24 -0
  161. package/build/resize-observer.js +102 -0
  162. package/build/resize-observer.js.map +1 -0
  163. package/build/scroll.d.ts +11 -0
  164. package/build/scroll.js +123 -0
  165. package/build/scroll.js.map +1 -0
  166. package/build/selection.d.ts +52 -0
  167. package/build/selection.js +359 -0
  168. package/build/selection.js.map +1 -0
  169. package/build/serialization.d.ts +25 -0
  170. package/build/serialization.js +224 -0
  171. package/build/serialization.js.map +1 -0
  172. package/build/squash-text-nodes.d.ts +16 -0
  173. package/build/squash-text-nodes.js +58 -0
  174. package/build/squash-text-nodes.js.map +1 -0
  175. package/build/styled-line.d.ts +58 -0
  176. package/build/styled-line.js +629 -0
  177. package/build/styled-line.js.map +1 -0
  178. package/build/styles.d.ts +286 -0
  179. package/build/styles.js +257 -0
  180. package/build/styles.js.map +1 -0
  181. package/build/terminal-buffer.d.ts +57 -0
  182. package/build/terminal-buffer.js +507 -0
  183. package/build/terminal-buffer.js.map +1 -0
  184. package/build/text-wrap.d.ts +12 -0
  185. package/build/text-wrap.js +154 -0
  186. package/build/text-wrap.js.map +1 -0
  187. package/build/tokenize.d.ts +47 -0
  188. package/build/tokenize.js +419 -0
  189. package/build/tokenize.js.map +1 -0
  190. package/build/vertical-gap.d.ts +17 -0
  191. package/build/vertical-gap.js +20 -0
  192. package/build/vertical-gap.js.map +1 -0
  193. package/build/worker/animation-controller.d.ts +72 -0
  194. package/build/worker/animation-controller.js +128 -0
  195. package/build/worker/animation-controller.js.map +1 -0
  196. package/build/worker/ansi-utils.d.ts +16 -0
  197. package/build/worker/ansi-utils.js +40 -0
  198. package/build/worker/ansi-utils.js.map +1 -0
  199. package/build/worker/canvas.d.ts +49 -0
  200. package/build/worker/canvas.js +90 -0
  201. package/build/worker/canvas.js.map +1 -0
  202. package/build/worker/compositor.d.ts +33 -0
  203. package/build/worker/compositor.js +308 -0
  204. package/build/worker/compositor.js.map +1 -0
  205. package/build/worker/platform.d.ts +15 -0
  206. package/build/worker/platform.js +19 -0
  207. package/build/worker/platform.js.map +1 -0
  208. package/build/worker/render-worker.d.ts +112 -0
  209. package/build/worker/render-worker.js +944 -0
  210. package/build/worker/render-worker.js.map +1 -0
  211. package/build/worker/scene-manager.d.ts +26 -0
  212. package/build/worker/scene-manager.js +109 -0
  213. package/build/worker/scene-manager.js.map +1 -0
  214. package/build/worker/scroll-optimizer.d.ts +32 -0
  215. package/build/worker/scroll-optimizer.js +110 -0
  216. package/build/worker/scroll-optimizer.js.map +1 -0
  217. package/build/worker/terminal-writer.d.ts +116 -0
  218. package/build/worker/terminal-writer.js +708 -0
  219. package/build/worker/terminal-writer.js.map +1 -0
  220. package/build/worker/worker-entry.d.ts +6 -0
  221. package/build/worker/worker-entry.js +130 -0
  222. package/build/worker/worker-entry.js.map +1 -0
  223. package/license +9 -0
  224. package/package.json +208 -0
  225. package/readme.md +2353 -0
@@ -0,0 +1,155 @@
1
+ import { isNodeSelectable } from './dom.js';
2
+ import { measureStyledChars, splitStyledCharsByNewline, toStyledCharacters, } from './measure-text.js';
3
+ import { wrapOrTruncateStyledChars } from './text-wrap.js';
4
+ import getMaxWidth from './get-max-width.js';
5
+ import squashTextNodes from './squash-text-nodes.js';
6
+ import { applySelectionToStyledChars } from './selection.js';
7
+ import { StyledLine } from './styled-line.js';
8
+ export const applyPaddingToStyledChars = (node, lines) => {
9
+ const yogaNode = node.childNodes[0]?.yogaNode;
10
+ if (yogaNode) {
11
+ const offsetX = yogaNode.getComputedLeft();
12
+ const offsetY = yogaNode.getComputedTop();
13
+ if (offsetX > 0 || offsetY > 0) {
14
+ const paddedLines = [];
15
+ const paddingLeft = offsetX > 0 ? StyledLine.empty(offsetX) : undefined;
16
+ for (const line of lines) {
17
+ paddedLines.push(paddingLeft ? paddingLeft.combine(line) : line);
18
+ }
19
+ lines = paddedLines;
20
+ for (let i = 0; i < offsetY; i++) {
21
+ lines.unshift(new StyledLine());
22
+ }
23
+ }
24
+ }
25
+ return lines;
26
+ };
27
+ export const calculateWrappedCursorPosition = (lines, _styledChars, targetOffset) => {
28
+ let cursorLineIndex = lines.length - 1;
29
+ let relativeCursorPosition = targetOffset;
30
+ let sourceIndex = 0;
31
+ for (const [i, line] of lines.entries()) {
32
+ // If the line is empty (e.g., from consecutive newlines), it consumes a newline
33
+ if (line.length === 0) {
34
+ if (targetOffset === sourceIndex) {
35
+ cursorLineIndex = i;
36
+ relativeCursorPosition = 0;
37
+ break;
38
+ }
39
+ sourceIndex++; // Consume the newline
40
+ continue;
41
+ }
42
+ // Advance sourceIndex over dropped characters (like \n or space)
43
+ while (sourceIndex < _styledChars.length &&
44
+ _styledChars.getValue(sourceIndex) !== line.getValue(0)) {
45
+ if (targetOffset === sourceIndex) {
46
+ // Target is on a dropped character BEFORE this line
47
+ // We return the END of the previous line (or start of this line if i=0)
48
+ if (i > 0) {
49
+ cursorLineIndex = i - 1;
50
+ relativeCursorPosition = lines[i - 1].length;
51
+ }
52
+ else {
53
+ cursorLineIndex = 0;
54
+ relativeCursorPosition = 0;
55
+ }
56
+ return { cursorLineIndex, relativeCursorPosition };
57
+ }
58
+ sourceIndex++;
59
+ }
60
+ const lineStartOffset = sourceIndex;
61
+ sourceIndex += line.length; // Advance past the line content
62
+ const lineEndOffset = sourceIndex;
63
+ if (targetOffset >= lineStartOffset && targetOffset <= lineEndOffset) {
64
+ cursorLineIndex = i;
65
+ relativeCursorPosition = targetOffset - lineStartOffset;
66
+ break;
67
+ }
68
+ else if (targetOffset > lineEndOffset && i === lines.length - 1) {
69
+ cursorLineIndex = i;
70
+ relativeCursorPosition = line.length;
71
+ }
72
+ }
73
+ return { cursorLineIndex, relativeCursorPosition };
74
+ };
75
+ export function handleTextNode(node, output, options) {
76
+ const { x, y, newTransformers, selectionMap, selectionStyle } = options;
77
+ const text = squashTextNodes(node);
78
+ let styledChars = toStyledCharacters(text);
79
+ let selectionState;
80
+ const selectionRange = selectionMap?.get(node);
81
+ if (selectionRange) {
82
+ selectionState = {
83
+ range: selectionRange,
84
+ currentOffset: 0,
85
+ };
86
+ }
87
+ if (selectionState) {
88
+ styledChars = applySelectionToStyledChars(styledChars, selectionState, selectionStyle);
89
+ }
90
+ if (styledChars.length > 0 || node.internal_terminalCursorFocus) {
91
+ let lines = [];
92
+ let cursorLineIndex = 0;
93
+ let relativeCursorPosition = node.internal_terminalCursorPosition ?? 0;
94
+ if (styledChars.length > 0) {
95
+ const { width: currentWidth } = measureStyledChars(styledChars);
96
+ const maxWidth = getMaxWidth(node.yogaNode);
97
+ lines =
98
+ currentWidth > maxWidth
99
+ ? wrapOrTruncateStyledChars(styledChars, maxWidth, node.style.textWrap ?? 'wrap')
100
+ : splitStyledCharsByNewline(styledChars);
101
+ if (node.internal_terminalCursorFocus &&
102
+ node.internal_terminalCursorPosition !== undefined) {
103
+ ({ cursorLineIndex, relativeCursorPosition } =
104
+ calculateWrappedCursorPosition(lines, styledChars, node.internal_terminalCursorPosition));
105
+ }
106
+ // Original code applied padding here.
107
+ // It was done BEFORE calculateWrappedCursorPosition in original?
108
+ // Wait, the original code did:
109
+ // lines = applyPaddingToStyledChars(node, lines);
110
+ // cursorLineIndex = lines.length - 1;
111
+ // if (node.internal_terminalCursorFocus) { ... }
112
+ // I moved it after, because mapping padding offsets is hard without objects.
113
+ // But padding affects the visual cursor index!
114
+ // If we pad, the cursor shifts. Let's do it after, but we need to shift the cursor position by the padding.
115
+ const yogaNode = node.childNodes[0]?.yogaNode;
116
+ const offsetX = yogaNode?.getComputedLeft() ?? 0;
117
+ const offsetY = yogaNode?.getComputedTop() ?? 0;
118
+ lines = applyPaddingToStyledChars(node, lines);
119
+ if (node.internal_terminalCursorFocus &&
120
+ node.internal_terminalCursorPosition !== undefined) {
121
+ cursorLineIndex += offsetY;
122
+ relativeCursorPosition += offsetX;
123
+ }
124
+ else if (node.internal_terminalCursorFocus) {
125
+ cursorLineIndex = lines.length - 1;
126
+ // Default to end of the last line
127
+ relativeCursorPosition = lines[cursorLineIndex].length;
128
+ }
129
+ }
130
+ else {
131
+ const yogaNode = node.childNodes[0]?.yogaNode;
132
+ const offsetX = yogaNode?.getComputedLeft() ?? 0;
133
+ const offsetY = yogaNode?.getComputedTop() ?? 0;
134
+ const line = StyledLine.empty(offsetX);
135
+ lines = [line];
136
+ for (let i = 0; i < offsetY; i++) {
137
+ lines.unshift(new StyledLine());
138
+ }
139
+ if (node.internal_terminalCursorFocus) {
140
+ cursorLineIndex = offsetY;
141
+ relativeCursorPosition = offsetX;
142
+ }
143
+ }
144
+ for (const [index, line] of lines.entries()) {
145
+ output.write(x, y + index, line, {
146
+ transformers: newTransformers,
147
+ lineIndex: index,
148
+ isTerminalCursorFocused: node.internal_terminalCursorFocus && index === cursorLineIndex,
149
+ terminalCursorPosition: relativeCursorPosition,
150
+ isSelectable: isNodeSelectable(node),
151
+ });
152
+ }
153
+ }
154
+ }
155
+ //# sourceMappingURL=render-text-node.js.map
@@ -0,0 +1 @@
1
+ {"version":3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eAAe;gBAC7B,SAAS,EAAE,KAAK;gBAChB,uBAAuB,EACtB,IAAI,CAAC,4BAA4B,IAAI,KAAK,KAAK,eAAe;gBAC/D,sBAAsB,EAAE,sBAAsB;gBAC9C,YAAY,EAAE,gBAAgB,CAAC,IAAI,CAAC;aACpC,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;AACF,CAAC"}
@@ -0,0 +1,165 @@
1
+ import type { ReactNode } from 'react';
2
+ import { type StyledLine } from './styled-line.js';
3
+ import Ink, { type RenderMetrics } from './ink.js';
4
+ import { type Selection } from './selection.js';
5
+ import { type DOMElement } from './dom.js';
6
+ export type RenderOptions = {
7
+ /**
8
+ Output stream where app will be rendered.
9
+
10
+ @default process.stdout
11
+ */
12
+ stdout?: NodeJS.WriteStream;
13
+ /**
14
+ Input stream where app will listen for input.
15
+
16
+ @default process.stdin
17
+ */
18
+ stdin?: NodeJS.ReadStream;
19
+ /**
20
+ Error stream.
21
+ @default process.stderr
22
+ */
23
+ stderr?: NodeJS.WriteStream;
24
+ /**
25
+ If true, each update will be rendered as separate output, without replacing the previous one.
26
+
27
+ @default false
28
+ */
29
+ debug?: boolean;
30
+ /**
31
+ Configure whether Ink should listen for Ctrl+C keyboard input and exit the app. This is needed in case `process.stdin` is in raw mode, because then Ctrl+C is ignored by default and the process is expected to handle it manually.
32
+
33
+ @default true
34
+ */
35
+ exitOnCtrlC?: boolean;
36
+ /**
37
+ Patch console methods to ensure console output doesn't mix with Ink's output.
38
+
39
+ @default true
40
+ */
41
+ patchConsole?: boolean;
42
+ /**
43
+ Runs the given callback after each render and re-render.
44
+ */
45
+ onRender?: (metrics: RenderMetrics) => void;
46
+ /**
47
+ Enable screen reader support. See https://github.com/vadimdemedes/ink/blob/master/readme.md#screen-reader-support
48
+
49
+ @default process.env['INK_SCREEN_READER'] === 'true'
50
+ */
51
+ isScreenReaderEnabled?: boolean;
52
+ /**
53
+ Maximum frames per second for render updates.
54
+ This controls how frequently the UI can update to prevent excessive re-rendering.
55
+ Higher values allow more frequent updates but may impact performance.
56
+
57
+ @default 30
58
+ */
59
+ maxFps?: number;
60
+ /**
61
+ * Render the app in an alternate screen buffer.
62
+ * This is useful for fullscreen applications.
63
+ * @default false
64
+ */
65
+ alternateBuffer?: boolean;
66
+ /**
67
+ * If true, Ink will not emit the control sequence to enter alternate buffer mode,
68
+ * but will still emit the sequence to exit it.
69
+ *
70
+ * @default false
71
+ */
72
+ alternateBufferAlreadyActive?: boolean;
73
+ /**
74
+ Enable incremental rendering mode which only updates changed lines instead of redrawing the entire output.
75
+ This can reduce flickering and improve performance for frequently updating UIs.
76
+
77
+ @default false
78
+ */
79
+ incrementalRendering?: boolean;
80
+ /**
81
+ If true, all content for the current frame will be rendered with background colors that alternate through a rainbow of options.
82
+ This is useful for debugging to see what content was actually updated on each frame.
83
+ Only content that was re-rendered gets a new rainbow color.
84
+
85
+ @default false
86
+ */
87
+ debugRainbow?: boolean;
88
+ /**
89
+ * Function to transform selected text characters.
90
+ */
91
+ selectionStyle?: (line: StyledLine, index: number) => void;
92
+ standardReactLayoutTiming?: boolean;
93
+ /**
94
+ * Use a separate process-based rendering mode so that render updates are
95
+ * not blocked by the main thread
96
+ *
97
+ * @default false
98
+ */
99
+ renderProcess?: boolean;
100
+ /**
101
+ * Use the terminal buffer logic (backbuffer tracking) for rendering.
102
+ * If `renderProcess` is also true, this is implied.
103
+ * If `renderProcess` is false and this is true, the terminal buffer logic runs in the main process.
104
+ *
105
+ * @default false
106
+ */
107
+ terminalBuffer?: boolean;
108
+ /**
109
+ * If true, the worker-based renderer will automatically scroll all scrollable regions
110
+ * by 1 line every 16ms. This is only supported when using `terminalBuffer` or `renderProcess`.
111
+ *
112
+ * @default false
113
+ */
114
+ animatedScroll?: boolean;
115
+ /**
116
+ * Render sticky headers stuck at the top/bottom of scrollable regions
117
+ * when they are pushed to the terminal backbuffer.
118
+ * @default false
119
+ */
120
+ stickyHeadersInBackbuffer?: boolean;
121
+ cacheToStyledCharacters?: boolean;
122
+ trackSelection?: boolean;
123
+ };
124
+ export type Instance = {
125
+ /**
126
+ Replace the previous root node with a new one or update props of the current root node.
127
+ */
128
+ rerender: Ink['render'];
129
+ /**
130
+ Manually unmount the whole Ink app.
131
+ */
132
+ unmount: Ink['unmount'];
133
+ /**
134
+ Returns a promise that resolves when the app is unmounted.
135
+ */
136
+ waitUntilExit: Ink['waitUntilExit'];
137
+ cleanup: () => void;
138
+ /**
139
+ Clear output.
140
+ */
141
+ clear: () => void;
142
+ /**
143
+ * Manually recalculate layout.
144
+ */
145
+ recalculateLayout: Ink['recalculateLayout'];
146
+ /**
147
+ * Get the selection object.
148
+ */
149
+ getSelection: () => Selection;
150
+ /**
151
+ * Exports the current internal rendering state to a JSON file and a human-readable text dump.
152
+ * Only supported when `terminalBuffer` is enabled.
153
+ * @param filename The path/name for the JSON file (e.g., 'snapshot.json').
154
+ */
155
+ dumpCurrentFrame: (filename: string) => void;
156
+ /**
157
+ * Internal root node of the Ink tree.
158
+ */
159
+ rootNode: DOMElement;
160
+ };
161
+ /**
162
+ Mount a component and render the output.
163
+ */
164
+ declare const render: (node: ReactNode, options?: NodeJS.WriteStream | RenderOptions) => Instance;
165
+ export default render;
@@ -0,0 +1,60 @@
1
+ import { Stream } from 'node:stream';
2
+ import process from 'node:process';
3
+ import Ink from './ink.js';
4
+ import instances from './instances.js';
5
+ /**
6
+ Mount a component and render the output.
7
+ */
8
+ const render = (node, options) => {
9
+ const inkOptions = {
10
+ stdout: process.stdout,
11
+ stdin: process.stdin,
12
+ stderr: process.stderr,
13
+ debug: false,
14
+ exitOnCtrlC: true,
15
+ patchConsole: true,
16
+ maxFps: 30,
17
+ alternateBuffer: false,
18
+ alternateBufferAlreadyActive: false,
19
+ incrementalRendering: false,
20
+ standardReactLayoutTiming: false,
21
+ renderProcess: false,
22
+ terminalBuffer: false,
23
+ animatedScroll: false,
24
+ ...getOptions(options),
25
+ };
26
+ const instance = getInstance(inkOptions.stdout, () => new Ink(inkOptions));
27
+ instance.render(node);
28
+ return {
29
+ rerender: instance.render,
30
+ unmount() {
31
+ instance.unmount();
32
+ },
33
+ waitUntilExit: instance.waitUntilExit,
34
+ cleanup: () => instances.delete(inkOptions.stdout),
35
+ clear: instance.clear,
36
+ recalculateLayout: instance.recalculateLayout,
37
+ getSelection: instance.getSelection,
38
+ dumpCurrentFrame: instance.dumpCurrentFrame,
39
+ rootNode: instance.rootNode,
40
+ };
41
+ };
42
+ export default render;
43
+ const getOptions = (stdout = {}) => {
44
+ if (stdout instanceof Stream) {
45
+ return {
46
+ stdout,
47
+ stdin: process.stdin,
48
+ };
49
+ }
50
+ return stdout;
51
+ };
52
+ const getInstance = (stdout, createInstance) => {
53
+ let instance = instances.get(stdout);
54
+ if (!instance) {
55
+ instance = createInstance();
56
+ instances.set(stdout, instance);
57
+ }
58
+ return instance;
59
+ };
60
+ //# sourceMappingURL=render.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AACnC,OAAO,OAAO,MAAM,cAAc,CAAC;AAGnC,OAAO,GAAqD,MAAM,UAAU,CAAC;AAC7E,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAkMvC;;EAEE;AACF,MAAM,MAAM,GAAG,CACd,IAAe,EACf,OAA4C,EACjC,EAAE;IACb,MAAM,UAAU,GAAe;QAC9B,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,KAAK,EAAE,KAAK;QACZ,WAAW,EAAE,IAAI;QACjB,YAAY,EAAE,IAAI;QAClB,MAAM,EAAE,EAAE;QACV,eAAe,EAAE,KAAK;QACtB,4BAA4B,EAAE,KAAK;QACnC,oBAAoB,EAAE,KAAK;QAC3B,yBAAyB,EAAE,KAAK;QAChC,aAAa,EAAE,KAAK;QACpB,cAAc,EAAE,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AC;IAED,OAAO,QAAQ,CAAC;AACjB,CAAC,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { type StyledLine } from './styled-line.js';
2
+ import { type Region } from './output.js';
3
+ import { type DOMElement, type StickyHeader } from './dom.js';
4
+ import { type Selection } from './selection.js';
5
+ type Result = {
6
+ output: string;
7
+ outputHeight: number;
8
+ staticOutput: string;
9
+ styledOutput: StyledLine[];
10
+ cursorPosition?: {
11
+ row: number;
12
+ col: number;
13
+ };
14
+ stickyHeaders: StickyHeader[];
15
+ root?: Region;
16
+ };
17
+ declare const renderer: (node: DOMElement, options: {
18
+ isScreenReaderEnabled: boolean;
19
+ selection?: Selection;
20
+ selectionStyle?: (line: StyledLine, index: number) => void;
21
+ skipScrollbars?: boolean;
22
+ trackSelection?: boolean;
23
+ }) => Result;
24
+ export default renderer;