ink 6.8.0 → 7.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.
Files changed (128) hide show
  1. package/build/components/AnimationContext.d.ts +9 -0
  2. package/build/components/AnimationContext.js +13 -0
  3. package/build/components/AnimationContext.js.map +1 -0
  4. package/build/components/App.d.ts +4 -1
  5. package/build/components/App.js +140 -20
  6. package/build/components/App.js.map +1 -1
  7. package/build/components/AppContext.d.ts +28 -2
  8. package/build/components/AppContext.js +2 -1
  9. package/build/components/AppContext.js.map +1 -1
  10. package/build/components/Box.d.ts +16 -3
  11. package/build/components/ErrorBoundary.d.ts +2 -2
  12. package/build/components/ErrorOverview.js +6 -6
  13. package/build/components/ErrorOverview.js.map +1 -1
  14. package/build/components/Static.js.map +1 -1
  15. package/build/components/StdinContext.d.ts +7 -1
  16. package/build/components/StdinContext.js +1 -0
  17. package/build/components/StdinContext.js.map +1 -1
  18. package/build/components/Text.d.ts +1 -1
  19. package/build/components/Text.js +1 -1
  20. package/build/components/Text.js.map +1 -1
  21. package/build/components/Transform.d.ts +1 -1
  22. package/build/devtools-window-polyfill.js +7 -4
  23. package/build/devtools-window-polyfill.js.map +1 -1
  24. package/build/devtools.js +31 -6
  25. package/build/devtools.js.map +1 -1
  26. package/build/dom.d.ts +5 -1
  27. package/build/dom.js +20 -1
  28. package/build/dom.js.map +1 -1
  29. package/build/hooks/use-animation.d.ts +49 -0
  30. package/build/hooks/use-animation.js +87 -0
  31. package/build/hooks/use-animation.js.map +1 -0
  32. package/build/hooks/use-app.d.ts +5 -2
  33. package/build/hooks/use-app.js +1 -1
  34. package/build/hooks/use-box-metrics.d.ts +59 -0
  35. package/build/hooks/use-box-metrics.js +88 -0
  36. package/build/hooks/use-box-metrics.js.map +1 -0
  37. package/build/hooks/use-cursor.d.ts +1 -1
  38. package/build/hooks/use-cursor.js +1 -1
  39. package/build/hooks/use-focus-manager.d.ts +17 -2
  40. package/build/hooks/use-focus-manager.js +2 -1
  41. package/build/hooks/use-focus-manager.js.map +1 -1
  42. package/build/hooks/use-focus.d.ts +2 -1
  43. package/build/hooks/use-focus.js +5 -4
  44. package/build/hooks/use-focus.js.map +1 -1
  45. package/build/hooks/use-input.d.ts +2 -1
  46. package/build/hooks/use-input.js +82 -80
  47. package/build/hooks/use-input.js.map +1 -1
  48. package/build/hooks/use-is-screen-reader-enabled.d.ts +2 -1
  49. package/build/hooks/use-is-screen-reader-enabled.js +2 -1
  50. package/build/hooks/use-is-screen-reader-enabled.js.map +1 -1
  51. package/build/hooks/use-paste.d.ts +35 -0
  52. package/build/hooks/use-paste.js +62 -0
  53. package/build/hooks/use-paste.js.map +1 -0
  54. package/build/hooks/use-stderr.d.ts +1 -1
  55. package/build/hooks/use-stderr.js +1 -1
  56. package/build/hooks/use-stdin.d.ts +4 -2
  57. package/build/hooks/use-stdin.js +2 -1
  58. package/build/hooks/use-stdin.js.map +1 -1
  59. package/build/hooks/use-stdout.d.ts +1 -1
  60. package/build/hooks/use-stdout.js +1 -1
  61. package/build/hooks/use-window-size.d.ts +18 -0
  62. package/build/hooks/use-window-size.js +22 -0
  63. package/build/hooks/use-window-size.js.map +1 -0
  64. package/build/index.d.ts +8 -1
  65. package/build/index.js +4 -0
  66. package/build/index.js.map +1 -1
  67. package/build/ink.d.ts +48 -3
  68. package/build/ink.js +325 -155
  69. package/build/ink.js.map +1 -1
  70. package/build/input-parser.d.ts +4 -1
  71. package/build/input-parser.js +70 -30
  72. package/build/input-parser.js.map +1 -1
  73. package/build/log-update.d.ts +1 -0
  74. package/build/log-update.js +13 -1
  75. package/build/log-update.js.map +1 -1
  76. package/build/measure-element.d.ts +4 -0
  77. package/build/measure-element.js +4 -0
  78. package/build/measure-element.js.map +1 -1
  79. package/build/output.js +25 -0
  80. package/build/output.js.map +1 -1
  81. package/build/parse-keypress.d.ts +1 -3
  82. package/build/parse-keypress.js +19 -17
  83. package/build/parse-keypress.js.map +1 -1
  84. package/build/reconciler.js +46 -27
  85. package/build/reconciler.js.map +1 -1
  86. package/build/render-border.js +29 -18
  87. package/build/render-border.js.map +1 -1
  88. package/build/render-to-string.js +2 -1
  89. package/build/render-to-string.js.map +1 -1
  90. package/build/render.d.ts +57 -2
  91. package/build/render.js +18 -11
  92. package/build/render.js.map +1 -1
  93. package/build/styles.d.ts +78 -16
  94. package/build/styles.js +102 -31
  95. package/build/styles.js.map +1 -1
  96. package/build/utils.d.ts +9 -2
  97. package/build/utils.js +18 -3
  98. package/build/utils.js.map +1 -1
  99. package/build/wrap-text.js +7 -0
  100. package/build/wrap-text.js.map +1 -1
  101. package/build/write-synchronized.d.ts +1 -1
  102. package/build/write-synchronized.js +4 -2
  103. package/build/write-synchronized.js.map +1 -1
  104. package/package.json +34 -98
  105. package/readme.md +554 -48
  106. package/build/apply-styles.js +0 -175
  107. package/build/build-layout.js +0 -77
  108. package/build/calculate-wrapped-text.js +0 -53
  109. package/build/components/Color.js +0 -62
  110. package/build/components/Cursor.d.ts +0 -83
  111. package/build/components/Cursor.js +0 -53
  112. package/build/components/Cursor.js.map +0 -1
  113. package/build/experimental/apply-style.js +0 -140
  114. package/build/experimental/dom.js +0 -123
  115. package/build/experimental/output.js +0 -91
  116. package/build/experimental/reconciler.js +0 -141
  117. package/build/experimental/renderer.js +0 -81
  118. package/build/hooks/useInput.js +0 -38
  119. package/build/instance.js +0 -205
  120. package/build/layout.d.ts +0 -7
  121. package/build/layout.js +0 -33
  122. package/build/layout.js.map +0 -1
  123. package/build/options.d.ts +0 -52
  124. package/build/options.js +0 -2
  125. package/build/options.js.map +0 -1
  126. package/build/screen-reader-update.d.ts +0 -13
  127. package/build/screen-reader-update.js +0 -38
  128. package/build/screen-reader-update.js.map +0 -1
@@ -1,123 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.setTextContent = exports.createTextNode = exports.setAttribute = exports.setStyle = exports.removeChildNode = exports.insertBeforeNode = exports.appendChildNode = exports.createNode = void 0;
7
-
8
- var _yogaLayoutPrebuilt = _interopRequireDefault(require("yoga-layout-prebuilt"));
9
-
10
- var _measureText = _interopRequireDefault(require("../measure-text"));
11
-
12
- var _applyStyle = _interopRequireDefault(require("./apply-style"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- // Helper utilities implementing some common DOM methods to simplify reconciliation code
17
- const createNode = tagName => ({
18
- nodeName: tagName.toUpperCase(),
19
- style: {},
20
- attributes: {},
21
- childNodes: [],
22
- parentNode: null,
23
- textContent: null,
24
- yogaNode: _yogaLayoutPrebuilt.default.Node.create()
25
- });
26
-
27
- exports.createNode = createNode;
28
-
29
- const appendChildNode = (node, childNode) => {
30
- if (childNode.parentNode) {
31
- removeChildNode(childNode.parentNode, childNode);
32
- }
33
-
34
- childNode.parentNode = node;
35
- node.childNodes.push(childNode);
36
- node.yogaNode.insertChild(childNode.yogaNode, node.yogaNode.getChildCount());
37
- };
38
-
39
- exports.appendChildNode = appendChildNode;
40
-
41
- const insertBeforeNode = (node, newChildNode, beforeChildNode) => {
42
- if (newChildNode.parentNode) {
43
- removeChildNode(newChildNode.parentNode, newChildNode);
44
- }
45
-
46
- newChildNode.parentNode = node;
47
- const index = node.childNodes.indexOf(beforeChildNode);
48
-
49
- if (index >= 0) {
50
- node.childNodes.splice(index, 0, newChildNode);
51
- node.yogaNode.insertChild(newChildNode.yogaNode, index);
52
- return;
53
- }
54
-
55
- node.childNodes.push(newChildNode);
56
- node.yogaNode.insertChild(newChildNode.yogaNode, node.yogaNode.getChildCount());
57
- };
58
-
59
- exports.insertBeforeNode = insertBeforeNode;
60
-
61
- const removeChildNode = (node, removeNode) => {
62
- removeNode.parentNode.yogaNode.removeChild(removeNode.yogaNode);
63
- removeNode.parentNode = null;
64
- const index = node.childNodes.indexOf(removeNode);
65
-
66
- if (index >= 0) {
67
- node.childNodes.splice(index, 1);
68
- }
69
- };
70
-
71
- exports.removeChildNode = removeChildNode;
72
-
73
- const setStyle = (node, style) => {
74
- node.style = style;
75
- (0, _applyStyle.default)(node.yogaNode, style);
76
- };
77
-
78
- exports.setStyle = setStyle;
79
-
80
- const setAttribute = (node, key, value) => {
81
- node.attributes[key] = value;
82
- };
83
-
84
- exports.setAttribute = setAttribute;
85
-
86
- const createTextNode = text => {
87
- const node = {
88
- nodeName: '#text',
89
- nodeValue: text,
90
- yogaNode: _yogaLayoutPrebuilt.default.Node.create()
91
- };
92
- setTextContent(node, text);
93
- return node;
94
- };
95
-
96
- exports.createTextNode = createTextNode;
97
-
98
- const setTextContent = (node, text) => {
99
- if (typeof text !== 'string') {
100
- text = String(text);
101
- }
102
-
103
- let width = 0;
104
- let height = 0;
105
-
106
- if (text.length > 0) {
107
- const dimensions = (0, _measureText.default)(text);
108
- width = dimensions.width;
109
- height = dimensions.height;
110
- }
111
-
112
- if (node.nodeName === '#text') {
113
- node.nodeValue = text;
114
- node.yogaNode.setWidth(width);
115
- node.yogaNode.setHeight(height);
116
- } else {
117
- node.textContent = text;
118
- node.yogaNode.setWidth(node.style.width || width);
119
- node.yogaNode.setHeight(node.style.height || height);
120
- }
121
- };
122
-
123
- exports.setTextContent = setTextContent;
@@ -1,91 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _stringLength = _interopRequireDefault(require("string-length"));
9
-
10
- var _sliceAnsi = _interopRequireDefault(require("slice-ansi"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- /**
15
- * "Virtual" output class
16
- *
17
- * Handles the positioning and saving of the output of each node in the tree.
18
- * Also responsible for applying transformations to each character of the output.
19
- *
20
- * Used to generate the final output of all nodes before writing it to actual output stream (e.g. stdout)
21
- */
22
- class Output {
23
- constructor({
24
- width,
25
- height
26
- }) {
27
- this.width = width;
28
- this.height = height;
29
- this.writes = []; // Initialize output array with a specific set of rows, so that margin/padding at the bottom is preserved
30
- }
31
-
32
- write(x, y, text, {
33
- transformers
34
- }) {
35
- if (!text) {
36
- return;
37
- }
38
-
39
- this.writes.push({
40
- x,
41
- y,
42
- text,
43
- transformers
44
- });
45
- }
46
-
47
- get() {
48
- const output = [];
49
-
50
- for (let y = 0; y < this.height; y++) {
51
- output.push(' '.repeat(this.width));
52
- }
53
-
54
- for (const write of this.writes) {
55
- const {
56
- x,
57
- y,
58
- text,
59
- transformers
60
- } = write;
61
- const lines = text.split('\n');
62
- let offsetY = 0;
63
-
64
- for (let line of lines) {
65
- const currentLine = output[y + offsetY]; // Line can be missing if `text` is taller than height of pre-initialized `this.output`
66
-
67
- if (!currentLine) {
68
- continue;
69
- }
70
-
71
- const length = (0, _stringLength.default)(line);
72
-
73
- for (const transformer of transformers) {
74
- line = transformer(line);
75
- }
76
-
77
- output[y + offsetY] = (0, _sliceAnsi.default)(currentLine, 0, x) + line + (0, _sliceAnsi.default)(currentLine, x + length);
78
- offsetY++;
79
- }
80
- }
81
-
82
- const generatedOutput = output.map(line => line.trimRight()).join('\n');
83
- return {
84
- output: generatedOutput,
85
- height: output.length
86
- };
87
- }
88
-
89
- }
90
-
91
- exports.default = Output;
@@ -1,141 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _scheduler = require("scheduler");
9
-
10
- var _reactReconciler = _interopRequireDefault(require("react-reconciler"));
11
-
12
- var _dom = require("./dom");
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- const NO_CONTEXT = true;
17
- const hostConfig = {
18
- schedulePassiveEffects: _scheduler.unstable_scheduleCallback,
19
- cancelPassiveEffects: _scheduler.unstable_cancelCallback,
20
- now: Date.now,
21
- getRootHostContext: () => NO_CONTEXT,
22
- prepareForCommit: () => {},
23
- resetAfterCommit: rootNode => {
24
- // Since renders are throttled at the instance level and <Static> component children
25
- // are rendered only once and then get deleted, we need an escape hatch to
26
- // trigger an immediate render to ensure <Static> children are written to output before they get erased
27
- if (rootNode.isStaticDirty) {
28
- rootNode.isStaticDirty = false;
29
- rootNode.onImmediateRender();
30
- return;
31
- }
32
-
33
- rootNode.onRender();
34
- },
35
- getChildHostContext: () => NO_CONTEXT,
36
- shouldSetTextContent: (type, props) => {
37
- return typeof props.children === 'string' || typeof props.children === 'number';
38
- },
39
- createInstance: (type, newProps) => {
40
- const node = (0, _dom.createNode)(type);
41
-
42
- for (const [key, value] of Object.entries(newProps)) {
43
- if (key === 'children') {
44
- if (typeof value === 'string' || typeof value === 'number') {
45
- if (type === 'div') {
46
- // Text node must be wrapped in another node, so that text can be aligned within container
47
- const textNode = (0, _dom.createNode)('div');
48
- (0, _dom.setTextContent)(textNode, value);
49
- (0, _dom.appendChildNode)(node, textNode);
50
- }
51
-
52
- if (type === 'span') {
53
- (0, _dom.setTextContent)(node, value);
54
- }
55
- }
56
- } else if (key === 'style') {
57
- (0, _dom.setStyle)(node, value);
58
- } else if (key === 'unstable__transformChildren') {
59
- node.unstable__transformChildren = value; // eslint-disable-line camelcase
60
- } else if (key === 'unstable__static') {
61
- node.unstable__static = true; // eslint-disable-line camelcase
62
- } else {
63
- (0, _dom.setAttribute)(node, key, value);
64
- }
65
- }
66
-
67
- return node;
68
- },
69
- createTextInstance: _dom.createTextNode,
70
- resetTextContent: node => {
71
- if (node.textContent) {
72
- node.textContent = '';
73
- }
74
-
75
- if (node.childNodes.length > 0) {
76
- for (const childNode of node.childNodes) {
77
- (0, _dom.removeChildNode)(node, childNode);
78
- }
79
- }
80
- },
81
- getPublicInstance: instance => instance,
82
- appendInitialChild: _dom.appendChildNode,
83
- appendChild: _dom.appendChildNode,
84
- insertBefore: _dom.insertBeforeNode,
85
- finalizeInitialChildren: (node, type, props, rootNode) => {
86
- if (node.unstable__static) {
87
- rootNode.isStaticDirty = true;
88
- }
89
- },
90
- supportsMutation: true,
91
- appendChildToContainer: _dom.appendChildNode,
92
- insertInContainerBefore: _dom.insertBeforeNode,
93
- removeChildFromContainer: _dom.removeChildNode,
94
- prepareUpdate: (node, type, oldProps, newProps, rootNode) => {
95
- if (node.unstable__static) {
96
- rootNode.isStaticDirty = true;
97
- }
98
-
99
- return true;
100
- },
101
- commitUpdate: (node, updatePayload, type, oldProps, newProps) => {
102
- for (const [key, value] of Object.entries(newProps)) {
103
- if (key === 'children') {
104
- if (typeof value === 'string' || typeof value === 'number') {
105
- if (type === 'div') {
106
- // Text node must be wrapped in another node, so that text can be aligned within container
107
- // If there's no such node, a new one must be created
108
- if (node.childNodes.length === 0) {
109
- const textNode = (0, _dom.createNode)('div');
110
- (0, _dom.setTextContent)(textNode, value);
111
- (0, _dom.appendChildNode)(node, textNode);
112
- } else {
113
- (0, _dom.setTextContent)(node.childNodes[0], value);
114
- }
115
- }
116
-
117
- if (type === 'span') {
118
- (0, _dom.setTextContent)(node, value);
119
- }
120
- }
121
- } else if (key === 'style') {
122
- (0, _dom.setStyle)(node, value);
123
- } else if (key === 'unstable__transformChildren') {
124
- node.unstable__transformChildren = value; // eslint-disable-line camelcase
125
- } else if (key === 'unstable__static') {
126
- node.unstable__static = true; // eslint-disable-line camelcase
127
- } else {
128
- (0, _dom.setAttribute)(node, key, value);
129
- }
130
- }
131
- },
132
- commitTextUpdate: (node, oldText, newText) => {
133
- (0, _dom.setTextContent)(node, newText);
134
- },
135
- removeChild: _dom.removeChildNode
136
- };
137
-
138
- var _default = (0, _reactReconciler.default)(hostConfig); // eslint-disable-line new-cap
139
-
140
-
141
- exports.default = _default;
@@ -1,81 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _yogaLayoutPrebuilt = _interopRequireDefault(require("yoga-layout-prebuilt"));
9
-
10
- var _renderNodeToOutput = _interopRequireDefault(require("../render-node-to-output"));
11
-
12
- var _calculateWrappedText = _interopRequireDefault(require("../calculate-wrapped-text"));
13
-
14
- var _output = _interopRequireDefault(require("./output"));
15
-
16
- var _dom = require("./dom");
17
-
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
- // Since <Static> components can be placed anywhere in the tree, this helper finds and returns them
21
- const findStaticNode = node => {
22
- if (node.unstable__static) {
23
- return node;
24
- }
25
-
26
- for (const childNode of node.childNodes) {
27
- if (childNode.unstable__static) {
28
- return childNode;
29
- }
30
-
31
- if (Array.isArray(childNode.childNodes) && childNode.childNodes.length > 0) {
32
- return findStaticNode(childNode);
33
- }
34
- }
35
- };
36
-
37
- var _default = ({
38
- terminalWidth = 100
39
- }) => {
40
- return node => {
41
- (0, _dom.setStyle)(node, {
42
- width: terminalWidth
43
- });
44
- node.yogaNode.calculateLayout(_yogaLayoutPrebuilt.default.UNDEFINED, _yogaLayoutPrebuilt.default.UNDEFINED, _yogaLayoutPrebuilt.default.DIRECTION_LTR);
45
- (0, _calculateWrappedText.default)(node);
46
- node.yogaNode.calculateLayout(_yogaLayoutPrebuilt.default.UNDEFINED, _yogaLayoutPrebuilt.default.UNDEFINED, _yogaLayoutPrebuilt.default.DIRECTION_LTR);
47
- const output = new _output.default({
48
- width: node.yogaNode.getComputedWidth(),
49
- height: node.yogaNode.getComputedHeight()
50
- });
51
- (0, _renderNodeToOutput.default)(node, output, {
52
- skipStaticElements: true
53
- });
54
- const staticNode = findStaticNode(node);
55
- let staticOutput;
56
-
57
- if (staticNode) {
58
- staticOutput = new _output.default({
59
- width: staticNode.yogaNode.getComputedWidth(),
60
- height: staticNode.yogaNode.getComputedHeight()
61
- });
62
- (0, _renderNodeToOutput.default)(staticNode, staticOutput, {
63
- skipStaticElements: false
64
- });
65
- }
66
-
67
- const {
68
- output: generatedOutput,
69
- height: outputHeight
70
- } = output.get();
71
- return {
72
- output: generatedOutput,
73
- outputHeight,
74
- // Newline at the end is needed, because static output doesn't have one, so
75
- // interactive output will override last line of static output
76
- staticOutput: staticOutput ? `${staticOutput.get().output}\n` : undefined
77
- };
78
- };
79
- };
80
-
81
- exports.default = _default;
@@ -1,38 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _react = require("react");
9
-
10
- var _ = require("..");
11
-
12
- var _default = inputHandler => {
13
- const {
14
- stdin,
15
- setRawMode
16
- } = (0, _react.useContext)(_.StdinContext);
17
- (0, _react.useLayoutEffect)(() => {
18
- setRawMode(true);
19
- return () => setRawMode(false);
20
- }, [setRawMode]);
21
- (0, _react.useLayoutEffect)(() => {
22
- const handleData = data => {
23
- const input = String(data);
24
- const meta = {
25
- up: input === '\u001B[A',
26
- down: input === '\u001B[B',
27
- left: input === '\u001B[D',
28
- right: input === '\u001B[C'
29
- };
30
- inputHandler(input, meta);
31
- };
32
-
33
- stdin.on('data', handleData);
34
- return () => stdin.off('data', handleData);
35
- }, [stdin, inputHandler]);
36
- };
37
-
38
- exports.default = _default;
package/build/instance.js DELETED
@@ -1,205 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _react = _interopRequireDefault(require("react"));
9
-
10
- var _lodash = _interopRequireDefault(require("lodash.throttle"));
11
-
12
- var _autoBind = _interopRequireDefault(require("auto-bind"));
13
-
14
- var _logUpdate = _interopRequireDefault(require("log-update"));
15
-
16
- var _isCi = _interopRequireDefault(require("is-ci"));
17
-
18
- var _signalExit = _interopRequireDefault(require("signal-exit"));
19
-
20
- var _ansiEscapes = _interopRequireDefault(require("ansi-escapes"));
21
-
22
- var _reconciler = _interopRequireDefault(require("./reconciler"));
23
-
24
- var _reconciler2 = _interopRequireDefault(require("./experimental/reconciler"));
25
-
26
- var _renderer = _interopRequireDefault(require("./renderer"));
27
-
28
- var _renderer2 = _interopRequireDefault(require("./experimental/renderer"));
29
-
30
- var dom = _interopRequireWildcard(require("./dom"));
31
-
32
- var experimentalDom = _interopRequireWildcard(require("./experimental/dom"));
33
-
34
- var _instances = _interopRequireDefault(require("./instances"));
35
-
36
- var _App = _interopRequireDefault(require("./components/App"));
37
-
38
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
39
-
40
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
41
-
42
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
43
-
44
- class Instance {
45
- constructor(options) {
46
- (0, _autoBind.default)(this);
47
- this.options = options;
48
-
49
- if (options.experimental) {
50
- this.rootNode = experimentalDom.createNode('root');
51
- this.rootNode.onRender = options.debug ? this.onRender : (0, _lodash.default)(this.onRender, 16, {
52
- leading: true,
53
- trailing: true
54
- });
55
- this.rootNode.onImmediateRender = this.onRender;
56
- this.renderer = (0, _renderer2.default)({
57
- terminalWidth: options.stdout.columns
58
- });
59
- } else {
60
- this.rootNode = dom.createNode('root');
61
- this.rootNode.onRender = this.onRender;
62
- this.renderer = (0, _renderer.default)({
63
- terminalWidth: options.stdout.columns
64
- });
65
- }
66
-
67
- this.log = _logUpdate.default.create(options.stdout);
68
- this.throttledLog = options.debug ? this.log : (0, _lodash.default)(this.log, {
69
- leading: true,
70
- trailing: true
71
- }); // Ignore last render after unmounting a tree to prevent empty output before exit
72
-
73
- this.isUnmounted = false; // Store last output to only rerender when needed
74
-
75
- this.lastOutput = ''; // This variable is used only in debug mode to store full static output
76
- // so that it's rerendered every time, not just new static parts, like in non-debug mode
77
-
78
- this.fullStaticOutput = '';
79
-
80
- if (options.experimental) {
81
- this.container = _reconciler2.default.createContainer(this.rootNode, false, false);
82
- } else {
83
- this.container = _reconciler.default.createContainer(this.rootNode, false, false);
84
- }
85
-
86
- this.exitPromise = new Promise((resolve, reject) => {
87
- this.resolveExitPromise = resolve;
88
- this.rejectExitPromise = reject;
89
- }); // Unmount when process exits
90
-
91
- this.unsubscribeExit = (0, _signalExit.default)(this.unmount, {
92
- alwaysLast: false
93
- });
94
- }
95
-
96
- onRender() {
97
- if (this.isUnmounted) {
98
- return;
99
- }
100
-
101
- const {
102
- output,
103
- outputHeight,
104
- staticOutput
105
- } = this.renderer(this.rootNode); // If <Static> output isn't empty, it means new children have been added to it
106
-
107
- const hasStaticOutput = staticOutput && staticOutput !== '\n';
108
-
109
- if (this.options.debug) {
110
- if (hasStaticOutput) {
111
- this.fullStaticOutput += staticOutput;
112
- }
113
-
114
- this.options.stdout.write(this.fullStaticOutput + output);
115
- return;
116
- }
117
-
118
- if (_isCi.default) {
119
- if (hasStaticOutput) {
120
- this.options.stdout.write(staticOutput);
121
- }
122
-
123
- this.lastOutput = output;
124
- return;
125
- }
126
-
127
- if (hasStaticOutput) {
128
- this.fullStaticOutput += staticOutput;
129
- }
130
-
131
- if (this.options.experimental && outputHeight >= this.options.stdout.rows) {
132
- this.options.stdout.write(_ansiEscapes.default.clearTerminal + this.fullStaticOutput + output);
133
- this.lastOutput = output;
134
- return;
135
- } // To ensure static output is cleanly rendered before main output, clear main output first
136
-
137
-
138
- if (hasStaticOutput) {
139
- this.log.clear();
140
- this.options.stdout.write(staticOutput);
141
- }
142
-
143
- if (output !== this.lastOutput) {
144
- if (this.options.experimental) {
145
- this.throttledLog(output);
146
- } else {
147
- this.log(output);
148
- }
149
- }
150
- }
151
-
152
- render(node) {
153
- const tree = _react.default.createElement(_App.default, {
154
- stdin: this.options.stdin,
155
- stdout: this.options.stdout,
156
- exitOnCtrlC: this.options.exitOnCtrlC,
157
- onExit: this.unmount
158
- }, node);
159
-
160
- if (this.options.experimental) {
161
- _reconciler2.default.updateContainer(tree, this.container);
162
- } else {
163
- _reconciler.default.updateContainer(tree, this.container);
164
- }
165
- }
166
-
167
- unmount(error) {
168
- if (this.isUnmounted) {
169
- return;
170
- }
171
-
172
- this.onRender();
173
- this.unsubscribeExit(); // CIs don't handle erasing ansi escapes well, so it's better to
174
- // only render last frame of non-static output
175
-
176
- if (_isCi.default) {
177
- this.options.stdout.write(this.lastOutput + '\n');
178
- } else if (!this.options.debug) {
179
- this.log.done();
180
- }
181
-
182
- this.isUnmounted = true;
183
-
184
- if (this.options.experimental) {
185
- _reconciler2.default.updateContainer(null, this.container);
186
- } else {
187
- _reconciler.default.updateContainer(null, this.container);
188
- }
189
-
190
- _instances.default.delete(this.options.stdout);
191
-
192
- if (error instanceof Error) {
193
- this.rejectExitPromise(error);
194
- } else {
195
- this.resolveExitPromise();
196
- }
197
- }
198
-
199
- waitUntilExit() {
200
- return this.exitPromise;
201
- }
202
-
203
- }
204
-
205
- exports.default = Instance;
package/build/layout.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import { type DOMElement } from './dom.js';
2
- export type Position = {
3
- x: number;
4
- y: number;
5
- };
6
- export declare const getAbsolutePosition: (node: DOMElement) => Position | undefined;
7
- export declare const getAbsoluteContentPosition: (node: DOMElement) => Position | undefined;