ink 3.2.0 → 4.0.0
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.
- package/build/colorize.d.ts +3 -3
- package/build/colorize.js +30 -35
- package/build/colorize.js.map +1 -1
- package/build/components/App.d.ts +12 -12
- package/build/components/App.js +287 -208
- package/build/components/App.js.map +1 -1
- package/build/components/AppContext.d.ts +2 -2
- package/build/components/AppContext.js +5 -6
- package/build/components/AppContext.js.map +1 -1
- package/build/components/Box.d.ts +5 -5
- package/build/components/Box.js +15 -38
- package/build/components/Box.js.map +1 -1
- package/build/components/ErrorOverview.d.ts +5 -5
- package/build/components/ErrorOverview.js +40 -58
- package/build/components/ErrorOverview.js.map +1 -1
- package/build/components/FocusContext.d.ts +2 -2
- package/build/components/FocusContext.js +13 -14
- package/build/components/FocusContext.js.map +1 -1
- package/build/components/Newline.d.ts +4 -5
- package/build/components/Newline.js +4 -9
- package/build/components/Newline.js.map +1 -1
- package/build/components/Spacer.d.ts +2 -3
- package/build/components/Spacer.js +5 -10
- package/build/components/Spacer.js.map +1 -1
- package/build/components/Static.d.ts +5 -9
- package/build/components/Static.js +12 -33
- package/build/components/Static.js.map +1 -1
- package/build/components/StderrContext.d.ts +4 -4
- package/build/components/StderrContext.js +7 -7
- package/build/components/StderrContext.js.map +1 -1
- package/build/components/StdinContext.d.ts +4 -4
- package/build/components/StdinContext.js +8 -7
- package/build/components/StdinContext.js.map +1 -1
- package/build/components/StdoutContext.d.ts +4 -4
- package/build/components/StdoutContext.js +7 -7
- package/build/components/StdoutContext.js.map +1 -1
- package/build/components/Text.d.ts +9 -10
- package/build/components/Text.js +14 -29
- package/build/components/Text.js.map +1 -1
- package/build/components/Transform.d.ts +4 -5
- package/build/components/Transform.js +4 -11
- package/build/components/Transform.js.map +1 -1
- package/build/devtools-window-polyfill.js +3 -8
- package/build/devtools-window-polyfill.js.map +1 -1
- package/build/devtools.d.ts +1 -1
- package/build/devtools.js +6 -6
- package/build/devtools.js.map +1 -1
- package/build/dom.d.ts +14 -17
- package/build/dom.js +34 -47
- package/build/dom.js.map +1 -1
- package/build/get-max-width.d.ts +2 -2
- package/build/get-max-width.js +7 -11
- package/build/get-max-width.js.map +1 -1
- package/build/hooks/use-app.d.ts +1 -1
- package/build/hooks/use-app.js +4 -9
- package/build/hooks/use-app.js.map +1 -1
- package/build/hooks/use-focus-manager.d.ts +3 -3
- package/build/hooks/use-focus-manager.js +4 -9
- package/build/hooks/use-focus-manager.js.map +1 -1
- package/build/hooks/use-focus.d.ts +4 -4
- package/build/hooks/use-focus.js +11 -16
- package/build/hooks/use-focus.js.map +1 -1
- package/build/hooks/use-input.d.ts +5 -5
- package/build/hooks/use-input.js +13 -14
- package/build/hooks/use-input.js.map +1 -1
- package/build/hooks/use-stderr.d.ts +1 -1
- package/build/hooks/use-stderr.js +4 -9
- package/build/hooks/use-stderr.js.map +1 -1
- package/build/hooks/use-stdin.d.ts +1 -1
- package/build/hooks/use-stdin.js +4 -9
- package/build/hooks/use-stdin.js.map +1 -1
- package/build/hooks/use-stdout.d.ts +1 -1
- package/build/hooks/use-stdout.js +4 -9
- package/build/hooks/use-stdout.js.map +1 -1
- package/build/index.d.ts +27 -20
- package/build/index.js +15 -32
- package/build/index.js.map +1 -1
- package/build/ink.d.ts +4 -4
- package/build/ink.js +165 -98
- package/build/ink.js.map +1 -1
- package/build/instances.d.ts +4 -2
- package/build/instances.js +2 -3
- package/build/instances.js.map +1 -1
- package/build/log-update.d.ts +5 -6
- package/build/log-update.js +8 -12
- package/build/log-update.js.map +1 -1
- package/build/measure-element.d.ts +5 -5
- package/build/measure-element.js +5 -9
- package/build/measure-element.js.map +1 -1
- package/build/measure-text.d.ts +4 -4
- package/build/measure-text.js +7 -10
- package/build/measure-text.js.map +1 -1
- package/build/output.d.ts +3 -3
- package/build/output.js +25 -15
- package/build/output.js.map +1 -1
- package/build/reconciler.d.ts +1 -1
- package/build/reconciler.js +97 -76
- package/build/reconciler.js.map +1 -1
- package/build/render-border.d.ts +4 -4
- package/build/render-border.js +8 -12
- package/build/render-border.js.map +1 -1
- package/build/render-node-to-output.d.ts +3 -3
- package/build/render-node-to-output.js +17 -24
- package/build/render-node-to-output.js.map +1 -1
- package/build/render.d.ts +8 -8
- package/build/render.js +23 -20
- package/build/render.js.map +1 -1
- package/build/renderer.d.ts +5 -5
- package/build/renderer.js +11 -16
- package/build/renderer.js.map +1 -1
- package/build/squash-text-nodes.d.ts +1 -1
- package/build/squash-text-nodes.js +1 -3
- package/build/squash-text-nodes.js.map +1 -1
- package/build/styles.d.ts +9 -9
- package/build/styles.js +39 -45
- package/build/styles.js.map +1 -1
- package/build/wrap-text.d.ts +3 -3
- package/build/wrap-text.js +9 -12
- package/build/wrap-text.js.map +1 -1
- package/license +1 -1
- package/package.json +86 -66
- package/readme.md +91 -49
package/build/output.js
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const slice_ansi_1 = __importDefault(require("slice-ansi"));
|
|
7
|
-
const string_width_1 = __importDefault(require("string-width"));
|
|
8
|
-
class Output {
|
|
1
|
+
import sliceAnsi from 'slice-ansi';
|
|
2
|
+
import stringWidth from 'string-width';
|
|
3
|
+
export default class Output {
|
|
9
4
|
constructor(options) {
|
|
5
|
+
Object.defineProperty(this, "width", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
writable: true,
|
|
9
|
+
value: void 0
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(this, "height", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: void 0
|
|
16
|
+
});
|
|
10
17
|
// Initialize output array with a specific set of rows, so that margin/padding at the bottom is preserved
|
|
11
|
-
this
|
|
18
|
+
Object.defineProperty(this, "writes", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
configurable: true,
|
|
21
|
+
writable: true,
|
|
22
|
+
value: []
|
|
23
|
+
});
|
|
12
24
|
const { width, height } = options;
|
|
13
25
|
this.width = width;
|
|
14
26
|
this.height = height;
|
|
@@ -35,24 +47,22 @@ class Output {
|
|
|
35
47
|
if (!currentLine) {
|
|
36
48
|
continue;
|
|
37
49
|
}
|
|
38
|
-
const width =
|
|
50
|
+
const width = stringWidth(line);
|
|
39
51
|
for (const transformer of transformers) {
|
|
40
52
|
line = transformer(line);
|
|
41
53
|
}
|
|
42
54
|
output[y + offsetY] =
|
|
43
|
-
|
|
55
|
+
sliceAnsi(currentLine, 0, x) +
|
|
44
56
|
line +
|
|
45
|
-
|
|
57
|
+
sliceAnsi(currentLine, x + width);
|
|
46
58
|
offsetY++;
|
|
47
59
|
}
|
|
48
60
|
}
|
|
49
|
-
|
|
50
|
-
const generatedOutput = output.map(line => line.trimRight()).join('\n');
|
|
61
|
+
const generatedOutput = output.map(line => line.trimEnd()).join('\n');
|
|
51
62
|
return {
|
|
52
63
|
output: generatedOutput,
|
|
53
64
|
height: output.length
|
|
54
65
|
};
|
|
55
66
|
}
|
|
56
67
|
}
|
|
57
|
-
exports.default = Output;
|
|
58
68
|
//# sourceMappingURL=output.js.map
|
package/build/output.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.js","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,WAAW,MAAM,cAAc,CAAC;AAwBvC,MAAM,CAAC,OAAO,OAAO,MAAM;IAO1B,YAAY,OAAgB;QAN5B;;;;;WAAc;QACd;;;;;WAAe;QAEf,yGAAyG;QACzG;;;;mBAAoC,EAAE;WAAC;QAGtC,MAAM,EAAC,KAAK,EAAE,MAAM,EAAC,GAAG,OAAO,CAAC;QAE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AS,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC,CAAC;wBAC5B,IAAI;wBACJ,SAAS,CAAC,WAAW,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC;gBAEnC,OAAO,EAAE,CAAC;aACV;SACD;QAED,MAAM,eAAe,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEtE,OAAO;YACN,MAAM,EAAE,eAAe;YACvB,MAAM,EAAE,MAAM,CAAC,MAAM;SACrB,CAAC;IACH,CAAC;CACD"}
|
package/build/reconciler.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import createReconciler from 'react-reconciler';
|
|
2
|
-
import { TextNode, DOMElement } from './dom';
|
|
2
|
+
import { type TextNode, type DOMElement } from './dom.js';
|
|
3
3
|
declare const _default: createReconciler.Reconciler<DOMElement, DOMElement, TextNode, DOMElement, unknown>;
|
|
4
4
|
export default _default;
|
package/build/reconciler.js
CHANGED
|
@@ -1,36 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const scheduler_1 = require("scheduler");
|
|
7
|
-
const react_reconciler_1 = __importDefault(require("react-reconciler"));
|
|
8
|
-
const yoga_layout_prebuilt_1 = __importDefault(require("yoga-layout-prebuilt"));
|
|
9
|
-
const dom_1 = require("./dom");
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import createReconciler from 'react-reconciler';
|
|
3
|
+
import { DefaultEventPriority } from 'react-reconciler/constants.js';
|
|
4
|
+
import Yoga from 'yoga-layout-prebuilt';
|
|
5
|
+
import { createTextNode, appendChildNode, insertBeforeNode, removeChildNode, setStyle, setTextNodeValue, createNode, setAttribute } from './dom.js';
|
|
10
6
|
// We need to conditionally perform devtools connection to avoid
|
|
11
7
|
// accidentally breaking other third-party code.
|
|
12
8
|
// See https://github.com/vadimdemedes/ink/issues/384
|
|
13
|
-
if (process.env
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
if (process.env['DEV'] === 'true') {
|
|
10
|
+
try {
|
|
11
|
+
await import('./devtools.js');
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-implicit-any-catch
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
if (error.code === 'MODULE_NOT_FOUND') {
|
|
16
|
+
console.warn(`
|
|
17
|
+
Debugging with React Devtools requires \`react-devtools-core\` dependency to be installed.
|
|
18
|
+
|
|
19
|
+
$ npm install --save-dev react-devtools-core
|
|
20
|
+
`.trim() + '\n');
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-throw-literal
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
16
27
|
}
|
|
17
28
|
const cleanupYogaNode = (node) => {
|
|
18
|
-
node
|
|
19
|
-
node
|
|
29
|
+
node?.unsetMeasureFunc();
|
|
30
|
+
node?.freeRecursive();
|
|
20
31
|
};
|
|
21
|
-
|
|
22
|
-
// @ts-ignore
|
|
23
|
-
schedulePassiveEffects: scheduler_1.unstable_scheduleCallback,
|
|
24
|
-
cancelPassiveEffects: scheduler_1.unstable_cancelCallback,
|
|
25
|
-
now: Date.now,
|
|
32
|
+
export default createReconciler({
|
|
26
33
|
getRootHostContext: () => ({
|
|
27
34
|
isInsideText: false
|
|
28
35
|
}),
|
|
29
36
|
prepareForCommit: () => null,
|
|
30
37
|
preparePortalMount: () => null,
|
|
31
38
|
clearContainer: () => false,
|
|
32
|
-
|
|
33
|
-
resetAfterCommit: rootNode => {
|
|
39
|
+
resetAfterCommit(rootNode) {
|
|
34
40
|
// Since renders are throttled at the instance level and <Static> component children
|
|
35
41
|
// are rendered only once and then get deleted, we need an escape hatch to
|
|
36
42
|
// trigger an immediate render to ensure <Static> children are written to output before they get erased
|
|
@@ -45,7 +51,7 @@ exports.default = react_reconciler_1.default({
|
|
|
45
51
|
rootNode.onRender();
|
|
46
52
|
}
|
|
47
53
|
},
|
|
48
|
-
getChildHostContext
|
|
54
|
+
getChildHostContext(parentHostContext, type) {
|
|
49
55
|
const previousIsInsideText = parentHostContext.isInsideText;
|
|
50
56
|
const isInsideText = type === 'ink-text' || type === 'ink-virtual-text';
|
|
51
57
|
if (previousIsInsideText === isInsideText) {
|
|
@@ -54,59 +60,58 @@ exports.default = react_reconciler_1.default({
|
|
|
54
60
|
return { isInsideText };
|
|
55
61
|
},
|
|
56
62
|
shouldSetTextContent: () => false,
|
|
57
|
-
createInstance
|
|
63
|
+
createInstance(originalType, newProps, _root, hostContext) {
|
|
58
64
|
if (hostContext.isInsideText && originalType === 'ink-box') {
|
|
59
65
|
throw new Error(`<Box> can’t be nested inside <Text> component`);
|
|
60
66
|
}
|
|
61
67
|
const type = originalType === 'ink-text' && hostContext.isInsideText
|
|
62
68
|
? 'ink-virtual-text'
|
|
63
69
|
: originalType;
|
|
64
|
-
const node =
|
|
70
|
+
const node = createNode(type);
|
|
65
71
|
for (const [key, value] of Object.entries(newProps)) {
|
|
66
72
|
if (key === 'children') {
|
|
67
73
|
continue;
|
|
68
74
|
}
|
|
69
|
-
|
|
70
|
-
|
|
75
|
+
if (key === 'style') {
|
|
76
|
+
setStyle(node, value);
|
|
77
|
+
continue;
|
|
71
78
|
}
|
|
72
|
-
|
|
79
|
+
if (key === 'internal_transform') {
|
|
73
80
|
node.internal_transform = value;
|
|
81
|
+
continue;
|
|
74
82
|
}
|
|
75
|
-
|
|
83
|
+
if (key === 'internal_static') {
|
|
76
84
|
node.internal_static = true;
|
|
85
|
+
continue;
|
|
77
86
|
}
|
|
78
|
-
|
|
79
|
-
dom_1.setAttribute(node, key, value);
|
|
80
|
-
}
|
|
87
|
+
setAttribute(node, key, value);
|
|
81
88
|
}
|
|
82
89
|
return node;
|
|
83
90
|
},
|
|
84
|
-
createTextInstance
|
|
91
|
+
createTextInstance(text, _root, hostContext) {
|
|
85
92
|
if (!hostContext.isInsideText) {
|
|
86
93
|
throw new Error(`Text string "${text}" must be rendered inside <Text> component`);
|
|
87
94
|
}
|
|
88
|
-
return
|
|
95
|
+
return createTextNode(text);
|
|
89
96
|
},
|
|
90
|
-
resetTextContent
|
|
91
|
-
hideTextInstance
|
|
92
|
-
|
|
97
|
+
resetTextContent() { },
|
|
98
|
+
hideTextInstance(node) {
|
|
99
|
+
setTextNodeValue(node, '');
|
|
93
100
|
},
|
|
94
|
-
unhideTextInstance
|
|
95
|
-
|
|
101
|
+
unhideTextInstance(node, text) {
|
|
102
|
+
setTextNodeValue(node, text);
|
|
96
103
|
},
|
|
97
104
|
getPublicInstance: instance => instance,
|
|
98
|
-
hideInstance
|
|
99
|
-
|
|
100
|
-
(_a = node.yogaNode) === null || _a === void 0 ? void 0 : _a.setDisplay(yoga_layout_prebuilt_1.default.DISPLAY_NONE);
|
|
105
|
+
hideInstance(node) {
|
|
106
|
+
node.yogaNode?.setDisplay(Yoga.DISPLAY_NONE);
|
|
101
107
|
},
|
|
102
|
-
unhideInstance
|
|
103
|
-
|
|
104
|
-
(_a = node.yogaNode) === null || _a === void 0 ? void 0 : _a.setDisplay(yoga_layout_prebuilt_1.default.DISPLAY_FLEX);
|
|
108
|
+
unhideInstance(node) {
|
|
109
|
+
node.yogaNode?.setDisplay(Yoga.DISPLAY_FLEX);
|
|
105
110
|
},
|
|
106
|
-
appendInitialChild:
|
|
107
|
-
appendChild:
|
|
108
|
-
insertBefore:
|
|
109
|
-
finalizeInitialChildren
|
|
111
|
+
appendInitialChild: appendChildNode,
|
|
112
|
+
appendChild: appendChildNode,
|
|
113
|
+
insertBefore: insertBeforeNode,
|
|
114
|
+
finalizeInitialChildren(node, _type, _props, rootNode) {
|
|
110
115
|
if (node.internal_static) {
|
|
111
116
|
rootNode.isStaticDirty = true;
|
|
112
117
|
// Save reference to <Static> node to skip traversal of entire
|
|
@@ -115,14 +120,27 @@ exports.default = react_reconciler_1.default({
|
|
|
115
120
|
}
|
|
116
121
|
return false;
|
|
117
122
|
},
|
|
123
|
+
isPrimaryRenderer: true,
|
|
118
124
|
supportsMutation: true,
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
125
|
+
supportsPersistence: false,
|
|
126
|
+
supportsHydration: false,
|
|
127
|
+
scheduleTimeout: setTimeout,
|
|
128
|
+
cancelTimeout: clearTimeout,
|
|
129
|
+
noTimeout: -1,
|
|
130
|
+
getCurrentEventPriority: () => DefaultEventPriority,
|
|
131
|
+
beforeActiveInstanceBlur() { },
|
|
132
|
+
afterActiveInstanceBlur() { },
|
|
133
|
+
detachDeletedInstance() { },
|
|
134
|
+
getInstanceFromNode: () => null,
|
|
135
|
+
prepareScopeUpdate() { },
|
|
136
|
+
getInstanceFromScope: () => null,
|
|
137
|
+
appendChildToContainer: appendChildNode,
|
|
138
|
+
insertInContainerBefore: insertBeforeNode,
|
|
139
|
+
removeChildFromContainer(node, removeNode) {
|
|
140
|
+
removeChildNode(node, removeNode);
|
|
123
141
|
cleanupYogaNode(removeNode.yogaNode);
|
|
124
142
|
},
|
|
125
|
-
prepareUpdate
|
|
143
|
+
prepareUpdate(node, _type, oldProps, newProps, rootNode) {
|
|
126
144
|
if (node.internal_static) {
|
|
127
145
|
rootNode.isStaticDirty = true;
|
|
128
146
|
}
|
|
@@ -131,32 +149,34 @@ exports.default = react_reconciler_1.default({
|
|
|
131
149
|
for (const key of keys) {
|
|
132
150
|
if (newProps[key] !== oldProps[key]) {
|
|
133
151
|
const isStyle = key === 'style' &&
|
|
134
|
-
typeof newProps
|
|
135
|
-
typeof oldProps
|
|
152
|
+
typeof newProps['style'] === 'object' &&
|
|
153
|
+
typeof oldProps['style'] === 'object';
|
|
136
154
|
if (isStyle) {
|
|
137
|
-
const newStyle = newProps
|
|
138
|
-
const oldStyle = oldProps
|
|
155
|
+
const newStyle = newProps['style'];
|
|
156
|
+
const oldStyle = oldProps['style'];
|
|
139
157
|
const styleKeys = Object.keys(newStyle);
|
|
140
158
|
for (const styleKey of styleKeys) {
|
|
141
159
|
// Always include `borderColor` and `borderStyle` to ensure border is rendered,
|
|
142
160
|
// otherwise resulting `updatePayload` may not contain them
|
|
143
161
|
// if they weren't changed during this update
|
|
144
162
|
if (styleKey === 'borderStyle' || styleKey === 'borderColor') {
|
|
145
|
-
if (typeof updatePayload
|
|
163
|
+
if (typeof updatePayload['style'] !== 'object') {
|
|
146
164
|
// Linter didn't like `= {} as Style`
|
|
147
165
|
const style = {};
|
|
148
|
-
updatePayload
|
|
166
|
+
updatePayload['style'] = style;
|
|
149
167
|
}
|
|
150
|
-
updatePayload
|
|
151
|
-
|
|
168
|
+
updatePayload['style'].borderStyle =
|
|
169
|
+
newStyle.borderStyle;
|
|
170
|
+
updatePayload['style'].borderColor =
|
|
171
|
+
newStyle.borderColor;
|
|
152
172
|
}
|
|
153
173
|
if (newStyle[styleKey] !== oldStyle[styleKey]) {
|
|
154
|
-
if (typeof updatePayload
|
|
174
|
+
if (typeof updatePayload['style'] !== 'object') {
|
|
155
175
|
// Linter didn't like `= {} as Style`
|
|
156
176
|
const style = {};
|
|
157
|
-
updatePayload
|
|
177
|
+
updatePayload['style'] = style;
|
|
158
178
|
}
|
|
159
|
-
updatePayload
|
|
179
|
+
updatePayload['style'][styleKey] = newStyle[styleKey];
|
|
160
180
|
}
|
|
161
181
|
}
|
|
162
182
|
continue;
|
|
@@ -166,30 +186,31 @@ exports.default = react_reconciler_1.default({
|
|
|
166
186
|
}
|
|
167
187
|
return updatePayload;
|
|
168
188
|
},
|
|
169
|
-
commitUpdate
|
|
189
|
+
commitUpdate(node, updatePayload) {
|
|
170
190
|
for (const [key, value] of Object.entries(updatePayload)) {
|
|
171
191
|
if (key === 'children') {
|
|
172
192
|
continue;
|
|
173
193
|
}
|
|
174
|
-
|
|
175
|
-
|
|
194
|
+
if (key === 'style') {
|
|
195
|
+
setStyle(node, value);
|
|
196
|
+
continue;
|
|
176
197
|
}
|
|
177
|
-
|
|
198
|
+
if (key === 'internal_transform') {
|
|
178
199
|
node.internal_transform = value;
|
|
200
|
+
continue;
|
|
179
201
|
}
|
|
180
|
-
|
|
202
|
+
if (key === 'internal_static') {
|
|
181
203
|
node.internal_static = true;
|
|
204
|
+
continue;
|
|
182
205
|
}
|
|
183
|
-
|
|
184
|
-
dom_1.setAttribute(node, key, value);
|
|
185
|
-
}
|
|
206
|
+
setAttribute(node, key, value);
|
|
186
207
|
}
|
|
187
208
|
},
|
|
188
|
-
commitTextUpdate
|
|
189
|
-
|
|
209
|
+
commitTextUpdate(node, _oldText, newText) {
|
|
210
|
+
setTextNodeValue(node, newText);
|
|
190
211
|
},
|
|
191
|
-
removeChild
|
|
192
|
-
|
|
212
|
+
removeChild(node, removeNode) {
|
|
213
|
+
removeChildNode(node, removeNode);
|
|
193
214
|
cleanupYogaNode(removeNode.yogaNode);
|
|
194
215
|
}
|
|
195
216
|
});
|
package/build/reconciler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reconciler.js","sourceRoot":"","sources":["../src/reconciler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reconciler.js","sourceRoot":"","sources":["../src/reconciler.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,gBAAgB,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAC,oBAAoB,EAAC,MAAM,+BAA+B,CAAC;AACnE,OAAO,IAAI,MAAM,sBAAsB,CAAC;AACxC,OAAO,EACN,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,QAAQ,EACR,gBAAgB,EAChB,UAAU,EACV,YAAY,EAKZ,MAAM,UAAU,CAAC;AAIlB,gEAAgE;AAChE,gDAAgD;AAChD,qDAAqD;AACrD,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,MAAM,EAAE;IAClC,IAAI;QACH,MAAM,MAAM,CAAC,eAAe,CAAC,CAAC;QAC9B,oE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,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,KAAyB,CAAC,CAAC;SACnD;IACF,CAAC;IACD,gBAAgB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO;QACvC,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACjC,CAAC;IACD,WAAW,CAAC,IAAI,EAAE,UAAU;QAC3B,eAAe,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QAClC,eAAe,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IACtC,CAAC;CACD,CAAC,CAAC"}
|
package/build/render-border.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DOMNode } from './dom';
|
|
2
|
-
import Output from './output';
|
|
3
|
-
declare const
|
|
4
|
-
export default
|
|
1
|
+
import { type DOMNode } from './dom.js';
|
|
2
|
+
import type Output from './output.js';
|
|
3
|
+
declare const renderBorder: (x: number, y: number, node: DOMNode, output: Output) => void;
|
|
4
|
+
export default renderBorder;
|
package/build/render-border.js
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const cli_boxes_1 = __importDefault(require("cli-boxes"));
|
|
7
|
-
const colorize_1 = __importDefault(require("./colorize"));
|
|
8
|
-
exports.default = (x, y, node, output) => {
|
|
1
|
+
import cliBoxes from 'cli-boxes';
|
|
2
|
+
import colorize from './colorize.js';
|
|
3
|
+
const renderBorder = (x, y, node, output) => {
|
|
9
4
|
if (typeof node.style.borderStyle === 'string') {
|
|
10
5
|
const width = node.yogaNode.getComputedWidth();
|
|
11
6
|
const height = node.yogaNode.getComputedHeight();
|
|
12
7
|
const color = node.style.borderColor;
|
|
13
|
-
const box =
|
|
14
|
-
const topBorder =
|
|
15
|
-
const verticalBorder = (
|
|
16
|
-
const bottomBorder =
|
|
8
|
+
const box = cliBoxes[node.style.borderStyle];
|
|
9
|
+
const topBorder = colorize(box.topLeft + box.top.repeat(width - 2) + box.topRight, color, 'foreground');
|
|
10
|
+
const verticalBorder = (colorize(box.left, color, 'foreground') + '\n').repeat(height - 2);
|
|
11
|
+
const bottomBorder = colorize(box.bottomLeft + box.bottom.repeat(width - 2) + box.bottomRight, color, 'foreground');
|
|
17
12
|
output.write(x, y, topBorder, { transformers: [] });
|
|
18
13
|
output.write(x, y + 1, verticalBorder, { transformers: [] });
|
|
19
14
|
output.write(x + width - 1, y + 1, verticalBorder, { transformers: [] });
|
|
20
15
|
output.write(x, y + height - 1, bottomBorder, { transformers: [] });
|
|
21
16
|
}
|
|
22
17
|
};
|
|
18
|
+
export default renderBorder;
|
|
23
19
|
//# sourceMappingURL=render-border.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-border.js","sourceRoot":"","sources":["../src/render-border.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"render-border.js","sourceRoot":"","sources":["../src/render-border.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,QAAQ,MAAM,eAAe,CAAC;AAIrC,MAAM,YAAY,GAAG,CACpB,CAAS,EACT,CAAS,EACT,IAAa,EACb,MAAc,EACP,EAAE;IACT,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,KAAK,QAAQ,EAAE;QAC/C,MAAM,KAAK,GAAG,IAAI,CAAC,QAAS,CAAC,gBAAgB,EAAE,CAAC;QAChD,MAAM,MAAM,GAAG,IAAI,CAAC,QAAS,CAAC,iBAAiB,EAAE,CAAC;QAClD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC;QACrC,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAE7C,MAAM,SAAS,GAAG,QAAQ,CACzB,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,QAAQ,EACtD,KAAK,EACL,YAAY,CACZ,CAAC;QAEF,MAAM,cAAc,GAAG,CACtB,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,YAAY,CAAC,GAAG,IAAI,CAC9C,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAErB,MAAM,YAAY,GAAG,QAAQ,CAC5B,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,WAAW,EAC/D,KAAK,EACL,YAAY,CACZ,CAAC;QAEF,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,EAAC,YAAY,EAAE,EAAE,EAAC,CAAC,CAAC;QAClD,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,cAAc,EAAE,EAAC,YAAY,EAAE,EAAE,EAAC,CAAC,CAAC;QAC3D,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,cAAc,EAAE,EAAC,YAAY,EAAE,EAAE,EAAC,CAAC,CAAC;QACvE,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,GAAG,CAAC,EAAE,YAAY,EAAE,EAAC,YAAY,EAAE,EAAE,EAAC,CAAC,CAAC;KAClE;AACF,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DOMElement } from './dom';
|
|
2
|
-
import Output from './output';
|
|
3
|
-
export
|
|
1
|
+
import { type DOMElement } from './dom.js';
|
|
2
|
+
import type Output from './output.js';
|
|
3
|
+
export type OutputTransformer = (s: string) => string;
|
|
4
4
|
declare const renderNodeToOutput: (node: DOMElement, output: Output, options: {
|
|
5
5
|
offsetX?: number;
|
|
6
6
|
offsetY?: number;
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const indent_string_1 = __importDefault(require("indent-string"));
|
|
9
|
-
const wrap_text_1 = __importDefault(require("./wrap-text"));
|
|
10
|
-
const get_max_width_1 = __importDefault(require("./get-max-width"));
|
|
11
|
-
const squash_text_nodes_1 = __importDefault(require("./squash-text-nodes"));
|
|
12
|
-
const render_border_1 = __importDefault(require("./render-border"));
|
|
1
|
+
import Yoga from 'yoga-layout-prebuilt';
|
|
2
|
+
import widestLine from 'widest-line';
|
|
3
|
+
import indentString from 'indent-string';
|
|
4
|
+
import wrapText from './wrap-text.js';
|
|
5
|
+
import getMaxWidth from './get-max-width.js';
|
|
6
|
+
import squashTextNodes from './squash-text-nodes.js';
|
|
7
|
+
import renderBorder from './render-border.js';
|
|
13
8
|
// If parent container is `<Box>`, text nodes will be treated as separate nodes in
|
|
14
9
|
// the tree and will have their own coordinates in the layout.
|
|
15
10
|
// To ensure text nodes are aligned correctly, take X and Y of the first text node
|
|
@@ -17,25 +12,23 @@ const render_border_1 = __importDefault(require("./render-border"));
|
|
|
17
12
|
// Only first node is taken into account, because other text nodes can't have margin or padding,
|
|
18
13
|
// so their coordinates will be relative to the first node anyway
|
|
19
14
|
const applyPaddingToText = (node, text) => {
|
|
20
|
-
|
|
21
|
-
const yogaNode = (_a = node.childNodes[0]) === null || _a === void 0 ? void 0 : _a.yogaNode;
|
|
15
|
+
const yogaNode = node.childNodes[0]?.yogaNode;
|
|
22
16
|
if (yogaNode) {
|
|
23
17
|
const offsetX = yogaNode.getComputedLeft();
|
|
24
18
|
const offsetY = yogaNode.getComputedTop();
|
|
25
|
-
text = '\n'.repeat(offsetY) +
|
|
19
|
+
text = '\n'.repeat(offsetY) + indentString(text, offsetX);
|
|
26
20
|
}
|
|
27
21
|
return text;
|
|
28
22
|
};
|
|
29
23
|
// After nodes are laid out, render each to output object, which later gets rendered to terminal
|
|
30
24
|
const renderNodeToOutput = (node, output, options) => {
|
|
31
|
-
var _a;
|
|
32
25
|
const { offsetX = 0, offsetY = 0, transformers = [], skipStaticElements } = options;
|
|
33
26
|
if (skipStaticElements && node.internal_static) {
|
|
34
27
|
return;
|
|
35
28
|
}
|
|
36
29
|
const { yogaNode } = node;
|
|
37
30
|
if (yogaNode) {
|
|
38
|
-
if (yogaNode.getDisplay() ===
|
|
31
|
+
if (yogaNode.getDisplay() === Yoga.DISPLAY_NONE) {
|
|
39
32
|
return;
|
|
40
33
|
}
|
|
41
34
|
// Left and top positions in Yoga are relative to their parent node
|
|
@@ -48,13 +41,13 @@ const renderNodeToOutput = (node, output, options) => {
|
|
|
48
41
|
newTransformers = [node.internal_transform, ...transformers];
|
|
49
42
|
}
|
|
50
43
|
if (node.nodeName === 'ink-text') {
|
|
51
|
-
let text =
|
|
44
|
+
let text = squashTextNodes(node);
|
|
52
45
|
if (text.length > 0) {
|
|
53
|
-
const currentWidth =
|
|
54
|
-
const maxWidth =
|
|
46
|
+
const currentWidth = widestLine(text);
|
|
47
|
+
const maxWidth = getMaxWidth(yogaNode);
|
|
55
48
|
if (currentWidth > maxWidth) {
|
|
56
|
-
const textWrap =
|
|
57
|
-
text =
|
|
49
|
+
const textWrap = node.style.textWrap ?? 'wrap';
|
|
50
|
+
text = wrapText(text, maxWidth, textWrap);
|
|
58
51
|
}
|
|
59
52
|
text = applyPaddingToText(node, text);
|
|
60
53
|
output.write(x, y, text, { transformers: newTransformers });
|
|
@@ -62,7 +55,7 @@ const renderNodeToOutput = (node, output, options) => {
|
|
|
62
55
|
return;
|
|
63
56
|
}
|
|
64
57
|
if (node.nodeName === 'ink-box') {
|
|
65
|
-
|
|
58
|
+
renderBorder(x, y, node, output);
|
|
66
59
|
}
|
|
67
60
|
if (node.nodeName === 'ink-root' || node.nodeName === 'ink-box') {
|
|
68
61
|
for (const childNode of node.childNodes) {
|
|
@@ -76,5 +69,5 @@ const renderNodeToOutput = (node, output, options) => {
|
|
|
76
69
|
}
|
|
77
70
|
}
|
|
78
71
|
};
|
|
79
|
-
|
|
72
|
+
export default renderNodeToOutput;
|
|
80
73
|
//# sourceMappingURL=render-node-to-output.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-node-to-output.js","sourceRoot":"","sources":["../src/render-node-to-output.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"render-node-to-output.js","sourceRoot":"","sources":["../src/render-node-to-output.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,sBAAsB,CAAC;AACxC,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,WAAW,MAAM,oBAAoB,CAAC;AAC7C,OAAO,eAAe,MAAM,wBAAwB,CAAC;AACrD,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAI9C,kFAAkF;AAClF,8DAA8D;AAC9D,kFAAkF;AAClF,iDAAiD;AACjD,gGAAgG;AAChG,iEAAiE;AACjE,MAAM,kBAAkB,GAAG,CAAC,IAAgB,EAAE,IAAY,EAAU,EAAE;IACrE,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC;IAE9C,IAAI,QAAQ,EAAE;QACb,MAAM,OAAO,GAAG,QAAQ,CAAC,eAAe,EAAE,CAAC;QAC3C,MAAM,OAAO,GAAG,QAAQ,CAAC,cAAc,EAAE,CAAC;QAC1C,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;KAC1D;IAED,OAAO,IAAI,CAAC;AACb,CAAC,CAAC;AAIF,gGAAgG;AAChG,MAAM,kBAAkB,GAAG,CAC1B,IAAgB,EAChB,MAAc,EACd,OAKC,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C,CAAC;gBACtC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,EAAC,YAAY,EAAE,eAAe,EAAC,CAAC,CAAC;aAC1D;YAED,OAAO;SACP;QAED,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE;YAChC,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;SACjC;QAED,IAAI,IAAI,CAAC,QAAQ,KAAK,UAAU,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE;YAChE,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,UAAU,EAAE;gBACxC,kBAAkB,CAAC,SAAuB,EAAE,MAAM,EAAE;oBACnD,OAAO,EAAE,CAAC;oBACV,OAAO,EAAE,CAAC;oBACV,YAAY,EAAE,eAAe;oBAC7B,kBAAkB;iBAClB,CAAC,CAAC;aACH;SACD;KACD;AACF,CAAC,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
package/build/render.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { ReactElement } from 'react';
|
|
3
|
-
import Ink from './ink';
|
|
4
|
-
export
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import { type ReactElement } from 'react';
|
|
3
|
+
import Ink from './ink.js';
|
|
4
|
+
export type RenderOptions = {
|
|
5
5
|
/**
|
|
6
6
|
* Output stream where app will be rendered.
|
|
7
7
|
*
|
|
@@ -37,8 +37,8 @@ export interface RenderOptions {
|
|
|
37
37
|
* @default true
|
|
38
38
|
*/
|
|
39
39
|
patchConsole?: boolean;
|
|
40
|
-
}
|
|
41
|
-
export
|
|
40
|
+
};
|
|
41
|
+
export type Instance = {
|
|
42
42
|
/**
|
|
43
43
|
* Replace previous root node with a new one or update props of the current root node.
|
|
44
44
|
*/
|
|
@@ -56,8 +56,8 @@ export interface Instance {
|
|
|
56
56
|
* Clear output.
|
|
57
57
|
*/
|
|
58
58
|
clear: () => void;
|
|
59
|
-
}
|
|
60
|
-
|
|
59
|
+
};
|
|
60
|
+
type RenderFunction = <Props, K extends NodeJS.WriteStream | RenderOptions>(tree: ReactElement<Props>, options?: K) => Instance;
|
|
61
61
|
/**
|
|
62
62
|
* Mount a component and render the output.
|
|
63
63
|
*/
|