ink 3.1.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/colorize.d.ts +3 -3
- package/build/colorize.js +30 -35
- package/build/colorize.js.map +1 -1
- package/build/components/App.d.ts +12 -12
- package/build/components/App.js +287 -208
- package/build/components/App.js.map +1 -1
- package/build/components/AppContext.d.ts +2 -2
- package/build/components/AppContext.js +5 -6
- package/build/components/AppContext.js.map +1 -1
- package/build/components/Box.d.ts +5 -5
- package/build/components/Box.js +15 -38
- package/build/components/Box.js.map +1 -1
- package/build/components/ErrorOverview.d.ts +5 -5
- package/build/components/ErrorOverview.js +40 -58
- package/build/components/ErrorOverview.js.map +1 -1
- package/build/components/FocusContext.d.ts +2 -2
- package/build/components/FocusContext.js +13 -14
- package/build/components/FocusContext.js.map +1 -1
- package/build/components/Newline.d.ts +4 -5
- package/build/components/Newline.js +4 -9
- package/build/components/Newline.js.map +1 -1
- package/build/components/Spacer.d.ts +2 -3
- package/build/components/Spacer.js +5 -10
- package/build/components/Spacer.js.map +1 -1
- package/build/components/Static.d.ts +5 -9
- package/build/components/Static.js +12 -33
- package/build/components/Static.js.map +1 -1
- package/build/components/StderrContext.d.ts +4 -4
- package/build/components/StderrContext.js +7 -7
- package/build/components/StderrContext.js.map +1 -1
- package/build/components/StdinContext.d.ts +4 -4
- package/build/components/StdinContext.js +8 -7
- package/build/components/StdinContext.js.map +1 -1
- package/build/components/StdoutContext.d.ts +4 -4
- package/build/components/StdoutContext.js +7 -7
- package/build/components/StdoutContext.js.map +1 -1
- package/build/components/Text.d.ts +9 -10
- package/build/components/Text.js +14 -29
- package/build/components/Text.js.map +1 -1
- package/build/components/Transform.d.ts +4 -5
- package/build/components/Transform.js +4 -11
- package/build/components/Transform.js.map +1 -1
- package/build/devtools-window-polyfill.js +3 -8
- package/build/devtools-window-polyfill.js.map +1 -1
- package/build/devtools.d.ts +1 -1
- package/build/devtools.js +6 -6
- package/build/devtools.js.map +1 -1
- package/build/dom.d.ts +14 -17
- package/build/dom.js +34 -47
- package/build/dom.js.map +1 -1
- package/build/get-max-width.d.ts +2 -2
- package/build/get-max-width.js +7 -11
- package/build/get-max-width.js.map +1 -1
- package/build/hooks/use-app.d.ts +1 -1
- package/build/hooks/use-app.js +4 -9
- package/build/hooks/use-app.js.map +1 -1
- package/build/hooks/use-focus-manager.d.ts +3 -3
- package/build/hooks/use-focus-manager.js +4 -9
- package/build/hooks/use-focus-manager.js.map +1 -1
- package/build/hooks/use-focus.d.ts +4 -4
- package/build/hooks/use-focus.js +11 -16
- package/build/hooks/use-focus.js.map +1 -1
- package/build/hooks/use-input.d.ts +5 -5
- package/build/hooks/use-input.js +13 -14
- package/build/hooks/use-input.js.map +1 -1
- package/build/hooks/use-stderr.d.ts +1 -1
- package/build/hooks/use-stderr.js +4 -9
- package/build/hooks/use-stderr.js.map +1 -1
- package/build/hooks/use-stdin.d.ts +1 -1
- package/build/hooks/use-stdin.js +4 -9
- package/build/hooks/use-stdin.js.map +1 -1
- package/build/hooks/use-stdout.d.ts +1 -1
- package/build/hooks/use-stdout.js +4 -9
- package/build/hooks/use-stdout.js.map +1 -1
- package/build/index.d.ts +27 -20
- package/build/index.js +15 -32
- package/build/index.js.map +1 -1
- package/build/ink.d.ts +4 -4
- package/build/ink.js +166 -97
- package/build/ink.js.map +1 -1
- package/build/instances.d.ts +4 -2
- package/build/instances.js +2 -3
- package/build/instances.js.map +1 -1
- package/build/log-update.d.ts +5 -6
- package/build/log-update.js +8 -12
- package/build/log-update.js.map +1 -1
- package/build/measure-element.d.ts +5 -5
- package/build/measure-element.js +5 -9
- package/build/measure-element.js.map +1 -1
- package/build/measure-text.d.ts +4 -4
- package/build/measure-text.js +7 -10
- package/build/measure-text.js.map +1 -1
- package/build/output.d.ts +3 -3
- package/build/output.js +25 -15
- package/build/output.js.map +1 -1
- package/build/reconciler.d.ts +2 -2
- package/build/reconciler.js +100 -76
- package/build/reconciler.js.map +1 -1
- package/build/render-border.d.ts +4 -4
- package/build/render-border.js +8 -12
- package/build/render-border.js.map +1 -1
- package/build/render-node-to-output.d.ts +3 -3
- package/build/render-node-to-output.js +17 -24
- package/build/render-node-to-output.js.map +1 -1
- package/build/render.d.ts +8 -8
- package/build/render.js +23 -20
- package/build/render.js.map +1 -1
- package/build/renderer.d.ts +5 -5
- package/build/renderer.js +11 -16
- package/build/renderer.js.map +1 -1
- package/build/squash-text-nodes.d.ts +1 -1
- package/build/squash-text-nodes.js +1 -3
- package/build/squash-text-nodes.js.map +1 -1
- package/build/styles.d.ts +9 -9
- package/build/styles.js +39 -45
- package/build/styles.js.map +1 -1
- package/build/wrap-text.d.ts +3 -3
- package/build/wrap-text.js +9 -12
- package/build/wrap-text.js.map +1 -1
- package/license +1 -1
- package/package.json +87 -67
- package/readme.md +91 -49
package/build/render.js
CHANGED
|
@@ -1,29 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const ink_1 = __importDefault(require("./ink"));
|
|
7
|
-
const instances_1 = __importDefault(require("./instances"));
|
|
8
|
-
const stream_1 = require("stream");
|
|
1
|
+
import { Stream } from 'node:stream';
|
|
2
|
+
import process from 'node:process';
|
|
3
|
+
import Ink from './ink.js';
|
|
4
|
+
import instances from './instances.js';
|
|
9
5
|
/**
|
|
10
6
|
* Mount a component and render the output.
|
|
11
7
|
*/
|
|
12
8
|
const render = (node, options) => {
|
|
13
|
-
const inkOptions =
|
|
14
|
-
|
|
9
|
+
const inkOptions = {
|
|
10
|
+
stdout: process.stdout,
|
|
11
|
+
stdin: process.stdin,
|
|
12
|
+
stderr: process.stderr,
|
|
13
|
+
debug: false,
|
|
14
|
+
exitOnCtrlC: true,
|
|
15
|
+
patchConsole: true,
|
|
16
|
+
...getOptions(options)
|
|
17
|
+
};
|
|
18
|
+
const instance = getInstance(inkOptions.stdout, () => new Ink(inkOptions));
|
|
15
19
|
instance.render(node);
|
|
16
20
|
return {
|
|
17
21
|
rerender: instance.render,
|
|
18
|
-
unmount
|
|
22
|
+
unmount() {
|
|
23
|
+
instance.unmount();
|
|
24
|
+
},
|
|
19
25
|
waitUntilExit: instance.waitUntilExit,
|
|
20
|
-
cleanup: () =>
|
|
26
|
+
cleanup: () => instances.delete(inkOptions.stdout),
|
|
21
27
|
clear: instance.clear
|
|
22
28
|
};
|
|
23
29
|
};
|
|
24
|
-
|
|
30
|
+
export default render;
|
|
25
31
|
const getOptions = (stdout = {}) => {
|
|
26
|
-
if (stdout instanceof
|
|
32
|
+
if (stdout instanceof Stream) {
|
|
27
33
|
return {
|
|
28
34
|
stdout,
|
|
29
35
|
stdin: process.stdin
|
|
@@ -32,13 +38,10 @@ const getOptions = (stdout = {}) => {
|
|
|
32
38
|
return stdout;
|
|
33
39
|
};
|
|
34
40
|
const getInstance = (stdout, createInstance) => {
|
|
35
|
-
let instance;
|
|
36
|
-
if (
|
|
37
|
-
instance = instances_1.default.get(stdout);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
41
|
+
let instance = instances.get(stdout);
|
|
42
|
+
if (!instance) {
|
|
40
43
|
instance = createInstance();
|
|
41
|
-
|
|
44
|
+
instances.set(stdout, instance);
|
|
42
45
|
}
|
|
43
46
|
return instance;
|
|
44
47
|
};
|
package/build/render.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AACnC,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,OAAO,GAAiC,MAAM,UAAU,CAAC;AACzD,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAmEvC;;GAEG;AACH,MAAM,MAAM,GAAmB,CAAC,IAAI,EAAE,OAA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KAChC;IAED,OAAO,QAAQ,CAAC;AACjB,CAAC,CAAC"}
|
package/build/renderer.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { DOMElement } from './dom';
|
|
2
|
-
|
|
1
|
+
import { type DOMElement } from './dom.js';
|
|
2
|
+
type Result = {
|
|
3
3
|
output: string;
|
|
4
4
|
outputHeight: number;
|
|
5
5
|
staticOutput: string;
|
|
6
|
-
}
|
|
7
|
-
declare const
|
|
8
|
-
export default
|
|
6
|
+
};
|
|
7
|
+
declare const renderer: (node: DOMElement, terminalWidth: number) => Result;
|
|
8
|
+
export default renderer;
|
package/build/renderer.js
CHANGED
|
@@ -1,28 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const yoga_layout_prebuilt_1 = __importDefault(require("yoga-layout-prebuilt"));
|
|
7
|
-
const render_node_to_output_1 = __importDefault(require("./render-node-to-output"));
|
|
8
|
-
const output_1 = __importDefault(require("./output"));
|
|
9
|
-
exports.default = (node, terminalWidth) => {
|
|
10
|
-
var _a;
|
|
1
|
+
import Yoga from 'yoga-layout-prebuilt';
|
|
2
|
+
import renderNodeToOutput from './render-node-to-output.js';
|
|
3
|
+
import Output from './output.js';
|
|
4
|
+
const renderer = (node, terminalWidth) => {
|
|
11
5
|
node.yogaNode.setWidth(terminalWidth);
|
|
12
6
|
if (node.yogaNode) {
|
|
13
|
-
node.yogaNode.calculateLayout(undefined, undefined,
|
|
14
|
-
const output = new
|
|
7
|
+
node.yogaNode.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR);
|
|
8
|
+
const output = new Output({
|
|
15
9
|
width: node.yogaNode.getComputedWidth(),
|
|
16
10
|
height: node.yogaNode.getComputedHeight()
|
|
17
11
|
});
|
|
18
|
-
|
|
12
|
+
renderNodeToOutput(node, output, { skipStaticElements: true });
|
|
19
13
|
let staticOutput;
|
|
20
|
-
if (
|
|
21
|
-
staticOutput = new
|
|
14
|
+
if (node.staticNode?.yogaNode) {
|
|
15
|
+
staticOutput = new Output({
|
|
22
16
|
width: node.staticNode.yogaNode.getComputedWidth(),
|
|
23
17
|
height: node.staticNode.yogaNode.getComputedHeight()
|
|
24
18
|
});
|
|
25
|
-
|
|
19
|
+
renderNodeToOutput(node.staticNode, staticOutput, {
|
|
26
20
|
skipStaticElements: false
|
|
27
21
|
});
|
|
28
22
|
}
|
|
@@ -41,4 +35,5 @@ exports.default = (node, terminalWidth) => {
|
|
|
41
35
|
staticOutput: ''
|
|
42
36
|
};
|
|
43
37
|
};
|
|
38
|
+
export default renderer;
|
|
44
39
|
//# sourceMappingURL=renderer.js.map
|
package/build/renderer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,sBAAsB,CAAC;AACxC,OAAO,kBAAkB,MAAM,4BAA4B,CAAC;AAC5D,OAAO,MAAM,MAAM,aAAa,CAAC;AASjC,MAAM,QAAQ,GAAG,CAAC,IAAgB,EAAE,aAAqB,EAAU,EAAE;IACpE,IAAI,CAAC,QAAS,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;IAEvC,IAAI,IAAI,CAAC,QAAQ,EAAE;QAClB,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAExE,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC;YACzB,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,gBAAgB,EAAE;YACvC,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,iBAAiB,EAAE;SACzC,CAAC,CAAC;QAEH,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAC,kBAAkB,EAAE,IAAI,EAAC,CAAC,CAAC;QAE7D,IAAI,YAAY,CAAC;QAEjB,IAAI,IAAI,CAAC,UAAU,EAAE,QAAQ,EAAE;YAC9B,YAAY,GAAG,IAAI,MAAM,CAAC;gBACzB,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,gBAAgB,EAAE;gBAClD,MAAM,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,iBAAiB,EAAE;aACpD,CAAC,CAAC;YAEH,kBAAkB,CAAC,IAAI,CAAC,UAAU,EAAE,YAAY,EAAE;gBACjD,kBAAkB,EAAE,KAAK;aACzB,CAAC,CAAC;SACH;QAED,MAAM,EAAC,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,YAAY,EAAC,GAAG,MAAM,CAAC,GAAG,EAAE,CAAC;QAErE,OAAO;YACN,MAAM,EAAE,eAAe;YACvB,YAAY;YACZ,2EAA2E;YAC3E,8DAA8D;YAC9D,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,GAAG,EAAE,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,EAAE;SAClE,CAAC;KACF;IAED,OAAO;QACN,MAAM,EAAE,EAAE;QACV,YAAY,EAAE,CAAC;QACf,YAAY,EAAE,EAAE;KAChB,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
1
|
// Squashing text nodes allows to combine multiple text nodes into one and write
|
|
4
2
|
// to `Output` instance only once. For example, <Text>hello{' '}world</Text>
|
|
5
3
|
// is actually 3 text nodes, which would result 3 writes to `Output`.
|
|
@@ -31,5 +29,5 @@ const squashTextNodes = (node) => {
|
|
|
31
29
|
}
|
|
32
30
|
return text;
|
|
33
31
|
};
|
|
34
|
-
|
|
32
|
+
export default squashTextNodes;
|
|
35
33
|
//# sourceMappingURL=squash-text-nodes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"squash-text-nodes.js","sourceRoot":"","sources":["../src/squash-text-nodes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"squash-text-nodes.js","sourceRoot":"","sources":["../src/squash-text-nodes.ts"],"names":[],"mappings":"AAEA,gFAAgF;AAChF,4EAA4E;AAC5E,qEAAqE;AACrE,EAAE;AACF,kGAAkG;AAClG,wFAAwF;AACxF,MAAM,eAAe,GAAG,CAAC,IAAgB,EAAU,EAAE;IACpD,IAAI,IAAI,GAAG,EAAE,CAAC;IAEd,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE;QAC/B,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,UAAU,EAAE;YACxC,IAAI,QAAQ,GAAG,EAAE,CAAC;YAElB,IAAI,SAAS,CAAC,QAAQ,KAAK,OAAO,EAAE;gBACnC,QAAQ,GAAG,SAAS,CAAC,SAAS,CAAC;aAC/B;iBAAM;gBACN,IACC,SAAS,CAAC,QAAQ,KAAK,UAAU;oBACjC,SAAS,CAAC,QAAQ,KAAK,kBAAkB,EACxC;oBACD,QAAQ,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;iBACtC;gBAED,oFAAoF;gBACpF,iFAAiF;gBACjF,IACC,QAAQ,CAAC,MAAM,GAAG,CAAC;oBACnB,OAAO,SAAS,CAAC,kBAAkB,KAAK,UAAU,EACjD;oBACD,QAAQ,GAAG,SAAS,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC;iBAClD;aACD;YAED,IAAI,IAAI,QAAQ,CAAC;SACjB;KACD;IAED,OAAO,IAAI,CAAC;AACb,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
package/build/styles.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { YogaNode } from 'yoga-layout-prebuilt';
|
|
2
|
-
import { Boxes } from 'cli-boxes';
|
|
3
|
-
import { LiteralUnion } from 'type-fest';
|
|
4
|
-
import {
|
|
5
|
-
export
|
|
1
|
+
import { type YogaNode } from 'yoga-layout-prebuilt';
|
|
2
|
+
import { type Boxes } from 'cli-boxes';
|
|
3
|
+
import { type LiteralUnion } from 'type-fest';
|
|
4
|
+
import { type ForegroundColorName } from 'chalk';
|
|
5
|
+
export type Styles = {
|
|
6
6
|
readonly textWrap?: 'wrap' | 'end' | 'middle' | 'truncate-end' | 'truncate' | 'truncate-middle' | 'truncate-start';
|
|
7
7
|
readonly position?: 'absolute' | 'relative';
|
|
8
8
|
/**
|
|
@@ -103,7 +103,7 @@ export interface Styles {
|
|
|
103
103
|
* Change border color.
|
|
104
104
|
* Accepts the same values as `color` in <Text> component.
|
|
105
105
|
*/
|
|
106
|
-
readonly borderColor?: LiteralUnion<
|
|
107
|
-
}
|
|
108
|
-
declare const
|
|
109
|
-
export default
|
|
106
|
+
readonly borderColor?: LiteralUnion<ForegroundColorName, string>;
|
|
107
|
+
};
|
|
108
|
+
declare const styles: (node: YogaNode, style?: Styles) => void;
|
|
109
|
+
export default styles;
|
package/build/styles.js
CHANGED
|
@@ -1,65 +1,59 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
1
|
/* eslint-disable @typescript-eslint/prefer-nullish-coalescing */
|
|
7
|
-
|
|
2
|
+
import Yoga from 'yoga-layout-prebuilt';
|
|
8
3
|
const applyPositionStyles = (node, style) => {
|
|
9
4
|
if ('position' in style) {
|
|
10
5
|
node.setPositionType(style.position === 'absolute'
|
|
11
|
-
?
|
|
12
|
-
:
|
|
6
|
+
? Yoga.POSITION_TYPE_ABSOLUTE
|
|
7
|
+
: Yoga.POSITION_TYPE_RELATIVE);
|
|
13
8
|
}
|
|
14
9
|
};
|
|
15
10
|
const applyMarginStyles = (node, style) => {
|
|
16
11
|
if ('marginLeft' in style) {
|
|
17
|
-
node.setMargin(
|
|
12
|
+
node.setMargin(Yoga.EDGE_START, style.marginLeft || 0);
|
|
18
13
|
}
|
|
19
14
|
if ('marginRight' in style) {
|
|
20
|
-
node.setMargin(
|
|
15
|
+
node.setMargin(Yoga.EDGE_END, style.marginRight || 0);
|
|
21
16
|
}
|
|
22
17
|
if ('marginTop' in style) {
|
|
23
|
-
node.setMargin(
|
|
18
|
+
node.setMargin(Yoga.EDGE_TOP, style.marginTop || 0);
|
|
24
19
|
}
|
|
25
20
|
if ('marginBottom' in style) {
|
|
26
|
-
node.setMargin(
|
|
21
|
+
node.setMargin(Yoga.EDGE_BOTTOM, style.marginBottom || 0);
|
|
27
22
|
}
|
|
28
23
|
};
|
|
29
24
|
const applyPaddingStyles = (node, style) => {
|
|
30
25
|
if ('paddingLeft' in style) {
|
|
31
|
-
node.setPadding(
|
|
26
|
+
node.setPadding(Yoga.EDGE_LEFT, style.paddingLeft || 0);
|
|
32
27
|
}
|
|
33
28
|
if ('paddingRight' in style) {
|
|
34
|
-
node.setPadding(
|
|
29
|
+
node.setPadding(Yoga.EDGE_RIGHT, style.paddingRight || 0);
|
|
35
30
|
}
|
|
36
31
|
if ('paddingTop' in style) {
|
|
37
|
-
node.setPadding(
|
|
32
|
+
node.setPadding(Yoga.EDGE_TOP, style.paddingTop || 0);
|
|
38
33
|
}
|
|
39
34
|
if ('paddingBottom' in style) {
|
|
40
|
-
node.setPadding(
|
|
35
|
+
node.setPadding(Yoga.EDGE_BOTTOM, style.paddingBottom || 0);
|
|
41
36
|
}
|
|
42
37
|
};
|
|
43
38
|
const applyFlexStyles = (node, style) => {
|
|
44
|
-
var _a;
|
|
45
39
|
if ('flexGrow' in style) {
|
|
46
|
-
node.setFlexGrow(
|
|
40
|
+
node.setFlexGrow(style.flexGrow ?? 0);
|
|
47
41
|
}
|
|
48
42
|
if ('flexShrink' in style) {
|
|
49
43
|
node.setFlexShrink(typeof style.flexShrink === 'number' ? style.flexShrink : 1);
|
|
50
44
|
}
|
|
51
45
|
if ('flexDirection' in style) {
|
|
52
46
|
if (style.flexDirection === 'row') {
|
|
53
|
-
node.setFlexDirection(
|
|
47
|
+
node.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
|
|
54
48
|
}
|
|
55
49
|
if (style.flexDirection === 'row-reverse') {
|
|
56
|
-
node.setFlexDirection(
|
|
50
|
+
node.setFlexDirection(Yoga.FLEX_DIRECTION_ROW_REVERSE);
|
|
57
51
|
}
|
|
58
52
|
if (style.flexDirection === 'column') {
|
|
59
|
-
node.setFlexDirection(
|
|
53
|
+
node.setFlexDirection(Yoga.FLEX_DIRECTION_COLUMN);
|
|
60
54
|
}
|
|
61
55
|
if (style.flexDirection === 'column-reverse') {
|
|
62
|
-
node.setFlexDirection(
|
|
56
|
+
node.setFlexDirection(Yoga.FLEX_DIRECTION_COLUMN_REVERSE);
|
|
63
57
|
}
|
|
64
58
|
}
|
|
65
59
|
if ('flexBasis' in style) {
|
|
@@ -71,57 +65,56 @@ const applyFlexStyles = (node, style) => {
|
|
|
71
65
|
}
|
|
72
66
|
else {
|
|
73
67
|
// This should be replaced with node.setFlexBasisAuto() when new Yoga release is out
|
|
74
|
-
node.setFlexBasis(NaN);
|
|
68
|
+
node.setFlexBasis(Number.NaN);
|
|
75
69
|
}
|
|
76
70
|
}
|
|
77
71
|
if ('alignItems' in style) {
|
|
78
72
|
if (style.alignItems === 'stretch' || !style.alignItems) {
|
|
79
|
-
node.setAlignItems(
|
|
73
|
+
node.setAlignItems(Yoga.ALIGN_STRETCH);
|
|
80
74
|
}
|
|
81
75
|
if (style.alignItems === 'flex-start') {
|
|
82
|
-
node.setAlignItems(
|
|
76
|
+
node.setAlignItems(Yoga.ALIGN_FLEX_START);
|
|
83
77
|
}
|
|
84
78
|
if (style.alignItems === 'center') {
|
|
85
|
-
node.setAlignItems(
|
|
79
|
+
node.setAlignItems(Yoga.ALIGN_CENTER);
|
|
86
80
|
}
|
|
87
81
|
if (style.alignItems === 'flex-end') {
|
|
88
|
-
node.setAlignItems(
|
|
82
|
+
node.setAlignItems(Yoga.ALIGN_FLEX_END);
|
|
89
83
|
}
|
|
90
84
|
}
|
|
91
85
|
if ('alignSelf' in style) {
|
|
92
86
|
if (style.alignSelf === 'auto' || !style.alignSelf) {
|
|
93
|
-
node.setAlignSelf(
|
|
87
|
+
node.setAlignSelf(Yoga.ALIGN_AUTO);
|
|
94
88
|
}
|
|
95
89
|
if (style.alignSelf === 'flex-start') {
|
|
96
|
-
node.setAlignSelf(
|
|
90
|
+
node.setAlignSelf(Yoga.ALIGN_FLEX_START);
|
|
97
91
|
}
|
|
98
92
|
if (style.alignSelf === 'center') {
|
|
99
|
-
node.setAlignSelf(
|
|
93
|
+
node.setAlignSelf(Yoga.ALIGN_CENTER);
|
|
100
94
|
}
|
|
101
95
|
if (style.alignSelf === 'flex-end') {
|
|
102
|
-
node.setAlignSelf(
|
|
96
|
+
node.setAlignSelf(Yoga.ALIGN_FLEX_END);
|
|
103
97
|
}
|
|
104
98
|
}
|
|
105
99
|
if ('justifyContent' in style) {
|
|
106
100
|
if (style.justifyContent === 'flex-start' || !style.justifyContent) {
|
|
107
|
-
node.setJustifyContent(
|
|
101
|
+
node.setJustifyContent(Yoga.JUSTIFY_FLEX_START);
|
|
108
102
|
}
|
|
109
103
|
if (style.justifyContent === 'center') {
|
|
110
|
-
node.setJustifyContent(
|
|
104
|
+
node.setJustifyContent(Yoga.JUSTIFY_CENTER);
|
|
111
105
|
}
|
|
112
106
|
if (style.justifyContent === 'flex-end') {
|
|
113
|
-
node.setJustifyContent(
|
|
107
|
+
node.setJustifyContent(Yoga.JUSTIFY_FLEX_END);
|
|
114
108
|
}
|
|
115
109
|
if (style.justifyContent === 'space-between') {
|
|
116
|
-
node.setJustifyContent(
|
|
110
|
+
node.setJustifyContent(Yoga.JUSTIFY_SPACE_BETWEEN);
|
|
117
111
|
}
|
|
118
112
|
if (style.justifyContent === 'space-around') {
|
|
119
|
-
node.setJustifyContent(
|
|
113
|
+
node.setJustifyContent(Yoga.JUSTIFY_SPACE_AROUND);
|
|
120
114
|
}
|
|
121
115
|
}
|
|
122
116
|
};
|
|
123
117
|
const applyDimensionStyles = (node, style) => {
|
|
124
|
-
var _a, _b;
|
|
125
118
|
if ('width' in style) {
|
|
126
119
|
if (typeof style.width === 'number') {
|
|
127
120
|
node.setWidth(style.width);
|
|
@@ -149,7 +142,7 @@ const applyDimensionStyles = (node, style) => {
|
|
|
149
142
|
node.setMinWidthPercent(Number.parseInt(style.minWidth, 10));
|
|
150
143
|
}
|
|
151
144
|
else {
|
|
152
|
-
node.setMinWidth(
|
|
145
|
+
node.setMinWidth(style.minWidth ?? 0);
|
|
153
146
|
}
|
|
154
147
|
}
|
|
155
148
|
if ('minHeight' in style) {
|
|
@@ -157,25 +150,25 @@ const applyDimensionStyles = (node, style) => {
|
|
|
157
150
|
node.setMinHeightPercent(Number.parseInt(style.minHeight, 10));
|
|
158
151
|
}
|
|
159
152
|
else {
|
|
160
|
-
node.setMinHeight(
|
|
153
|
+
node.setMinHeight(style.minHeight ?? 0);
|
|
161
154
|
}
|
|
162
155
|
}
|
|
163
156
|
};
|
|
164
157
|
const applyDisplayStyles = (node, style) => {
|
|
165
158
|
if ('display' in style) {
|
|
166
|
-
node.setDisplay(style.display === 'flex' ?
|
|
159
|
+
node.setDisplay(style.display === 'flex' ? Yoga.DISPLAY_FLEX : Yoga.DISPLAY_NONE);
|
|
167
160
|
}
|
|
168
161
|
};
|
|
169
162
|
const applyBorderStyles = (node, style) => {
|
|
170
163
|
if ('borderStyle' in style) {
|
|
171
164
|
const borderWidth = typeof style.borderStyle === 'string' ? 1 : 0;
|
|
172
|
-
node.setBorder(
|
|
173
|
-
node.setBorder(
|
|
174
|
-
node.setBorder(
|
|
175
|
-
node.setBorder(
|
|
165
|
+
node.setBorder(Yoga.EDGE_TOP, borderWidth);
|
|
166
|
+
node.setBorder(Yoga.EDGE_BOTTOM, borderWidth);
|
|
167
|
+
node.setBorder(Yoga.EDGE_LEFT, borderWidth);
|
|
168
|
+
node.setBorder(Yoga.EDGE_RIGHT, borderWidth);
|
|
176
169
|
}
|
|
177
170
|
};
|
|
178
|
-
|
|
171
|
+
const styles = (node, style = {}) => {
|
|
179
172
|
applyPositionStyles(node, style);
|
|
180
173
|
applyMarginStyles(node, style);
|
|
181
174
|
applyPaddingStyles(node, style);
|
|
@@ -184,4 +177,5 @@ exports.default = (node, style = {}) => {
|
|
|
184
177
|
applyDisplayStyles(node, style);
|
|
185
178
|
applyBorderStyles(node, style);
|
|
186
179
|
};
|
|
180
|
+
export default styles;
|
|
187
181
|
//# sourceMappingURL=styles.js.map
|
package/build/styles.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.js","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"styles.js","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,OAAO,IAAqB,MAAM,sBAAsB,CAAC;AAgJzD,MAAM,mBAAmB,GAAG,CAAC,IAAmB,EAAE,KAAa,EAAQ,EAAE;IACxE,IAAI,UAAU,IAAI,KAAK,EAAE;QACxB,IAAI,CAAC,eAAe,CACnB,KAAK,CAAC,QAAQ,KAAK,UAAU;YAC5B,CAAC,CAAC,IAAI,CAAC,sBAAsB;YAC7B,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAC9B,CAAC;KACF;AACF,CAAC,CAAC;AAEF,MAAM,iBAAiB,GAAG,CAAC,IAAmB,EAAE,KAAa,EAAQ,EAAE;IACtE,IAAI,YAAY,IAAI,KAAK,EAAE;QAC1B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,IAAI,CAAC,CAAC,CAAC;KACvD;IAED,IAAI,aAAa,IAAI,KAAK,EAAE;QAC3B,IAAI,CAAC,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,EAAE,WAAW,CAAC,CAAC;QAC5C,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;KAC7C;AACF,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,CAAC,IAAc,EAAE,QAAgB,EAAE,EAAQ,EAAE;IAC3D,mBAAmB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACjC,iBAAiB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC/B,kBAAkB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAChC,eAAe,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC7B,oBAAoB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAClC,kBAAkB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAChC,iBAAiB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAChC,CAAC,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
package/build/wrap-text.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Styles } from './styles';
|
|
2
|
-
declare const
|
|
3
|
-
export default
|
|
1
|
+
import { type Styles } from './styles.js';
|
|
2
|
+
declare const wrapText: (text: string, maxWidth: number, wrapType: Styles['textWrap']) => string;
|
|
3
|
+
export default wrapText;
|
package/build/wrap-text.js
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const wrap_ansi_1 = __importDefault(require("wrap-ansi"));
|
|
7
|
-
const cli_truncate_1 = __importDefault(require("cli-truncate"));
|
|
1
|
+
import wrapAnsi from 'wrap-ansi';
|
|
2
|
+
import cliTruncate from 'cli-truncate';
|
|
8
3
|
const cache = {};
|
|
9
|
-
|
|
4
|
+
const wrapText = (text, maxWidth, wrapType) => {
|
|
10
5
|
const cacheKey = text + String(maxWidth) + String(wrapType);
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
const cachedText = cache[cacheKey];
|
|
7
|
+
if (cachedText) {
|
|
8
|
+
return cachedText;
|
|
13
9
|
}
|
|
14
10
|
let wrappedText = text;
|
|
15
11
|
if (wrapType === 'wrap') {
|
|
16
|
-
wrappedText =
|
|
12
|
+
wrappedText = wrapAnsi(text, maxWidth, {
|
|
17
13
|
trim: false,
|
|
18
14
|
hard: true
|
|
19
15
|
});
|
|
@@ -26,9 +22,10 @@ exports.default = (text, maxWidth, wrapType) => {
|
|
|
26
22
|
if (wrapType === 'truncate-start') {
|
|
27
23
|
position = 'start';
|
|
28
24
|
}
|
|
29
|
-
wrappedText =
|
|
25
|
+
wrappedText = cliTruncate(text, maxWidth, { position });
|
|
30
26
|
}
|
|
31
27
|
cache[cacheKey] = wrappedText;
|
|
32
28
|
return wrappedText;
|
|
33
29
|
};
|
|
30
|
+
export default wrapText;
|
|
34
31
|
//# sourceMappingURL=wrap-text.js.map
|
package/build/wrap-text.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrap-text.js","sourceRoot":"","sources":["../src/wrap-text.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wrap-text.js","sourceRoot":"","sources":["../src/wrap-text.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,WAAW,MAAM,cAAc,CAAC;AAGvC,MAAM,KAAK,GAA2B,EAAE,CAAC;AAEzC,MAAM,QAAQ,GAAG,CAChB,IAAY,EACZ,QAAgB,EAChB,QAA4B,EACnB,EAAE;IACX,MAAM,QAAQ,GAAG,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC5D,MAAM,UAAU,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;IAEnC,IAAI,UAAU,EAAE;QACf,OAAO,UAAU,CAAC;KAClB;IAED,IAAI,WAAW,GAAG,IAAI,CAAC;IAEvB,IAAI,QAAQ,KAAK,MAAM,EAAE;QACxB,WAAW,GAAG,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE;YACtC,IAAI,EAAE,KAAK;YACX,IAAI,EAAE,IAAI;SACV,CAAC,CAAC;KACH;IAED,IAAI,QAAS,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE;QACrC,IAAI,QAAQ,GAA+B,KAAK,CAAC;QAEjD,IAAI,QAAQ,KAAK,iBAAiB,EAAE;YACnC,QAAQ,GAAG,QAAQ,CAAC;SACpB;QAED,IAAI,QAAQ,KAAK,gBAAgB,EAAE;YAClC,QAAQ,GAAG,OAAO,CAAC;SACnB;QAED,WAAW,GAAG,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAC,QAAQ,EAAC,CAAC,CAAC;KACtD;IAED,KAAK,CAAC,QAAQ,CAAC,GAAG,WAAW,CAAC;IAE9B,OAAO,WAAW,CAAC;AACpB,CAAC,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
package/license
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) Vadym Demedes <vadimdemedes@hey.com> (github.com/vadimdemedes)
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
6
|
|