console-toolkit 1.2.15 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/README.md +3 -0
  2. package/llms-full.txt +64 -4
  3. package/package.json +6 -6
  4. package/src/alphanumeric/arrows.js +0 -23
  5. package/src/alphanumeric/fractions.js +0 -49
  6. package/src/alphanumeric/number-formatters.js +0 -44
  7. package/src/alphanumeric/roman.js +0 -12
  8. package/src/alphanumeric/unicode-cultural-numbers.js +0 -1
  9. package/src/alphanumeric/unicode-letters.js +0 -8
  10. package/src/alphanumeric/unicode-numbers.js +0 -21
  11. package/src/alphanumeric/utils.js +0 -26
  12. package/src/ansi/csi.js +0 -49
  13. package/src/ansi/sgr-state.js +7 -50
  14. package/src/ansi/sgr.js +0 -420
  15. package/src/box.d.ts +4 -1
  16. package/src/box.js +15 -115
  17. package/src/charts/bars/block-frac-grouped.js +0 -6
  18. package/src/charts/bars/block-frac.js +1 -14
  19. package/src/charts/bars/block-grouped.js +0 -6
  20. package/src/charts/bars/block.js +1 -14
  21. package/src/charts/bars/draw-grouped.js +0 -4
  22. package/src/charts/bars/draw-stacked.js +0 -4
  23. package/src/charts/bars/frac-grouped.js +2 -14
  24. package/src/charts/bars/plain-grouped.js +0 -6
  25. package/src/charts/bars/plain.js +1 -28
  26. package/src/charts/columns/block-frac-grouped.js +0 -6
  27. package/src/charts/columns/block-frac.js +0 -13
  28. package/src/charts/columns/block-grouped.js +0 -6
  29. package/src/charts/columns/block.js +0 -13
  30. package/src/charts/columns/draw-grouped.js +1 -5
  31. package/src/charts/columns/draw-stacked.js +0 -4
  32. package/src/charts/columns/frac-grouped.js +1 -13
  33. package/src/charts/columns/plain-grouped.js +0 -6
  34. package/src/charts/columns/plain.js +0 -13
  35. package/src/charts/themes/default.js +0 -1
  36. package/src/charts/themes/rainbow-reversed.js +0 -1
  37. package/src/charts/themes/rainbow.js +0 -1
  38. package/src/charts/utils.js +2 -28
  39. package/src/draw-block-frac.js +0 -14
  40. package/src/draw-block.js +0 -24
  41. package/src/meta.js +0 -64
  42. package/src/output/show.d.ts +8 -3
  43. package/src/output/show.js +7 -38
  44. package/src/output/updater.d.ts +8 -3
  45. package/src/output/updater.js +4 -51
  46. package/src/output/writer.js +1 -53
  47. package/src/panel.d.ts +16 -10
  48. package/src/panel.js +21 -276
  49. package/src/plot/bitmap.js +5 -33
  50. package/src/plot/draw-line.js +0 -8
  51. package/src/plot/draw-rect.js +25 -103
  52. package/src/plot/index.js +0 -22
  53. package/src/plot/to-quads.js +3 -6
  54. package/src/spinner/spin.js +23 -20
  55. package/src/spinner/spinner.d.ts +16 -2
  56. package/src/spinner/spinner.js +22 -34
  57. package/src/spinner/spinners.js +0 -16
  58. package/src/strings/clip.js +0 -10
  59. package/src/strings/parse.js +0 -7
  60. package/src/strings/split.js +0 -15
  61. package/src/strings.d.ts +2 -0
  62. package/src/strings.js +2 -32
  63. package/src/style.js +2 -58
  64. package/src/symbols.js +0 -84
  65. package/src/table/draw-borders.js +0 -9
  66. package/src/table/index.d.ts +1 -1
  67. package/src/table/index.js +0 -1
  68. package/src/table/table.js +3 -58
  69. package/src/themes/blocks/unicode-half.js +0 -1
  70. package/src/themes/blocks/unicode-thin.js +0 -1
  71. package/src/themes/lines/ascii-compact.js +5 -9
  72. package/src/themes/lines/ascii-dots.js +2 -7
  73. package/src/themes/lines/ascii-girder.js +4 -7
  74. package/src/themes/lines/ascii-github.js +5 -9
  75. package/src/themes/lines/ascii-reddit.js +5 -9
  76. package/src/themes/lines/ascii-rounded.js +5 -9
  77. package/src/themes/lines/ascii.js +5 -9
  78. package/src/themes/lines/unicode-bold.js +8 -14
  79. package/src/themes/lines/unicode-rounded.js +8 -14
  80. package/src/themes/lines/unicode.js +8 -14
  81. package/src/themes/utils.d.ts +6 -0
  82. package/src/themes/utils.js +6 -7
  83. package/src/turtle/draw-line-art.js +26 -18
  84. package/src/turtle/draw-unicode.js +0 -8
  85. package/src/turtle/index.d.ts +1 -1
  86. package/src/turtle/index.js +0 -8
  87. package/src/turtle/turtle.js +0 -120
@@ -10,9 +10,6 @@ import {
10
10
  matchSgr
11
11
  } from './sgr.js';
12
12
 
13
- /** The fully reset SGR state with all properties set to `null`.
14
- * @type {object}
15
- */
16
13
  export const RESET_STATE = {
17
14
  bold: null,
18
15
  dim: null,
@@ -33,11 +30,6 @@ const defaultState = Symbol('defaultState');
33
30
 
34
31
  let toState;
35
32
 
36
- /** Extracts the cumulative SGR state from a string by parsing all SGR sequences.
37
- * @param {string} s - The string to parse.
38
- * @param {object} [initState] - Initial state to build upon.
39
- * @returns {object} The resulting SGR state.
40
- */
41
33
  export const extractState = (s, initState = defaultState) => {
42
34
  let state = toState(initState);
43
35
  matchSgr.lastIndex = 0;
@@ -48,7 +40,7 @@ export const extractState = (s, initState = defaultState) => {
48
40
  toState = value => {
49
41
  switch (typeof value) {
50
42
  case 'object':
51
- if (!value) return RESET_STATE;
43
+ if (!value) return {...RESET_STATE};
52
44
  if (typeof value.getState == 'function') return value.getState();
53
45
  return value;
54
46
  case 'string':
@@ -59,22 +51,19 @@ toState = value => {
59
51
  };
60
52
  export {toState};
61
53
 
62
- const TOTAL_RESETS = Array.from(Object.keys(RESET_STATE)).length;
54
+ const RESET_KEYS = Object.keys(RESET_STATE);
55
+ const TOTAL_RESETS = RESET_KEYS.length;
63
56
 
64
57
  const getStateResets = state => {
65
58
  let resetCount = 0;
66
59
 
67
- for (const name of Object.keys(RESET_STATE)) {
60
+ for (const name of RESET_KEYS) {
68
61
  if (state[name] === null) ++resetCount;
69
62
  }
70
63
 
71
64
  return resetCount;
72
65
  };
73
66
 
74
- /** Combines multiple SGR states, with later states overriding earlier ones.
75
- * @param {...(object|string)} states - States to combine.
76
- * @returns {object} The combined state.
77
- */
78
67
  export const combineStates = (...states) => {
79
68
  let state = {};
80
69
  for (const s of states) {
@@ -86,10 +75,6 @@ export const combineStates = (...states) => {
86
75
  return state;
87
76
  };
88
77
 
89
- /** Converts an array of SGR command strings into an SGR state object.
90
- * @param {string[]} commands - Array of SGR command strings.
91
- * @returns {object} The resulting state.
92
- */
93
78
  export const commandsToState = commands => {
94
79
  let state = {};
95
80
  for (let i = 0; i < commands.length; ++i) {
@@ -97,7 +82,7 @@ export const commandsToState = commands => {
97
82
  switch (currentCommand) {
98
83
  case '': // reset
99
84
  case Commands.RESET_ALL:
100
- state = RESET_STATE;
85
+ state = {...RESET_STATE};
101
86
  continue;
102
87
  case Commands.BOLD:
103
88
  state.bold = currentCommand;
@@ -207,11 +192,6 @@ export const commandsToState = commands => {
207
192
  return state;
208
193
  };
209
194
 
210
- /** Adds SGR commands to an existing state.
211
- * @param {object} state - The current state.
212
- * @param {string[]} commands - Commands to add.
213
- * @returns {object} The updated state.
214
- */
215
195
  export const addCommandsToState = (state, commands) => combineStates(state, commandsToState(commands));
216
196
 
217
197
  const equalColors = (a, b) => {
@@ -238,10 +218,6 @@ const resetColorProperties = {
238
218
 
239
219
  const chainedStates = {bold: 1, dim: 1};
240
220
 
241
- /** Converts an SGR state to an array of SGR command strings.
242
- * @param {object|string} state - The state to convert.
243
- * @returns {string[]} The command strings.
244
- */
245
221
  export const stateToCommands = state => {
246
222
  state = toState(state);
247
223
  const commands = [];
@@ -282,11 +258,6 @@ export const stateToCommands = state => {
282
258
  return resetCount === TOTAL_RESETS ? [''] : commands;
283
259
  };
284
260
 
285
- /** Computes the minimal SGR commands needed to transition from one state to another.
286
- * @param {object|string} prev - The previous state.
287
- * @param {object|string} next - The next state.
288
- * @returns {string[]} The transition commands.
289
- */
290
261
  export const stateTransition = (prev, next) => {
291
262
  prev = toState(prev);
292
263
  next = toState(next);
@@ -315,7 +286,7 @@ export const stateTransition = (prev, next) => {
315
286
  if (next.bold === null) ++resetCount;
316
287
  if (next.dim === null) ++resetCount;
317
288
 
318
- for (const name of Object.keys(RESET_STATE)) {
289
+ for (const name of RESET_KEYS) {
319
290
  if (chainedStates[name] === 1) continue; // skip chained states
320
291
  const value = next[name];
321
292
  if (resetColorProperties.hasOwnProperty(name)) {
@@ -348,11 +319,6 @@ export const stateTransition = (prev, next) => {
348
319
  return commands;
349
320
  };
350
321
 
351
- /** Computes the minimal SGR commands to reverse a state transition (from next back to prev).
352
- * @param {object|string} prev - The state to restore.
353
- * @param {object|string} next - The current state.
354
- * @returns {string[]} The reverse transition commands.
355
- */
356
322
  export const stateReverseTransition = (prev, next) => {
357
323
  prev = toState(prev);
358
324
  next = toState(next);
@@ -381,7 +347,7 @@ export const stateReverseTransition = (prev, next) => {
381
347
  if (prev.bold === null) ++resetCount;
382
348
  if (prev.dim === null) ++resetCount;
383
349
 
384
- for (const name of Object.keys(RESET_STATE)) {
350
+ for (const name of RESET_KEYS) {
385
351
  if (chainedStates[name] === 1) continue; // skip chained states
386
352
  const value = prev[name];
387
353
  if (resetColorProperties.hasOwnProperty(name)) {
@@ -410,17 +376,8 @@ export const stateReverseTransition = (prev, next) => {
410
376
  return commands;
411
377
  };
412
378
 
413
- /** Converts an array of SGR commands to an escape sequence string, or empty string if no commands.
414
- * @param {string[]} commands
415
- * @returns {string}
416
- */
417
379
  export const stringifyCommands = commands => (commands?.length ? setCommands(commands) : '');
418
380
 
419
- /** Optimizes SGR sequences in a string by computing minimal state transitions.
420
- * @param {string} s - The string to optimize.
421
- * @param {object} [initState] - Initial state.
422
- * @returns {string} The optimized string.
423
- */
424
381
  export const optimize = (s, initState = defaultState) => {
425
382
  let state = toState(initState),
426
383
  result = '',