console-toolkit 1.2.8 → 1.2.10

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 (156) hide show
  1. package/README.md +70 -25
  2. package/package.json +26 -6
  3. package/src/alphanumeric/arrows.d.ts +48 -0
  4. package/src/alphanumeric/arrows.js +23 -0
  5. package/src/alphanumeric/fractions.d.ts +65 -0
  6. package/src/alphanumeric/fractions.js +49 -0
  7. package/src/alphanumeric/number-formatters.d.ts +91 -0
  8. package/src/alphanumeric/number-formatters.js +45 -1
  9. package/src/alphanumeric/roman.d.ts +15 -0
  10. package/src/alphanumeric/roman.js +12 -0
  11. package/src/alphanumeric/unicode-cultural-numbers.d.ts +65 -0
  12. package/src/alphanumeric/unicode-cultural-numbers.js +1 -0
  13. package/src/alphanumeric/unicode-letters.d.ts +32 -0
  14. package/src/alphanumeric/unicode-letters.js +8 -0
  15. package/src/alphanumeric/unicode-numbers.d.ts +44 -0
  16. package/src/alphanumeric/unicode-numbers.js +21 -0
  17. package/src/alphanumeric/utils.d.ts +45 -0
  18. package/src/alphanumeric/utils.js +26 -0
  19. package/src/ansi/csi.d.ts +141 -0
  20. package/src/ansi/csi.js +51 -2
  21. package/src/ansi/index.d.ts +26 -0
  22. package/src/ansi/sgr-constants.d.ts +173 -0
  23. package/src/ansi/sgr-state.d.ts +91 -0
  24. package/src/ansi/sgr-state.js +45 -0
  25. package/src/ansi/sgr.d.ts +587 -0
  26. package/src/ansi/sgr.js +426 -6
  27. package/src/box.d.ts +160 -0
  28. package/src/box.js +113 -12
  29. package/src/charts/bars/block-frac-grouped.d.ts +12 -0
  30. package/src/charts/bars/block-frac-grouped.js +6 -0
  31. package/src/charts/bars/block-frac.d.ts +34 -0
  32. package/src/charts/bars/block-frac.js +13 -0
  33. package/src/charts/bars/block-grouped.d.ts +12 -0
  34. package/src/charts/bars/block-grouped.js +6 -0
  35. package/src/charts/bars/block.d.ts +43 -0
  36. package/src/charts/bars/block.js +13 -0
  37. package/src/charts/bars/draw-grouped.d.ts +41 -0
  38. package/src/charts/bars/draw-grouped.js +4 -0
  39. package/src/charts/bars/draw-stacked.d.ts +47 -0
  40. package/src/charts/bars/draw-stacked.js +4 -0
  41. package/src/charts/bars/frac-grouped.d.ts +32 -0
  42. package/src/charts/bars/frac-grouped.js +13 -0
  43. package/src/charts/bars/plain-grouped.d.ts +12 -0
  44. package/src/charts/bars/plain-grouped.js +6 -0
  45. package/src/charts/bars/plain.d.ts +75 -0
  46. package/src/charts/bars/plain.js +27 -0
  47. package/src/charts/columns/block-frac-grouped.d.ts +12 -0
  48. package/src/charts/columns/block-frac-grouped.js +6 -0
  49. package/src/charts/columns/block-frac.d.ts +39 -0
  50. package/src/charts/columns/block-frac.js +13 -0
  51. package/src/charts/columns/block-grouped.d.ts +12 -0
  52. package/src/charts/columns/block-grouped.js +6 -0
  53. package/src/charts/columns/block.d.ts +43 -0
  54. package/src/charts/columns/block.js +13 -0
  55. package/src/charts/columns/draw-grouped.d.ts +41 -0
  56. package/src/charts/columns/draw-grouped.js +4 -0
  57. package/src/charts/columns/draw-stacked.d.ts +39 -0
  58. package/src/charts/columns/draw-stacked.js +4 -0
  59. package/src/charts/columns/frac-grouped.d.ts +37 -0
  60. package/src/charts/columns/frac-grouped.js +13 -0
  61. package/src/charts/columns/plain-grouped.d.ts +12 -0
  62. package/src/charts/columns/plain-grouped.js +6 -0
  63. package/src/charts/columns/plain.d.ts +32 -0
  64. package/src/charts/columns/plain.js +13 -0
  65. package/src/charts/themes/default.d.ts +6 -0
  66. package/src/charts/themes/default.js +1 -0
  67. package/src/charts/themes/rainbow-reversed.d.ts +6 -0
  68. package/src/charts/themes/rainbow-reversed.js +2 -1
  69. package/src/charts/themes/rainbow.d.ts +6 -0
  70. package/src/charts/themes/rainbow.js +1 -0
  71. package/src/charts/utils.d.ts +79 -0
  72. package/src/charts/utils.js +32 -4
  73. package/src/draw-block-frac.d.ts +16 -0
  74. package/src/draw-block-frac.js +14 -0
  75. package/src/draw-block.d.ts +53 -0
  76. package/src/draw-block.js +25 -1
  77. package/src/meta.d.ts +84 -0
  78. package/src/meta.js +64 -0
  79. package/src/output/show.d.ts +55 -0
  80. package/src/output/show.js +28 -0
  81. package/src/output/updater.d.ts +114 -0
  82. package/src/output/updater.js +58 -4
  83. package/src/output/writer.d.ts +87 -0
  84. package/src/output/writer.js +57 -5
  85. package/src/panel.d.ts +402 -0
  86. package/src/panel.js +219 -5
  87. package/src/plot/bitmap.d.ts +80 -0
  88. package/src/plot/bitmap.js +33 -4
  89. package/src/plot/draw-line.d.ts +13 -0
  90. package/src/plot/draw-line.js +8 -0
  91. package/src/plot/draw-rect.d.ts +13 -0
  92. package/src/plot/draw-rect.js +38 -30
  93. package/src/plot/index.d.ts +39 -0
  94. package/src/plot/index.js +22 -0
  95. package/src/plot/to-quads.d.ts +10 -0
  96. package/src/plot/to-quads.js +5 -0
  97. package/src/spinner/index.d.ts +4 -0
  98. package/src/spinner/index.js +0 -2
  99. package/src/spinner/spin.d.ts +13 -0
  100. package/src/spinner/spin.js +13 -2
  101. package/src/spinner/spinner.d.ts +69 -0
  102. package/src/spinner/spinner.js +30 -2
  103. package/src/spinner/spinners.d.ts +34 -0
  104. package/src/spinner/spinners.js +23 -9
  105. package/src/strings/clip.d.ts +21 -0
  106. package/src/strings/clip.js +10 -0
  107. package/src/strings/parse.d.ts +23 -0
  108. package/src/strings/parse.js +7 -0
  109. package/src/strings/split.d.ts +38 -0
  110. package/src/strings/split.js +15 -0
  111. package/src/strings.d.ts +44 -0
  112. package/src/strings.js +34 -4
  113. package/src/style.d.ts +462 -0
  114. package/src/style.js +58 -4
  115. package/src/symbols.d.ts +167 -0
  116. package/src/symbols.js +91 -7
  117. package/src/table/draw-borders.d.ts +38 -0
  118. package/src/table/draw-borders.js +10 -2
  119. package/src/table/index.d.ts +8 -0
  120. package/src/table/index.js +1 -0
  121. package/src/table/table.d.ts +234 -0
  122. package/src/table/table.js +59 -1
  123. package/src/themes/blocks/unicode-half.d.ts +6 -0
  124. package/src/themes/blocks/unicode-half.js +1 -0
  125. package/src/themes/blocks/unicode-thin.d.ts +6 -0
  126. package/src/themes/blocks/unicode-thin.js +1 -0
  127. package/src/themes/lines/ascii-compact.d.ts +6 -0
  128. package/src/themes/lines/ascii-compact.js +1 -0
  129. package/src/themes/lines/ascii-dots.d.ts +6 -0
  130. package/src/themes/lines/ascii-dots.js +1 -0
  131. package/src/themes/lines/ascii-girder.d.ts +6 -0
  132. package/src/themes/lines/ascii-girder.js +1 -0
  133. package/src/themes/lines/ascii-github.d.ts +6 -0
  134. package/src/themes/lines/ascii-github.js +1 -0
  135. package/src/themes/lines/ascii-reddit.d.ts +6 -0
  136. package/src/themes/lines/ascii-reddit.js +1 -0
  137. package/src/themes/lines/ascii-rounded.d.ts +6 -0
  138. package/src/themes/lines/ascii-rounded.js +1 -0
  139. package/src/themes/lines/ascii.d.ts +6 -0
  140. package/src/themes/lines/ascii.js +1 -0
  141. package/src/themes/lines/unicode-bold.d.ts +6 -0
  142. package/src/themes/lines/unicode-bold.js +1 -0
  143. package/src/themes/lines/unicode-rounded.d.ts +6 -0
  144. package/src/themes/lines/unicode-rounded.js +1 -0
  145. package/src/themes/lines/unicode.d.ts +6 -0
  146. package/src/themes/lines/unicode.js +1 -0
  147. package/src/themes/utils.d.ts +33 -0
  148. package/src/themes/utils.js +7 -0
  149. package/src/turtle/draw-line-art.d.ts +19 -0
  150. package/src/turtle/draw-line-art.js +7 -0
  151. package/src/turtle/draw-unicode.d.ts +19 -0
  152. package/src/turtle/draw-unicode.js +8 -0
  153. package/src/turtle/index.d.ts +21 -0
  154. package/src/turtle/index.js +8 -0
  155. package/src/turtle/turtle.d.ts +269 -0
  156. package/src/turtle/turtle.js +124 -4
package/src/box.d.ts ADDED
@@ -0,0 +1,160 @@
1
+ import {ClipOptions} from './strings/clip.js';
2
+ import {StringsInput} from './strings.js';
3
+
4
+ /** Options for `Box.make()`. */
5
+ export interface BoxMakeOptions {
6
+ /** Padding character (default: ' '). */
7
+ symbol?: string;
8
+ /** Horizontal alignment for shorter strings (default: 'left'). */
9
+ align?: 'left' | 'l' | 'right' | 'r' | 'center' | 'c';
10
+ }
11
+
12
+ /** Options for `Box.addBottom()`. */
13
+ export interface AddBottomOptions {
14
+ /** Padding character (default: ' '). */
15
+ symbol?: string;
16
+ /** Horizontal alignment (default: 'left'). */
17
+ align?: 'left' | 'l' | 'right' | 'r' | 'center' | 'c';
18
+ }
19
+
20
+ /** Options for `Box.addRight()`. */
21
+ export interface AddRightOptions {
22
+ /** Padding character (default: ' '). */
23
+ symbol?: string;
24
+ /** Vertical alignment (default: 'top'). */
25
+ align?: 'top' | 't' | 'bottom' | 'b' | 'center' | 'c';
26
+ }
27
+
28
+ /** A rectangular text container that normalizes string arrays so all lines have the same display width.
29
+ * @see {@link https://github.com/uhop/console-toolkit/wiki/Module:-box}
30
+ */
31
+ export class Box {
32
+ /** The array of strings representing the box content. */
33
+ box: string[];
34
+
35
+ /** Creates a Box from a string, string array, or another Box.
36
+ * @param s - Input data: a Box (copied), a string array, or a string.
37
+ * @param normalized - If true, assume strings are already equal width.
38
+ */
39
+ constructor(s: Box | string | string[], normalized?: boolean);
40
+
41
+ /** The display width of the box in columns. */
42
+ readonly width: number;
43
+ /** The number of lines in the box. */
44
+ readonly height: number;
45
+
46
+ /** Creates a Box from various input types.
47
+ * @param s - Input: Box, object with `toBox()`/`toPanel()`, function, string, or string array.
48
+ * @param options - Make options.
49
+ * @returns A new Box instance.
50
+ */
51
+ static make(s: StringsInput, options?: BoxMakeOptions): Box;
52
+ /** Creates a blank Box filled with a symbol.
53
+ * @param width - Width in columns.
54
+ * @param height - Height in rows.
55
+ * @param symbol - Fill character (default: ' ').
56
+ * @returns A new blank Box.
57
+ */
58
+ static makeBlank(width: number, height: number, symbol?: string): Box;
59
+
60
+ /** Returns the box content as a string array.
61
+ * @returns The array of strings.
62
+ */
63
+ toStrings(): string[];
64
+ /** Returns a clone of this Box.
65
+ * @returns A new Box copy.
66
+ */
67
+ toBox(): Box;
68
+ /** Creates a copy of this Box.
69
+ * @returns A new Box copy.
70
+ */
71
+ clone(): Box;
72
+ /** Clips the box to a given width.
73
+ * @param width - Maximum display width.
74
+ * @param options - Clip options.
75
+ * @returns A new clipped Box.
76
+ */
77
+ clip(width: number, options?: ClipOptions): Box;
78
+
79
+ /** Pads the left and right sides with a symbol.
80
+ * @param left - Left padding columns.
81
+ * @param right - Right padding columns.
82
+ * @param symbol - Pad character.
83
+ * @returns A new padded Box.
84
+ */
85
+ padLeftRight(left: number, right: number, symbol?: string): Box;
86
+ /** Pads the top and bottom with a symbol.
87
+ * @param top - Top padding rows.
88
+ * @param bottom - Bottom padding rows.
89
+ * @param symbol - Pad character.
90
+ * @returns A new padded Box.
91
+ */
92
+ padTopBottom(top: number, bottom: number, symbol?: string): Box;
93
+ /** Pads the right side.
94
+ * @param n - Columns.
95
+ * @param symbol - Pad character.
96
+ * @returns A new padded Box.
97
+ */
98
+ padRight(n: number, symbol?: string): Box;
99
+ /** Pads the left side.
100
+ * @param n - Columns.
101
+ * @param symbol - Pad character.
102
+ * @returns A new padded Box.
103
+ */
104
+ padLeft(n: number, symbol?: string): Box;
105
+ /** Pads the top.
106
+ * @param n - Rows.
107
+ * @param symbol - Pad character.
108
+ * @returns A new padded Box.
109
+ */
110
+ padTop(n: number, symbol?: string): Box;
111
+ /** Pads the bottom.
112
+ * @param n - Rows.
113
+ * @param symbol - Pad character.
114
+ * @returns A new padded Box.
115
+ */
116
+ padBottom(n: number, symbol?: string): Box;
117
+ /** Pads using CSS-style shorthand (top, right, bottom, left).
118
+ * @param t - Top padding.
119
+ * @param r - Right padding (or symbol).
120
+ * @param b - Bottom padding (or symbol).
121
+ * @param l - Left padding (or symbol).
122
+ * @param symbol - Pad character.
123
+ * @returns A new padded Box.
124
+ */
125
+ pad(t: number, r?: number | string, b?: number | string, l?: number | string, symbol?: string): Box;
126
+
127
+ /** Removes `n` rows starting at row `y`.
128
+ * @param y - Starting row index.
129
+ * @param n - Number of rows to remove.
130
+ * @returns A new Box with the specified rows removed.
131
+ */
132
+ removeRows(y: number, n: number): Box;
133
+
134
+ /** Appends another box below this one.
135
+ * @param box - Input convertible to a Box.
136
+ * @param options - Alignment and padding options.
137
+ * @returns A new combined Box.
138
+ */
139
+ addBottom(box: StringsInput, options?: AddBottomOptions): Box;
140
+ /** Appends another box to the right of this one.
141
+ * @param box - Input convertible to a Box.
142
+ * @param options - Alignment and padding options.
143
+ * @returns A new combined Box.
144
+ */
145
+ addRight(box: StringsInput, options?: AddRightOptions): Box;
146
+
147
+ /** Flips the box vertically.
148
+ * @returns A new vertically flipped Box.
149
+ */
150
+ flipV(): Box;
151
+ }
152
+
153
+ /** Alias for `Box.make()`. Creates a Box from various input types.
154
+ * @param s - Input convertible to a Box.
155
+ * @param options - Make options.
156
+ * @returns A new Box instance.
157
+ */
158
+ export function toBox(s: StringsInput, options?: BoxMakeOptions): Box;
159
+
160
+ export default Box;
package/src/box.js CHANGED
@@ -1,7 +1,15 @@
1
1
  import {addAlias} from './meta.js';
2
2
  import {getLength, clipStrings, toStrings} from './strings.js';
3
3
 
4
+ /** A rectangular text container where all strings have equal display width.
5
+ * Provides methods for padding, stacking, clipping, and flipping.
6
+ * @see {@link https://github.com/uhop/console-toolkit/wiki/Module:-box}
7
+ */
4
8
  export class Box {
9
+ /** Creates a new Box.
10
+ * @param {Box|string|string[]|*} s - Input data. If a Box, it is copied. If `normalized` is true, the array is used as-is.
11
+ * @param {boolean} [normalized=false] - If true, assumes strings are already equal width and takes ownership of the array.
12
+ */
5
13
  constructor(s, normalized) {
6
14
  if (s instanceof Box) {
7
15
  this.box = [...s.box]; // copy
@@ -10,13 +18,22 @@ export class Box {
10
18
  }
11
19
  }
12
20
 
21
+ /** The display width of the box (length of the first string, or 0 if empty). */
13
22
  get width() {
14
23
  return this.box.length ? getLength(this.box[0]) : 0;
15
24
  }
25
+ /** The number of rows in the box. */
16
26
  get height() {
17
27
  return this.box.length;
18
28
  }
19
29
 
30
+ /** Creates a Box from various input types.
31
+ * @param {import('./strings.js').StringsInput} s - Input: Box, object with toBox()/toPanel(), function, string, array, etc.
32
+ * @param {object} [options] - Options.
33
+ * @param {string} [options.symbol=' '] - The padding character.
34
+ * @param {'left'|'l'|'right'|'r'|'center'|'c'} [options.align='left'] - Alignment for shorter strings.
35
+ * @returns {Box} A new Box instance.
36
+ */
20
37
  static make(s, options) {
21
38
  main: for (;;) {
22
39
  switch (typeof s) {
@@ -38,7 +55,7 @@ export class Box {
38
55
 
39
56
  const {symbol = ' ', align = 'left'} = options || {},
40
57
  widths = s.map(s => getLength(s)),
41
- width = Math.max(0, ...widths);
58
+ width = widths.reduce((a, b) => (a > b ? a : b), 0);
42
59
  switch (align) {
43
60
  case 'left':
44
61
  case 'l':
@@ -66,40 +83,72 @@ export class Box {
66
83
  );
67
84
  }
68
85
 
86
+ /** Creates a blank Box filled with a symbol.
87
+ * @param {number} width - The width of the box.
88
+ * @param {number} height - The height of the box.
89
+ * @param {string} [symbol=' '] - The fill character.
90
+ * @returns {Box} A new blank Box.
91
+ */
69
92
  static makeBlank(width, height, symbol = ' ') {
70
93
  return new Box(height <= 0 ? [] : new Array(height).fill(symbol.repeat(width)), true);
71
94
  }
72
95
 
96
+ /** Returns the underlying array of strings.
97
+ * @returns {string[]} The box content.
98
+ */
73
99
  toStrings() {
74
100
  return this.box;
75
101
  }
76
102
 
103
+ /** Creates a shallow copy of this Box.
104
+ * @returns {Box} A new Box with the same content.
105
+ */
77
106
  clone() {
78
107
  return new Box(this);
79
108
  }
80
109
 
110
+ /** Clips all strings to a given display width.
111
+ * @param {number} width - The maximum display width.
112
+ * @param {object} [options] - Options passed to `clip()`.
113
+ * @returns {Box} A new clipped Box.
114
+ */
81
115
  clip(width, options) {
82
116
  return Box.make(clipStrings(this.box, width, options));
83
117
  }
84
118
 
85
119
  // padding
86
120
 
121
+ /** Pads the box on both left and right sides.
122
+ * @param {number} left - Left padding amount.
123
+ * @param {number} right - Right padding amount.
124
+ * @param {string} [symbol=' '] - The padding character.
125
+ * @returns {Box} A new padded Box.
126
+ */
87
127
  padLeftRight(left, right, symbol = ' ') {
88
- const paddingSmall = symbol.repeat(Math.min(left, right)),
89
- paddingLarge = paddingSmall + symbol.repeat(Math.max(left - right, right - left));
128
+ const paddingLeft = symbol.repeat(left),
129
+ paddingRight = symbol.repeat(right);
90
130
  return new Box(
91
- left < right
92
- ? this.box.map(s => paddingSmall + s + paddingLarge)
93
- : this.box.map(s => paddingLarge + s + paddingSmall),
131
+ this.box.map(s => paddingLeft + s + paddingRight),
94
132
  true
95
133
  );
96
134
  }
97
135
 
136
+ /** Pads the box on both top and bottom sides.
137
+ * @param {number} top - Top padding amount (number of rows).
138
+ * @param {number} bottom - Bottom padding amount (number of rows).
139
+ * @param {string} [symbol=' '] - The padding character.
140
+ * @returns {Box} A new padded Box.
141
+ */
98
142
  padTopBottom(top, bottom, symbol = ' ') {
99
143
  const padding = symbol.repeat(this.width);
100
144
  return new Box([...new Array(top).fill(padding), ...this.box, ...new Array(bottom).fill(padding)], true);
101
145
  }
102
146
 
147
+ /** Pads the box on the right side.
148
+ * @param {number} n - Right padding amount.
149
+ * @param {string} [symbol=' '] - The padding character.
150
+ * @returns {Box} A new padded Box.
151
+ */
103
152
  padRight(n, symbol = ' ') {
104
153
  const padding = symbol.repeat(n);
105
154
  return new Box(
@@ -108,6 +157,11 @@ export class Box {
108
157
  );
109
158
  }
110
159
 
160
+ /** Pads the box on the left side.
161
+ * @param {number} n - Left padding amount.
162
+ * @param {string} [symbol=' '] - The padding character.
163
+ * @returns {Box} A new padded Box.
164
+ */
111
165
  padLeft(n, symbol = ' ') {
112
166
  const padding = symbol.repeat(n);
113
167
  return new Box(
@@ -116,27 +170,49 @@ export class Box {
116
170
  );
117
171
  }
118
172
 
173
+ /** Pads the box on the top side.
174
+ * @param {number} n - Top padding amount (number of rows).
175
+ * @param {string} [symbol=' '] - The padding character.
176
+ * @returns {Box} A new padded Box.
177
+ */
119
178
  padTop(n, symbol = ' ') {
120
179
  const padding = symbol.repeat(this.width);
121
180
  return new Box([...new Array(n).fill(padding), ...this.box], true);
122
181
  }
123
182
 
183
+ /** Pads the box on the bottom side.
184
+ * @param {number} n - Bottom padding amount (number of rows).
185
+ * @param {string} [symbol=' '] - The padding character.
186
+ * @returns {Box} A new padded Box.
187
+ */
124
188
  padBottom(n, symbol = ' ') {
125
189
  const padding = symbol.repeat(this.width);
126
190
  return new Box([...this.box, ...new Array(n).fill(padding)], true);
127
191
  }
128
192
 
193
+ /** Pads the box on all sides (CSS padding order: top, right, bottom, left).
194
+ * - `pad(t)` → equal padding on all sides.
195
+ * - `pad(t, r)` → top/bottom = t, left/right = r.
196
+ * - `pad(t, r, b)` → top = t, left/right = r, bottom = b.
197
+ * - `pad(t, r, b, l)` → individual padding.
198
+ * @param {number} t - Top padding.
199
+ * @param {number|string} [r] - Right padding or symbol.
200
+ * @param {number|string} [b] - Bottom padding or symbol.
201
+ * @param {number|string} [l] - Left padding or symbol.
202
+ * @param {string} [symbol=' '] - The padding character.
203
+ * @returns {Box} A new padded Box.
204
+ */
129
205
  pad(t, r, b, l, symbol = ' ') {
130
206
  // implemented the CSS padding order
131
207
  if (typeof r != 'number') {
132
- symbol = r;
208
+ symbol = r || symbol;
133
209
  r = b = l = t;
134
210
  } else if (typeof b != 'number') {
135
- symbol = b;
211
+ symbol = b || symbol;
136
212
  l = r;
137
213
  b = t;
138
214
  } else if (typeof l != 'number') {
139
- symbol = l;
215
+ symbol = l || symbol;
140
216
  l = r;
141
217
  }
142
218
  return this.padLeftRight(l, r, symbol).padTopBottom(t, b, symbol);
@@ -144,6 +220,11 @@ export class Box {
144
220
 
145
221
  // removing
146
222
 
223
+ /** Removes rows from the box.
224
+ * @param {number} y - The starting row index.
225
+ * @param {number} n - The number of rows to remove.
226
+ * @returns {Box} A new Box with rows removed.
227
+ */
147
228
  removeRows(y, n) {
148
229
  const result = [...this.box];
149
230
  result.splice(y, n);
@@ -152,6 +233,13 @@ export class Box {
152
233
 
153
234
  // stack
154
235
 
236
+ /** Stacks another box below this one.
237
+ * @param {import('./strings.js').StringsInput} box - The box to add at the bottom.
238
+ * @param {object} [options] - Options.
239
+ * @param {string} [options.symbol=' '] - The padding character for width alignment.
240
+ * @param {'left'|'l'|'right'|'r'|'center'|'c'} [options.align='left'] - Horizontal alignment if widths differ.
241
+ * @returns {Box} A new combined Box.
242
+ */
155
243
  addBottom(box, {symbol = ' ', align = 'left'} = {}) {
156
244
  let a = this,
157
245
  b = toBox(box);
@@ -170,7 +258,7 @@ export class Box {
170
258
  break;
171
259
  default: // center
172
260
  const half = d >> 1;
173
- x = x.padLeftRight(half, half + (d & 1 ? 1 : 0));
261
+ x = x.padLeftRight(half, half + (d & 1 ? 1 : 0), symbol);
174
262
  break;
175
263
  }
176
264
  a = diff < 0 ? x : a;
@@ -179,7 +267,15 @@ export class Box {
179
267
  return new Box([...a.box, ...b.box], true);
180
268
  }
181
269
 
270
+ /** Stacks another box to the right of this one.
271
+ * @param {import('./strings.js').StringsInput} box - The box to add on the right.
272
+ * @param {object} [options] - Options.
273
+ * @param {string} [options.symbol=' '] - The padding character for height alignment.
274
+ * @param {'top'|'t'|'bottom'|'b'|'center'|'c'} [options.align='top'] - Vertical alignment if heights differ.
275
+ * @returns {Box} A new combined Box.
276
+ */
182
277
  addRight(box, {symbol = ' ', align = 'top'} = {}) {
278
+ box = toBox(box);
183
279
  const ah = this.height,
184
280
  bh = box.height;
185
281
  if (ah == bh)
@@ -240,14 +336,19 @@ export class Box {
240
336
 
241
337
  // flipping
242
338
 
339
+ /** Flips the box vertically (reverses the row order).
340
+ * @returns {Box} A new vertically flipped Box.
341
+ */
243
342
  flipV() {
244
- // return new Box(this.box.toReversed(), true);
245
- return new Box([...this.box].reverse(), true);
343
+ return new Box(this.box.toReversed(), true);
246
344
  }
247
345
  }
248
346
 
249
347
  addAlias(Box, 'toBox', 'clone');
250
348
 
349
+ /** Alias for `Box.make()`. Converts its argument to a Box.
350
+ * @type {typeof Box.make}
351
+ */
251
352
  export const toBox = Box.make;
252
353
 
253
354
  export default Box;
@@ -0,0 +1,12 @@
1
+ import {ChartDataInput} from '../utils.js';
2
+ import {GroupedChartOptions} from './draw-grouped.js';
3
+
4
+ /** Draws a complete fractional block grouped bar chart.
5
+ * @param values - Chart data.
6
+ * @param width - Available width.
7
+ * @param options - Options.
8
+ * @returns Array of strings representing the chart.
9
+ */
10
+ export function drawChart(values: ChartDataInput, width: number, options?: GroupedChartOptions): string[];
11
+
12
+ export default drawChart;
@@ -1,6 +1,12 @@
1
1
  import {drawRow} from './block-frac.js';
2
2
  import drawGroupedChart from './draw-grouped.js';
3
3
 
4
+ /** Draws a complete fractional block grouped bar chart.
5
+ * @param {any[]} values - Chart data.
6
+ * @param {number} width - Available width.
7
+ * @param {object} [options] - Options.
8
+ * @returns {string[]} Array of strings representing the chart.
9
+ */
4
10
  export const drawChart = drawGroupedChart(drawRow);
5
11
 
6
12
  export default drawChart;
@@ -0,0 +1,34 @@
1
+ import {ChartDatum, ChartDataInput} from '../utils.js';
2
+ import {SgrState} from '../../ansi/sgr-state.js';
3
+ import {StackedChartOptions} from './draw-stacked.js';
4
+
5
+ /** Options for fractional block bar charts. */
6
+ export interface BlockFracBarOptions extends StackedChartOptions {
7
+ /** Size of each rectangle in characters. */
8
+ rectSize?: number;
9
+ /** Initial SGR state. */
10
+ initState?: SgrState | string | null;
11
+ /** If true, reverse the drawing direction. */
12
+ reverse?: boolean;
13
+ /** If true, draw an empty border when fractional part is 0. */
14
+ drawEmptyBorder?: boolean;
15
+ }
16
+
17
+ /** Draws a single stacked bar row using fractional block characters.
18
+ * @param data - Chart data items.
19
+ * @param width - Available width.
20
+ * @param maxValue - Maximum value.
21
+ * @param options - Options.
22
+ * @returns Array of strings for the row.
23
+ */
24
+ export function drawRow(data: ChartDatum[], width: number, maxValue: number, options?: BlockFracBarOptions): string[];
25
+
26
+ /** Draws a complete fractional block stacked bar chart.
27
+ * @param values - Chart data.
28
+ * @param width - Available width.
29
+ * @param options - Options.
30
+ * @returns Array of strings representing the chart.
31
+ */
32
+ export function drawChart(values: ChartDataInput, width: number, options?: BlockFracBarOptions): string[];
33
+
34
+ export default drawChart;
@@ -8,6 +8,13 @@ import {drawRealHeightBlock} from '../../draw-block-frac.js';
8
8
  // data = [datum]
9
9
  // datum = {value, colorState, symbol, state}
10
10
 
11
+ /** Draws a single stacked bar row using fractional block characters.
12
+ * @param {object[]} data - Normalized data series.
13
+ * @param {number} width - Total width.
14
+ * @param {number} maxValue - Maximum value for scaling.
15
+ * @param {object} [options] - Options including `reverse`, `drawEmptyBorder`, `rectSize`, `initState`.
16
+ * @returns {string[]} The drawn row lines.
17
+ */
11
18
  export const drawRow = (data, width, maxValue, options = {}) => {
12
19
  const {reverse, drawEmptyBorder, initState = {}} = options,
13
20
  rectSize = Math.max(0, options.rectSize ?? 0.5),
@@ -31,6 +38,12 @@ export const drawRow = (data, width, maxValue, options = {}) => {
31
38
  return result.map(line => optimize(line));
32
39
  };
33
40
 
41
+ /** Draws a complete fractional block stacked bar chart.
42
+ * @param {any[]} values - Chart data.
43
+ * @param {number} width - Available width.
44
+ * @param {object} [options] - Options.
45
+ * @returns {string[]} Array of strings representing the chart.
46
+ */
34
47
  export const drawChart = drawStackedChart(drawRow);
35
48
 
36
49
  export default drawChart;
@@ -0,0 +1,12 @@
1
+ import {ChartDataInput} from '../utils.js';
2
+ import {GroupedChartOptions} from './draw-grouped.js';
3
+
4
+ /** Draws a complete block grouped bar chart.
5
+ * @param values - Chart data.
6
+ * @param width - Available width.
7
+ * @param options - Options.
8
+ * @returns Array of strings representing the chart.
9
+ */
10
+ export function drawChart(values: ChartDataInput, width: number, options?: GroupedChartOptions): string[];
11
+
12
+ export default drawChart;
@@ -1,6 +1,12 @@
1
1
  import {drawRow} from './block.js';
2
2
  import drawGroupedChart from './draw-grouped.js';
3
3
 
4
+ /** Draws a complete block grouped bar chart.
5
+ * @param {any[]} values - Chart data.
6
+ * @param {number} width - Available width.
7
+ * @param {object} [options] - Options.
8
+ * @returns {string[]} Array of strings representing the chart.
9
+ */
4
10
  export const drawChart = drawGroupedChart(drawRow);
5
11
 
6
12
  export default drawChart;
@@ -0,0 +1,43 @@
1
+ import {ChartDatum, ChartDataInput} from '../utils.js';
2
+ import {SgrState} from '../../ansi/sgr-state.js';
3
+ import {LineTheme} from '../../themes/utils.js';
4
+ import {StackedChartOptions} from './draw-stacked.js';
5
+
6
+ /** Options for block bar charts. */
7
+ export interface BlockBarOptions extends StackedChartOptions {
8
+ /** Block theme for drawing. */
9
+ blockTheme?: LineTheme;
10
+ /** Size of each rectangle in characters. */
11
+ rectSize?: number;
12
+ /** Initial SGR state. */
13
+ initState?: SgrState | string | null;
14
+ /** If true, reverse the drawing direction. */
15
+ reverse?: boolean;
16
+ /** If set, draw the top border. */
17
+ t?: number;
18
+ /** If set, draw the bottom border. */
19
+ b?: number;
20
+ /** If set, draw the left border. */
21
+ l?: number;
22
+ /** If set, draw the right border. */
23
+ r?: number;
24
+ }
25
+
26
+ /** Draws a single stacked bar row using block-drawing characters.
27
+ * @param data - Chart data items.
28
+ * @param width - Available width.
29
+ * @param maxValue - Maximum value.
30
+ * @param options - Block bar options.
31
+ * @returns Array of strings for the row.
32
+ */
33
+ export function drawRow(data: ChartDatum[], width: number, maxValue: number, options?: BlockBarOptions): string[];
34
+
35
+ /** Draws a complete block stacked bar chart.
36
+ * @param values - Chart data.
37
+ * @param width - Available width.
38
+ * @param options - Block bar options.
39
+ * @returns Array of strings representing the chart.
40
+ */
41
+ export function drawChart(values: ChartDataInput, width: number, options?: BlockBarOptions): string[];
42
+
43
+ export default drawChart;
@@ -9,6 +9,13 @@ import defaultBlockTheme from '../../themes/blocks/unicode-half.js';
9
9
  // data = [datum]
10
10
  // datum = {value, colorState, symbol, state}
11
11
 
12
+ /** Draws a single stacked bar row using block-drawing characters.
13
+ * @param {object[]} data - Normalized data series.
14
+ * @param {number} width - Total width.
15
+ * @param {number} maxValue - Maximum value for scaling.
16
+ * @param {object} [options] - Options including `reverse`, `blockTheme`, `rectSize`, `initState`.
17
+ * @returns {string[]} The drawn row lines.
18
+ */
12
19
  export const drawRow = (data, width, maxValue, options = {}) => {
13
20
  const {reverse, blockTheme = defaultBlockTheme, rectSize = 0, initState = {}} = options,
14
21
  sizes = allocateSizes(data, maxValue, width),
@@ -38,6 +45,12 @@ export const drawRow = (data, width, maxValue, options = {}) => {
38
45
  return result.map(line => optimize(line));
39
46
  };
40
47
 
48
+ /** Draws a complete block stacked bar chart.
49
+ * @param {any[]} values - Chart data.
50
+ * @param {number} width - Available width.
51
+ * @param {object} [options] - Block bar options.
52
+ * @returns {string[]} Array of strings representing the chart.
53
+ */
41
54
  export const drawChart = drawStackedChart(drawRow);
42
55
 
43
56
  export default drawChart;
@@ -0,0 +1,41 @@
1
+ import {ChartDatum, ChartDataInput, ChartTheme} from '../utils.js';
2
+ import {SgrState} from '../../ansi/sgr-state.js';
3
+
4
+ /** Options for grouped bar/column charts. */
5
+ export interface GroupedChartOptions {
6
+ /** Maximum value for scaling (default: auto). */
7
+ maxValue?: number;
8
+ /** Gap between groups in lines. */
9
+ groupGap?: number;
10
+ /** Gap between items within a group. */
11
+ gap?: number;
12
+ /** Chart theme. */
13
+ theme?: ChartTheme;
14
+ /** Size of each rectangle in characters. */
15
+ rectSize?: number;
16
+ /** Initial SGR state. */
17
+ initState?: SgrState | string | null;
18
+ /** If true, reverse the drawing direction. */
19
+ reverse?: boolean;
20
+ /** Additional custom options. */
21
+ [key: string]: unknown;
22
+ }
23
+
24
+ /** Function that draws a single row of a chart.
25
+ * @param data - Array of chart data items.
26
+ * @param width - Available width in characters.
27
+ * @param maxValue - Maximum value for scaling.
28
+ * @param options - Optional chart options.
29
+ * @returns The drawn row as a string or string array.
30
+ */
31
+ type DrawRowFn = (data: ChartDatum[], width: number, maxValue: number, options?: GroupedChartOptions) => string | string[];
32
+
33
+ /** Creates a grouped bar chart drawing function from a row-drawing function.
34
+ * @param drawRow - The row-drawing function.
35
+ * @returns A chart-drawing function.
36
+ */
37
+ export function drawChart(
38
+ drawRow: DrawRowFn
39
+ ): (values: ChartDataInput, width: number, options?: GroupedChartOptions) => string[];
40
+
41
+ export default drawChart;
@@ -1,6 +1,10 @@
1
1
  import defaultTheme from '../themes/default.js';
2
2
  import {normalizeData} from '../utils.js';
3
3
 
4
+ /** Creates a grouped bar chart drawing function from a row-drawing function.
5
+ * @param {Function} drawRow - Function `(data, width, maxValue, options) => string|string[]`.
6
+ * @returns {Function} Chart drawing function `(values, width, options) => string[]`.
7
+ */
4
8
  export const drawChart =
5
9
  drawRow =>
6
10
  (values, width, options = {}) => {