@jrichman/ink 6.3.1

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 (141) hide show
  1. package/build/colorize.d.ts +3 -0
  2. package/build/colorize.js +48 -0
  3. package/build/colorize.js.map +1 -0
  4. package/build/components/AccessibilityContext.d.ts +3 -0
  5. package/build/components/AccessibilityContext.js +5 -0
  6. package/build/components/AccessibilityContext.js.map +1 -0
  7. package/build/components/App.d.ts +59 -0
  8. package/build/components/App.js +286 -0
  9. package/build/components/App.js.map +1 -0
  10. package/build/components/AppContext.d.ts +11 -0
  11. package/build/components/AppContext.js +11 -0
  12. package/build/components/AppContext.js.map +1 -0
  13. package/build/components/BackgroundContext.d.ts +4 -0
  14. package/build/components/BackgroundContext.js +3 -0
  15. package/build/components/BackgroundContext.js.map +1 -0
  16. package/build/components/Box.d.ts +122 -0
  17. package/build/components/Box.js +34 -0
  18. package/build/components/Box.js.map +1 -0
  19. package/build/components/ErrorOverview.d.ts +6 -0
  20. package/build/components/ErrorOverview.js +84 -0
  21. package/build/components/ErrorOverview.js.map +1 -0
  22. package/build/components/FocusContext.d.ts +16 -0
  23. package/build/components/FocusContext.js +17 -0
  24. package/build/components/FocusContext.js.map +1 -0
  25. package/build/components/Newline.d.ts +13 -0
  26. package/build/components/Newline.js +8 -0
  27. package/build/components/Newline.js.map +1 -0
  28. package/build/components/Spacer.d.ts +7 -0
  29. package/build/components/Spacer.js +11 -0
  30. package/build/components/Spacer.js.map +1 -0
  31. package/build/components/Static.d.ts +24 -0
  32. package/build/components/Static.js +28 -0
  33. package/build/components/Static.js.map +1 -0
  34. package/build/components/StderrContext.d.ts +15 -0
  35. package/build/components/StderrContext.js +13 -0
  36. package/build/components/StderrContext.js.map +1 -0
  37. package/build/components/StdinContext.d.ts +22 -0
  38. package/build/components/StdinContext.js +19 -0
  39. package/build/components/StdinContext.js.map +1 -0
  40. package/build/components/StdoutContext.d.ts +15 -0
  41. package/build/components/StdoutContext.js +13 -0
  42. package/build/components/StdoutContext.js.map +1 -0
  43. package/build/components/Text.d.ts +55 -0
  44. package/build/components/Text.js +50 -0
  45. package/build/components/Text.js.map +1 -0
  46. package/build/components/Transform.d.ts +16 -0
  47. package/build/components/Transform.js +15 -0
  48. package/build/components/Transform.js.map +1 -0
  49. package/build/devtools-window-polyfill.d.ts +1 -0
  50. package/build/devtools-window-polyfill.js +65 -0
  51. package/build/devtools-window-polyfill.js.map +1 -0
  52. package/build/devtools.d.ts +1 -0
  53. package/build/devtools.js +2 -0
  54. package/build/devtools.js.map +1 -0
  55. package/build/dom.d.ts +62 -0
  56. package/build/dom.js +123 -0
  57. package/build/dom.js.map +1 -0
  58. package/build/get-max-width.d.ts +3 -0
  59. package/build/get-max-width.js +10 -0
  60. package/build/get-max-width.js.map +1 -0
  61. package/build/hooks/use-app.d.ts +5 -0
  62. package/build/hooks/use-app.js +8 -0
  63. package/build/hooks/use-app.js.map +1 -0
  64. package/build/hooks/use-focus-manager.d.ts +28 -0
  65. package/build/hooks/use-focus-manager.js +17 -0
  66. package/build/hooks/use-focus-manager.js.map +1 -0
  67. package/build/hooks/use-focus.d.ts +29 -0
  68. package/build/hooks/use-focus.js +42 -0
  69. package/build/hooks/use-focus.js.map +1 -0
  70. package/build/hooks/use-input.d.ts +93 -0
  71. package/build/hooks/use-input.js +93 -0
  72. package/build/hooks/use-input.js.map +1 -0
  73. package/build/hooks/use-is-screen-reader-enabled.d.ts +5 -0
  74. package/build/hooks/use-is-screen-reader-enabled.js +11 -0
  75. package/build/hooks/use-is-screen-reader-enabled.js.map +1 -0
  76. package/build/hooks/use-stderr.d.ts +5 -0
  77. package/build/hooks/use-stderr.js +8 -0
  78. package/build/hooks/use-stderr.js.map +1 -0
  79. package/build/hooks/use-stdin.d.ts +5 -0
  80. package/build/hooks/use-stdin.js +8 -0
  81. package/build/hooks/use-stdin.js.map +1 -0
  82. package/build/hooks/use-stdout.d.ts +5 -0
  83. package/build/hooks/use-stdout.js +8 -0
  84. package/build/hooks/use-stdout.js.map +1 -0
  85. package/build/index.d.ts +28 -0
  86. package/build/index.js +17 -0
  87. package/build/index.js.map +1 -0
  88. package/build/ink.d.ts +43 -0
  89. package/build/ink.js +315 -0
  90. package/build/ink.js.map +1 -0
  91. package/build/instances.d.ts +3 -0
  92. package/build/instances.js +8 -0
  93. package/build/instances.js.map +1 -0
  94. package/build/log-update.d.ts +15 -0
  95. package/build/log-update.js +109 -0
  96. package/build/log-update.js.map +1 -0
  97. package/build/measure-element.d.ts +38 -0
  98. package/build/measure-element.js +118 -0
  99. package/build/measure-element.js.map +1 -0
  100. package/build/measure-text.d.ts +6 -0
  101. package/build/measure-text.js +21 -0
  102. package/build/measure-text.js.map +1 -0
  103. package/build/output.d.ts +36 -0
  104. package/build/output.js +191 -0
  105. package/build/output.js.map +1 -0
  106. package/build/parse-keypress.d.ts +14 -0
  107. package/build/parse-keypress.js +225 -0
  108. package/build/parse-keypress.js.map +1 -0
  109. package/build/reconciler.d.ts +4 -0
  110. package/build/reconciler.js +254 -0
  111. package/build/reconciler.js.map +1 -0
  112. package/build/render-background.d.ts +4 -0
  113. package/build/render-background.js +25 -0
  114. package/build/render-background.js.map +1 -0
  115. package/build/render-border.d.ts +4 -0
  116. package/build/render-border.js +73 -0
  117. package/build/render-border.js.map +1 -0
  118. package/build/render-node-to-output.d.ts +14 -0
  119. package/build/render-node-to-output.js +296 -0
  120. package/build/render-node-to-output.js.map +1 -0
  121. package/build/render.d.ts +87 -0
  122. package/build/render.js +50 -0
  123. package/build/render.js.map +1 -0
  124. package/build/renderer.d.ts +8 -0
  125. package/build/renderer.js +55 -0
  126. package/build/renderer.js.map +1 -0
  127. package/build/scroll.d.ts +8 -0
  128. package/build/scroll.js +35 -0
  129. package/build/scroll.js.map +1 -0
  130. package/build/squash-text-nodes.d.ts +3 -0
  131. package/build/squash-text-nodes.js +35 -0
  132. package/build/squash-text-nodes.js.map +1 -0
  133. package/build/styles.d.ts +260 -0
  134. package/build/styles.js +257 -0
  135. package/build/styles.js.map +1 -0
  136. package/build/wrap-text.d.ts +3 -0
  137. package/build/wrap-text.js +31 -0
  138. package/build/wrap-text.js.map +1 -0
  139. package/license +9 -0
  140. package/package.json +194 -0
  141. package/readme.md +2331 -0
@@ -0,0 +1,260 @@
1
+ import { type Boxes, type BoxStyle } from 'cli-boxes';
2
+ import { type LiteralUnion } from 'type-fest';
3
+ import { type ForegroundColorName } from 'ansi-styles';
4
+ import { type Node as YogaNode } from 'yoga-layout';
5
+ export type Styles = {
6
+ readonly textWrap?: 'wrap' | 'end' | 'middle' | 'truncate-end' | 'truncate' | 'truncate-middle' | 'truncate-start';
7
+ readonly position?: 'absolute' | 'relative';
8
+ /**
9
+ Size of the gap between an element's columns.
10
+ */
11
+ readonly columnGap?: number;
12
+ /**
13
+ Size of the gap between an element's rows.
14
+ */
15
+ readonly rowGap?: number;
16
+ /**
17
+ Size of the gap between an element's columns and rows. A shorthand for `columnGap` and `rowGap`.
18
+ */
19
+ readonly gap?: number;
20
+ /**
21
+ Margin on all sides. Equivalent to setting `marginTop`, `marginBottom`, `marginLeft`, and `marginRight`.
22
+ */
23
+ readonly margin?: number;
24
+ /**
25
+ Horizontal margin. Equivalent to setting `marginLeft` and `marginRight`.
26
+ */
27
+ readonly marginX?: number;
28
+ /**
29
+ Vertical margin. Equivalent to setting `marginTop` and `marginBottom`.
30
+ */
31
+ readonly marginY?: number;
32
+ /**
33
+ Top margin.
34
+ */
35
+ readonly marginTop?: number;
36
+ /**
37
+ Bottom margin.
38
+ */
39
+ readonly marginBottom?: number;
40
+ /**
41
+ Left margin.
42
+ */
43
+ readonly marginLeft?: number;
44
+ /**
45
+ Right margin.
46
+ */
47
+ readonly marginRight?: number;
48
+ /**
49
+ Padding on all sides. Equivalent to setting `paddingTop`, `paddingBottom`, `paddingLeft`, and `paddingRight`.
50
+ */
51
+ readonly padding?: number;
52
+ /**
53
+ Horizontal padding. Equivalent to setting `paddingLeft` and `paddingRight`.
54
+ */
55
+ readonly paddingX?: number;
56
+ /**
57
+ Vertical padding. Equivalent to setting `paddingTop` and `paddingBottom`.
58
+ */
59
+ readonly paddingY?: number;
60
+ /**
61
+ Top padding.
62
+ */
63
+ readonly paddingTop?: number;
64
+ /**
65
+ Bottom padding.
66
+ */
67
+ readonly paddingBottom?: number;
68
+ /**
69
+ Left padding.
70
+ */
71
+ readonly paddingLeft?: number;
72
+ /**
73
+ Right padding.
74
+ */
75
+ readonly paddingRight?: number;
76
+ /**
77
+ This property defines the ability for a flex item to grow if necessary.
78
+ See [flex-grow](https://css-tricks.com/almanac/properties/f/flex-grow/).
79
+ */
80
+ readonly flexGrow?: number;
81
+ /**
82
+ It specifies the “flex shrink factor”, which determines how much the flex item will shrink relative to the rest of the flex items in the flex container when there isn’t enough space on the row.
83
+ See [flex-shrink](https://css-tricks.com/almanac/properties/f/flex-shrink/).
84
+ */
85
+ readonly flexShrink?: number;
86
+ /**
87
+ It establishes the main-axis, thus defining the direction flex items are placed in the flex container.
88
+ See [flex-direction](https://css-tricks.com/almanac/properties/f/flex-direction/).
89
+ */
90
+ readonly flexDirection?: 'row' | 'column' | 'row-reverse' | 'column-reverse';
91
+ /**
92
+ It specifies the initial size of the flex item, before any available space is distributed according to the flex factors.
93
+ See [flex-basis](https://css-tricks.com/almanac/properties/f/flex-basis/).
94
+ */
95
+ readonly flexBasis?: number | string;
96
+ /**
97
+ 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.
98
+ See [flex-wrap](https://css-tricks.com/almanac/properties/f/flex-wrap/).
99
+ */
100
+ readonly flexWrap?: 'nowrap' | 'wrap' | 'wrap-reverse';
101
+ /**
102
+ The align-items property defines the default behavior for how items are laid out along the cross axis (perpendicular to the main axis).
103
+ See [align-items](https://css-tricks.com/almanac/properties/a/align-items/).
104
+ */
105
+ readonly alignItems?: 'flex-start' | 'center' | 'flex-end' | 'stretch';
106
+ /**
107
+ It makes possible to override the align-items value for specific flex items.
108
+ See [align-self](https://css-tricks.com/almanac/properties/a/align-self/).
109
+ */
110
+ readonly alignSelf?: 'flex-start' | 'center' | 'flex-end' | 'auto';
111
+ /**
112
+ It defines the alignment along the main axis.
113
+ See [justify-content](https://css-tricks.com/almanac/properties/j/justify-content/).
114
+ */
115
+ readonly justifyContent?: 'flex-start' | 'flex-end' | 'space-between' | 'space-around' | 'space-evenly' | 'center';
116
+ /**
117
+ Width of the element in spaces. You can also set it as a percentage, which will calculate the width based on the width of the parent element.
118
+ */
119
+ readonly width?: number | string;
120
+ /**
121
+ Height of the element in lines (rows). You can also set it as a percentage, which will calculate the height based on the height of the parent element.
122
+ */
123
+ readonly height?: number | string;
124
+ /**
125
+ Sets a minimum width of the element.
126
+ */
127
+ readonly minWidth?: number | string;
128
+ /**
129
+ Sets a minimum height of the element.
130
+ */
131
+ readonly minHeight?: number | string;
132
+ /**
133
+ Maximum width of the element.
134
+ */
135
+ readonly maxWidth?: number | string;
136
+ /**
137
+ Maximum height of the element.
138
+ */
139
+ readonly maxHeight?: number | string;
140
+ /**
141
+ Set this property to `none` to hide the element.
142
+ */
143
+ readonly display?: 'flex' | 'none';
144
+ /**
145
+ Add a border with a specified style. If `borderStyle` is `undefined` (the default), no border will be added.
146
+ */
147
+ readonly borderStyle?: keyof Boxes | BoxStyle;
148
+ /**
149
+ Determines whether top border is visible.
150
+
151
+ @default true
152
+ */
153
+ readonly borderTop?: boolean;
154
+ /**
155
+ Determines whether bottom border is visible.
156
+
157
+ @default true
158
+ */
159
+ readonly borderBottom?: boolean;
160
+ /**
161
+ Determines whether left border is visible.
162
+
163
+ @default true
164
+ */
165
+ readonly borderLeft?: boolean;
166
+ /**
167
+ Determines whether right border is visible.
168
+
169
+ @default true
170
+ */
171
+ readonly borderRight?: boolean;
172
+ /**
173
+ Change border color. A shorthand for setting `borderTopColor`, `borderRightColor`, `borderBottomColor`, and `borderLeftColor`.
174
+ */
175
+ readonly borderColor?: LiteralUnion<ForegroundColorName, string>;
176
+ /**
177
+ Change top border color. Accepts the same values as `color` in `Text` component.
178
+ */
179
+ readonly borderTopColor?: LiteralUnion<ForegroundColorName, string>;
180
+ /**
181
+ Change bottom border color. Accepts the same values as `color` in `Text` component.
182
+ */
183
+ readonly borderBottomColor?: LiteralUnion<ForegroundColorName, string>;
184
+ /**
185
+ Change left border color. Accepts the same values as `color` in `Text` component.
186
+ */
187
+ readonly borderLeftColor?: LiteralUnion<ForegroundColorName, string>;
188
+ /**
189
+ Change right border color. Accepts the same values as `color` in `Text` component.
190
+ */
191
+ readonly borderRightColor?: LiteralUnion<ForegroundColorName, string>;
192
+ /**
193
+ Dim the border color. A shorthand for setting `borderTopDimColor`, `borderBottomDimColor`, `borderLeftDimColor`, and `borderRightDimColor`.
194
+
195
+ @default false
196
+ */
197
+ readonly borderDimColor?: boolean;
198
+ /**
199
+ Dim the top border color.
200
+
201
+ @default false
202
+ */
203
+ readonly borderTopDimColor?: boolean;
204
+ /**
205
+ Dim the bottom border color.
206
+
207
+ @default false
208
+ */
209
+ readonly borderBottomDimColor?: boolean;
210
+ /**
211
+ Dim the left border color.
212
+
213
+ @default false
214
+ */
215
+ readonly borderLeftDimColor?: boolean;
216
+ /**
217
+ Dim the right border color.
218
+
219
+ @default false
220
+ */
221
+ readonly borderRightDimColor?: boolean;
222
+ /**
223
+ Behavior for an element's overflow in both directions.
224
+
225
+ @default 'visible'
226
+ */
227
+ readonly overflow?: 'visible' | 'hidden' | 'scroll';
228
+ /**
229
+ Behavior for an element's overflow in the horizontal direction.
230
+
231
+ @default 'visible'
232
+ */
233
+ readonly overflowX?: 'visible' | 'hidden' | 'scroll';
234
+ /**
235
+ Behavior for an element's overflow in the vertical direction.
236
+
237
+ @default 'visible'
238
+ */
239
+ readonly overflowY?: 'visible' | 'hidden' | 'scroll';
240
+ /**
241
+ Background color for the element.
242
+
243
+ Accepts the same values as `color` in the `<Text>` component.
244
+ */
245
+ readonly backgroundColor?: LiteralUnion<ForegroundColorName, string>;
246
+ /**
247
+ Vertical scroll position.
248
+ */
249
+ readonly scrollTop?: number;
250
+ /**
251
+ Horizontal scroll position.
252
+ */
253
+ readonly scrollLeft?: number;
254
+ /**
255
+ Color of the scrollbar thumb.
256
+ */
257
+ readonly scrollbarThumbColor?: LiteralUnion<ForegroundColorName, string>;
258
+ };
259
+ declare const styles: (node: YogaNode, style?: Styles) => void;
260
+ export default styles;
@@ -0,0 +1,257 @@
1
+ import Yoga from 'yoga-layout';
2
+ const applyPositionStyles = (node, style) => {
3
+ if ('position' in style) {
4
+ node.setPositionType(style.position === 'absolute'
5
+ ? Yoga.POSITION_TYPE_ABSOLUTE
6
+ : Yoga.POSITION_TYPE_RELATIVE);
7
+ }
8
+ };
9
+ const applyMarginStyles = (node, style) => {
10
+ if ('margin' in style) {
11
+ node.setMargin(Yoga.EDGE_ALL, style.margin ?? 0);
12
+ }
13
+ if ('marginX' in style) {
14
+ node.setMargin(Yoga.EDGE_HORIZONTAL, style.marginX ?? 0);
15
+ }
16
+ if ('marginY' in style) {
17
+ node.setMargin(Yoga.EDGE_VERTICAL, style.marginY ?? 0);
18
+ }
19
+ if ('marginLeft' in style) {
20
+ node.setMargin(Yoga.EDGE_START, style.marginLeft || 0);
21
+ }
22
+ if ('marginRight' in style) {
23
+ node.setMargin(Yoga.EDGE_END, style.marginRight || 0);
24
+ }
25
+ if ('marginTop' in style) {
26
+ node.setMargin(Yoga.EDGE_TOP, style.marginTop || 0);
27
+ }
28
+ if ('marginBottom' in style) {
29
+ node.setMargin(Yoga.EDGE_BOTTOM, style.marginBottom || 0);
30
+ }
31
+ };
32
+ const applyPaddingStyles = (node, style) => {
33
+ if ('padding' in style) {
34
+ node.setPadding(Yoga.EDGE_ALL, style.padding ?? 0);
35
+ }
36
+ if ('paddingX' in style) {
37
+ node.setPadding(Yoga.EDGE_HORIZONTAL, style.paddingX ?? 0);
38
+ }
39
+ if ('paddingY' in style) {
40
+ node.setPadding(Yoga.EDGE_VERTICAL, style.paddingY ?? 0);
41
+ }
42
+ if ('paddingLeft' in style) {
43
+ node.setPadding(Yoga.EDGE_LEFT, style.paddingLeft || 0);
44
+ }
45
+ if ('paddingRight' in style) {
46
+ node.setPadding(Yoga.EDGE_RIGHT, style.paddingRight || 0);
47
+ }
48
+ if ('paddingTop' in style) {
49
+ node.setPadding(Yoga.EDGE_TOP, style.paddingTop || 0);
50
+ }
51
+ if ('paddingBottom' in style) {
52
+ node.setPadding(Yoga.EDGE_BOTTOM, style.paddingBottom || 0);
53
+ }
54
+ };
55
+ const applyFlexStyles = (node, style) => {
56
+ if ('flexGrow' in style) {
57
+ node.setFlexGrow(style.flexGrow ?? 0);
58
+ }
59
+ if ('flexShrink' in style) {
60
+ node.setFlexShrink(typeof style.flexShrink === 'number' ? style.flexShrink : 1);
61
+ }
62
+ if ('flexWrap' in style) {
63
+ if (style.flexWrap === 'nowrap') {
64
+ node.setFlexWrap(Yoga.WRAP_NO_WRAP);
65
+ }
66
+ if (style.flexWrap === 'wrap') {
67
+ node.setFlexWrap(Yoga.WRAP_WRAP);
68
+ }
69
+ if (style.flexWrap === 'wrap-reverse') {
70
+ node.setFlexWrap(Yoga.WRAP_WRAP_REVERSE);
71
+ }
72
+ }
73
+ if ('flexDirection' in style) {
74
+ if (style.flexDirection === 'row') {
75
+ node.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
76
+ }
77
+ if (style.flexDirection === 'row-reverse') {
78
+ node.setFlexDirection(Yoga.FLEX_DIRECTION_ROW_REVERSE);
79
+ }
80
+ if (style.flexDirection === 'column') {
81
+ node.setFlexDirection(Yoga.FLEX_DIRECTION_COLUMN);
82
+ }
83
+ if (style.flexDirection === 'column-reverse') {
84
+ node.setFlexDirection(Yoga.FLEX_DIRECTION_COLUMN_REVERSE);
85
+ }
86
+ }
87
+ if ('flexBasis' in style) {
88
+ if (typeof style.flexBasis === 'number') {
89
+ node.setFlexBasis(style.flexBasis);
90
+ }
91
+ else if (typeof style.flexBasis === 'string') {
92
+ node.setFlexBasisPercent(Number.parseInt(style.flexBasis, 10));
93
+ }
94
+ else {
95
+ // This should be replaced with node.setFlexBasisAuto() when new Yoga release is out
96
+ node.setFlexBasis(Number.NaN);
97
+ }
98
+ }
99
+ if ('alignItems' in style) {
100
+ if (style.alignItems === 'stretch' || !style.alignItems) {
101
+ node.setAlignItems(Yoga.ALIGN_STRETCH);
102
+ }
103
+ if (style.alignItems === 'flex-start') {
104
+ node.setAlignItems(Yoga.ALIGN_FLEX_START);
105
+ }
106
+ if (style.alignItems === 'center') {
107
+ node.setAlignItems(Yoga.ALIGN_CENTER);
108
+ }
109
+ if (style.alignItems === 'flex-end') {
110
+ node.setAlignItems(Yoga.ALIGN_FLEX_END);
111
+ }
112
+ }
113
+ if ('alignSelf' in style) {
114
+ if (style.alignSelf === 'auto' || !style.alignSelf) {
115
+ node.setAlignSelf(Yoga.ALIGN_AUTO);
116
+ }
117
+ if (style.alignSelf === 'flex-start') {
118
+ node.setAlignSelf(Yoga.ALIGN_FLEX_START);
119
+ }
120
+ if (style.alignSelf === 'center') {
121
+ node.setAlignSelf(Yoga.ALIGN_CENTER);
122
+ }
123
+ if (style.alignSelf === 'flex-end') {
124
+ node.setAlignSelf(Yoga.ALIGN_FLEX_END);
125
+ }
126
+ }
127
+ if ('justifyContent' in style) {
128
+ if (style.justifyContent === 'flex-start' || !style.justifyContent) {
129
+ node.setJustifyContent(Yoga.JUSTIFY_FLEX_START);
130
+ }
131
+ if (style.justifyContent === 'center') {
132
+ node.setJustifyContent(Yoga.JUSTIFY_CENTER);
133
+ }
134
+ if (style.justifyContent === 'flex-end') {
135
+ node.setJustifyContent(Yoga.JUSTIFY_FLEX_END);
136
+ }
137
+ if (style.justifyContent === 'space-between') {
138
+ node.setJustifyContent(Yoga.JUSTIFY_SPACE_BETWEEN);
139
+ }
140
+ if (style.justifyContent === 'space-around') {
141
+ node.setJustifyContent(Yoga.JUSTIFY_SPACE_AROUND);
142
+ }
143
+ if (style.justifyContent === 'space-evenly') {
144
+ node.setJustifyContent(Yoga.JUSTIFY_SPACE_EVENLY);
145
+ }
146
+ }
147
+ };
148
+ const applyDimensionStyles = (node, style) => {
149
+ if ('width' in style) {
150
+ if (typeof style.width === 'number') {
151
+ node.setWidth(style.width);
152
+ }
153
+ else if (typeof style.width === 'string') {
154
+ node.setWidthPercent(Number.parseInt(style.width, 10));
155
+ }
156
+ else {
157
+ node.setWidthAuto();
158
+ }
159
+ }
160
+ if ('height' in style) {
161
+ if (typeof style.height === 'number') {
162
+ node.setHeight(style.height);
163
+ }
164
+ else if (typeof style.height === 'string') {
165
+ node.setHeightPercent(Number.parseInt(style.height, 10));
166
+ }
167
+ else {
168
+ node.setHeightAuto();
169
+ }
170
+ }
171
+ if ('minWidth' in style) {
172
+ if (typeof style.minWidth === 'string') {
173
+ node.setMinWidthPercent(Number.parseInt(style.minWidth, 10));
174
+ }
175
+ else {
176
+ node.setMinWidth(style.minWidth ?? 0);
177
+ }
178
+ }
179
+ if ('minHeight' in style) {
180
+ if (typeof style.minHeight === 'string') {
181
+ node.setMinHeightPercent(Number.parseInt(style.minHeight, 10));
182
+ }
183
+ else {
184
+ node.setMinHeight(style.minHeight ?? 0);
185
+ }
186
+ }
187
+ if ('maxWidth' in style) {
188
+ if (typeof style.maxWidth === 'string') {
189
+ node.setMaxWidthPercent(Number.parseInt(style.maxWidth, 10));
190
+ }
191
+ else {
192
+ node.setMaxWidth(style.maxWidth);
193
+ }
194
+ }
195
+ if ('maxHeight' in style) {
196
+ if (typeof style.maxHeight === 'string') {
197
+ node.setMaxHeightPercent(Number.parseInt(style.maxHeight, 10));
198
+ }
199
+ else {
200
+ node.setMaxHeight(style.maxHeight);
201
+ }
202
+ }
203
+ };
204
+ const applyDisplayStyles = (node, style) => {
205
+ if ('display' in style) {
206
+ node.setDisplay(style.display === 'flex' ? Yoga.DISPLAY_FLEX : Yoga.DISPLAY_NONE);
207
+ }
208
+ };
209
+ const applyBorderStyles = (node, style) => {
210
+ if ('borderStyle' in style) {
211
+ const borderWidth = style.borderStyle ? 1 : 0;
212
+ if (style.borderTop !== false) {
213
+ node.setBorder(Yoga.EDGE_TOP, borderWidth);
214
+ }
215
+ if (style.borderBottom !== false) {
216
+ node.setBorder(Yoga.EDGE_BOTTOM, borderWidth);
217
+ }
218
+ if (style.borderLeft !== false) {
219
+ node.setBorder(Yoga.EDGE_LEFT, borderWidth);
220
+ }
221
+ if (style.borderRight !== false) {
222
+ node.setBorder(Yoga.EDGE_RIGHT, borderWidth);
223
+ }
224
+ }
225
+ };
226
+ const applyGapStyles = (node, style) => {
227
+ if ('gap' in style) {
228
+ node.setGap(Yoga.GUTTER_ALL, style.gap ?? 0);
229
+ }
230
+ if ('columnGap' in style) {
231
+ node.setGap(Yoga.GUTTER_COLUMN, style.columnGap ?? 0);
232
+ }
233
+ if ('rowGap' in style) {
234
+ node.setGap(Yoga.GUTTER_ROW, style.rowGap ?? 0);
235
+ }
236
+ };
237
+ const applyOverflowStyles = (node, style) => {
238
+ const overflow = style.overflow ?? 'visible';
239
+ const overflowX = style.overflowX ?? overflow;
240
+ const overflowY = style.overflowY ?? overflow;
241
+ if (overflowX === 'scroll' || overflowY === 'scroll') {
242
+ node.setOverflow(Yoga.OVERFLOW_SCROLL);
243
+ }
244
+ };
245
+ const styles = (node, style = {}) => {
246
+ applyPositionStyles(node, style);
247
+ applyMarginStyles(node, style);
248
+ applyPaddingStyles(node, style);
249
+ applyFlexStyles(node, style);
250
+ applyDimensionStyles(node, style);
251
+ applyDisplayStyles(node, style);
252
+ applyBorderStyles(node, style);
253
+ applyGapStyles(node, style);
254
+ applyOverflowStyles(node, style);
255
+ };
256
+ export default styles;
257
+ //# sourceMappingURL=styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styles.js","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":"AAIA,OAAO,IAA6B,MAAM,aAAa,CAAC;AAqUxD,MAAM,mBAAmB,GAAG,CAAC,IAAc,EAAE,KAAa,EAAQ,EAAE;IACnE,IAAI,UAAU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Ac,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC5B,mBAAmB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAClC,CAAC,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { type Styles } from './styles.js';
2
+ declare const wrapText: (text: string, maxWidth: number, wrapType: Styles["textWrap"]) => string;
3
+ export default wrapText;
@@ -0,0 +1,31 @@
1
+ import wrapAnsi from 'wrap-ansi';
2
+ import cliTruncate from 'cli-truncate';
3
+ const cache = {};
4
+ const wrapText = (text, maxWidth, wrapType) => {
5
+ const cacheKey = text + String(maxWidth) + String(wrapType);
6
+ const cachedText = cache[cacheKey];
7
+ if (cachedText) {
8
+ return cachedText;
9
+ }
10
+ let wrappedText = text;
11
+ if (wrapType === 'wrap') {
12
+ wrappedText = wrapAnsi(text, maxWidth, {
13
+ trim: false,
14
+ hard: true,
15
+ });
16
+ }
17
+ if (wrapType.startsWith('truncate')) {
18
+ let position = 'end';
19
+ if (wrapType === 'truncate-middle') {
20
+ position = 'middle';
21
+ }
22
+ if (wrapType === 'truncate-start') {
23
+ position = 'start';
24
+ }
25
+ wrappedText = cliTruncate(text, maxWidth, { position });
26
+ }
27
+ cache[cacheKey] = wrappedText;
28
+ return wrappedText;
29
+ };
30
+ export default wrapText;
31
+ //# sourceMappingURL=wrap-text.js.map
@@ -0,0 +1 @@
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,CAAC;QAChB,OAAO,UAAU,CAAC;IACnB,CAAC;IAED,IAAI,WAAW,GAAG,IAAI,CAAC;IAEvB,IAAI,QAAQ,KAAK,MAAM,EAAE,CAAC;QACzB,WAAW,GAAG,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE;YACtC,IAAI,EAAE,KAAK;YACX,IAAI,EAAE,IAAI;SACV,CAAC,CAAC;IACJ,CAAC;IAED,IAAI,QAAS,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QACtC,IAAI,QAAQ,GAA+B,KAAK,CAAC;QAEjD,IAAI,QAAQ,KAAK,iBAAiB,EAAE,CAAC;YACpC,QAAQ,GAAG,QAAQ,CAAC;QACrB,CAAC;QAED,IAAI,QAAQ,KAAK,gBAAgB,EAAE,CAAC;YACnC,QAAQ,GAAG,OAAO,CAAC;QACpB,CAAC;QAED,WAAW,GAAG,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAC,QAAQ,EAAC,CAAC,CAAC;IACvD,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,GAAG,WAAW,CAAC;IAE9B,OAAO,WAAW,CAAC;AACpB,CAAC,CAAC;AAEF,eAAe,QAAQ,CAAC"}
package/license ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) Vadym Demedes <vadimdemedes@hey.com> (github.com/vadimdemedes)
4
+
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
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.