@jrichman/ink 7.0.1-beta.8 → 7.0.1-beta.9
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.
|
@@ -1,19 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2026 Google LLC
|
|
4
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
*/
|
|
6
1
|
import { type ReactNode } from 'react';
|
|
7
2
|
import { type Region } from './output.js';
|
|
8
|
-
/**
|
|
9
|
-
* Renders a React node to an offline Region.
|
|
10
|
-
* This is useful for measuring the size of a component before rendering it to the screen,
|
|
11
|
-
* or caching complex static renders.
|
|
12
|
-
*
|
|
13
|
-
* @param node The React node to render.
|
|
14
|
-
* @param options Configuration options, such as the `width` of the terminal.
|
|
15
|
-
* @returns The cached Region containing the layout and rendered lines.
|
|
16
|
-
*/
|
|
17
3
|
export declare const renderToRegion: (node: ReactNode, options: {
|
|
18
4
|
width: number;
|
|
19
5
|
}) => Region;
|
|
@@ -1,60 +1,61 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2026 Google LLC
|
|
4
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
*/
|
|
6
1
|
import React from 'react';
|
|
7
2
|
import { LegacyRoot } from 'react-reconciler/constants.js';
|
|
3
|
+
import Yoga from 'yoga-layout';
|
|
8
4
|
import reconciler from './reconciler.js';
|
|
9
5
|
import { createNode } from './dom.js';
|
|
10
6
|
import { renderToStatic } from './render-node-to-output.js';
|
|
11
7
|
import { accessibilityContext } from './components/AccessibilityContext.js';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
8
|
+
const noop = () => { };
|
|
9
|
+
const renderPendingStaticRenderNodes = (node, width) => {
|
|
10
|
+
for (const child of node.childNodes) {
|
|
11
|
+
if (child.nodeName !== '#text') {
|
|
12
|
+
renderPendingStaticRenderNodes(child, width);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
if (node.nodeName !== 'ink-static-render' || node.cachedRender) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const staticWidth = typeof node.style.width === 'number' ? node.style.width : width;
|
|
19
|
+
node.yogaNode?.setWidth(staticWidth);
|
|
20
|
+
node.yogaNode?.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR);
|
|
21
|
+
renderToStatic(node, {
|
|
22
|
+
calculateLayout: true,
|
|
23
|
+
skipStaticElements: false,
|
|
24
|
+
});
|
|
25
|
+
};
|
|
21
26
|
export const renderToRegion = (node, options) => {
|
|
22
27
|
const rootNode = createNode('ink-root');
|
|
23
28
|
rootNode.yogaNode.setWidth(options.width);
|
|
24
29
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
25
|
-
const container = reconciler.createContainer(rootNode, LegacyRoot, null, false, null, `id-${Math.random()}`,
|
|
30
|
+
const container = reconciler.createContainer(rootNode, LegacyRoot, null, false, null, `id-${Math.random()}`, noop, noop, noop, noop, null);
|
|
26
31
|
const tree = (React.createElement(accessibilityContext.Provider, { value: { isScreenReaderEnabled: false } }, node));
|
|
27
|
-
//
|
|
28
|
-
|
|
29
|
-
//
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
flushSync(() => {
|
|
33
|
-
reconciler.updateContainer(tree, container, null, () => { });
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
// @ts-expect-error the types for `react-reconciler` are not up to date with the library.
|
|
38
|
-
reconciler.updateContainerSync(tree, container, null, () => { });
|
|
39
|
-
// @ts-expect-error the types for `react-reconciler` are not up to date with the library.
|
|
40
|
-
reconciler.flushSyncWork();
|
|
41
|
-
}
|
|
32
|
+
// @ts-expect-error the types for `react-reconciler` are not up to date with the library.
|
|
33
|
+
reconciler.updateContainerSync(tree, container, null, noop);
|
|
34
|
+
// @ts-expect-error the types for `react-reconciler` are not up to date with the library.
|
|
35
|
+
reconciler.flushSyncWork();
|
|
36
|
+
renderPendingStaticRenderNodes(rootNode, options.width);
|
|
42
37
|
renderToStatic(rootNode, {
|
|
43
38
|
calculateLayout: true,
|
|
44
39
|
skipStaticElements: false,
|
|
45
40
|
});
|
|
41
|
+
const triggerOnRendered = (n) => {
|
|
42
|
+
if (n.nodeName === 'ink-static-render' && n.cachedRender) {
|
|
43
|
+
n.internal_onRendered?.(n);
|
|
44
|
+
}
|
|
45
|
+
for (const child of n.childNodes) {
|
|
46
|
+
if (child.nodeName !== '#text') {
|
|
47
|
+
triggerOnRendered(child);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
triggerOnRendered(rootNode);
|
|
52
|
+
// @ts-expect-error the types for `react-reconciler` are not up to date with the library.
|
|
53
|
+
reconciler.flushSyncWork();
|
|
46
54
|
const region = rootNode.cachedRender;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
// @ts-expect-error the types for `react-reconciler` are not up to date with the library.
|
|
54
|
-
reconciler.updateContainerSync(null, container, null, () => { });
|
|
55
|
-
// @ts-expect-error the types for `react-reconciler` are not up to date with the library.
|
|
56
|
-
reconciler.flushSyncWork();
|
|
57
|
-
}
|
|
55
|
+
// @ts-expect-error the types for `react-reconciler` are not up to date with the library.
|
|
56
|
+
reconciler.updateContainerSync(null, container, null, noop);
|
|
57
|
+
// @ts-expect-error the types for `react-reconciler` are not up to date with the library.
|
|
58
|
+
reconciler.flushSyncWork();
|
|
58
59
|
return region;
|
|
59
60
|
};
|
|
60
61
|
//# sourceMappingURL=render-to-region.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-to-region.js","sourceRoot":"","sources":["../src/render-to-region.tsx"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"render-to-region.js","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AC;QACF,CAAC;IACF,CAAC,CAAC;IACF,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAE5B,yFAAyF;IACzF,UAAU,CAAC,aAAa,EAAE,CAAC;IAE3B,MAAM,MAAM,GAAG,QAAQ,CAAC,YAAa,CAAC;IAEtC,yFAAyF;IACzF,UAAU,CAAC,mBAAmB,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5D,yFAAyF;IACzF,UAAU,CAAC,aAAa,EAAE,CAAC;IAE3B,OAAO,MAAM,CAAC;AACf,CAAC,CAAC"}
|
package/build/render.d.ts
CHANGED
|
@@ -118,6 +118,13 @@ export type RenderOptions = {
|
|
|
118
118
|
* @default false
|
|
119
119
|
*/
|
|
120
120
|
stickyHeadersInBackbuffer?: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Maximum number of lines to keep in the terminal backbuffer.
|
|
123
|
+
* This is only supported when using `terminalBuffer` or `renderProcess`.
|
|
124
|
+
*
|
|
125
|
+
* @default 1000
|
|
126
|
+
*/
|
|
127
|
+
maxScrollbackLength?: number;
|
|
121
128
|
cacheToStyledCharacters?: boolean;
|
|
122
129
|
trackSelection?: boolean;
|
|
123
130
|
};
|
package/build/render.js.map
CHANGED
|
@@ -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;AAGnC,OAAO,GAAqD,MAAM,UAAU,CAAC;AAC7E,OAAO,SAAS,MAAM,gBAAgB,CAAC;
|
|
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,OAA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