WIP - add extractor, generate snippet_data
This commit is contained in:
179
node_modules/ink/build/apply-styles.js
generated
vendored
Normal file
179
node_modules/ink/build/apply-styles.js
generated
vendored
Normal file
@ -0,0 +1,179 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _yogaLayoutPrebuilt = _interopRequireDefault(require("yoga-layout-prebuilt"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
const hasOwnProperty = (obj, prop) => {
|
||||
return {}.hasOwnProperty.call(obj, prop);
|
||||
};
|
||||
|
||||
const applyMarginStyles = (node, style) => {
|
||||
if (style.margin) {
|
||||
node.setMargin(_yogaLayoutPrebuilt.default.EDGE_TOP, style.margin);
|
||||
node.setMargin(_yogaLayoutPrebuilt.default.EDGE_BOTTOM, style.margin);
|
||||
node.setMargin(_yogaLayoutPrebuilt.default.EDGE_START, style.margin);
|
||||
node.setMargin(_yogaLayoutPrebuilt.default.EDGE_END, style.margin);
|
||||
}
|
||||
|
||||
if (style.marginX) {
|
||||
node.setMargin(_yogaLayoutPrebuilt.default.EDGE_START, style.marginX);
|
||||
node.setMargin(_yogaLayoutPrebuilt.default.EDGE_END, style.marginX);
|
||||
}
|
||||
|
||||
if (style.marginY) {
|
||||
node.setMargin(_yogaLayoutPrebuilt.default.EDGE_TOP, style.marginY);
|
||||
node.setMargin(_yogaLayoutPrebuilt.default.EDGE_BOTTOM, style.marginY);
|
||||
}
|
||||
|
||||
if (style.marginTop) {
|
||||
node.setMargin(_yogaLayoutPrebuilt.default.EDGE_TOP, style.marginTop);
|
||||
}
|
||||
|
||||
if (style.marginBottom) {
|
||||
node.setMargin(_yogaLayoutPrebuilt.default.EDGE_BOTTOM, style.marginBottom);
|
||||
}
|
||||
|
||||
if (style.marginLeft) {
|
||||
node.setMargin(_yogaLayoutPrebuilt.default.EDGE_START, style.marginLeft);
|
||||
}
|
||||
|
||||
if (style.marginRight) {
|
||||
node.setMargin(_yogaLayoutPrebuilt.default.EDGE_END, style.marginRight);
|
||||
}
|
||||
};
|
||||
|
||||
const applyPaddingStyles = (node, style) => {
|
||||
if (style.padding) {
|
||||
node.setPadding(_yogaLayoutPrebuilt.default.EDGE_TOP, style.padding);
|
||||
node.setPadding(_yogaLayoutPrebuilt.default.EDGE_BOTTOM, style.padding);
|
||||
node.setPadding(_yogaLayoutPrebuilt.default.EDGE_LEFT, style.padding);
|
||||
node.setPadding(_yogaLayoutPrebuilt.default.EDGE_RIGHT, style.padding);
|
||||
}
|
||||
|
||||
if (style.paddingX) {
|
||||
node.setPadding(_yogaLayoutPrebuilt.default.EDGE_LEFT, style.paddingX);
|
||||
node.setPadding(_yogaLayoutPrebuilt.default.EDGE_RIGHT, style.paddingX);
|
||||
}
|
||||
|
||||
if (style.paddingY) {
|
||||
node.setPadding(_yogaLayoutPrebuilt.default.EDGE_TOP, style.paddingY);
|
||||
node.setPadding(_yogaLayoutPrebuilt.default.EDGE_BOTTOM, style.paddingY);
|
||||
}
|
||||
|
||||
if (style.paddingTop) {
|
||||
node.setPadding(_yogaLayoutPrebuilt.default.EDGE_TOP, style.paddingTop);
|
||||
}
|
||||
|
||||
if (style.paddingBottom) {
|
||||
node.setPadding(_yogaLayoutPrebuilt.default.EDGE_BOTTOM, style.paddingBottom);
|
||||
}
|
||||
|
||||
if (style.paddingLeft) {
|
||||
node.setPadding(_yogaLayoutPrebuilt.default.EDGE_LEFT, style.paddingLeft);
|
||||
}
|
||||
|
||||
if (style.paddingRight) {
|
||||
node.setPadding(_yogaLayoutPrebuilt.default.EDGE_RIGHT, style.paddingRight);
|
||||
}
|
||||
};
|
||||
|
||||
const applyFlexStyles = (node, style) => {
|
||||
if (style.flexGrow) {
|
||||
node.setFlexGrow(style.flexGrow);
|
||||
}
|
||||
|
||||
if (style.flexShrink) {
|
||||
node.setFlexShrink(style.flexShrink);
|
||||
}
|
||||
|
||||
if (style.flexDirection) {
|
||||
if (style.flexDirection === 'row') {
|
||||
node.setFlexDirection(_yogaLayoutPrebuilt.default.FLEX_DIRECTION_ROW);
|
||||
}
|
||||
|
||||
if (style.flexDirection === 'row-reverse') {
|
||||
node.setFlexDirection(_yogaLayoutPrebuilt.default.FLEX_DIRECTION_ROW_REVERSE);
|
||||
}
|
||||
|
||||
if (style.flexDirection === 'column') {
|
||||
node.setFlexDirection(_yogaLayoutPrebuilt.default.FLEX_DIRECTION_COLUMN);
|
||||
}
|
||||
|
||||
if (style.flexDirection === 'column-reverse') {
|
||||
node.setFlexDirection(_yogaLayoutPrebuilt.default.FLEX_DIRECTION_COLUMN_REVERSE);
|
||||
}
|
||||
}
|
||||
|
||||
if (hasOwnProperty(style, 'flexBasis')) {
|
||||
node.setFlexBasis(style.flexBasis);
|
||||
}
|
||||
|
||||
if (style.alignItems) {
|
||||
if (style.alignItems === 'flex-start') {
|
||||
node.setAlignItems(_yogaLayoutPrebuilt.default.ALIGN_FLEX_START);
|
||||
}
|
||||
|
||||
if (style.alignItems === 'center') {
|
||||
node.setAlignItems(_yogaLayoutPrebuilt.default.ALIGN_CENTER);
|
||||
}
|
||||
|
||||
if (style.alignItems === 'flex-end') {
|
||||
node.setAlignItems(_yogaLayoutPrebuilt.default.ALIGN_FLEX_END);
|
||||
}
|
||||
}
|
||||
|
||||
if (style.justifyContent) {
|
||||
if (style.justifyContent === 'flex-start') {
|
||||
node.setJustifyContent(_yogaLayoutPrebuilt.default.JUSTIFY_FLEX_START);
|
||||
}
|
||||
|
||||
if (style.justifyContent === 'center') {
|
||||
node.setJustifyContent(_yogaLayoutPrebuilt.default.JUSTIFY_CENTER);
|
||||
}
|
||||
|
||||
if (style.justifyContent === 'flex-end') {
|
||||
node.setJustifyContent(_yogaLayoutPrebuilt.default.JUSTIFY_FLEX_END);
|
||||
}
|
||||
|
||||
if (style.justifyContent === 'space-between') {
|
||||
node.setJustifyContent(_yogaLayoutPrebuilt.default.JUSTIFY_SPACE_BETWEEN);
|
||||
}
|
||||
|
||||
if (style.justifyContent === 'space-around') {
|
||||
node.setJustifyContent(_yogaLayoutPrebuilt.default.JUSTIFY_SPACE_AROUND);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const applyDimensionStyles = (node, style) => {
|
||||
if (hasOwnProperty(style, 'width')) {
|
||||
node.setWidth(style.width);
|
||||
}
|
||||
|
||||
if (hasOwnProperty(style, 'height')) {
|
||||
node.setHeight(style.height);
|
||||
}
|
||||
|
||||
if (hasOwnProperty(style, 'minWidth')) {
|
||||
node.setMinWidth(style.minWidth);
|
||||
}
|
||||
|
||||
if (hasOwnProperty(style, 'minHeight')) {
|
||||
node.setMinHeight(style.minHeight);
|
||||
}
|
||||
};
|
||||
|
||||
var _default = (node, style = {}) => {
|
||||
applyMarginStyles(node, style);
|
||||
applyPaddingStyles(node, style);
|
||||
applyFlexStyles(node, style);
|
||||
applyDimensionStyles(node, style);
|
||||
};
|
||||
|
||||
exports.default = _default;
|
||||
77
node_modules/ink/build/build-layout.js
generated
vendored
Normal file
77
node_modules/ink/build/build-layout.js
generated
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _yogaLayoutPrebuilt = _interopRequireDefault(require("yoga-layout-prebuilt"));
|
||||
|
||||
var _applyStyles = _interopRequireDefault(require("./apply-styles"));
|
||||
|
||||
var _measureText = _interopRequireDefault(require("./measure-text"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// Traverse the node tree, create Yoga nodes and assign styles to each Yoga node
|
||||
const buildLayout = (node, options) => {
|
||||
const {
|
||||
config,
|
||||
terminalWidth,
|
||||
skipStaticElements
|
||||
} = options;
|
||||
|
||||
const yogaNode = _yogaLayoutPrebuilt.default.Node.create(config);
|
||||
|
||||
node.yogaNode = yogaNode;
|
||||
const style = node.style || {}; // Root node of the tree
|
||||
|
||||
if (node.nodeName === 'ROOT') {
|
||||
// `terminalWidth` can be `undefined` if env isn't a TTY
|
||||
yogaNode.setWidth(terminalWidth || 100);
|
||||
|
||||
if (node.childNodes.length > 0) {
|
||||
const childNodes = node.childNodes.filter(childNode => {
|
||||
return skipStaticElements ? !childNode.unstable__static : true;
|
||||
});
|
||||
|
||||
for (const [index, childNode] of Object.entries(childNodes)) {
|
||||
const childYogaNode = buildLayout(childNode, options).yogaNode;
|
||||
yogaNode.insertChild(childYogaNode, index);
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
} // Apply margin, padding, flex, etc styles
|
||||
|
||||
|
||||
(0, _applyStyles.default)(yogaNode, style); // Nodes with only text have a child Yoga node dedicated for that text
|
||||
|
||||
if (node.textContent || node.nodeValue) {
|
||||
const {
|
||||
width,
|
||||
height
|
||||
} = (0, _measureText.default)(node.textContent || node.nodeValue);
|
||||
yogaNode.setWidth(style.width || width);
|
||||
yogaNode.setHeight(style.height || height);
|
||||
return node;
|
||||
}
|
||||
|
||||
if (Array.isArray(node.childNodes) && node.childNodes.length > 0) {
|
||||
const childNodes = node.childNodes.filter(childNode => {
|
||||
return skipStaticElements ? !childNode.unstable__static : true;
|
||||
});
|
||||
|
||||
for (const [index, childNode] of Object.entries(childNodes)) {
|
||||
const {
|
||||
yogaNode: childYogaNode
|
||||
} = buildLayout(childNode, options);
|
||||
yogaNode.insertChild(childYogaNode, index);
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
};
|
||||
|
||||
var _default = buildLayout;
|
||||
exports.default = _default;
|
||||
49
node_modules/ink/build/calculate-wrapped-text.js
generated
vendored
Normal file
49
node_modules/ink/build/calculate-wrapped-text.js
generated
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _wrapText = _interopRequireDefault(require("./wrap-text"));
|
||||
|
||||
var _measureText = _interopRequireDefault(require("./measure-text"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
const calculateWrappedText = node => {
|
||||
if (node.textContent && typeof node.parentNode.style.textWrap === 'string') {
|
||||
const {
|
||||
yogaNode
|
||||
} = node;
|
||||
const parentYogaNode = node.parentNode.yogaNode;
|
||||
const maxWidth = parentYogaNode.getComputedWidth() - parentYogaNode.getComputedPadding() * 2;
|
||||
const currentWidth = yogaNode.getComputedWidth();
|
||||
|
||||
if (currentWidth > maxWidth) {
|
||||
const {
|
||||
textWrap
|
||||
} = node.parentNode.style;
|
||||
const wrappedText = (0, _wrapText.default)(node.textContent, maxWidth, {
|
||||
textWrap
|
||||
});
|
||||
const {
|
||||
width,
|
||||
height
|
||||
} = (0, _measureText.default)(wrappedText);
|
||||
yogaNode.setWidth(width);
|
||||
yogaNode.setHeight(height);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (Array.isArray(node.childNodes) && node.childNodes.length > 0) {
|
||||
for (const childNode of node.childNodes) {
|
||||
calculateWrappedText(childNode);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var _default = calculateWrappedText;
|
||||
exports.default = _default;
|
||||
142
node_modules/ink/build/components/App.js
generated
vendored
Normal file
142
node_modules/ink/build/components/App.js
generated
vendored
Normal file
@ -0,0 +1,142 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _readline = _interopRequireDefault(require("readline"));
|
||||
|
||||
var _react = _interopRequireWildcard(require("react"));
|
||||
|
||||
var _propTypes = _interopRequireDefault(require("prop-types"));
|
||||
|
||||
var _cliCursor = _interopRequireDefault(require("cli-cursor"));
|
||||
|
||||
var _AppContext = _interopRequireDefault(require("./AppContext"));
|
||||
|
||||
var _StdinContext = _interopRequireDefault(require("./StdinContext"));
|
||||
|
||||
var _StdoutContext = _interopRequireDefault(require("./StdoutContext"));
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
|
||||
// Root component for all Ink apps
|
||||
// It renders stdin and stdout contexts, so that children can access them if needed
|
||||
// It also handles Ctrl+C exiting and cursor visibility
|
||||
class App extends _react.PureComponent {
|
||||
// Determines if TTY is supported on the provided stdin
|
||||
isRawModeSupported() {
|
||||
return this.props.stdin.isTTY;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super(); // Count how many components enabled raw mode to avoid disabling
|
||||
// raw mode until all components don't need it anymore
|
||||
|
||||
_defineProperty(this, "handleSetRawMode", isEnabled => {
|
||||
const {
|
||||
stdin
|
||||
} = this.props;
|
||||
|
||||
if (!this.isRawModeSupported()) {
|
||||
if (stdin === process.stdin) {
|
||||
throw new Error('Raw mode is not supported on the current process.stdin, which Ink uses as input stream by default.\nRead about how to prevent this error on https://github.com/vadimdemedes/ink/#israwmodesupported');
|
||||
} else {
|
||||
throw new Error('Raw mode is not supported on the stdin provided to Ink.\nRead about how to prevent this error on https://github.com/vadimdemedes/ink/#israwmodesupported');
|
||||
}
|
||||
}
|
||||
|
||||
stdin.setEncoding('utf8');
|
||||
|
||||
if (isEnabled) {
|
||||
// Ensure raw mode is enabled only once
|
||||
if (this.rawModeEnabledCount === 0) {
|
||||
stdin.addListener('data', this.handleInput);
|
||||
stdin.resume();
|
||||
stdin.setRawMode(true);
|
||||
|
||||
_readline.default.emitKeypressEvents(stdin);
|
||||
}
|
||||
|
||||
this.rawModeEnabledCount++;
|
||||
return;
|
||||
} // Disable raw mode only when no components left that are using it
|
||||
|
||||
|
||||
if (--this.rawModeEnabledCount === 0) {
|
||||
stdin.setRawMode(false);
|
||||
stdin.removeListener('data', this.handleInput);
|
||||
stdin.pause();
|
||||
}
|
||||
});
|
||||
|
||||
_defineProperty(this, "handleInput", input => {
|
||||
// Exit on Ctrl+C
|
||||
if (input === '\x03' && this.props.exitOnCtrlC) {
|
||||
// eslint-disable-line unicorn/no-hex-escape
|
||||
this.handleExit();
|
||||
}
|
||||
});
|
||||
|
||||
_defineProperty(this, "handleExit", error => {
|
||||
if (this.isRawModeSupported()) {
|
||||
this.handleSetRawMode(false);
|
||||
}
|
||||
|
||||
this.props.onExit(error);
|
||||
});
|
||||
|
||||
this.rawModeEnabledCount = 0;
|
||||
}
|
||||
|
||||
render() {
|
||||
return _react.default.createElement(_AppContext.default.Provider, {
|
||||
value: {
|
||||
exit: this.handleExit
|
||||
}
|
||||
}, _react.default.createElement(_StdinContext.default.Provider, {
|
||||
value: {
|
||||
stdin: this.props.stdin,
|
||||
setRawMode: this.handleSetRawMode,
|
||||
isRawModeSupported: this.isRawModeSupported()
|
||||
}
|
||||
}, _react.default.createElement(_StdoutContext.default.Provider, {
|
||||
value: {
|
||||
stdout: this.props.stdout
|
||||
}
|
||||
}, this.props.children)));
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
_cliCursor.default.hide(this.props.stdout);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
_cliCursor.default.show(this.props.stdout); // ignore calling setRawMode on an handle stdin it cannot be called
|
||||
|
||||
|
||||
if (this.isRawModeSupported()) {
|
||||
this.handleSetRawMode(false);
|
||||
}
|
||||
}
|
||||
|
||||
componentDidCatch(error) {
|
||||
this.handleExit(error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exports.default = App;
|
||||
|
||||
_defineProperty(App, "propTypes", {
|
||||
children: _propTypes.default.node.isRequired,
|
||||
stdin: _propTypes.default.object.isRequired,
|
||||
stdout: _propTypes.default.object.isRequired,
|
||||
exitOnCtrlC: _propTypes.default.bool.isRequired,
|
||||
onExit: _propTypes.default.func.isRequired
|
||||
});
|
||||
17
node_modules/ink/build/components/AppContext.js
generated
vendored
Normal file
17
node_modules/ink/build/components/AppContext.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _react = _interopRequireDefault(require("react"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var _default = _react.default.createContext({
|
||||
exit() {}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
85
node_modules/ink/build/components/Box.js
generated
vendored
Normal file
85
node_modules/ink/build/components/Box.js
generated
vendored
Normal file
@ -0,0 +1,85 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _react = _interopRequireWildcard(require("react"));
|
||||
|
||||
var _propTypes = _interopRequireDefault(require("prop-types"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
||||
|
||||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
||||
|
||||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
||||
|
||||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
|
||||
class Box extends _react.PureComponent {
|
||||
constructor() {
|
||||
super();
|
||||
this.nodeRef = _react.default.createRef();
|
||||
}
|
||||
|
||||
render() {
|
||||
const _this$props = this.props,
|
||||
{
|
||||
children,
|
||||
unstable__transformChildren
|
||||
} = _this$props,
|
||||
style = _objectWithoutProperties(_this$props, ["children", "unstable__transformChildren"]);
|
||||
|
||||
return _react.default.createElement("div", {
|
||||
ref: this.nodeRef,
|
||||
style: style,
|
||||
unstable__transformChildren: unstable__transformChildren
|
||||
}, children);
|
||||
}
|
||||
|
||||
unstable__getComputedWidth() {
|
||||
return this.nodeRef.current.yogaNode.getComputedWidth();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exports.default = Box;
|
||||
|
||||
_defineProperty(Box, "propTypes", {
|
||||
margin: _propTypes.default.number,
|
||||
marginX: _propTypes.default.number,
|
||||
marginY: _propTypes.default.number,
|
||||
marginTop: _propTypes.default.number,
|
||||
marginBottom: _propTypes.default.number,
|
||||
marginLeft: _propTypes.default.number,
|
||||
marginRight: _propTypes.default.number,
|
||||
padding: _propTypes.default.number,
|
||||
paddingX: _propTypes.default.number,
|
||||
paddingY: _propTypes.default.number,
|
||||
paddingTop: _propTypes.default.number,
|
||||
paddingBottom: _propTypes.default.number,
|
||||
paddingLeft: _propTypes.default.number,
|
||||
paddingRight: _propTypes.default.number,
|
||||
width: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
|
||||
minWidth: _propTypes.default.number,
|
||||
height: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
|
||||
minHeight: _propTypes.default.number,
|
||||
flexGrow: _propTypes.default.number,
|
||||
flexShrink: _propTypes.default.number,
|
||||
flexDirection: _propTypes.default.oneOf(['row', 'row-reverse', 'column', 'column-reverse']),
|
||||
flexBasis: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
|
||||
alignItems: _propTypes.default.oneOf(['flex-start', 'center', 'flex-end']),
|
||||
justifyContent: _propTypes.default.oneOf(['flex-start', 'center', 'flex-end', 'space-between', 'space-around']),
|
||||
textWrap: _propTypes.default.oneOf(['wrap', 'truncate', 'truncate-start', 'truncate-middle', 'truncate-end']),
|
||||
unstable__transformChildren: _propTypes.default.func,
|
||||
children: _propTypes.default.node
|
||||
});
|
||||
|
||||
_defineProperty(Box, "defaultProps", {
|
||||
flexDirection: 'row',
|
||||
flexGrow: 0,
|
||||
flexShrink: 1
|
||||
});
|
||||
55
node_modules/ink/build/components/Color.js
generated
vendored
Normal file
55
node_modules/ink/build/components/Color.js
generated
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _react = _interopRequireDefault(require("react"));
|
||||
|
||||
var _propTypes = _interopRequireDefault(require("prop-types"));
|
||||
|
||||
var _arrify = _interopRequireDefault(require("arrify"));
|
||||
|
||||
var _chalk = _interopRequireDefault(require("chalk"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
||||
|
||||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
||||
|
||||
const methods = ['hex', 'hsl', 'hsv', 'hwb', 'rgb', 'keyword', 'bgHex', 'bgHsl', 'bgHsv', 'bgHwb', 'bgRgb', 'bgKeyword'];
|
||||
|
||||
const Color = (_ref) => {
|
||||
let {
|
||||
children
|
||||
} = _ref,
|
||||
colorProps = _objectWithoutProperties(_ref, ["children"]);
|
||||
|
||||
const transformChildren = children => {
|
||||
Object.keys(colorProps).forEach(method => {
|
||||
if (colorProps[method]) {
|
||||
if (methods.includes(method)) {
|
||||
children = _chalk.default[method](...(0, _arrify.default)(colorProps[method]))(children);
|
||||
} else if (typeof _chalk.default[method] === 'function') {
|
||||
children = _chalk.default[method](children);
|
||||
}
|
||||
}
|
||||
});
|
||||
return children;
|
||||
};
|
||||
|
||||
return _react.default.createElement("span", {
|
||||
style: {
|
||||
flexDirection: 'row'
|
||||
},
|
||||
unstable__transformChildren: transformChildren
|
||||
}, children);
|
||||
};
|
||||
|
||||
Color.propTypes = {
|
||||
children: _propTypes.default.node.isRequired
|
||||
};
|
||||
var _default = Color;
|
||||
exports.default = _default;
|
||||
91
node_modules/ink/build/components/Static.js
generated
vendored
Normal file
91
node_modules/ink/build/components/Static.js
generated
vendored
Normal file
@ -0,0 +1,91 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _react = _interopRequireWildcard(require("react"));
|
||||
|
||||
var _propTypes = _interopRequireDefault(require("prop-types"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
||||
|
||||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
||||
|
||||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
||||
|
||||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
|
||||
const childrenToArray = children => Array.isArray(children) ? children : [children]; // This component allows developers to render output before main output from all the other components.
|
||||
// The reason it's called <Static> is it's append-only output. Output from <Static> components
|
||||
// is written permantently to stdout and is never updated afterwards. If <Static> component
|
||||
// receives new children, Ink will detect the changes and write them to stdout.
|
||||
// In order for this mechanism to work perfectly, <Static> children must never update their output
|
||||
// once they've been appended to <Static>.
|
||||
//
|
||||
// A good example of where this component might be useful is interface like Jest's.
|
||||
// When running tests, Jest keeps writing completed tests to output, while continuously
|
||||
// rendering test stats at the end of the output.
|
||||
|
||||
|
||||
class Static extends _react.Component {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
|
||||
_defineProperty(this, "state", {
|
||||
lastIndex: null
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
const _this$props = this.props,
|
||||
{
|
||||
children
|
||||
} = _this$props,
|
||||
otherProps = _objectWithoutProperties(_this$props, ["children"]);
|
||||
|
||||
const {
|
||||
lastIndex
|
||||
} = this.state;
|
||||
let newChildren = children;
|
||||
|
||||
if (typeof lastIndex === 'number') {
|
||||
newChildren = childrenToArray(children).slice(lastIndex);
|
||||
}
|
||||
|
||||
return _react.default.createElement("div", {
|
||||
unstable__static: true,
|
||||
style: otherProps
|
||||
}, newChildren);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.saveLastIndex(this.props.children);
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps, prevState) {
|
||||
if (prevState.lastIndex === this.state.lastIndex) {
|
||||
this.saveLastIndex(this.props.children);
|
||||
}
|
||||
}
|
||||
|
||||
saveLastIndex(children) {
|
||||
const nextIndex = childrenToArray(children).length;
|
||||
|
||||
if (this.state.lastIndex !== nextIndex) {
|
||||
this.setState({
|
||||
lastIndex: nextIndex
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exports.default = Static;
|
||||
|
||||
_defineProperty(Static, "propTypes", {
|
||||
children: _propTypes.default.node
|
||||
});
|
||||
17
node_modules/ink/build/components/StdinContext.js
generated
vendored
Normal file
17
node_modules/ink/build/components/StdinContext.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _react = _interopRequireDefault(require("react"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var _default = _react.default.createContext({
|
||||
stdin: undefined,
|
||||
setRawMode: undefined
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
16
node_modules/ink/build/components/StdoutContext.js
generated
vendored
Normal file
16
node_modules/ink/build/components/StdoutContext.js
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _react = _interopRequireDefault(require("react"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var _default = _react.default.createContext({
|
||||
stdout: undefined
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
73
node_modules/ink/build/components/Text.js
generated
vendored
Normal file
73
node_modules/ink/build/components/Text.js
generated
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _react = _interopRequireDefault(require("react"));
|
||||
|
||||
var _propTypes = _interopRequireDefault(require("prop-types"));
|
||||
|
||||
var _chalk = _interopRequireDefault(require("chalk"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
const Text = ({
|
||||
bold,
|
||||
italic,
|
||||
underline,
|
||||
strikethrough,
|
||||
children,
|
||||
unstable__transformChildren
|
||||
}) => {
|
||||
const transformChildren = children => {
|
||||
if (bold) {
|
||||
children = _chalk.default.bold(children);
|
||||
}
|
||||
|
||||
if (italic) {
|
||||
children = _chalk.default.italic(children);
|
||||
}
|
||||
|
||||
if (underline) {
|
||||
children = _chalk.default.underline(children);
|
||||
}
|
||||
|
||||
if (strikethrough) {
|
||||
children = _chalk.default.strikethrough(children);
|
||||
}
|
||||
|
||||
if (unstable__transformChildren) {
|
||||
children = unstable__transformChildren(children);
|
||||
}
|
||||
|
||||
return children;
|
||||
};
|
||||
|
||||
return _react.default.createElement("span", {
|
||||
style: {
|
||||
flexDirection: 'row'
|
||||
},
|
||||
unstable__transformChildren: transformChildren
|
||||
}, children);
|
||||
};
|
||||
|
||||
Text.propTypes = {
|
||||
bold: _propTypes.default.bool,
|
||||
italic: _propTypes.default.bool,
|
||||
underline: _propTypes.default.bool,
|
||||
strikethrough: _propTypes.default.bool,
|
||||
children: _propTypes.default.node.isRequired,
|
||||
unstable__transformChildren: _propTypes.default.func
|
||||
};
|
||||
Text.defaultProps = {
|
||||
bold: false,
|
||||
italic: false,
|
||||
underline: false,
|
||||
strikethrough: false,
|
||||
unstable__transformChildren: undefined
|
||||
};
|
||||
var _default = Text;
|
||||
exports.default = _default;
|
||||
77
node_modules/ink/build/dom.js
generated
vendored
Normal file
77
node_modules/ink/build/dom.js
generated
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.createTextNode = exports.setAttribute = exports.removeChildNode = exports.insertBeforeNode = exports.appendStaticNode = exports.appendChildNode = exports.createNode = void 0;
|
||||
|
||||
// Helper utilities implementing some common DOM methods to simplify reconciliation code
|
||||
const createNode = tagName => ({
|
||||
nodeName: tagName.toUpperCase(),
|
||||
style: {},
|
||||
attributes: {},
|
||||
childNodes: [],
|
||||
parentNode: null
|
||||
});
|
||||
|
||||
exports.createNode = createNode;
|
||||
|
||||
const appendChildNode = (node, childNode) => {
|
||||
if (childNode.parentNode) {
|
||||
removeChildNode(childNode.parentNode, childNode);
|
||||
}
|
||||
|
||||
childNode.parentNode = node;
|
||||
node.childNodes.push(childNode);
|
||||
}; // Same as `appendChildNode`, but without removing child node from parent node
|
||||
|
||||
|
||||
exports.appendChildNode = appendChildNode;
|
||||
|
||||
const appendStaticNode = (node, childNode) => {
|
||||
node.childNodes.push(childNode);
|
||||
};
|
||||
|
||||
exports.appendStaticNode = appendStaticNode;
|
||||
|
||||
const insertBeforeNode = (node, newChildNode, beforeChildNode) => {
|
||||
if (newChildNode.parentNode) {
|
||||
removeChildNode(newChildNode.parentNode, newChildNode);
|
||||
}
|
||||
|
||||
newChildNode.parentNode = node;
|
||||
const index = node.childNodes.indexOf(beforeChildNode);
|
||||
|
||||
if (index >= 0) {
|
||||
node.childNodes.splice(index, 0, newChildNode);
|
||||
return;
|
||||
}
|
||||
|
||||
node.childNodes.push(newChildNode);
|
||||
};
|
||||
|
||||
exports.insertBeforeNode = insertBeforeNode;
|
||||
|
||||
const removeChildNode = (node, removeNode) => {
|
||||
removeNode.parentNode = null;
|
||||
const index = node.childNodes.indexOf(removeNode);
|
||||
|
||||
if (index >= 0) {
|
||||
node.childNodes.splice(index, 1);
|
||||
}
|
||||
};
|
||||
|
||||
exports.removeChildNode = removeChildNode;
|
||||
|
||||
const setAttribute = (node, key, value) => {
|
||||
node.attributes[key] = value;
|
||||
};
|
||||
|
||||
exports.setAttribute = setAttribute;
|
||||
|
||||
const createTextNode = text => ({
|
||||
nodeName: '#text',
|
||||
nodeValue: text
|
||||
});
|
||||
|
||||
exports.createTextNode = createTextNode;
|
||||
12
node_modules/ink/build/get-max-width.js
generated
vendored
Normal file
12
node_modules/ink/build/get-max-width.js
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _default = yogaNode => {
|
||||
return yogaNode.getComputedWidth() - yogaNode.getComputedPadding() * 2;
|
||||
};
|
||||
|
||||
exports.default = _default;
|
||||
71
node_modules/ink/build/index.js
generated
vendored
Normal file
71
node_modules/ink/build/index.js
generated
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "render", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _render.default;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "Box", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _Box.default;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "Text", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _Text.default;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "Color", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _Color.default;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "AppContext", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _AppContext.default;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "StdinContext", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _StdinContext.default;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "StdoutContext", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _StdoutContext.default;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "Static", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _Static.default;
|
||||
}
|
||||
});
|
||||
|
||||
var _render = _interopRequireDefault(require("./render"));
|
||||
|
||||
var _Box = _interopRequireDefault(require("./components/Box"));
|
||||
|
||||
var _Text = _interopRequireDefault(require("./components/Text"));
|
||||
|
||||
var _Color = _interopRequireDefault(require("./components/Color"));
|
||||
|
||||
var _AppContext = _interopRequireDefault(require("./components/AppContext"));
|
||||
|
||||
var _StdinContext = _interopRequireDefault(require("./components/StdinContext"));
|
||||
|
||||
var _StdoutContext = _interopRequireDefault(require("./components/StdoutContext"));
|
||||
|
||||
var _Static = _interopRequireDefault(require("./components/Static"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
152
node_modules/ink/build/instance.js
generated
vendored
Normal file
152
node_modules/ink/build/instance.js
generated
vendored
Normal file
@ -0,0 +1,152 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _react = _interopRequireDefault(require("react"));
|
||||
|
||||
var _lodash = _interopRequireDefault(require("lodash.throttle"));
|
||||
|
||||
var _autoBind = _interopRequireDefault(require("auto-bind"));
|
||||
|
||||
var _logUpdate = _interopRequireDefault(require("log-update"));
|
||||
|
||||
var _isCi = _interopRequireDefault(require("is-ci"));
|
||||
|
||||
var _signalExit = _interopRequireDefault(require("signal-exit"));
|
||||
|
||||
var _reconciler = _interopRequireDefault(require("./reconciler"));
|
||||
|
||||
var _renderer = _interopRequireDefault(require("./renderer"));
|
||||
|
||||
var _dom = require("./dom");
|
||||
|
||||
var _instances = _interopRequireDefault(require("./instances"));
|
||||
|
||||
var _App = _interopRequireDefault(require("./components/App"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
class Instance {
|
||||
constructor(options) {
|
||||
(0, _autoBind.default)(this);
|
||||
this.options = options;
|
||||
this.rootNode = (0, _dom.createNode)('root');
|
||||
this.rootNode.onRender = this.onRender;
|
||||
this.renderer = (0, _renderer.default)({
|
||||
terminalWidth: options.stdout.columns
|
||||
});
|
||||
this.log = _logUpdate.default.create(options.stdout);
|
||||
this.throttledLog = options.debug ? this.log : (0, _lodash.default)(this.log, {
|
||||
leading: true,
|
||||
trailing: true
|
||||
}); // Ignore last render after unmounting a tree to prevent empty output before exit
|
||||
|
||||
this.isUnmounted = false; // Store last output to only rerender when needed
|
||||
|
||||
this.lastOutput = ''; // This variable is used only in debug mode to store full static output
|
||||
// so that it's rerendered every time, not just new static parts, like in non-debug mode
|
||||
|
||||
this.fullStaticOutput = '';
|
||||
this.container = _reconciler.default.createContainer(this.rootNode, false, false);
|
||||
this.exitPromise = new Promise((resolve, reject) => {
|
||||
this.resolveExitPromise = resolve;
|
||||
this.rejectExitPromise = reject;
|
||||
}); // Unmount when process exits
|
||||
|
||||
this.unsubscribeExit = (0, _signalExit.default)(this.unmount, {
|
||||
alwaysLast: false
|
||||
});
|
||||
}
|
||||
|
||||
onRender() {
|
||||
if (this.isUnmounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
const {
|
||||
output,
|
||||
staticOutput
|
||||
} = this.renderer(this.rootNode); // If <Static> output isn't empty, it means new children have been added to it
|
||||
|
||||
const hasStaticOutput = staticOutput && staticOutput !== '\n';
|
||||
|
||||
if (this.options.debug) {
|
||||
if (hasStaticOutput) {
|
||||
this.fullStaticOutput += staticOutput;
|
||||
}
|
||||
|
||||
this.options.stdout.write(this.fullStaticOutput + output);
|
||||
return;
|
||||
} // To ensure static output is cleanly rendered before main output, clear main output first
|
||||
|
||||
|
||||
if (hasStaticOutput) {
|
||||
if (!_isCi.default) {
|
||||
this.log.clear();
|
||||
}
|
||||
|
||||
this.options.stdout.write(staticOutput);
|
||||
|
||||
if (!_isCi.default) {
|
||||
this.log(output);
|
||||
}
|
||||
}
|
||||
|
||||
if (output !== this.lastOutput) {
|
||||
if (!_isCi.default) {
|
||||
this.throttledLog(output);
|
||||
}
|
||||
|
||||
this.lastOutput = output;
|
||||
}
|
||||
}
|
||||
|
||||
render(node) {
|
||||
const tree = _react.default.createElement(_App.default, {
|
||||
stdin: this.options.stdin,
|
||||
stdout: this.options.stdout,
|
||||
exitOnCtrlC: this.options.exitOnCtrlC,
|
||||
onExit: this.unmount
|
||||
}, node);
|
||||
|
||||
_reconciler.default.updateContainer(tree, this.container);
|
||||
}
|
||||
|
||||
unmount(error) {
|
||||
if (this.isUnmounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.onRender();
|
||||
this.unsubscribeExit(); // CIs don't handle erasing ansi escapes well, so it's better to
|
||||
// only render last frame of non-static output
|
||||
|
||||
if (_isCi.default) {
|
||||
this.options.stdout.write(this.lastOutput + '\n');
|
||||
} else if (!this.options.debug) {
|
||||
this.log.done();
|
||||
}
|
||||
|
||||
this.isUnmounted = true;
|
||||
|
||||
_reconciler.default.updateContainer(null, this.container);
|
||||
|
||||
_instances.default.delete(this.options.stdout);
|
||||
|
||||
if (error instanceof Error) {
|
||||
this.rejectExitPromise(error);
|
||||
} else {
|
||||
this.resolveExitPromise();
|
||||
}
|
||||
}
|
||||
|
||||
waitUntilExit() {
|
||||
return this.exitPromise;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exports.default = Instance;
|
||||
15
node_modules/ink/build/instances.js
generated
vendored
Normal file
15
node_modules/ink/build/instances.js
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
// Store all instances of Ink (instance.js) to ensure that consecutive render() calls
|
||||
// use the same instance of Ink and don't create a new one
|
||||
//
|
||||
// This map has to be stored in a separate file, because render.js creates instances,
|
||||
// but instance.js should delete itself from the map on unmount
|
||||
var _default = new WeakMap();
|
||||
|
||||
exports.default = _default;
|
||||
21
node_modules/ink/build/measure-text.js
generated
vendored
Normal file
21
node_modules/ink/build/measure-text.js
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _widestLine = _interopRequireDefault(require("widest-line"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var _default = text => {
|
||||
const width = (0, _widestLine.default)(text);
|
||||
const height = text.split('\n').length;
|
||||
return {
|
||||
width,
|
||||
height
|
||||
};
|
||||
};
|
||||
|
||||
exports.default = _default;
|
||||
70
node_modules/ink/build/output.js
generated
vendored
Normal file
70
node_modules/ink/build/output.js
generated
vendored
Normal file
@ -0,0 +1,70 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _stringLength = _interopRequireDefault(require("string-length"));
|
||||
|
||||
var _sliceAnsi = _interopRequireDefault(require("slice-ansi"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* "Virtual" output class
|
||||
*
|
||||
* Handles the positioning and saving of the output of each node in the tree.
|
||||
* Also responsible for applying transformations to each character of the output.
|
||||
*
|
||||
* Used to generate the final output of all nodes before writing it to actual output stream (e.g. stdout)
|
||||
*/
|
||||
class Output {
|
||||
constructor({
|
||||
width,
|
||||
height
|
||||
}) {
|
||||
// Initialize output array with a specific set of rows, so that margin/padding at the bottom is preserved
|
||||
const output = [];
|
||||
|
||||
for (let y = 0; y < height; y++) {
|
||||
output.push(' '.repeat(width));
|
||||
}
|
||||
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
write(x, y, text, {
|
||||
transformers
|
||||
}) {
|
||||
if (!text) {
|
||||
return;
|
||||
}
|
||||
|
||||
const lines = text.split('\n');
|
||||
let offsetY = 0;
|
||||
|
||||
for (let line of lines) {
|
||||
const length = (0, _stringLength.default)(line);
|
||||
const currentLine = this.output[y + offsetY]; // Line can be missing if `text` is taller than height of pre-initialized `this.output`
|
||||
|
||||
if (!currentLine) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const transformer of transformers) {
|
||||
line = transformer(line);
|
||||
}
|
||||
|
||||
this.output[y + offsetY] = (0, _sliceAnsi.default)(currentLine, 0, x) + line + (0, _sliceAnsi.default)(currentLine, x + length);
|
||||
offsetY++;
|
||||
}
|
||||
}
|
||||
|
||||
get() {
|
||||
return this.output.map(line => line.trimRight()).join('\n');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exports.default = Output;
|
||||
127
node_modules/ink/build/reconciler.js
generated
vendored
Normal file
127
node_modules/ink/build/reconciler.js
generated
vendored
Normal file
@ -0,0 +1,127 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _scheduler = require("scheduler");
|
||||
|
||||
var _reactReconciler = _interopRequireDefault(require("react-reconciler"));
|
||||
|
||||
var _dom = require("./dom");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
const NO_CONTEXT = true;
|
||||
const hostConfig = {
|
||||
schedulePassiveEffects: _scheduler.unstable_scheduleCallback,
|
||||
cancelPassiveEffects: _scheduler.unstable_cancelCallback,
|
||||
now: Date.now,
|
||||
getRootHostContext: () => NO_CONTEXT,
|
||||
prepareForCommit: () => {},
|
||||
resetAfterCommit: rootNode => {
|
||||
rootNode.onRender();
|
||||
},
|
||||
getChildHostContext: () => NO_CONTEXT,
|
||||
shouldSetTextContent: (type, props) => {
|
||||
return typeof props.children === 'string' || typeof props.children === 'number';
|
||||
},
|
||||
createInstance: (type, newProps) => {
|
||||
const node = (0, _dom.createNode)(type);
|
||||
|
||||
for (const [key, value] of Object.entries(newProps)) {
|
||||
if (key === 'children') {
|
||||
if (typeof value === 'string' || typeof value === 'number') {
|
||||
if (type === 'div') {
|
||||
// Text node must be wrapped in another node, so that text can be aligned within container
|
||||
const textElement = (0, _dom.createNode)('div');
|
||||
textElement.textContent = String(value);
|
||||
(0, _dom.appendChildNode)(node, textElement);
|
||||
}
|
||||
|
||||
if (type === 'span') {
|
||||
node.textContent = String(value);
|
||||
}
|
||||
}
|
||||
} else if (key === 'style') {
|
||||
Object.assign(node.style, value);
|
||||
} else if (key === 'unstable__transformChildren') {
|
||||
node.unstable__transformChildren = value; // eslint-disable-line camelcase
|
||||
} else if (key === 'unstable__static') {
|
||||
node.unstable__static = true; // eslint-disable-line camelcase
|
||||
} else {
|
||||
(0, _dom.setAttribute)(node, key, value);
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
},
|
||||
createTextInstance: _dom.createTextNode,
|
||||
resetTextContent: node => {
|
||||
if (node.textContent) {
|
||||
node.textContent = '';
|
||||
}
|
||||
|
||||
if (node.childNodes.length > 0) {
|
||||
for (const childNode of node.childNodes) {
|
||||
childNode.yogaNode.free();
|
||||
(0, _dom.removeChildNode)(node, childNode);
|
||||
}
|
||||
}
|
||||
},
|
||||
getPublicInstance: instance => instance,
|
||||
appendInitialChild: _dom.appendChildNode,
|
||||
appendChild: _dom.appendChildNode,
|
||||
insertBefore: _dom.insertBeforeNode,
|
||||
finalizeInitialChildren: () => {},
|
||||
supportsMutation: true,
|
||||
appendChildToContainer: _dom.appendChildNode,
|
||||
insertInContainerBefore: _dom.insertBeforeNode,
|
||||
removeChildFromContainer: _dom.removeChildNode,
|
||||
prepareUpdate: () => true,
|
||||
commitUpdate: (node, updatePayload, type, oldProps, newProps) => {
|
||||
for (const [key, value] of Object.entries(newProps)) {
|
||||
if (key === 'children') {
|
||||
if (typeof value === 'string' || typeof value === 'number') {
|
||||
if (type === 'div') {
|
||||
// Text node must be wrapped in another node, so that text can be aligned within container
|
||||
// If there's no such node, a new one must be created
|
||||
if (node.childNodes.length === 0) {
|
||||
const textElement = (0, _dom.createNode)('div');
|
||||
textElement.textContent = String(value);
|
||||
(0, _dom.appendChildNode)(node, textElement);
|
||||
} else {
|
||||
node.childNodes[0].textContent = String(value);
|
||||
}
|
||||
}
|
||||
|
||||
if (type === 'span') {
|
||||
node.textContent = String(value);
|
||||
}
|
||||
}
|
||||
} else if (key === 'style') {
|
||||
Object.assign(node.style, value);
|
||||
} else if (key === 'unstable__transformChildren') {
|
||||
node.unstable__transformChildren = value; // eslint-disable-line camelcase
|
||||
} else if (key === 'unstable__static') {
|
||||
node.unstable__static = true; // eslint-disable-line camelcase
|
||||
} else {
|
||||
(0, _dom.setAttribute)(node, key, value);
|
||||
}
|
||||
}
|
||||
},
|
||||
commitTextUpdate: (node, oldText, newText) => {
|
||||
if (node.nodeName === '#text') {
|
||||
node.nodeValue = newText;
|
||||
} else {
|
||||
node.textContent = newText;
|
||||
}
|
||||
},
|
||||
removeChild: _dom.removeChildNode
|
||||
};
|
||||
|
||||
var _default = (0, _reactReconciler.default)(hostConfig); // eslint-disable-line new-cap
|
||||
|
||||
|
||||
exports.default = _default;
|
||||
157
node_modules/ink/build/render-node-to-output.js
generated
vendored
Normal file
157
node_modules/ink/build/render-node-to-output.js
generated
vendored
Normal file
@ -0,0 +1,157 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _widestLine = _interopRequireDefault(require("widest-line"));
|
||||
|
||||
var _wrapText = _interopRequireDefault(require("./wrap-text"));
|
||||
|
||||
var _getMaxWidth = _interopRequireDefault(require("./get-max-width"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
const isAllTextNodes = node => {
|
||||
if (node.nodeName === '#text') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (node.nodeName === 'SPAN') {
|
||||
if (node.textContent) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Array.isArray(node.childNodes)) {
|
||||
return node.childNodes.every(isAllTextNodes);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}; // Squashing text nodes allows to combine multiple text nodes into one and write
|
||||
// to `Output` instance only once. For example, <Text>hello{' '}world</Text>
|
||||
// is actually 3 text nodes, which would result 3 writes to `Output`.
|
||||
//
|
||||
// Also, this is necessary for libraries like ink-link (https://github.com/sindresorhus/ink-link),
|
||||
// which need to wrap all children at once, instead of wrapping 3 text nodes separately.
|
||||
|
||||
|
||||
const squashTextNodes = node => {
|
||||
let text = '';
|
||||
|
||||
for (const childNode of node.childNodes) {
|
||||
let nodeText;
|
||||
|
||||
if (childNode.nodeName === '#text') {
|
||||
nodeText = childNode.nodeValue;
|
||||
}
|
||||
|
||||
if (childNode.nodeName === 'SPAN') {
|
||||
nodeText = childNode.textContent || squashTextNodes(childNode);
|
||||
} // Since these text nodes are being concatenated, `Output` instance won't be able to
|
||||
// apply children transform, so we have to do it manually here for each text node
|
||||
|
||||
|
||||
if (childNode.unstable__transformChildren) {
|
||||
nodeText = childNode.unstable__transformChildren(nodeText);
|
||||
}
|
||||
|
||||
text += nodeText;
|
||||
}
|
||||
|
||||
return text;
|
||||
}; // After nodes are laid out, render each to output object, which later gets rendered to terminal
|
||||
|
||||
|
||||
const renderNodeToOutput = (node, output, {
|
||||
offsetX = 0,
|
||||
offsetY = 0,
|
||||
transformers = [],
|
||||
skipStaticElements
|
||||
}) => {
|
||||
if (node.unstable__static && skipStaticElements) {
|
||||
return;
|
||||
}
|
||||
|
||||
const {
|
||||
yogaNode
|
||||
} = node; // Left and top positions in Yoga are relative to their parent node
|
||||
|
||||
const x = offsetX + yogaNode.getComputedLeft();
|
||||
const y = offsetY + yogaNode.getComputedTop(); // Transformers are functions that transform final text output of each component
|
||||
// See Output class for logic that applies transformers
|
||||
|
||||
let newTransformers = transformers;
|
||||
|
||||
if (node.unstable__transformChildren) {
|
||||
newTransformers = [node.unstable__transformChildren, ...transformers];
|
||||
} // Nodes with only text inside
|
||||
|
||||
|
||||
if (node.textContent) {
|
||||
let text = node.textContent; // Since text nodes are always wrapped in an additional node, parent node
|
||||
// is where we should look for attributes
|
||||
|
||||
if (node.parentNode.style.textWrap) {
|
||||
const currentWidth = (0, _widestLine.default)(text);
|
||||
const maxWidth = (0, _getMaxWidth.default)(node.parentNode.yogaNode);
|
||||
|
||||
if (currentWidth > maxWidth) {
|
||||
text = (0, _wrapText.default)(text, maxWidth, {
|
||||
textWrap: node.parentNode.style.textWrap
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
output.write(x, y, text, {
|
||||
transformers: newTransformers
|
||||
});
|
||||
return;
|
||||
} // Text nodes
|
||||
|
||||
|
||||
if (node.nodeName === '#text') {
|
||||
output.write(x, y, node.nodeValue, {
|
||||
transformers: newTransformers
|
||||
});
|
||||
return;
|
||||
} // Nodes that have other nodes as children
|
||||
|
||||
|
||||
if (Array.isArray(node.childNodes) && node.childNodes.length > 0) {
|
||||
const isFlexDirectionRow = node.style.flexDirection === 'row';
|
||||
|
||||
if (isFlexDirectionRow && node.childNodes.every(isAllTextNodes)) {
|
||||
let text = squashTextNodes(node);
|
||||
|
||||
if (node.style.textWrap) {
|
||||
const currentWidth = (0, _widestLine.default)(text);
|
||||
const maxWidth = (0, _getMaxWidth.default)(yogaNode);
|
||||
|
||||
if (currentWidth > maxWidth) {
|
||||
text = (0, _wrapText.default)(text, maxWidth, {
|
||||
textWrap: node.style.textWrap
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
output.write(x, y, text, {
|
||||
transformers: newTransformers
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
for (const childNode of node.childNodes) {
|
||||
renderNodeToOutput(childNode, output, {
|
||||
offsetX: x,
|
||||
offsetY: y,
|
||||
transformers: newTransformers,
|
||||
skipStaticElements
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var _default = renderNodeToOutput;
|
||||
exports.default = _default;
|
||||
52
node_modules/ink/build/render.js
generated
vendored
Normal file
52
node_modules/ink/build/render.js
generated
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _instance = _interopRequireDefault(require("./instance"));
|
||||
|
||||
var _instances = _interopRequireDefault(require("./instances"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
|
||||
|
||||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
|
||||
var _default = (node, options = {}) => {
|
||||
// Stream was passed instead of `options` object
|
||||
if (typeof options.write === 'function') {
|
||||
options = {
|
||||
stdout: options,
|
||||
stdin: process.stdin
|
||||
};
|
||||
}
|
||||
|
||||
options = _objectSpread({
|
||||
stdout: process.stdout,
|
||||
stdin: process.stdin,
|
||||
debug: false,
|
||||
exitOnCtrlC: true
|
||||
}, options);
|
||||
let instance;
|
||||
|
||||
if (_instances.default.has(options.stdout)) {
|
||||
instance = _instances.default.get(options.stdout);
|
||||
} else {
|
||||
instance = new _instance.default(options);
|
||||
|
||||
_instances.default.set(options.stdout, instance);
|
||||
}
|
||||
|
||||
instance.render(node);
|
||||
return {
|
||||
rerender: instance.render,
|
||||
unmount: () => instance.unmount(),
|
||||
waitUntilExit: instance.waitUntilExit,
|
||||
cleanup: () => _instances.default.delete(options.stdout)
|
||||
};
|
||||
};
|
||||
|
||||
exports.default = _default;
|
||||
158
node_modules/ink/build/renderer.js
generated
vendored
Normal file
158
node_modules/ink/build/renderer.js
generated
vendored
Normal file
@ -0,0 +1,158 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _yogaLayoutPrebuilt = _interopRequireDefault(require("yoga-layout-prebuilt"));
|
||||
|
||||
var _output = _interopRequireDefault(require("./output"));
|
||||
|
||||
var _dom = require("./dom");
|
||||
|
||||
var _buildLayout = _interopRequireDefault(require("./build-layout"));
|
||||
|
||||
var _renderNodeToOutput = _interopRequireDefault(require("./render-node-to-output"));
|
||||
|
||||
var _measureText = _interopRequireDefault(require("./measure-text"));
|
||||
|
||||
var _wrapText = _interopRequireDefault(require("./wrap-text"));
|
||||
|
||||
var _getMaxWidth = _interopRequireDefault(require("./get-max-width"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// Since we need to know the width of text container to wrap text, we have to calculate layout twice
|
||||
// This function is executed after first layout calculation to reassign width and height of text nodes
|
||||
const calculateWrappedText = node => {
|
||||
if (node.textContent && typeof node.parentNode.style.textWrap === 'string') {
|
||||
const {
|
||||
yogaNode
|
||||
} = node;
|
||||
const parentYogaNode = node.parentNode.yogaNode;
|
||||
const maxWidth = (0, _getMaxWidth.default)(parentYogaNode);
|
||||
const currentWidth = yogaNode.getComputedWidth();
|
||||
|
||||
if (currentWidth > maxWidth) {
|
||||
const {
|
||||
textWrap
|
||||
} = node.parentNode.style;
|
||||
const wrappedText = (0, _wrapText.default)(node.textContent, maxWidth, {
|
||||
textWrap
|
||||
});
|
||||
const {
|
||||
width,
|
||||
height
|
||||
} = (0, _measureText.default)(wrappedText);
|
||||
yogaNode.setWidth(width);
|
||||
yogaNode.setHeight(height);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (Array.isArray(node.childNodes) && node.childNodes.length > 0) {
|
||||
for (const childNode of node.childNodes) {
|
||||
calculateWrappedText(childNode);
|
||||
}
|
||||
}
|
||||
}; // Since <Static> components can be placed anywhere in the tree, this helper finds and returns them
|
||||
|
||||
|
||||
const getStaticNodes = element => {
|
||||
const staticNodes = [];
|
||||
|
||||
for (const childNode of element.childNodes) {
|
||||
if (childNode.unstable__static) {
|
||||
staticNodes.push(childNode);
|
||||
}
|
||||
|
||||
if (Array.isArray(childNode.childNodes) && childNode.childNodes.length > 0) {
|
||||
staticNodes.push(...getStaticNodes(childNode));
|
||||
}
|
||||
}
|
||||
|
||||
return staticNodes;
|
||||
}; // Build layout, apply styles, build text output of all nodes and return it
|
||||
|
||||
|
||||
var _default = ({
|
||||
terminalWidth
|
||||
}) => {
|
||||
const config = _yogaLayoutPrebuilt.default.Config.create(); // Used to free up memory used by last Yoga node tree
|
||||
|
||||
|
||||
let lastYogaNode;
|
||||
let lastStaticYogaNode;
|
||||
return node => {
|
||||
if (lastYogaNode) {
|
||||
lastYogaNode.freeRecursive();
|
||||
}
|
||||
|
||||
if (lastStaticYogaNode) {
|
||||
lastStaticYogaNode.freeRecursive();
|
||||
}
|
||||
|
||||
const staticElements = getStaticNodes(node);
|
||||
|
||||
if (staticElements.length > 1) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
console.error('Warning: There can only be one <Static> component');
|
||||
}
|
||||
} // <Static> component must be built and rendered separately, so that the layout of the other output is unaffected
|
||||
|
||||
|
||||
let staticOutput;
|
||||
|
||||
if (staticElements.length === 1) {
|
||||
const rootNode = (0, _dom.createNode)('root');
|
||||
(0, _dom.appendStaticNode)(rootNode, staticElements[0]);
|
||||
const {
|
||||
yogaNode: staticYogaNode
|
||||
} = (0, _buildLayout.default)(rootNode, {
|
||||
config,
|
||||
terminalWidth,
|
||||
skipStaticElements: false
|
||||
});
|
||||
staticYogaNode.calculateLayout(_yogaLayoutPrebuilt.default.UNDEFINED, _yogaLayoutPrebuilt.default.UNDEFINED, _yogaLayoutPrebuilt.default.DIRECTION_LTR);
|
||||
calculateWrappedText(rootNode);
|
||||
staticYogaNode.calculateLayout(_yogaLayoutPrebuilt.default.UNDEFINED, _yogaLayoutPrebuilt.default.UNDEFINED, _yogaLayoutPrebuilt.default.DIRECTION_LTR); // Save current Yoga node tree to free up memory later
|
||||
|
||||
lastStaticYogaNode = staticYogaNode;
|
||||
staticOutput = new _output.default({
|
||||
width: staticYogaNode.getComputedWidth(),
|
||||
height: staticYogaNode.getComputedHeight()
|
||||
});
|
||||
(0, _renderNodeToOutput.default)(rootNode, staticOutput, {
|
||||
skipStaticElements: false
|
||||
});
|
||||
}
|
||||
|
||||
const {
|
||||
yogaNode
|
||||
} = (0, _buildLayout.default)(node, {
|
||||
config,
|
||||
terminalWidth,
|
||||
skipStaticElements: true
|
||||
});
|
||||
yogaNode.calculateLayout(_yogaLayoutPrebuilt.default.UNDEFINED, _yogaLayoutPrebuilt.default.UNDEFINED, _yogaLayoutPrebuilt.default.DIRECTION_LTR);
|
||||
calculateWrappedText(node);
|
||||
yogaNode.calculateLayout(_yogaLayoutPrebuilt.default.UNDEFINED, _yogaLayoutPrebuilt.default.UNDEFINED, _yogaLayoutPrebuilt.default.DIRECTION_LTR); // Save current node tree to free up memory later
|
||||
|
||||
lastYogaNode = yogaNode;
|
||||
const output = new _output.default({
|
||||
width: yogaNode.getComputedWidth(),
|
||||
height: yogaNode.getComputedHeight()
|
||||
});
|
||||
(0, _renderNodeToOutput.default)(node, output, {
|
||||
skipStaticElements: true
|
||||
});
|
||||
return {
|
||||
output: output.get(),
|
||||
staticOutput: staticOutput ? `${staticOutput.get()}\n` : undefined
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
exports.default = _default;
|
||||
81
node_modules/ink/build/vendor/hook-std.js
generated
vendored
Normal file
81
node_modules/ink/build/vendor/hook-std.js
generated
vendored
Normal file
@ -0,0 +1,81 @@
|
||||
// This is a fork of https://github.com/sindresorhus/hook-std adapted to Ink's needs
|
||||
'use strict';
|
||||
|
||||
const hook = (stream, options, transform) => {
|
||||
if (typeof options !== 'object') {
|
||||
transform = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
options = Object.assign({
|
||||
silent: true,
|
||||
once: false
|
||||
}, options);
|
||||
let unhookFn;
|
||||
const promise = new Promise(resolve => {
|
||||
const {
|
||||
write
|
||||
} = stream;
|
||||
|
||||
const unhook = () => {
|
||||
stream.write = write;
|
||||
resolve();
|
||||
};
|
||||
|
||||
stream.write = (output, enc, cb, writeOptions) => {
|
||||
if (typeof options.onBeforeWrite === 'function') {
|
||||
options.onBeforeWrite(writeOptions);
|
||||
}
|
||||
|
||||
const cbRet = transform(String(output), unhook);
|
||||
|
||||
if (options.once) {
|
||||
unhook();
|
||||
}
|
||||
|
||||
if (options.silent) {
|
||||
return typeof cbRet === 'boolean' ? cbRet : true;
|
||||
}
|
||||
|
||||
let ret;
|
||||
|
||||
if (typeof cbRet === 'string') {
|
||||
ret = typeof enc === 'string' ? Buffer.from(cbRet).toString(enc) : cbRet;
|
||||
}
|
||||
|
||||
ret = ret || (Buffer.isBuffer(cbRet) ? cbRet : output);
|
||||
const writeRet = write.call(stream, ret, enc, cb);
|
||||
|
||||
if (typeof options.onAfterWrite === 'function') {
|
||||
options.onAfterWrite(writeOptions);
|
||||
}
|
||||
|
||||
return writeRet;
|
||||
};
|
||||
|
||||
unhookFn = unhook;
|
||||
});
|
||||
promise.unhook = unhookFn;
|
||||
return promise;
|
||||
};
|
||||
|
||||
const hookStd = (options, transform) => {
|
||||
const streams = options.streams || [process.stdout, process.stderr];
|
||||
const streamPromises = streams.map(stream => hook(stream, options, transform));
|
||||
const promise = Promise.all(streamPromises);
|
||||
|
||||
promise.unhook = () => {
|
||||
for (const streamPromise of streamPromises) {
|
||||
streamPromise.unhook();
|
||||
}
|
||||
};
|
||||
|
||||
return promise;
|
||||
};
|
||||
|
||||
hookStd.stdout = (...args) => hook(process.stdout, ...args);
|
||||
|
||||
hookStd.stderr = (...args) => hook(process.stderr, ...args);
|
||||
|
||||
module.exports = hookStd;
|
||||
module.exports.default = hookStd;
|
||||
47
node_modules/ink/build/wrap-text.js
generated
vendored
Normal file
47
node_modules/ink/build/wrap-text.js
generated
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _wrapAnsi = _interopRequireDefault(require("wrap-ansi"));
|
||||
|
||||
var _cliTruncate = _interopRequireDefault(require("cli-truncate"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var _default = (text, maxWidth, {
|
||||
textWrap
|
||||
} = {}) => {
|
||||
if (textWrap === 'wrap') {
|
||||
return (0, _wrapAnsi.default)(text, maxWidth, {
|
||||
trim: false,
|
||||
hard: true
|
||||
});
|
||||
}
|
||||
|
||||
if (String(textWrap).startsWith('truncate')) {
|
||||
let position;
|
||||
|
||||
if (textWrap === 'truncate' || textWrap === 'truncate-end') {
|
||||
position = 'end';
|
||||
}
|
||||
|
||||
if (textWrap === 'truncate-middle') {
|
||||
position = 'middle';
|
||||
}
|
||||
|
||||
if (textWrap === 'truncate-start') {
|
||||
position = 'start';
|
||||
}
|
||||
|
||||
return (0, _cliTruncate.default)(text, maxWidth, {
|
||||
position
|
||||
});
|
||||
}
|
||||
|
||||
return text;
|
||||
};
|
||||
|
||||
exports.default = _default;
|
||||
Reference in New Issue
Block a user