@nuvin/ink 6.6.6 → 7.0.0-alpha

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 (149) hide show
  1. package/build/ansi-tokenizer.d.ts +38 -0
  2. package/build/ansi-tokenizer.js +316 -0
  3. package/build/ansi-tokenizer.js.map +1 -0
  4. package/build/components/AnimationContext.d.ts +9 -0
  5. package/build/components/AnimationContext.js +13 -0
  6. package/build/components/AnimationContext.js.map +1 -0
  7. package/build/components/App.d.ts +11 -49
  8. package/build/components/App.js +412 -227
  9. package/build/components/App.js.map +1 -1
  10. package/build/components/AppContext.d.ts +33 -3
  11. package/build/components/AppContext.js +2 -1
  12. package/build/components/AppContext.js.map +1 -1
  13. package/build/components/Box.d.ts +15 -8
  14. package/build/components/Box.js +12 -10
  15. package/build/components/Box.js.map +1 -1
  16. package/build/components/CursorContext.d.ts +11 -0
  17. package/build/components/CursorContext.js +8 -0
  18. package/build/components/CursorContext.js.map +1 -0
  19. package/build/components/ErrorBoundary.d.ts +18 -0
  20. package/build/components/ErrorBoundary.js +23 -0
  21. package/build/components/ErrorBoundary.js.map +1 -0
  22. package/build/components/ErrorOverview.js +6 -6
  23. package/build/components/ErrorOverview.js.map +1 -1
  24. package/build/components/Static.js.map +1 -1
  25. package/build/components/StdinContext.d.ts +7 -1
  26. package/build/components/StdinContext.js +1 -0
  27. package/build/components/StdinContext.js.map +1 -1
  28. package/build/components/Text.d.ts +1 -1
  29. package/build/components/Text.js +1 -1
  30. package/build/components/Text.js.map +1 -1
  31. package/build/components/Transform.d.ts +1 -1
  32. package/build/cursor-helpers.d.ts +38 -0
  33. package/build/cursor-helpers.js +56 -0
  34. package/build/cursor-helpers.js.map +1 -0
  35. package/build/devtools-window-polyfill.js +7 -4
  36. package/build/devtools-window-polyfill.js.map +1 -1
  37. package/build/devtools.js +31 -6
  38. package/build/devtools.js.map +1 -1
  39. package/build/dom.d.ts +5 -1
  40. package/build/dom.js +20 -1
  41. package/build/dom.js.map +1 -1
  42. package/build/hooks/use-animation.d.ts +49 -0
  43. package/build/hooks/use-animation.js +87 -0
  44. package/build/hooks/use-animation.js.map +1 -0
  45. package/build/hooks/use-app.d.ts +5 -2
  46. package/build/hooks/use-app.js +1 -1
  47. package/build/hooks/use-box-metrics.d.ts +59 -0
  48. package/build/hooks/use-box-metrics.js +88 -0
  49. package/build/hooks/use-box-metrics.js.map +1 -0
  50. package/build/hooks/use-cursor.d.ts +12 -0
  51. package/build/hooks/use-cursor.js +29 -0
  52. package/build/hooks/use-cursor.js.map +1 -0
  53. package/build/hooks/use-focus-manager.d.ts +17 -2
  54. package/build/hooks/use-focus-manager.js +2 -1
  55. package/build/hooks/use-focus-manager.js.map +1 -1
  56. package/build/hooks/use-focus.d.ts +2 -1
  57. package/build/hooks/use-focus.js +5 -4
  58. package/build/hooks/use-focus.js.map +1 -1
  59. package/build/hooks/use-input.d.ts +40 -1
  60. package/build/hooks/use-input.js +84 -51
  61. package/build/hooks/use-input.js.map +1 -1
  62. package/build/hooks/use-is-screen-reader-enabled.d.ts +2 -1
  63. package/build/hooks/use-is-screen-reader-enabled.js +2 -1
  64. package/build/hooks/use-is-screen-reader-enabled.js.map +1 -1
  65. package/build/hooks/use-paste.d.ts +35 -0
  66. package/build/hooks/use-paste.js +62 -0
  67. package/build/hooks/use-paste.js.map +1 -0
  68. package/build/hooks/use-stderr.d.ts +1 -1
  69. package/build/hooks/use-stderr.js +1 -1
  70. package/build/hooks/use-stdin.d.ts +4 -2
  71. package/build/hooks/use-stdin.js +2 -1
  72. package/build/hooks/use-stdin.js.map +1 -1
  73. package/build/hooks/use-stdout.d.ts +1 -1
  74. package/build/hooks/use-stdout.js +1 -1
  75. package/build/hooks/use-window-size.d.ts +18 -0
  76. package/build/hooks/use-window-size.js +22 -0
  77. package/build/hooks/use-window-size.js.map +1 -0
  78. package/build/index.d.ts +14 -1
  79. package/build/index.js +7 -0
  80. package/build/index.js.map +1 -1
  81. package/build/ink.d.ts +86 -5
  82. package/build/ink.js +581 -80
  83. package/build/ink.js.map +1 -1
  84. package/build/input-parser.d.ts +10 -0
  85. package/build/input-parser.js +194 -0
  86. package/build/input-parser.js.map +1 -0
  87. package/build/kitty-keyboard.d.ts +23 -0
  88. package/build/kitty-keyboard.js +32 -0
  89. package/build/kitty-keyboard.js.map +1 -0
  90. package/build/log-update.d.ts +7 -1
  91. package/build/log-update.js +181 -56
  92. package/build/log-update.js.map +1 -1
  93. package/build/measure-element.d.ts +4 -0
  94. package/build/measure-element.js +4 -0
  95. package/build/measure-element.js.map +1 -1
  96. package/build/measure-text.js +3 -11
  97. package/build/measure-text.js.map +1 -1
  98. package/build/output.d.ts +2 -1
  99. package/build/output.js +62 -58
  100. package/build/output.js.map +1 -1
  101. package/build/parse-keypress.d.ts +9 -3
  102. package/build/parse-keypress.js +283 -13
  103. package/build/parse-keypress.js.map +1 -1
  104. package/build/reconciler.js +57 -37
  105. package/build/reconciler.js.map +1 -1
  106. package/build/render-background.js +2 -0
  107. package/build/render-background.js.map +1 -1
  108. package/build/render-border.d.ts +1 -1
  109. package/build/render-border.js +35 -24
  110. package/build/render-border.js.map +1 -1
  111. package/build/render-node-to-output.d.ts +1 -1
  112. package/build/render-node-to-output.js +35 -18
  113. package/build/render-node-to-output.js.map +1 -1
  114. package/build/render-to-string.d.ts +38 -0
  115. package/build/render-to-string.js +116 -0
  116. package/build/render-to-string.js.map +1 -0
  117. package/build/render.d.ts +91 -3
  118. package/build/render.js +17 -5
  119. package/build/render.js.map +1 -1
  120. package/build/sanitize-ansi.d.ts +2 -0
  121. package/build/sanitize-ansi.js +27 -0
  122. package/build/sanitize-ansi.js.map +1 -0
  123. package/build/squash-text-nodes.js +2 -1
  124. package/build/squash-text-nodes.js.map +1 -1
  125. package/build/styles.d.ts +75 -37
  126. package/build/styles.js +87 -44
  127. package/build/styles.js.map +1 -1
  128. package/build/utils.d.ts +9 -2
  129. package/build/utils.js +18 -3
  130. package/build/utils.js.map +1 -1
  131. package/build/wrap-text.js +7 -0
  132. package/build/wrap-text.js.map +1 -1
  133. package/build/write-synchronized.d.ts +4 -0
  134. package/build/write-synchronized.js +9 -0
  135. package/build/write-synchronized.js.map +1 -0
  136. package/package.json +45 -105
  137. package/readme.md +850 -64
  138. package/build/components/FixedLayout.d.ts +0 -12
  139. package/build/components/FixedLayout.js +0 -19
  140. package/build/components/FixedLayout.js.map +0 -1
  141. package/build/components/VirtualizedList.d.ts +0 -21
  142. package/build/components/VirtualizedList.js +0 -55
  143. package/build/components/VirtualizedList.js.map +0 -1
  144. package/build/hooks/use-mouse.d.ts +0 -15
  145. package/build/hooks/use-mouse.js +0 -121
  146. package/build/hooks/use-mouse.js.map +0 -1
  147. package/build/hooks/use-virtualization.d.ts +0 -19
  148. package/build/hooks/use-virtualization.js +0 -56
  149. package/build/hooks/use-virtualization.js.map +0 -1
package/build/render.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import type { ReactNode } from 'react';
2
2
  import Ink, { type RenderMetrics } from './ink.js';
3
+ import { type KittyKeyboardOptions } from './kitty-keyboard.js';
3
4
  export type RenderOptions = {
4
5
  /**
5
- Output stream where app will be rendered.
6
+ Output stream where the app will be rendered.
6
7
 
7
8
  @default process.stdout
8
9
  */
@@ -33,11 +34,16 @@ export type RenderOptions = {
33
34
  /**
34
35
  Patch console methods to ensure console output doesn't mix with Ink's output.
35
36
 
37
+ Note: Once unmount starts, Ink restores the native console before React cleanup runs. Teardown-time `console.*` output then follows the normal console behavior instead of being rerouted through Ink.
38
+
36
39
  @default true
37
40
  */
38
41
  patchConsole?: boolean;
39
42
  /**
40
- Runs the given callback after each render and re-render.
43
+ Runs the given callback after each render and re-render with render metrics.
44
+
45
+ Note: this callback runs after Ink commits a frame, but it does not wait for `stdout`/`stderr` stream callbacks.
46
+ To run code after output is flushed, use `waitUntilRenderFlush()`.
41
47
  */
42
48
  onRender?: (metrics: RenderMetrics) => void;
43
49
  /**
@@ -61,6 +67,55 @@ export type RenderOptions = {
61
67
  @default false
62
68
  */
63
69
  incrementalRendering?: boolean;
70
+ /**
71
+ Enable React Concurrent Rendering mode.
72
+
73
+ When enabled:
74
+ - Suspense boundaries work correctly with async data
75
+ - `useTransition` and `useDeferredValue` are fully functional
76
+ - Updates can be interrupted for higher priority work
77
+
78
+ Note: Concurrent mode changes the timing of renders. Some tests may need to use `act()` to properly await updates. Reusing the same stdout across multiple `render()` calls without unmounting is unsupported. Call `unmount()` first if you need to change the rendering mode or create a fresh instance.
79
+
80
+ @default false
81
+ */
82
+ concurrent?: boolean;
83
+ /**
84
+ Configure kitty keyboard protocol support for enhanced keyboard input.
85
+ Enables additional modifiers (super, hyper, capsLock, numLock) and
86
+ disambiguated key events in terminals that support the protocol.
87
+
88
+ @see https://sw.kovidgoyal.net/kitty/keyboard-protocol/
89
+ */
90
+ kittyKeyboard?: KittyKeyboardOptions;
91
+ /**
92
+ Override automatic interactive mode detection.
93
+
94
+ By default, Ink detects whether the environment is interactive based on CI detection (via [`is-in-ci`](https://github.com/sindresorhus/is-in-ci)) and `stdout.isTTY`. Most users should not need to set this.
95
+
96
+ When non-interactive, Ink disables ANSI erase sequences, cursor manipulation, synchronized output, resize handling, and kitty keyboard auto-detection, writing only the final frame at unmount.
97
+
98
+ Set to `false` to force non-interactive mode or `true` to force interactive mode when the automatic detection doesn't suit your use case.
99
+
100
+ Note: Reusing the same stdout across multiple `render()` calls without unmounting is unsupported. Call `unmount()` first if you need to change this option or create a fresh instance.
101
+
102
+ @default true (false if in CI or `stdout.isTTY` is falsy)
103
+ */
104
+ interactive?: boolean;
105
+ /**
106
+ Render the app in the terminal's alternate screen buffer. When enabled, the app renders on a separate screen, and the original terminal content is restored when the app exits. This is the same mechanism used by programs like vim, htop, and less.
107
+
108
+ Note: The terminal's scrollback buffer is not available while in the alternate screen. This is standard terminal behavior; programs like vim use the alternate screen specifically to avoid polluting the user's scrollback history.
109
+
110
+ Note: Ink intentionally treats alternate-screen teardown output as disposable. It does not preserve or replay teardown-time frames, hook writes, or `console.*` output after restoring the primary screen.
111
+
112
+ Only works in interactive mode. Ignored when `interactive` is `false` or in a non-interactive environment (CI, piped stdout).
113
+
114
+ Note: Reusing the same stdout across multiple `render()` calls without unmounting is unsupported. Call `unmount()` first if you need to change this option or create a fresh instance.
115
+
116
+ @default false
117
+ */
118
+ alternateScreen?: boolean;
64
119
  };
65
120
  export type Instance = {
66
121
  /**
@@ -72,9 +127,42 @@ export type Instance = {
72
127
  */
73
128
  unmount: Ink['unmount'];
74
129
  /**
75
- Returns a promise that resolves when the app is unmounted.
130
+ Returns a promise that settles when the app is unmounted.
131
+
132
+ It resolves with the value passed to `exit(value)` and rejects with the error passed to `exit(error)`.
133
+ When `unmount()` is called manually, it settles after unmount-related stdout writes complete.
134
+
135
+ @example
136
+ ```jsx
137
+ const {unmount, waitUntilExit} = render(<MyApp />);
138
+
139
+ setTimeout(unmount, 1000);
140
+
141
+ await waitUntilExit(); // resolves after `unmount()` is called
142
+ ```
76
143
  */
77
144
  waitUntilExit: Ink['waitUntilExit'];
145
+ /**
146
+ Returns a promise that settles after pending render output is flushed to stdout.
147
+
148
+ This can be used after `rerender()` when you need to run code only after the frame is written.
149
+
150
+ @example
151
+ ```jsx
152
+ const {rerender, waitUntilRenderFlush} = render(<MyApp step="loading" />);
153
+
154
+ rerender(<MyApp step="ready" />);
155
+ await waitUntilRenderFlush(); // output for "ready" is flushed
156
+
157
+ runNextCommand();
158
+ ```
159
+ */
160
+ waitUntilRenderFlush: Ink['waitUntilRenderFlush'];
161
+ /**
162
+ Unmount the current app and remove the internal Ink instance for this stdout.
163
+
164
+ This is mostly useful for advanced cases where you need `render()` to create a fresh instance for the same stream without leaving terminal state such as the alternate screen behind.
165
+ */
78
166
  cleanup: () => void;
79
167
  /**
80
168
  Clear output.
package/build/render.js CHANGED
@@ -15,6 +15,8 @@ const render = (node, options) => {
15
15
  patchConsole: true,
16
16
  maxFps: 30,
17
17
  incrementalRendering: false,
18
+ concurrent: false,
19
+ alternateScreen: false,
18
20
  ...getOptions(options),
19
21
  };
20
22
  const instance = getInstance(inkOptions.stdout, () => new Ink(inkOptions));
@@ -25,7 +27,10 @@ const render = (node, options) => {
25
27
  instance.unmount();
26
28
  },
27
29
  waitUntilExit: instance.waitUntilExit,
28
- cleanup: () => instances.delete(inkOptions.stdout),
30
+ waitUntilRenderFlush: instance.waitUntilRenderFlush,
31
+ cleanup() {
32
+ instance.unmount();
33
+ },
29
34
  clear: instance.clear,
30
35
  };
31
36
  };
@@ -40,11 +45,18 @@ const getOptions = (stdout = {}) => {
40
45
  return stdout;
41
46
  };
42
47
  const getInstance = (stdout, createInstance) => {
43
- let instance = instances.get(stdout);
44
- if (!instance) {
45
- instance = createInstance();
46
- instances.set(stdout, instance);
48
+ const instance = instances.get(stdout);
49
+ if (instance === undefined) {
50
+ const newInstance = createInstance();
51
+ instances.set(stdout, newInstance);
52
+ return newInstance;
47
53
  }
54
+ // Ink keeps one live renderer per stdout. Reusing the same stream without
55
+ // unmounting is unsupported, but return the existing instance so we don't
56
+ // create two renderers that compete for the same output. Write the warning
57
+ // directly to native stderr so an existing alternate-screen renderer cannot
58
+ // swallow it via patchConsole.
59
+ process.stderr.write('Warning: render() was called again for the same stdout before the previous Ink instance was unmounted. Reusing stdout across multiple render() calls is unsupported. Call unmount() first.\n');
48
60
  return instance;
49
61
  };
50
62
  //# sourceMappingURL=render.js.map
@@ -1 +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;AAEnC,OAAO,GAAqD,MAAM,UAAU,CAAC;AAC7E,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAkGvC;;EAEE;AACF,MAAM,MAAM,GAAG,CACd,IAAe,EACf,OAA4C,EACjC,EAAE;IACb,MAAM,UAAU,GAAe;QAC9B,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,KA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yD,EAAE,EAC3C,EAAE;IAClB,IAAI,MAAM,YAAY,MAAM,EAAE,CAAC;QAC9B,OAAO;YACN,MAAM;YACN,KAAK,EAAE,OAAO,CAAC,KAAK;SACpB,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,CACnB,MAA0B,EAC1B,cAAyB,EACnB,EAAE;IACR,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAEvC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC5B,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;QACrC,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QACnC,OAAO,WAAW,CAAC;IACpB,CAAC;IAED,0EAA0E;IAC1E,0EAA0E;IAC1E,2EAA2E;IAC3E,4EAA4E;IAC5E,+BAA+B;IAC/B,OAAO,CAAC,MAAM,CAAC,KAAK,CACnB,8LAA8L,CAC9L,CAAC;IAEF,OAAO,QAAQ,CAAC;AACjB,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ declare const sanitizeAnsi: (text: string) => string;
2
+ export default sanitizeAnsi;
@@ -0,0 +1,27 @@
1
+ import { hasAnsiControlCharacters, tokenizeAnsi } from './ansi-tokenizer.js';
2
+ const sgrParametersRegex = /^[\d:;]*$/;
3
+ // Strip ANSI escape sequences that would conflict with Ink's layout.
4
+ // Preserved: SGR sequences (colors, bold, etc. - end with 'm') and
5
+ // OSC sequences (hyperlinks, etc. - ESC ] or C1 OSC).
6
+ // Stripped: cursor movement, screen clearing, and other control sequences.
7
+ const sanitizeAnsi = (text) => {
8
+ if (!hasAnsiControlCharacters(text)) {
9
+ return text;
10
+ }
11
+ let output = '';
12
+ for (const token of tokenizeAnsi(text)) {
13
+ if (token.type === 'text' || token.type === 'osc') {
14
+ output += token.value;
15
+ continue;
16
+ }
17
+ if (token.type === 'csi' &&
18
+ token.finalCharacter === 'm' &&
19
+ token.intermediateString === '' &&
20
+ sgrParametersRegex.test(token.parameterString)) {
21
+ output += token.value;
22
+ }
23
+ }
24
+ return output;
25
+ };
26
+ export default sanitizeAnsi;
27
+ //# sourceMappingURL=sanitize-ansi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitize-ansi.js","sourceRoot":"","sources":["../src/sanitize-ansi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,wBAAwB,EAAE,YAAY,EAAC,MAAM,qBAAqB,CAAC;AAE3E,MAAM,kBAAkB,GAAG,WAAW,CAAC;AAEvC,qEAAqE;AACrE,mEAAmE;AACnE,sDAAsD;AACtD,2EAA2E;AAC3E,MAAM,YAAY,GAAG,CAAC,IAAY,EAAU,EAAE;IAC7C,IAAI,CAAC,wBAAwB,CAAC,IAAI,CAAC,EAAE,CAAC;QACrC,OAAO,IAAI,CAAC;IACb,CAAC;IAED,IAAI,MAAM,GAAG,EAAE,CAAC;IAEhB,KAAK,MAAM,KAAK,IAAI,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;QACxC,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;YACnD,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC;YACtB,SAAS;QACV,CAAC;QAED,IACC,KAAK,CAAC,IAAI,KAAK,KAAK;YACpB,KAAK,CAAC,cAAc,KAAK,GAAG;YAC5B,KAAK,CAAC,kBAAkB,KAAK,EAAE;YAC/B,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,EAC7C,CAAC;YACF,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC;QACvB,CAAC;IACF,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -1,3 +1,4 @@
1
+ import sanitizeAnsi from './sanitize-ansi.js';
1
2
  // Squashing text nodes allows to combine multiple text nodes into one and write
2
3
  // to `Output` instance only once. For example, <Text>hello{' '}world</Text>
3
4
  // is actually 3 text nodes, which would result 3 writes to `Output`.
@@ -29,7 +30,7 @@ const squashTextNodes = (node) => {
29
30
  }
30
31
  text += nodeText;
31
32
  }
32
- return text;
33
+ return sanitizeAnsi(text);
33
34
  };
34
35
  export default squashTextNodes;
35
36
  //# sourceMappingURL=squash-text-nodes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"squash-text-nodes.js","sourceRoot":"","sources":["../src/squash-text-nodes.ts"],"names":[],"mappings":"AAEA,gFAAgF;AAChF,4EAA4E;AAC5E,qEAAqE;AACrE,EAAE;AACF,kGAAkG;AAClG,wFAAwF;AACxF,MAAM,eAAe,GAAG,CAAC,IAAgB,EAAU,EAAE;IACpD,IAAI,IAAI,GAAG,EAAE,CAAC;IAEd,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QAC7D,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAEzC,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC7B,SAAS;QACV,CAAC;QAED,IAAI,QAAQ,GAAG,EAAE,CAAC;QAElB,IAAI,SAAS,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;YACpC,QAAQ,GAAG,SAAS,CAAC,SAAS,CAAC;QAChC,CAAC;aAAM,CAAC;YACP,IACC,SAAS,CAAC,QAAQ,KAAK,UAAU;gBACjC,SAAS,CAAC,QAAQ,KAAK,kBAAkB,EACxC,CAAC;gBACF,QAAQ,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;YACvC,CAAC;YAED,oFAAoF;YACpF,iFAAiF;YACjF,IACC,QAAQ,CAAC,MAAM,GAAG,CAAC;gBACnB,OAAO,SAAS,CAAC,kBAAkB,KAAK,UAAU,EACjD,CAAC;gBACF,QAAQ,GAAG,SAAS,CAAC,kBAAkB,CA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C;QACF,CAAC;QAED,IAAI,IAAI,QAAQ,CAAC;IAClB,CAAC;IAED,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC"}
package/build/styles.d.ts CHANGED
@@ -3,24 +3,29 @@ import { type LiteralUnion } from 'type-fest';
3
3
  import { type ForegroundColorName } from 'ansi-styles';
4
4
  import { type Node as YogaNode } from 'yoga-layout';
5
5
  export type Styles = {
6
- readonly textWrap?: 'wrap' | 'end' | 'middle' | 'truncate-end' | 'truncate' | 'truncate-middle' | 'truncate-start';
7
- readonly position?: 'absolute' | 'relative' | 'sticky';
6
+ readonly textWrap?: 'wrap' | 'hard' | 'truncate-end' | 'truncate' | 'truncate-middle' | 'truncate-start';
8
7
  /**
9
- Top offset. Used with position="absolute" or position="sticky".
8
+ Controls how the element is positioned.
9
+
10
+ When `position` is `static`, `top`, `right`, `bottom`, and `left` are ignored.
11
+ */
12
+ readonly position?: 'absolute' | 'relative' | 'static' | 'sticky';
13
+ /**
14
+ Top offset for positioned elements.
10
15
  */
11
- readonly top?: number;
16
+ readonly top?: number | string;
12
17
  /**
13
- Bottom offset. Used with position="absolute" or position="sticky".
18
+ Right offset for positioned elements.
14
19
  */
15
- readonly bottom?: number;
20
+ readonly right?: number | string;
16
21
  /**
17
- Left offset. Used with position="absolute" or position="sticky".
22
+ Bottom offset for positioned elements.
18
23
  */
19
- readonly left?: number;
24
+ readonly bottom?: number | string;
20
25
  /**
21
- Right offset. Used with position="absolute" or position="sticky".
26
+ Left offset for positioned elements.
22
27
  */
23
- readonly right?: number;
28
+ readonly left?: number | string;
24
29
  /**
25
30
  Size of the gap between an element's columns.
26
31
  */
@@ -118,12 +123,17 @@ export type Styles = {
118
123
  The align-items property defines the default behavior for how items are laid out along the cross axis (perpendicular to the main axis).
119
124
  See [align-items](https://css-tricks.com/almanac/properties/a/align-items/).
120
125
  */
121
- readonly alignItems?: 'flex-start' | 'center' | 'flex-end' | 'stretch';
126
+ readonly alignItems?: 'flex-start' | 'center' | 'flex-end' | 'stretch' | 'baseline';
122
127
  /**
123
128
  It makes possible to override the align-items value for specific flex items.
124
129
  See [align-self](https://css-tricks.com/almanac/properties/a/align-self/).
125
130
  */
126
- readonly alignSelf?: 'flex-start' | 'center' | 'flex-end' | 'auto';
131
+ readonly alignSelf?: 'flex-start' | 'center' | 'flex-end' | 'auto' | 'stretch' | 'baseline';
132
+ /**
133
+ It defines the alignment along the cross axis when there are multiple lines of flex items (when using flex-wrap).
134
+ See [align-content](https://css-tricks.com/almanac/properties/a/align-content/).
135
+ */
136
+ readonly alignContent?: 'flex-start' | 'flex-end' | 'center' | 'stretch' | 'space-between' | 'space-around' | 'space-evenly';
127
137
  /**
128
138
  It defines the alignment along the main axis.
129
139
  See [justify-content](https://css-tricks.com/almanac/properties/j/justify-content/).
@@ -139,20 +149,28 @@ export type Styles = {
139
149
  readonly height?: number | string;
140
150
  /**
141
151
  Sets a minimum width of the element.
152
+ Percentages aren't supported yet; see https://github.com/facebook/yoga/issues/872.
142
153
  */
143
154
  readonly minWidth?: number | string;
144
155
  /**
145
- Sets a minimum height of the element.
156
+ Sets a minimum height of the element in lines (rows). You can also set it as a percentage, which will calculate the minimum height based on the height of the parent element.
146
157
  */
147
158
  readonly minHeight?: number | string;
148
159
  /**
149
- Sets a maximum height of the element.
160
+ Sets a maximum width of the element.
161
+ Percentages aren't supported yet; see https://github.com/facebook/yoga/issues/872.
162
+ */
163
+ readonly maxWidth?: number | string;
164
+ /**
165
+ Sets a maximum height of the element in lines (rows). You can also set it as a percentage, which will calculate the maximum height based on the height of the parent element.
150
166
  */
151
167
  readonly maxHeight?: number | string;
152
168
  /**
153
- Sets a maximum width of the element.
169
+ Defines the aspect ratio (width/height) for the element.
170
+
171
+ Use it with at least one size constraint (`width`, `height`, `minHeight`, or `maxHeight`) so Ink can derive the missing dimension.
154
172
  */
155
- readonly maxWidth?: number | string;
173
+ readonly aspectRatio?: number;
156
174
  /**
157
175
  Set this property to `none` to hide the element.
158
176
  */
@@ -162,26 +180,26 @@ export type Styles = {
162
180
  */
163
181
  readonly borderStyle?: keyof Boxes | BoxStyle;
164
182
  /**
165
- Determines whether top border is visible.
166
-
183
+ Determines whether the top border is visible.
184
+
167
185
  @default true
168
186
  */
169
187
  readonly borderTop?: boolean;
170
188
  /**
171
- Determines whether bottom border is visible.
172
-
189
+ Determines whether the bottom border is visible.
190
+
173
191
  @default true
174
192
  */
175
193
  readonly borderBottom?: boolean;
176
194
  /**
177
- Determines whether left border is visible.
178
-
195
+ Determines whether the left border is visible.
196
+
179
197
  @default true
180
198
  */
181
199
  readonly borderLeft?: boolean;
182
200
  /**
183
- Determines whether right border is visible.
184
-
201
+ Determines whether the right border is visible.
202
+
185
203
  @default true
186
204
  */
187
205
  readonly borderRight?: boolean;
@@ -190,19 +208,19 @@ export type Styles = {
190
208
  */
191
209
  readonly borderColor?: LiteralUnion<ForegroundColorName, string>;
192
210
  /**
193
- Change top border color. Accepts the same values as `color` in `Text` component.
211
+ Change the top border color. Accepts the same values as `color` in `Text` component.
194
212
  */
195
213
  readonly borderTopColor?: LiteralUnion<ForegroundColorName, string>;
196
214
  /**
197
- Change bottom border color. Accepts the same values as `color` in `Text` component.
215
+ Change the bottom border color. Accepts the same values as `color` in `Text` component.
198
216
  */
199
217
  readonly borderBottomColor?: LiteralUnion<ForegroundColorName, string>;
200
218
  /**
201
- Change left border color. Accepts the same values as `color` in `Text` component.
219
+ Change the left border color. Accepts the same values as `color` in `Text` component.
202
220
  */
203
221
  readonly borderLeftColor?: LiteralUnion<ForegroundColorName, string>;
204
222
  /**
205
- Change right border color. Accepts the same values as `color` in `Text` component.
223
+ Change the right border color. Accepts the same values as `color` in `Text` component.
206
224
  */
207
225
  readonly borderRightColor?: LiteralUnion<ForegroundColorName, string>;
208
226
  /**
@@ -213,31 +231,51 @@ export type Styles = {
213
231
  readonly borderDimColor?: boolean;
214
232
  /**
215
233
  Dim the top border color.
216
-
234
+
217
235
  @default false
218
236
  */
219
237
  readonly borderTopDimColor?: boolean;
220
238
  /**
221
239
  Dim the bottom border color.
222
-
240
+
223
241
  @default false
224
242
  */
225
243
  readonly borderBottomDimColor?: boolean;
226
244
  /**
227
245
  Dim the left border color.
228
-
246
+
229
247
  @default false
230
248
  */
231
249
  readonly borderLeftDimColor?: boolean;
232
250
  /**
233
251
  Dim the right border color.
234
-
252
+
235
253
  @default false
236
254
  */
237
255
  readonly borderRightDimColor?: boolean;
238
256
  /**
257
+ Change border background color. A shorthand for setting `borderTopBackgroundColor`, `borderRightBackgroundColor`, `borderBottomBackgroundColor`, and `borderLeftBackgroundColor`.
258
+ */
259
+ readonly borderBackgroundColor?: LiteralUnion<ForegroundColorName, string>;
260
+ /**
261
+ Change top border background color. Accepts the same values as `backgroundColor` in `Text` component.
262
+ */
263
+ readonly borderTopBackgroundColor?: LiteralUnion<ForegroundColorName, string>;
264
+ /**
265
+ Change bottom border background color. Accepts the same values as `backgroundColor` in `Text` component.
266
+ */
267
+ readonly borderBottomBackgroundColor?: LiteralUnion<ForegroundColorName, string>;
268
+ /**
269
+ Change left border background color. Accepts the same values as `backgroundColor` in `Text` component.
270
+ */
271
+ readonly borderLeftBackgroundColor?: LiteralUnion<ForegroundColorName, string>;
272
+ /**
273
+ Change right border background color. Accepts the same values as `backgroundColor` in `Text` component.
274
+ */
275
+ readonly borderRightBackgroundColor?: LiteralUnion<ForegroundColorName, string>;
276
+ /**
239
277
  Behavior for an element's overflow in both directions.
240
-
278
+
241
279
  @default 'visible'
242
280
  */
243
281
  readonly overflow?: 'visible' | 'hidden' | 'scroll';
@@ -255,18 +293,18 @@ export type Styles = {
255
293
  readonly overflowY?: 'visible' | 'hidden' | 'scroll';
256
294
  /**
257
295
  Background color for the element.
258
-
296
+
259
297
  Accepts the same values as `color` in the `<Text>` component.
260
298
  */
261
299
  readonly backgroundColor?: LiteralUnion<ForegroundColorName, string>;
262
300
  /**
263
301
  Controls the stacking order of positioned elements.
264
302
  Higher values are rendered on top of lower values.
265
- Only affects elements with position: 'absolute' or 'relative'.
266
-
303
+ Only affects positioned elements.
304
+
267
305
  @default 0
268
306
  */
269
307
  readonly zIndex?: number;
270
308
  };
271
- declare const styles: (node: YogaNode, style?: Styles) => void;
309
+ declare const styles: (node: YogaNode, style?: Styles, currentStyle?: Styles) => void;
272
310
  export default styles;