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/style.js CHANGED
@@ -177,34 +177,67 @@ class Reset {
177
177
  }
178
178
  }
179
179
 
180
+ /** Chainable API for building SGR (Select Graphics Rendition) states.
181
+ * Provides namespaces for foreground (`fg`), background (`bg`), decoration colors, brightness, and reset.
182
+ * @see {@link https://github.com/uhop/console-toolkit/wiki/Module:-style}
183
+ */
180
184
  export class Style {
185
+ /**
186
+ * @param {object|string|null} [initState] - The initial SGR state (SgrState, string, or null for reset).
187
+ * @param {object|string|null} [currentState] - The current SGR state (defaults to initState).
188
+ * @param {number} [colorDepth=24] - Color depth (1, 4, 8, or 24).
189
+ */
181
190
  constructor(initState, currentState, colorDepth = 24) {
182
191
  this[initStateSymbol] = toState(initState);
183
192
  this[stateSymbol] = currentState ? toState(currentState) : this[initStateSymbol];
184
193
  this[colorDepthSymbol] = colorDepth;
185
194
  }
195
+ /** Creates a new Style with additional SGR commands applied.
196
+ * @param {string|string[]} [newCommands=[]] - SGR command(s) to add.
197
+ * @returns {Style}
198
+ */
186
199
  make(newCommands = []) {
187
200
  if (!Array.isArray(newCommands)) newCommands = [newCommands];
188
201
  return new Style(this[initStateSymbol], addCommandsToState(this[stateSymbol], newCommands), this[colorDepthSymbol]);
189
202
  }
203
+ /** Adds SGR commands from an escape sequence string.
204
+ * @param {string} commandSequence - An ANSI escape sequence string.
205
+ * @returns {Style}
206
+ */
190
207
  add(commandSequence) {
191
208
  const state = extractState(String(commandSequence), this[stateSymbol]);
192
209
  return state === this[stateSymbol] ? this : new Style(this[initStateSymbol], state, this[colorDepthSymbol]);
193
210
  }
211
+ /** Combines an SGR state into the current state.
212
+ * @param {object|string|null} state - State to combine (SgrState, string, or null).
213
+ * @returns {Style}
214
+ */
194
215
  addState(state) {
195
216
  return new Style(this[initStateSymbol], combineStates(this[stateSymbol], toState(state)), this[colorDepthSymbol]);
196
217
  }
218
+ /** Creates a new Style with the current state as the initial state, optionally calling a function.
219
+ * @param {Function} [fn] - Optional callback receiving the new Style.
220
+ * @returns {Style|this}
221
+ */
197
222
  mark(fn) {
198
223
  const newStyle = new Style(this[stateSymbol], null, this[colorDepthSymbol]);
199
224
  if (typeof fn != 'function') return newStyle;
200
225
  fn(newStyle);
201
226
  return this;
202
227
  }
228
+ /** Returns the initial state, or passes it to a callback.
229
+ * @param {Function} [fn] - Optional callback.
230
+ * @returns {object|this}
231
+ */
203
232
  getInitialState(fn) {
204
233
  if (typeof fn != 'function') return this[initStateSymbol];
205
234
  fn(this[initStateSymbol]);
206
235
  return this;
207
236
  }
237
+ /** Returns the current state, or passes it to a callback.
238
+ * @param {Function} [fn] - Optional callback.
239
+ * @returns {object|this}
240
+ */
208
241
  getState(fn) {
209
242
  if (typeof fn != 'function') return this[stateSymbol];
210
243
  fn(this[stateSymbol]);
@@ -214,6 +247,10 @@ export class Style {
214
247
  get colorDepth() {
215
248
  return this[colorDepthSymbol]; // 1, 4, 8, 24
216
249
  }
250
+ /** Creates a new Style with a different color depth.
251
+ * @param {number} colorDepth - New color depth (1, 4, 8, or 24).
252
+ * @returns {Style}
253
+ */
217
254
  setColorDepth(colorDepth) {
218
255
  return new Style(this[initStateSymbol], this[stateSymbol], colorDepth);
219
256
  }
@@ -290,7 +327,7 @@ export class Style {
290
327
  return this[colorDepthSymbol] > 8 ? this.hexTrueColor(hex) : this.hex256(hex);
291
328
  }
292
329
  bgStdRgb(r, g, b) {
293
- return this.make(getBgStdRgb(r, g, b));
330
+ return this.make(sgr.getBgStdRgb(r, g, b));
294
331
  }
295
332
  bgBrightStdRgb(r, g, b) {
296
333
  return this.make(sgr.getBgBrightStdRgb(r, g, b));
@@ -335,7 +372,7 @@ export class Style {
335
372
  return this.make(sgr.getDecorationStdColor256(r, g, b));
336
373
  }
337
374
  decorationBrightStdRgb256(r, g, b) {
338
- return this.make(getDecorationBrightStdColor256(r, g, b));
375
+ return this.make(sgr.getDecorationBrightStdColor256(r, g, b));
339
376
  }
340
377
  decorationColor(c) {
341
378
  return this.make(sgr.getDecorationRawColor256(c));
@@ -373,7 +410,11 @@ export class Style {
373
410
  decorationHex(hex) {
374
411
  return this[colorDepthSymbol] > 8 ? this.decorationHexTrueColor(hex) : this.decorationHex256(hex);
375
412
  }
376
- // wrap a string
413
+ /** Wraps a string (or array of strings) with SGR escape sequences for the current style.
414
+ * Applies the style at the start and reverses it at the end.
415
+ * @param {string|string[]} s - String(s) to wrap.
416
+ * @returns {string|string[]} The styled string(s).
417
+ */
377
418
  text(s) {
378
419
  if (Array.isArray(s)) return s.map(s => this.text(s));
379
420
  s = String(s);
@@ -389,7 +430,9 @@ export class Style {
389
430
  const cleanupCommands = stateReverseTransition(this[initStateSymbol], state);
390
431
  return stringifyCommands(initialCommands) + s + stringifyCommands(cleanupCommands);
391
432
  }
392
- // convert to string
433
+ /** Converts the style to an SGR escape sequence string (transition from initial to current state).
434
+ * @returns {string}
435
+ */
393
436
  toString() {
394
437
  const initialCommands = stateTransition(this[initStateSymbol], this[stateSymbol]);
395
438
  return stringifyCommands(initialCommands);
@@ -611,10 +654,21 @@ const makeBq =
611
654
  return bq(strings, ...args);
612
655
  };
613
656
 
657
+ /** Tagged template literal for styled text. Style changes persist after the string.
658
+ * Can also be called as `s({initState, setState})` to create a configured tagger.
659
+ * @type {Function}
660
+ */
614
661
  export const s = makeBq(false);
662
+ /** Tagged template literal for styled text. Automatically resets the style at the end.
663
+ * Can also be called as `c({initState, setState})` to create a configured tagger.
664
+ * @type {Function}
665
+ */
615
666
  export const c = makeBq(true);
616
667
 
617
668
  // singleton
669
+ /** The default Style singleton with an empty initial state.
670
+ * @type {Style}
671
+ */
618
672
  export const style = new Style({});
619
673
 
620
674
  export default style;
@@ -0,0 +1,167 @@
1
+ /** @module symbols
2
+ * Unicode characters for drawing lines, tables, charts, and other visual elements.
3
+ * @see {@link https://github.com/uhop/console-toolkit/wiki/Module:-symbols}
4
+ */
5
+
6
+ /** Vertical block elements in 1/8th increments (index 0 = space, 7 = full block). */
7
+ export const vBlocks8th: string[];
8
+ /** Horizontal block elements in 1/8th increments (index 0 = space, 7 = full block). */
9
+ export const hBlocks8th: string[];
10
+ /** Full block character (█). */
11
+ export const fullBlock: string;
12
+
13
+ /** Left 1/8th block line. */
14
+ export const lLine: string;
15
+ /** Right 1/8th block line. */
16
+ export const rLine: string;
17
+ /** Top 1/8th block line. */
18
+ export const tLine: string;
19
+ /** Bottom 1/8th block line. */
20
+ export const bLine: string;
21
+
22
+ /** Left half block. */
23
+ export const lHalf: string;
24
+ /** Right half block. */
25
+ export const rHalf: string;
26
+ /** Top half block. */
27
+ export const tHalf: string;
28
+ /** Bottom half block. */
29
+ export const bHalf: string;
30
+
31
+ /** Top-left quadrant block. */
32
+ export const tlQuadrant: string;
33
+ /** Bottom-left quadrant block. */
34
+ export const blQuadrant: string;
35
+ /** Top-right quadrant block. */
36
+ export const trQuadrant: string;
37
+ /** Bottom-right quadrant block. */
38
+ export const brQuadrant: string;
39
+
40
+ /** Top-left + bottom-right diagonal quadrants. */
41
+ export const tlBrQuadrants: string;
42
+ /** Top-right + bottom-left diagonal quadrants. */
43
+ export const trBlQuadrants: string;
44
+
45
+ /** Negative (inverse) top-left quadrant. */
46
+ export const tlNegativeQuadrant: string;
47
+ /** Negative (inverse) bottom-left quadrant. */
48
+ export const blNegativeQuadrant: string;
49
+ /** Negative (inverse) top-right quadrant. */
50
+ export const trNegativeQuadrant: string;
51
+ /** Negative (inverse) bottom-right quadrant. */
52
+ export const brNegativeQuadrant: string;
53
+
54
+ /** All 16 quadrant block characters indexed by bitmask (TL=1, TR=2, BL=4, BR=8). */
55
+ export const quadrants: string[];
56
+
57
+ /** Returns the quadrant character for the given corner flags.
58
+ * @param tl - Top-left filled.
59
+ * @param tr - Top-right filled.
60
+ * @param bl - Bottom-left filled.
61
+ * @param br - Bottom-right filled.
62
+ * @returns The quadrant block character.
63
+ */
64
+ export function quadrant(tl: boolean, tr: boolean, bl: boolean, br: boolean): string;
65
+
66
+ /** Shade characters from empty to full: space, light, medium, dark, full block. */
67
+ export const shades: string[];
68
+ /** Light shade character (░). */
69
+ export const shadeLight: string;
70
+ /** Medium shade character (▒). */
71
+ export const shadeMedium: string;
72
+ /** Dark shade character (▓). */
73
+ export const shadeDark: string;
74
+
75
+ // ellipses
76
+ /** Horizontal ellipsis (…). */
77
+ export const hellip: string;
78
+ /** Vertical ellipsis (⋮). */
79
+ export const vellip: string;
80
+ /** Centered triple dots (⋯). */
81
+ export const ctdot: string;
82
+ /** Up-pointing triple dots (⋰). */
83
+ export const utdot: string;
84
+ /** Down-pointing triple dots (⋱). */
85
+ export const dtdot: string;
86
+
87
+ /** Alias for `hellip`. */
88
+ export {hellip as ellipsis};
89
+
90
+ // math
91
+ /** Infinity symbol (∞). */
92
+ export const infinity: string;
93
+ /** Plus-minus sign (±). */
94
+ export const plusMinus: string;
95
+ /** Minus-plus sign (∓). */
96
+ export const minusPlus: string;
97
+ /** Tilde operator (∼). */
98
+ export const tilde: string;
99
+ /** Minus sign (−). */
100
+ export const minus: string;
101
+ /** Multiplication sign (×). */
102
+ export const multiplication: string;
103
+ /** Division sign (÷). */
104
+ export const division: string;
105
+ /** N-ary product (∏). */
106
+ export const product: string;
107
+ /** N-ary summation (∑). */
108
+ export const sum: string;
109
+ /** For all (∀). */
110
+ export const forAll: string;
111
+ /** There exists (∃). */
112
+ export const exist: string;
113
+ /** Degree sign (°). */
114
+ export const degree: string;
115
+
116
+ /** Alias for `multiplication`. */
117
+ export {multiplication as times};
118
+
119
+ /** Superscript plus (⁺). */
120
+ export const superscriptPlus: string;
121
+ /** Superscript minus (⁻). */
122
+ export const superscriptMinus: string;
123
+ /** Subscript plus (₊). */
124
+ export const subscriptPlus: string;
125
+ /** Subscript minus (₋). */
126
+ export const subscriptMinus: string;
127
+
128
+ /** Per mille sign (‰). */
129
+ export const permille: string;
130
+ /** Per myriad sign (‱). */
131
+ export const permyriad: string;
132
+
133
+ // dashes
134
+ /** Hyphen (‐). */
135
+ export const hyphen: string;
136
+ /** Figure dash (‒). */
137
+ export const figureDash: string;
138
+ /** En dash (–). */
139
+ export const ndash: string;
140
+ /** Em dash (—). */
141
+ export const mdash: string;
142
+ /** Horizontal bar (―). */
143
+ export const horbar: string;
144
+
145
+ // marks
146
+ /** Ballot box (☐). */
147
+ export const ballotBox: string;
148
+ /** Ballot box with check (☑). */
149
+ export const ballotBoxChecked: string;
150
+ /** Ballot box with bold check (☒-variant). */
151
+ export const ballotBoxBoldChecked: string;
152
+ /** Ballot box with X (☒). */
153
+ export const ballotBoxX: string;
154
+
155
+ /** Check mark (✓). */
156
+ export const checkMark: string;
157
+ /** Heavy check mark (✔). */
158
+ export const checkMarkHeavy: string;
159
+ /** Light check mark (✓-variant). */
160
+ export const checkMarkLight: string;
161
+
162
+ /** Ballot X (✗). */
163
+ export const ballotX: string;
164
+ /** Heavy ballot X (✘). */
165
+ export const ballotXHeavy: string;
166
+ /** Light ballot X (✗-variant). */
167
+ export const ballotXLight: string;
package/src/symbols.js CHANGED
@@ -1,3 +1,8 @@
1
+ /** @module symbols
2
+ * A collection of frequently used Unicode characters for drawing lines, tables, charts, and other visual elements.
3
+ * @see {@link https://github.com/uhop/console-toolkit/wiki/Module:-symbols}
4
+ */
5
+
1
6
  const generateSequence = (base, from, to) => {
2
7
  const result = [];
3
8
 
@@ -16,33 +21,61 @@ const generateSequence = (base, from, to) => {
16
21
 
17
22
  // blocks
18
23
 
24
+ /** Vertical block elements in 1/8th increments (index 0 = space, 7 = full block).
25
+ * @type {string[]}
26
+ */
19
27
  export const vBlocks8th = [' ', ...generateSequence(0x2581, 0, 7)];
28
+ /** Horizontal block elements in 1/8th increments (index 0 = space, 7 = full block).
29
+ * @type {string[]}
30
+ */
20
31
  export const hBlocks8th = [' ', ...generateSequence(0x2588, 7, 0, -1)];
32
+ /** Full block character (█). */
21
33
  export const fullBlock = '\u{2588}';
22
34
 
35
+ /** Left 1/8th block line. */
23
36
  export const lLine = hBlocks8th[1];
37
+ /** Right 1/8th block line. */
24
38
  export const rLine = `\u{2595}`;
39
+ /** Top 1/8th block line. */
25
40
  export const tLine = `\u{2594}`;
41
+ /** Bottom 1/8th block line. */
26
42
  export const bLine = vBlocks8th[1];
27
43
 
44
+ /** Left half block. */
28
45
  export const lHalf = hBlocks8th[4];
46
+ /** Right half block. */
29
47
  export const rHalf = `\u{2590}`;
48
+ /** Top half block. */
30
49
  export const tHalf = `\u{2580}`;
50
+ /** Bottom half block. */
31
51
  export const bHalf = vBlocks8th[4];
32
52
 
53
+ /** Top-left quadrant block. */
33
54
  export const tlQuadrant = '\u{2598}';
55
+ /** Bottom-left quadrant block. */
34
56
  export const blQuadrant = '\u{2596}';
57
+ /** Top-right quadrant block. */
35
58
  export const trQuadrant = '\u{259D}';
59
+ /** Bottom-right quadrant block. */
36
60
  export const brQuadrant = '\u{2597}';
37
61
 
62
+ /** Top-left + bottom-right diagonal quadrants. */
38
63
  export const tlBrQuadrants = `\u{259A}`;
64
+ /** Top-right + bottom-left diagonal quadrants. */
39
65
  export const trBlQuadrants = `\u{259E}`;
40
66
 
67
+ /** Negative (inverse) top-left quadrant. */
41
68
  export const tlNegativeQuadrant = '\u{259F}';
69
+ /** Negative (inverse) bottom-left quadrant. */
42
70
  export const blNegativeQuadrant = '\u{259C}';
71
+ /** Negative (inverse) top-right quadrant. */
43
72
  export const trNegativeQuadrant = '\u{2599}';
73
+ /** Negative (inverse) bottom-right quadrant. */
44
74
  export const brNegativeQuadrant = '\u{259B}';
45
75
 
76
+ /** All 16 quadrant block characters indexed by bitmask (TL=1, TR=2, BL=4, BR=8).
77
+ * @type {string[]}
78
+ */
46
79
  export const quadrants = [
47
80
  ' ',
48
81
  tlQuadrant,
@@ -62,70 +95,121 @@ export const quadrants = [
62
95
  fullBlock
63
96
  ];
64
97
 
98
+ /** Returns the quadrant character for the given corner flags.
99
+ * @param {boolean} tl - Top-left.
100
+ * @param {boolean} tr - Top-right.
101
+ * @param {boolean} bl - Bottom-left.
102
+ * @param {boolean} br - Bottom-right.
103
+ * @returns {string}
104
+ */
65
105
  export const quadrant = (tl, tr, bl, br) => quadrants[(tl ? 1 : 0) + (tr ? 2 : 0) + (bl ? 4 : 0) + (br ? 8 : 0)];
66
106
 
67
107
  // shades
68
108
 
109
+ /** Shade characters from empty to full: space, light, medium, dark, full block.
110
+ * @type {string[]}
111
+ */
69
112
  export const shades = [' ', ...generateSequence(0x2591, 0, 2), fullBlock];
70
113
 
114
+ /** Light shade character (░). */
71
115
  export const shadeLight = shades[1];
116
+ /** Medium shade character (▒). */
72
117
  export const shadeMedium = shades[2];
118
+ /** Dark shade character (▓). */
73
119
  export const shadeDark = shades[3];
74
120
 
75
121
  // ellipses
76
122
 
77
- export const hellip = '\u{2026}'; // horizontal ellipsis
78
- export const vellip = '\u{22EE}'; // vertical ellipsis
79
- export const ctdot = '\u{22EF}'; // midline horizontal ellipsis
80
- export const utdot = '\u{22F0}'; // up right diagonal ellipsis
81
- export const dtdot = '\u{22F1}'; // down right diagonal ellipsis
123
+ /** Horizontal ellipsis (…). */
124
+ export const hellip = '\u{2026}';
125
+ /** Vertical ellipsis (⋮). */
126
+ export const vellip = '\u{22EE}';
127
+ /** Centered triple dots (⋯). */
128
+ export const ctdot = '\u{22EF}';
129
+ /** Up-pointing triple dots (⋰). */
130
+ export const utdot = '\u{22F0}';
131
+ /** Down-pointing triple dots (⋱). */
132
+ export const dtdot = '\u{22F1}';
82
133
 
83
134
  export {hellip as ellipsis};
84
135
 
85
136
  // math
86
137
 
138
+ /** Infinity symbol (∞). */
87
139
  export const infinity = '\u{221e}';
140
+ /** Plus-minus sign (±). */
88
141
  export const plusMinus = '\u{00B1}';
142
+ /** Minus-plus sign (∓). */
89
143
  export const minusPlus = '\u{2213}';
144
+ /** Tilde operator (∼). */
90
145
  export const tilde = '\u{223C}';
146
+ /** Minus sign (−). */
91
147
  export const minus = '\u{2212}';
148
+ /** Multiplication sign (×). */
92
149
  export const multiplication = '\u{00D7}';
150
+ /** Division sign (÷). */
93
151
  export const division = '\u{00F7}';
152
+ /** N-ary product (∏). */
94
153
  export const product = '\u{220F}';
154
+ /** N-ary summation (∑). */
95
155
  export const sum = '\u{2211}';
156
+ /** For all (∀). */
96
157
  export const forAll = '\u{2200}';
158
+ /** There exists (∃). */
97
159
  export const exist = '\u{2203}';
160
+ /** Degree sign (°). */
98
161
  export const degree = '\u{00B0}';
99
162
 
100
163
  export {multiplication as times};
101
164
 
165
+ /** Superscript plus (⁺). */
102
166
  export const superscriptPlus = '\u{207A}';
167
+ /** Superscript minus (⁻). */
103
168
  export const superscriptMinus = '\u{207B}';
169
+ /** Subscript plus (₊). */
104
170
  export const subscriptPlus = '\u{208A}';
171
+ /** Subscript minus (₋). */
105
172
  export const subscriptMinus = '\u{208B}';
106
173
 
107
- export const permille = '\u{2030}'; // per thousand
108
- export const permyriad = '\u{2031}'; // per ten thousand
174
+ /** Per mille sign (‰). */
175
+ export const permille = '\u{2030}';
176
+ /** Per myriad sign (‱). */
177
+ export const permyriad = '\u{2031}';
109
178
 
110
179
  // dashes
111
180
 
181
+ /** Hyphen (‐). */
112
182
  export const hyphen = '\u{2010}';
183
+ /** Figure dash (‒). */
113
184
  export const figureDash = '\u{2012}';
185
+ /** En dash (–). */
114
186
  export const ndash = '\u{2013}';
187
+ /** Em dash (—). */
115
188
  export const mdash = '\u{2014}';
189
+ /** Horizontal bar (―). */
116
190
  export const horbar = '\u{2015}';
117
191
 
118
192
  // marks
119
193
 
194
+ /** Ballot box (☐). */
120
195
  export const ballotBox = '\u{2610}';
196
+ /** Ballot box with check (☑). */
121
197
  export const ballotBoxChecked = '\u{2611}';
198
+ /** Ballot box with bold check (🗹). */
122
199
  export const ballotBoxBoldChecked = '\u{1f5f9}';
200
+ /** Ballot box with X (☒). */
123
201
  export const ballotBoxX = '\u{2612}';
124
202
 
203
+ /** Check mark (✓). */
125
204
  export const checkMark = '\u{2713}';
205
+ /** Heavy check mark (✔). */
126
206
  export const checkMarkHeavy = '\u{2714}';
207
+ /** Light check mark (🗸). */
127
208
  export const checkMarkLight = '\u{1f5f8}';
128
209
 
210
+ /** Ballot X (✖). */
129
211
  export const ballotX = '\u{2716}';
212
+ /** Heavy ballot X (✗). */
130
213
  export const ballotXHeavy = '\u{2717}';
214
+ /** Light ballot X (🗷). */
131
215
  export const ballotXLight = '\u{1f5f7}';
@@ -0,0 +1,38 @@
1
+ import Box from '../box.js';
2
+ import {LineTheme} from '../themes/utils.js';
3
+
4
+ /** A rectangular region to skip when drawing borders (merged cell area). */
5
+ export interface SkipRect {
6
+ /** Left column. */
7
+ x: number;
8
+ /** Top row. */
9
+ y: number;
10
+ /** Width in columns. */
11
+ width: number;
12
+ /** Height in rows. */
13
+ height: number;
14
+ }
15
+
16
+ /** Options for `draw()`. */
17
+ export interface DrawOptions {
18
+ /** Rectangular regions to skip (merged cells). */
19
+ skip?: SkipRect[];
20
+ /** Fill symbol for cell interiors (default: ' '). */
21
+ symbol?: string;
22
+ }
23
+
24
+ /** Draws table borders based on a line theme and axis definitions.
25
+ * @param lineTheme - Line theme object defining border characters.
26
+ * @param hAxis - Horizontal axis pattern.
27
+ * @param vAxis - Vertical axis pattern.
28
+ * @param options - Draw options.
29
+ * @returns A Box containing the drawn borders.
30
+ */
31
+ export function draw(
32
+ lineTheme: LineTheme,
33
+ hAxis: (string | number)[],
34
+ vAxis: (string | number)[],
35
+ options?: DrawOptions
36
+ ): Box;
37
+
38
+ export default draw;
@@ -13,8 +13,7 @@ import Box from '../box.js';
13
13
 
14
14
  const isSkipped = (skip, x, y) => {
15
15
  for (const rect of skip) {
16
- if (rect.x <= x && x < rect.x + rect.width && rect.y <= y && y < rect.y + rect.height)
17
- return true;
16
+ if (rect.x <= x && x < rect.x + rect.width && rect.y <= y && y < rect.y + rect.height) return true;
18
17
  }
19
18
  return false;
20
19
  };
@@ -69,6 +68,15 @@ const drawRow = (lineTheme, hAxis, vAxis, skip, symbol, y, i) =>
69
68
  })
70
69
  .join('');
71
70
 
71
+ /** Draws table borders using a line theme and axis definitions.
72
+ * @param {object} lineTheme - The line theme defining border characters.
73
+ * @param {(string|number)[]} hAxis - Horizontal axis definition (alternating style/size values).
74
+ * @param {(string|number)[]} vAxis - Vertical axis definition (alternating style/size values).
75
+ * @param {object} [options] - Options.
76
+ * @param {{x: number, y: number, width: number, height: number}[]} [options.skip=[]] - Rectangles to skip (for merged cells).
77
+ * @param {string} [options.symbol=' '] - Fill character for cell interiors.
78
+ * @returns {import('../box.js').Box} A Box with the drawn borders.
79
+ */
72
80
  export const draw = (lineTheme, hAxis, vAxis, {skip = [], symbol = ' '} = {}) =>
73
81
  new Box(
74
82
  vAxis
@@ -0,0 +1,8 @@
1
+ import {draw} from './draw-borders.js';
2
+ import Table from './table.js';
3
+
4
+ export {Table, draw};
5
+ /** Shortcut for `Table.make()`. */
6
+ export const make: typeof Table.make;
7
+
8
+ export default make;
@@ -2,6 +2,7 @@ import draw from './draw-borders.js';
2
2
  import Table from './table.js';
3
3
 
4
4
  export {Table, draw};
5
+ /** Shortcut for `Table.make()`. */
5
6
  export const make = Table.make;
6
7
 
7
8
  export default make;