ink 3.2.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/build/colorize.d.ts +3 -3
  2. package/build/colorize.js +30 -35
  3. package/build/colorize.js.map +1 -1
  4. package/build/components/App.d.ts +12 -12
  5. package/build/components/App.js +287 -208
  6. package/build/components/App.js.map +1 -1
  7. package/build/components/AppContext.d.ts +2 -2
  8. package/build/components/AppContext.js +5 -6
  9. package/build/components/AppContext.js.map +1 -1
  10. package/build/components/Box.d.ts +77 -5
  11. package/build/components/Box.js +20 -38
  12. package/build/components/Box.js.map +1 -1
  13. package/build/components/ErrorOverview.d.ts +5 -5
  14. package/build/components/ErrorOverview.js +40 -58
  15. package/build/components/ErrorOverview.js.map +1 -1
  16. package/build/components/FocusContext.d.ts +2 -2
  17. package/build/components/FocusContext.js +13 -14
  18. package/build/components/FocusContext.js.map +1 -1
  19. package/build/components/Newline.d.ts +4 -5
  20. package/build/components/Newline.js +4 -9
  21. package/build/components/Newline.js.map +1 -1
  22. package/build/components/Spacer.d.ts +2 -3
  23. package/build/components/Spacer.js +5 -10
  24. package/build/components/Spacer.js.map +1 -1
  25. package/build/components/Static.d.ts +5 -9
  26. package/build/components/Static.js +12 -33
  27. package/build/components/Static.js.map +1 -1
  28. package/build/components/StderrContext.d.ts +4 -4
  29. package/build/components/StderrContext.js +7 -7
  30. package/build/components/StderrContext.js.map +1 -1
  31. package/build/components/StdinContext.d.ts +4 -4
  32. package/build/components/StdinContext.js +8 -7
  33. package/build/components/StdinContext.js.map +1 -1
  34. package/build/components/StdoutContext.d.ts +4 -4
  35. package/build/components/StdoutContext.js +7 -7
  36. package/build/components/StdoutContext.js.map +1 -1
  37. package/build/components/Text.d.ts +9 -10
  38. package/build/components/Text.js +14 -29
  39. package/build/components/Text.js.map +1 -1
  40. package/build/components/Transform.d.ts +4 -5
  41. package/build/components/Transform.js +4 -11
  42. package/build/components/Transform.js.map +1 -1
  43. package/build/devtools-window-polyfill.js +3 -8
  44. package/build/devtools-window-polyfill.js.map +1 -1
  45. package/build/devtools.d.ts +1 -1
  46. package/build/devtools.js +6 -6
  47. package/build/devtools.js.map +1 -1
  48. package/build/dom.d.ts +17 -20
  49. package/build/dom.js +35 -47
  50. package/build/dom.js.map +1 -1
  51. package/build/get-max-width.d.ts +3 -3
  52. package/build/get-max-width.js +8 -11
  53. package/build/get-max-width.js.map +1 -1
  54. package/build/hooks/use-app.d.ts +1 -1
  55. package/build/hooks/use-app.js +4 -9
  56. package/build/hooks/use-app.js.map +1 -1
  57. package/build/hooks/use-focus-manager.d.ts +3 -3
  58. package/build/hooks/use-focus-manager.js +4 -9
  59. package/build/hooks/use-focus-manager.js.map +1 -1
  60. package/build/hooks/use-focus.d.ts +4 -4
  61. package/build/hooks/use-focus.js +11 -16
  62. package/build/hooks/use-focus.js.map +1 -1
  63. package/build/hooks/use-input.d.ts +5 -5
  64. package/build/hooks/use-input.js +13 -14
  65. package/build/hooks/use-input.js.map +1 -1
  66. package/build/hooks/use-stderr.d.ts +1 -1
  67. package/build/hooks/use-stderr.js +4 -9
  68. package/build/hooks/use-stderr.js.map +1 -1
  69. package/build/hooks/use-stdin.d.ts +1 -1
  70. package/build/hooks/use-stdin.js +4 -9
  71. package/build/hooks/use-stdin.js.map +1 -1
  72. package/build/hooks/use-stdout.d.ts +1 -1
  73. package/build/hooks/use-stdout.js +4 -9
  74. package/build/hooks/use-stdout.js.map +1 -1
  75. package/build/index.d.ts +27 -20
  76. package/build/index.js +15 -32
  77. package/build/index.js.map +1 -1
  78. package/build/ink.d.ts +6 -4
  79. package/build/ink.js +188 -99
  80. package/build/ink.js.map +1 -1
  81. package/build/instances.d.ts +4 -2
  82. package/build/instances.js +2 -3
  83. package/build/instances.js.map +1 -1
  84. package/build/log-update.d.ts +5 -6
  85. package/build/log-update.js +8 -12
  86. package/build/log-update.js.map +1 -1
  87. package/build/measure-element.d.ts +5 -5
  88. package/build/measure-element.js +5 -9
  89. package/build/measure-element.js.map +1 -1
  90. package/build/measure-text.d.ts +4 -4
  91. package/build/measure-text.js +7 -10
  92. package/build/measure-text.js.map +1 -1
  93. package/build/output.d.ts +12 -4
  94. package/build/output.js +108 -31
  95. package/build/output.js.map +1 -1
  96. package/build/reconciler.d.ts +1 -1
  97. package/build/reconciler.js +104 -76
  98. package/build/reconciler.js.map +1 -1
  99. package/build/render-border.d.ts +4 -4
  100. package/build/render-border.js +8 -12
  101. package/build/render-border.js.map +1 -1
  102. package/build/render-node-to-output.d.ts +3 -3
  103. package/build/render-node-to-output.js +44 -24
  104. package/build/render-node-to-output.js.map +1 -1
  105. package/build/render.d.ts +8 -8
  106. package/build/render.js +23 -20
  107. package/build/render.js.map +1 -1
  108. package/build/renderer.d.ts +5 -5
  109. package/build/renderer.js +9 -17
  110. package/build/renderer.js.map +1 -1
  111. package/build/squash-text-nodes.d.ts +1 -1
  112. package/build/squash-text-nodes.js +1 -3
  113. package/build/squash-text-nodes.js.map +1 -1
  114. package/build/styles.d.ts +30 -9
  115. package/build/styles.js +60 -46
  116. package/build/styles.js.map +1 -1
  117. package/build/wrap-text.d.ts +3 -3
  118. package/build/wrap-text.js +9 -12
  119. package/build/wrap-text.js.map +1 -1
  120. package/license +1 -1
  121. package/package.json +87 -67
  122. package/readme.md +202 -57
@@ -1,15 +1,11 @@
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
- const yoga_layout_prebuilt_1 = __importDefault(require("yoga-layout-prebuilt"));
7
- const widest_line_1 = __importDefault(require("widest-line"));
8
- const indent_string_1 = __importDefault(require("indent-string"));
9
- const wrap_text_1 = __importDefault(require("./wrap-text"));
10
- const get_max_width_1 = __importDefault(require("./get-max-width"));
11
- const squash_text_nodes_1 = __importDefault(require("./squash-text-nodes"));
12
- const render_border_1 = __importDefault(require("./render-border"));
1
+ import widestLine from 'widest-line';
2
+ import indentString from 'indent-string';
3
+ // eslint-disable-next-line n/file-extension-in-import
4
+ import Yoga from 'yoga-wasm-web/auto';
5
+ import wrapText from './wrap-text.js';
6
+ import getMaxWidth from './get-max-width.js';
7
+ import squashTextNodes from './squash-text-nodes.js';
8
+ import renderBorder from './render-border.js';
13
9
  // If parent container is `<Box>`, text nodes will be treated as separate nodes in
14
10
  // the tree and will have their own coordinates in the layout.
15
11
  // To ensure text nodes are aligned correctly, take X and Y of the first text node
@@ -17,25 +13,23 @@ const render_border_1 = __importDefault(require("./render-border"));
17
13
  // Only first node is taken into account, because other text nodes can't have margin or padding,
18
14
  // so their coordinates will be relative to the first node anyway
19
15
  const applyPaddingToText = (node, text) => {
20
- var _a;
21
- const yogaNode = (_a = node.childNodes[0]) === null || _a === void 0 ? void 0 : _a.yogaNode;
16
+ const yogaNode = node.childNodes[0]?.yogaNode;
22
17
  if (yogaNode) {
23
18
  const offsetX = yogaNode.getComputedLeft();
24
19
  const offsetY = yogaNode.getComputedTop();
25
- text = '\n'.repeat(offsetY) + indent_string_1.default(text, offsetX);
20
+ text = '\n'.repeat(offsetY) + indentString(text, offsetX);
26
21
  }
27
22
  return text;
28
23
  };
29
24
  // After nodes are laid out, render each to output object, which later gets rendered to terminal
30
25
  const renderNodeToOutput = (node, output, options) => {
31
- var _a;
32
26
  const { offsetX = 0, offsetY = 0, transformers = [], skipStaticElements } = options;
33
27
  if (skipStaticElements && node.internal_static) {
34
28
  return;
35
29
  }
36
30
  const { yogaNode } = node;
37
31
  if (yogaNode) {
38
- if (yogaNode.getDisplay() === yoga_layout_prebuilt_1.default.DISPLAY_NONE) {
32
+ if (yogaNode.getDisplay() === Yoga.DISPLAY_NONE) {
39
33
  return;
40
34
  }
41
35
  // Left and top positions in Yoga are relative to their parent node
@@ -48,21 +42,44 @@ const renderNodeToOutput = (node, output, options) => {
48
42
  newTransformers = [node.internal_transform, ...transformers];
49
43
  }
50
44
  if (node.nodeName === 'ink-text') {
51
- let text = squash_text_nodes_1.default(node);
45
+ let text = squashTextNodes(node);
52
46
  if (text.length > 0) {
53
- const currentWidth = widest_line_1.default(text);
54
- const maxWidth = get_max_width_1.default(yogaNode);
47
+ const currentWidth = widestLine(text);
48
+ const maxWidth = getMaxWidth(yogaNode);
55
49
  if (currentWidth > maxWidth) {
56
- const textWrap = (_a = node.style.textWrap) !== null && _a !== void 0 ? _a : 'wrap';
57
- text = wrap_text_1.default(text, maxWidth, textWrap);
50
+ const textWrap = node.style.textWrap ?? 'wrap';
51
+ text = wrapText(text, maxWidth, textWrap);
58
52
  }
59
53
  text = applyPaddingToText(node, text);
60
54
  output.write(x, y, text, { transformers: newTransformers });
61
55
  }
62
56
  return;
63
57
  }
58
+ let clipped = false;
64
59
  if (node.nodeName === 'ink-box') {
65
- render_border_1.default(x, y, node, output);
60
+ renderBorder(x, y, node, output);
61
+ const clipHorizontally = node.style.overflowX === 'hidden';
62
+ const clipVertically = node.style.overflowY === 'hidden';
63
+ if (clipHorizontally || clipVertically) {
64
+ const x1 = clipHorizontally
65
+ ? x + yogaNode.getComputedBorder(Yoga.EDGE_LEFT)
66
+ : undefined;
67
+ const x2 = clipHorizontally
68
+ ? x +
69
+ yogaNode.getComputedWidth() -
70
+ yogaNode.getComputedBorder(Yoga.EDGE_RIGHT)
71
+ : undefined;
72
+ const y1 = clipVertically
73
+ ? y + yogaNode.getComputedBorder(Yoga.EDGE_TOP)
74
+ : undefined;
75
+ const y2 = clipVertically
76
+ ? y +
77
+ yogaNode.getComputedHeight() -
78
+ yogaNode.getComputedBorder(Yoga.EDGE_BOTTOM)
79
+ : undefined;
80
+ output.clip({ x1, x2, y1, y2 });
81
+ clipped = true;
82
+ }
66
83
  }
67
84
  if (node.nodeName === 'ink-root' || node.nodeName === 'ink-box') {
68
85
  for (const childNode of node.childNodes) {
@@ -73,8 +90,11 @@ const renderNodeToOutput = (node, output, options) => {
73
90
  skipStaticElements
74
91
  });
75
92
  }
93
+ if (clipped) {
94
+ output.unclip();
95
+ }
76
96
  }
77
97
  }
78
98
  };
79
- exports.default = renderNodeToOutput;
99
+ export default renderNodeToOutput;
80
100
  //# sourceMappingURL=render-node-to-output.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"render-node-to-output.js","sourceRoot":"","sources":["../src/render-node-to-output.ts"],"names":[],"mappings":";;;;;AAAA,gFAAwC;AACxC,8DAAqC;AACrC,kEAAyC;AACzC,4DAAmC;AACnC,oEAA0C;AAC1C,4EAAkD;AAClD,oEAA2C;AAI3C,kFAAkF;AAClF,8DAA8D;AAC9D,kFAAkF;AAClF,iDAAiD;AACjD,gGAAgG;AAChG,iEAAiE;AACjE,MAAM,kBAAkB,GAAG,CAAC,IAAgB,EAAE,IAAY,EAAU,EAAE;;IACrE,MAAM,QAAQ,SAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,0CAAE,QAAQ,CAAC;IAE9C,IAAI,QAAQ,EAAE;QACb,MAAM,OAAO,GAAG,QAAQ,CAAC,eAAe,EAAE,CAAC;QAC3C,MAAM,OAAO,GAAG,QAAQ,CAAC,cAAc,EAAE,CAAC;QAC1C,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,uBAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;KAC1D;IAED,OAAO,IAAI,CAAC;AACb,CAAC,CAAC;AAIF,gGAAgG;AAChG,MAAM,kBAAkB,GAAG,CAC1B,IAAgB,EAChB,MAAc,EACd,OAKC,EACA,EAAE;;IACH,MAAM,EACL,OAAO,GAAG,CAAC,EACX,OAAO,GAAG,CAAC,EACX,YAAY,GAAG,EAAE,EACjB,kBAAkB,EAClB,GAAG,OAAO,CAAC;IAEZ,IAAI,kBAAkB,IAAI,IAAI,CAAC,eAAe,EAAE;QAC/C,OAAO;KACP;IAED,MAAM,EAAC,QAAQ,EAAC,GAAG,IAAI,CAAC;IAExB,IAAI,QAAQ,EAAE;QACb,IAAI,QAAQ,CAAC,UAAU,EAAE,KAAK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,EAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAC,CAAC,CAAC;gBAC9B,OAAO,GAAG,IAAI,CAAC;aACf;SACD;QAED,IAAI,IAAI,CAAC,QAAQ,KAAK,UAAU,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE;YAChE,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,UAAU,EAAE;gBACxC,kBAAkB,CAAC,SAAuB,EAAE,MAAM,EAAE;oBACnD,OAAO,EAAE,CAAC;oBACV,OAAO,EAAE,CAAC;oBACV,YAAY,EAAE,eAAe;oBAC7B,kBAAkB;iBAClB,CAAC,CAAC;aACH;YAED,IAAI,OAAO,EAAE;gBACZ,MAAM,CAAC,MAAM,EAAE,CAAC;aAChB;SACD;KACD;AACF,CAAC,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
package/build/render.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- /// <reference types="node" />
2
- import { ReactElement } from 'react';
3
- import Ink from './ink';
4
- export interface RenderOptions {
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import { type ReactElement } from 'react';
3
+ import Ink from './ink.js';
4
+ export type RenderOptions = {
5
5
  /**
6
6
  * Output stream where app will be rendered.
7
7
  *
@@ -37,8 +37,8 @@ export interface RenderOptions {
37
37
  * @default true
38
38
  */
39
39
  patchConsole?: boolean;
40
- }
41
- export interface Instance {
40
+ };
41
+ export type Instance = {
42
42
  /**
43
43
  * Replace previous root node with a new one or update props of the current root node.
44
44
  */
@@ -56,8 +56,8 @@ export interface Instance {
56
56
  * Clear output.
57
57
  */
58
58
  clear: () => void;
59
- }
60
- declare type RenderFunction = <Props, K extends NodeJS.WriteStream | RenderOptions>(tree: ReactElement<Props>, options?: K) => Instance;
59
+ };
60
+ type RenderFunction = <Props, K extends NodeJS.WriteStream | RenderOptions>(tree: ReactElement<Props>, options?: K) => Instance;
61
61
  /**
62
62
  * Mount a component and render the output.
63
63
  */
package/build/render.js CHANGED
@@ -1,29 +1,35 @@
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
- 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 = Object.assign({ stdout: process.stdout, stdin: process.stdin, stderr: process.stderr, debug: false, exitOnCtrlC: true, patchConsole: true }, getOptions(options));
14
- const instance = getInstance(inkOptions.stdout, () => new ink_1.default(inkOptions));
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: () => instance.unmount(),
22
+ unmount() {
23
+ instance.unmount();
24
+ },
19
25
  waitUntilExit: instance.waitUntilExit,
20
- cleanup: () => instances_1.default.delete(inkOptions.stdout),
26
+ cleanup: () => instances.delete(inkOptions.stdout),
21
27
  clear: instance.clear
22
28
  };
23
29
  };
24
- exports.default = render;
30
+ export default render;
25
31
  const getOptions = (stdout = {}) => {
26
- if (stdout instanceof stream_1.Stream) {
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 (instances_1.default.has(stdout)) {
37
- instance = instances_1.default.get(stdout);
38
- }
39
- else {
41
+ let instance = instances.get(stdout);
42
+ if (!instance) {
40
43
  instance = createInstance();
41
- instances_1.default.set(stdout, instance);
44
+ instances.set(stdout, instance);
42
45
  }
43
46
  return instance;
44
47
  };
@@ -1 +1 @@
1
- {"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":";;;;;AACA,gDAAiD;AACjD,4DAAoC;AACpC,mCAA8B;AAmE9B;;GAEG;AACH,MAAM,MAAM,GAAmB,CAAC,IAAI,EAAE,OAAO,EAAY,EAAE;IAC1D,MAAM,UAAU,mBACf,MAAM,EAAE,OAAO,CAAC,MAAM,EACtB,KAAK,EAAE,OAAO,CAAC,KAAK,EACpB,MAAM,EAAE,OAAO,CAAC,MAAM,EACtB,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,IAAI,EACjB,YAAY,EAAE,IAAI,IACf,UAAU,CAAC,OAAO,CAAC,CACtB,CAAC;IAEF,MAAM,QAAQ,GAAQ,WAAW,CAChC,UAAU,CAAC,MAAM,EACjB,GAAG,EAAE,CAAC,IAAI,aAAG,CAAC,UAAU,CAAC,CACzB,CAAC;IAEF,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAEtB,OAAO;QACN,QAAQ,EAAE,QAAQ,CAAC,MAAM;QACzB,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE;QACjC,aAAa,EAAE,QAAQ,CAAC,aAAa;QACrC,OAAO,EAAE,GAAG,EAAE,CAAC,mBAAS,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC;QAClD,KAAK,EAAE,QAAQ,CAAC,KAAK;KACrB,CAAC;AACH,CAAC,CAAC;AAEF,kBAAe,MAAM,CAAC;AAEtB,MAAM,UAAU,GAAG,CAClB,SAAyD,EAAE,EAC3C,EAAE;IAClB,IAAI,MAAM,YAAY,eAAM,EAAE;QAC7B,OAAO;YACN,MAAM;YACN,KAAK,EAAE,OAAO,CAAC,KAAK;SACpB,CAAC;KACF;IAED,OAAO,MAAM,CAAC;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EAAE,QAAQ,CAAC,aAAa;QACrC,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC;QAClD,KAAK,EAAE,QAAQ,CAAC,KAAK;KACrB,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,MAAM,CAAC;AAEtB,MAAM,UAAU,GAAG,CAClB,SAAyD,EAAE,EAC3C,EAAE;IAClB,IAAI,MAAM,YAAY,MAAM,EAAE;QAC7B,OAAO;YACN,MAAM;YACN,KAAK,EAAE,OAAO,CAAC,KAAK;SACpB,CAAC;KACF;IAED,OAAO,MAAM,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,CACnB,MAA0B,EAC1B,cAAyB,EACnB,EAAE;IACR,IAAI,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAErC,IAAI,CAAC,QAAQ,EAAE;QACd,QAAQ,GAAG,cAAc,EAAE,CAAC;QAC5B,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;KAChC;IAED,OAAO,QAAQ,CAAC;AACjB,CAAC,CAAC"}
@@ -1,8 +1,8 @@
1
- import { DOMElement } from './dom';
2
- interface Result {
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 _default: (node: DOMElement, terminalWidth: number) => Result;
8
- export default _default;
6
+ };
7
+ declare const renderer: (node: DOMElement) => Result;
8
+ export default renderer;
package/build/renderer.js CHANGED
@@ -1,28 +1,19 @@
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
- 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;
11
- node.yogaNode.setWidth(terminalWidth);
1
+ import renderNodeToOutput from './render-node-to-output.js';
2
+ import Output from './output.js';
3
+ const renderer = (node) => {
12
4
  if (node.yogaNode) {
13
- node.yogaNode.calculateLayout(undefined, undefined, yoga_layout_prebuilt_1.default.DIRECTION_LTR);
14
- const output = new output_1.default({
5
+ const output = new Output({
15
6
  width: node.yogaNode.getComputedWidth(),
16
7
  height: node.yogaNode.getComputedHeight()
17
8
  });
18
- render_node_to_output_1.default(node, output, { skipStaticElements: true });
9
+ renderNodeToOutput(node, output, { skipStaticElements: true });
19
10
  let staticOutput;
20
- if ((_a = node.staticNode) === null || _a === void 0 ? void 0 : _a.yogaNode) {
21
- staticOutput = new output_1.default({
11
+ if (node.staticNode?.yogaNode) {
12
+ staticOutput = new Output({
22
13
  width: node.staticNode.yogaNode.getComputedWidth(),
23
14
  height: node.staticNode.yogaNode.getComputedHeight()
24
15
  });
25
- render_node_to_output_1.default(node.staticNode, staticOutput, {
16
+ renderNodeToOutput(node.staticNode, staticOutput, {
26
17
  skipStaticElements: false
27
18
  });
28
19
  }
@@ -41,4 +32,5 @@ exports.default = (node, terminalWidth) => {
41
32
  staticOutput: ''
42
33
  };
43
34
  };
35
+ export default renderer;
44
36
  //# sourceMappingURL=renderer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"renderer.js","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":";;;;;AAAA,gFAAwC;AACxC,oFAAyD;AACzD,sDAA8B;AAS9B,kBAAe,CAAC,IAAgB,EAAE,aAAqB,EAAU,EAAE;;IAClE,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,8BAAI,CAAC,aAAa,CAAC,CAAC;QAExE,MAAM,MAAM,GAAG,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) => string;
3
3
  export default squashTextNodes;
@@ -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
- exports.default = squashTextNodes;
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":";;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,kBAAe,eAAe,CAAC"}
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,10 +1,18 @@
1
- import { YogaNode } from 'yoga-layout-prebuilt';
2
- import { Boxes } from 'cli-boxes';
3
- import { LiteralUnion } from 'type-fest';
4
- import { ForegroundColor } from 'chalk';
5
- export interface Styles {
1
+ import { type Boxes } from 'cli-boxes';
2
+ import { type LiteralUnion } from 'type-fest';
3
+ import { type ForegroundColorName } from 'chalk';
4
+ import { type Node as YogaNode } from 'yoga-wasm-web/auto';
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
+ /**
9
+ * Gap between element's columns.
10
+ */
11
+ readonly columnGap?: number;
12
+ /**
13
+ * Gap between element's rows.
14
+ */
15
+ readonly rowGap?: number;
8
16
  /**
9
17
  * Top margin.
10
18
  */
@@ -57,6 +65,11 @@ export interface Styles {
57
65
  * See [flex-basis](https://css-tricks.com/almanac/properties/f/flex-basis/).
58
66
  */
59
67
  readonly flexBasis?: number | string;
68
+ /**
69
+ * It defines whether the flex items are forced in a single line or can be flowed into multiple lines. If set to multiple lines, it also defines the cross-axis which determines the direction new lines are stacked in.
70
+ * See [flex-wrap](https://css-tricks.com/almanac/properties/f/flex-wrap/).
71
+ */
72
+ readonly flexWrap?: 'nowrap' | 'wrap' | 'wrap-reverse';
60
73
  /**
61
74
  * The align-items property defines the default behavior for how items are laid out along the cross axis (perpendicular to the main axis).
62
75
  * See [align-items](https://css-tricks.com/almanac/properties/a/align-items/).
@@ -103,7 +116,15 @@ export interface Styles {
103
116
  * Change border color.
104
117
  * Accepts the same values as `color` in <Text> component.
105
118
  */
106
- readonly borderColor?: LiteralUnion<typeof ForegroundColor, string>;
107
- }
108
- declare const _default: (node: YogaNode, style?: Styles) => void;
109
- export default _default;
119
+ readonly borderColor?: LiteralUnion<ForegroundColorName, string>;
120
+ /**
121
+ * Behavior for an element's overflow in horizontal direction.
122
+ */
123
+ readonly overflowX?: 'visible' | 'hidden';
124
+ /**
125
+ * Behavior for an element's overflow in vertical direction.
126
+ */
127
+ readonly overflowY?: 'visible' | 'hidden';
128
+ };
129
+ declare const styles: (node: YogaNode, style?: Styles) => void;
130
+ export default styles;
package/build/styles.js CHANGED
@@ -1,65 +1,70 @@
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
- /* eslint-disable @typescript-eslint/prefer-nullish-coalescing */
7
- const yoga_layout_prebuilt_1 = __importDefault(require("yoga-layout-prebuilt"));
1
+ // eslint-disable-next-line n/file-extension-in-import
2
+ import Yoga from 'yoga-wasm-web/auto';
8
3
  const applyPositionStyles = (node, style) => {
9
4
  if ('position' in style) {
10
5
  node.setPositionType(style.position === 'absolute'
11
- ? yoga_layout_prebuilt_1.default.POSITION_TYPE_ABSOLUTE
12
- : yoga_layout_prebuilt_1.default.POSITION_TYPE_RELATIVE);
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(yoga_layout_prebuilt_1.default.EDGE_START, style.marginLeft || 0);
12
+ node.setMargin(Yoga.EDGE_START, style.marginLeft || 0);
18
13
  }
19
14
  if ('marginRight' in style) {
20
- node.setMargin(yoga_layout_prebuilt_1.default.EDGE_END, style.marginRight || 0);
15
+ node.setMargin(Yoga.EDGE_END, style.marginRight || 0);
21
16
  }
22
17
  if ('marginTop' in style) {
23
- node.setMargin(yoga_layout_prebuilt_1.default.EDGE_TOP, style.marginTop || 0);
18
+ node.setMargin(Yoga.EDGE_TOP, style.marginTop || 0);
24
19
  }
25
20
  if ('marginBottom' in style) {
26
- node.setMargin(yoga_layout_prebuilt_1.default.EDGE_BOTTOM, style.marginBottom || 0);
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(yoga_layout_prebuilt_1.default.EDGE_LEFT, style.paddingLeft || 0);
26
+ node.setPadding(Yoga.EDGE_LEFT, style.paddingLeft || 0);
32
27
  }
33
28
  if ('paddingRight' in style) {
34
- node.setPadding(yoga_layout_prebuilt_1.default.EDGE_RIGHT, style.paddingRight || 0);
29
+ node.setPadding(Yoga.EDGE_RIGHT, style.paddingRight || 0);
35
30
  }
36
31
  if ('paddingTop' in style) {
37
- node.setPadding(yoga_layout_prebuilt_1.default.EDGE_TOP, style.paddingTop || 0);
32
+ node.setPadding(Yoga.EDGE_TOP, style.paddingTop || 0);
38
33
  }
39
34
  if ('paddingBottom' in style) {
40
- node.setPadding(yoga_layout_prebuilt_1.default.EDGE_BOTTOM, style.paddingBottom || 0);
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((_a = style.flexGrow) !== null && _a !== void 0 ? _a : 0);
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
  }
45
+ if ('flexWrap' in style) {
46
+ if (style.flexWrap === 'nowrap') {
47
+ node.setFlexWrap(Yoga.WRAP_NO_WRAP);
48
+ }
49
+ if (style.flexWrap === 'wrap') {
50
+ node.setFlexWrap(Yoga.WRAP_WRAP);
51
+ }
52
+ if (style.flexWrap === 'wrap-reverse') {
53
+ node.setFlexWrap(Yoga.WRAP_WRAP_REVERSE);
54
+ }
55
+ }
51
56
  if ('flexDirection' in style) {
52
57
  if (style.flexDirection === 'row') {
53
- node.setFlexDirection(yoga_layout_prebuilt_1.default.FLEX_DIRECTION_ROW);
58
+ node.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
54
59
  }
55
60
  if (style.flexDirection === 'row-reverse') {
56
- node.setFlexDirection(yoga_layout_prebuilt_1.default.FLEX_DIRECTION_ROW_REVERSE);
61
+ node.setFlexDirection(Yoga.FLEX_DIRECTION_ROW_REVERSE);
57
62
  }
58
63
  if (style.flexDirection === 'column') {
59
- node.setFlexDirection(yoga_layout_prebuilt_1.default.FLEX_DIRECTION_COLUMN);
64
+ node.setFlexDirection(Yoga.FLEX_DIRECTION_COLUMN);
60
65
  }
61
66
  if (style.flexDirection === 'column-reverse') {
62
- node.setFlexDirection(yoga_layout_prebuilt_1.default.FLEX_DIRECTION_COLUMN_REVERSE);
67
+ node.setFlexDirection(Yoga.FLEX_DIRECTION_COLUMN_REVERSE);
63
68
  }
64
69
  }
65
70
  if ('flexBasis' in style) {
@@ -71,57 +76,56 @@ const applyFlexStyles = (node, style) => {
71
76
  }
72
77
  else {
73
78
  // This should be replaced with node.setFlexBasisAuto() when new Yoga release is out
74
- node.setFlexBasis(NaN);
79
+ node.setFlexBasis(Number.NaN);
75
80
  }
76
81
  }
77
82
  if ('alignItems' in style) {
78
83
  if (style.alignItems === 'stretch' || !style.alignItems) {
79
- node.setAlignItems(yoga_layout_prebuilt_1.default.ALIGN_STRETCH);
84
+ node.setAlignItems(Yoga.ALIGN_STRETCH);
80
85
  }
81
86
  if (style.alignItems === 'flex-start') {
82
- node.setAlignItems(yoga_layout_prebuilt_1.default.ALIGN_FLEX_START);
87
+ node.setAlignItems(Yoga.ALIGN_FLEX_START);
83
88
  }
84
89
  if (style.alignItems === 'center') {
85
- node.setAlignItems(yoga_layout_prebuilt_1.default.ALIGN_CENTER);
90
+ node.setAlignItems(Yoga.ALIGN_CENTER);
86
91
  }
87
92
  if (style.alignItems === 'flex-end') {
88
- node.setAlignItems(yoga_layout_prebuilt_1.default.ALIGN_FLEX_END);
93
+ node.setAlignItems(Yoga.ALIGN_FLEX_END);
89
94
  }
90
95
  }
91
96
  if ('alignSelf' in style) {
92
97
  if (style.alignSelf === 'auto' || !style.alignSelf) {
93
- node.setAlignSelf(yoga_layout_prebuilt_1.default.ALIGN_AUTO);
98
+ node.setAlignSelf(Yoga.ALIGN_AUTO);
94
99
  }
95
100
  if (style.alignSelf === 'flex-start') {
96
- node.setAlignSelf(yoga_layout_prebuilt_1.default.ALIGN_FLEX_START);
101
+ node.setAlignSelf(Yoga.ALIGN_FLEX_START);
97
102
  }
98
103
  if (style.alignSelf === 'center') {
99
- node.setAlignSelf(yoga_layout_prebuilt_1.default.ALIGN_CENTER);
104
+ node.setAlignSelf(Yoga.ALIGN_CENTER);
100
105
  }
101
106
  if (style.alignSelf === 'flex-end') {
102
- node.setAlignSelf(yoga_layout_prebuilt_1.default.ALIGN_FLEX_END);
107
+ node.setAlignSelf(Yoga.ALIGN_FLEX_END);
103
108
  }
104
109
  }
105
110
  if ('justifyContent' in style) {
106
111
  if (style.justifyContent === 'flex-start' || !style.justifyContent) {
107
- node.setJustifyContent(yoga_layout_prebuilt_1.default.JUSTIFY_FLEX_START);
112
+ node.setJustifyContent(Yoga.JUSTIFY_FLEX_START);
108
113
  }
109
114
  if (style.justifyContent === 'center') {
110
- node.setJustifyContent(yoga_layout_prebuilt_1.default.JUSTIFY_CENTER);
115
+ node.setJustifyContent(Yoga.JUSTIFY_CENTER);
111
116
  }
112
117
  if (style.justifyContent === 'flex-end') {
113
- node.setJustifyContent(yoga_layout_prebuilt_1.default.JUSTIFY_FLEX_END);
118
+ node.setJustifyContent(Yoga.JUSTIFY_FLEX_END);
114
119
  }
115
120
  if (style.justifyContent === 'space-between') {
116
- node.setJustifyContent(yoga_layout_prebuilt_1.default.JUSTIFY_SPACE_BETWEEN);
121
+ node.setJustifyContent(Yoga.JUSTIFY_SPACE_BETWEEN);
117
122
  }
118
123
  if (style.justifyContent === 'space-around') {
119
- node.setJustifyContent(yoga_layout_prebuilt_1.default.JUSTIFY_SPACE_AROUND);
124
+ node.setJustifyContent(Yoga.JUSTIFY_SPACE_AROUND);
120
125
  }
121
126
  }
122
127
  };
123
128
  const applyDimensionStyles = (node, style) => {
124
- var _a, _b;
125
129
  if ('width' in style) {
126
130
  if (typeof style.width === 'number') {
127
131
  node.setWidth(style.width);
@@ -149,7 +153,7 @@ const applyDimensionStyles = (node, style) => {
149
153
  node.setMinWidthPercent(Number.parseInt(style.minWidth, 10));
150
154
  }
151
155
  else {
152
- node.setMinWidth((_a = style.minWidth) !== null && _a !== void 0 ? _a : 0);
156
+ node.setMinWidth(style.minWidth ?? 0);
153
157
  }
154
158
  }
155
159
  if ('minHeight' in style) {
@@ -157,25 +161,33 @@ const applyDimensionStyles = (node, style) => {
157
161
  node.setMinHeightPercent(Number.parseInt(style.minHeight, 10));
158
162
  }
159
163
  else {
160
- node.setMinHeight((_b = style.minHeight) !== null && _b !== void 0 ? _b : 0);
164
+ node.setMinHeight(style.minHeight ?? 0);
161
165
  }
162
166
  }
163
167
  };
164
168
  const applyDisplayStyles = (node, style) => {
165
169
  if ('display' in style) {
166
- node.setDisplay(style.display === 'flex' ? yoga_layout_prebuilt_1.default.DISPLAY_FLEX : yoga_layout_prebuilt_1.default.DISPLAY_NONE);
170
+ node.setDisplay(style.display === 'flex' ? Yoga.DISPLAY_FLEX : Yoga.DISPLAY_NONE);
167
171
  }
168
172
  };
169
173
  const applyBorderStyles = (node, style) => {
170
174
  if ('borderStyle' in style) {
171
175
  const borderWidth = typeof style.borderStyle === 'string' ? 1 : 0;
172
- node.setBorder(yoga_layout_prebuilt_1.default.EDGE_TOP, borderWidth);
173
- node.setBorder(yoga_layout_prebuilt_1.default.EDGE_BOTTOM, borderWidth);
174
- node.setBorder(yoga_layout_prebuilt_1.default.EDGE_LEFT, borderWidth);
175
- node.setBorder(yoga_layout_prebuilt_1.default.EDGE_RIGHT, borderWidth);
176
+ node.setBorder(Yoga.EDGE_TOP, borderWidth);
177
+ node.setBorder(Yoga.EDGE_BOTTOM, borderWidth);
178
+ node.setBorder(Yoga.EDGE_LEFT, borderWidth);
179
+ node.setBorder(Yoga.EDGE_RIGHT, borderWidth);
180
+ }
181
+ };
182
+ const applyGapStyles = (node, style) => {
183
+ if ('columnGap' in style) {
184
+ node.setGap(Yoga.GUTTER_COLUMN, style.columnGap ?? 0);
185
+ }
186
+ if ('rowGap' in style) {
187
+ node.setGap(Yoga.GUTTER_ROW, style.rowGap ?? 0);
176
188
  }
177
189
  };
178
- exports.default = (node, style = {}) => {
190
+ const styles = (node, style = {}) => {
179
191
  applyPositionStyles(node, style);
180
192
  applyMarginStyles(node, style);
181
193
  applyPaddingStyles(node, style);
@@ -183,5 +195,7 @@ exports.default = (node, style = {}) => {
183
195
  applyDimensionStyles(node, style);
184
196
  applyDisplayStyles(node, style);
185
197
  applyBorderStyles(node, style);
198
+ applyGapStyles(node, style);
186
199
  };
200
+ export default styles;
187
201
  //# sourceMappingURL=styles.js.map