console-toolkit 1.2.14 → 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 (88) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +4 -0
  3. package/llms-full.txt +64 -4
  4. package/package.json +6 -6
  5. package/src/alphanumeric/arrows.js +0 -23
  6. package/src/alphanumeric/fractions.js +0 -49
  7. package/src/alphanumeric/number-formatters.js +0 -44
  8. package/src/alphanumeric/roman.js +0 -12
  9. package/src/alphanumeric/unicode-cultural-numbers.js +0 -1
  10. package/src/alphanumeric/unicode-letters.js +0 -8
  11. package/src/alphanumeric/unicode-numbers.js +0 -21
  12. package/src/alphanumeric/utils.js +0 -26
  13. package/src/ansi/csi.js +0 -49
  14. package/src/ansi/sgr-state.js +7 -50
  15. package/src/ansi/sgr.js +0 -420
  16. package/src/box.d.ts +4 -1
  17. package/src/box.js +15 -115
  18. package/src/charts/bars/block-frac-grouped.js +0 -6
  19. package/src/charts/bars/block-frac.js +1 -14
  20. package/src/charts/bars/block-grouped.js +0 -6
  21. package/src/charts/bars/block.js +1 -14
  22. package/src/charts/bars/draw-grouped.js +0 -4
  23. package/src/charts/bars/draw-stacked.js +0 -4
  24. package/src/charts/bars/frac-grouped.js +2 -14
  25. package/src/charts/bars/plain-grouped.js +0 -6
  26. package/src/charts/bars/plain.js +1 -28
  27. package/src/charts/columns/block-frac-grouped.js +0 -6
  28. package/src/charts/columns/block-frac.js +0 -13
  29. package/src/charts/columns/block-grouped.js +0 -6
  30. package/src/charts/columns/block.js +0 -13
  31. package/src/charts/columns/draw-grouped.js +1 -5
  32. package/src/charts/columns/draw-stacked.js +0 -4
  33. package/src/charts/columns/frac-grouped.js +1 -13
  34. package/src/charts/columns/plain-grouped.js +0 -6
  35. package/src/charts/columns/plain.js +0 -13
  36. package/src/charts/themes/default.js +0 -1
  37. package/src/charts/themes/rainbow-reversed.js +0 -1
  38. package/src/charts/themes/rainbow.js +0 -1
  39. package/src/charts/utils.js +2 -28
  40. package/src/draw-block-frac.js +0 -14
  41. package/src/draw-block.js +0 -24
  42. package/src/meta.js +0 -64
  43. package/src/output/show.d.ts +8 -3
  44. package/src/output/show.js +7 -38
  45. package/src/output/updater.d.ts +8 -3
  46. package/src/output/updater.js +4 -51
  47. package/src/output/writer.js +1 -53
  48. package/src/panel.d.ts +16 -10
  49. package/src/panel.js +21 -276
  50. package/src/plot/bitmap.js +5 -33
  51. package/src/plot/draw-line.js +0 -8
  52. package/src/plot/draw-rect.js +25 -103
  53. package/src/plot/index.js +0 -22
  54. package/src/plot/to-quads.js +3 -6
  55. package/src/spinner/spin.js +23 -20
  56. package/src/spinner/spinner.d.ts +16 -2
  57. package/src/spinner/spinner.js +22 -34
  58. package/src/spinner/spinners.js +0 -16
  59. package/src/strings/clip.js +0 -10
  60. package/src/strings/parse.js +0 -7
  61. package/src/strings/split.js +0 -15
  62. package/src/strings.d.ts +2 -0
  63. package/src/strings.js +2 -32
  64. package/src/style.js +2 -58
  65. package/src/symbols.js +0 -84
  66. package/src/table/draw-borders.js +0 -9
  67. package/src/table/index.d.ts +1 -1
  68. package/src/table/index.js +0 -1
  69. package/src/table/table.js +3 -58
  70. package/src/themes/blocks/unicode-half.js +0 -1
  71. package/src/themes/blocks/unicode-thin.js +0 -1
  72. package/src/themes/lines/ascii-compact.js +5 -9
  73. package/src/themes/lines/ascii-dots.js +2 -7
  74. package/src/themes/lines/ascii-girder.js +4 -7
  75. package/src/themes/lines/ascii-github.js +5 -9
  76. package/src/themes/lines/ascii-reddit.js +5 -9
  77. package/src/themes/lines/ascii-rounded.js +5 -9
  78. package/src/themes/lines/ascii.js +5 -9
  79. package/src/themes/lines/unicode-bold.js +8 -14
  80. package/src/themes/lines/unicode-rounded.js +8 -14
  81. package/src/themes/lines/unicode.js +8 -14
  82. package/src/themes/utils.d.ts +6 -0
  83. package/src/themes/utils.js +6 -7
  84. package/src/turtle/draw-line-art.js +26 -18
  85. package/src/turtle/draw-unicode.js +0 -8
  86. package/src/turtle/index.d.ts +1 -1
  87. package/src/turtle/index.js +0 -8
  88. package/src/turtle/turtle.js +0 -120
@@ -1,12 +1,8 @@
1
- import {populateTheme} from '../utils.js';
1
+ import {makeLineTheme} from '../utils.js';
2
2
 
3
- /** ASCII Reddit-style line theme. */
4
- export const lineTheme = {};
5
-
6
- const markdownReddit11 = {t: ' | ', m: ' | ', b: ' | ', v: ' | ', h: '---'},
7
- markdownReddit21 = {t: ' | ', m: ' | ', b: ' | ', v: ' | ', h: '==='};
8
-
9
- populateTheme(lineTheme, markdownReddit11, 1, 1);
10
- populateTheme(lineTheme, markdownReddit21, 2, 1);
3
+ export const lineTheme = makeLineTheme([
4
+ [{t: ' | ', m: ' | ', b: ' | ', v: ' | ', h: '---'}, 1, 1],
5
+ [{t: ' | ', m: ' | ', b: ' | ', v: ' | ', h: '==='}, 2, 1]
6
+ ]);
11
7
 
12
8
  export default lineTheme;
@@ -1,12 +1,8 @@
1
- import {populateTheme} from '../utils.js';
1
+ import {makeLineTheme} from '../utils.js';
2
2
 
3
- /** ASCII rounded line theme. */
4
- export const lineTheme = {};
5
-
6
- const rounded11 = {t: '...', m: ':+:', b: "'''", v: '|||', h: '---'},
7
- rounded21 = {t: '...', m: ':+:', b: "'''", v: '|||', h: '==='};
8
-
9
- populateTheme(lineTheme, rounded11, 1, 1);
10
- populateTheme(lineTheme, rounded21, 2, 1);
3
+ export const lineTheme = makeLineTheme([
4
+ [{t: '...', m: ':+:', b: "'''", v: '|||', h: '---'}, 1, 1],
5
+ [{t: '...', m: ':+:', b: "'''", v: '|||', h: '==='}, 2, 1]
6
+ ]);
11
7
 
12
8
  export default lineTheme;
@@ -1,12 +1,8 @@
1
- import {populateTheme} from '../utils.js';
1
+ import {makeLineTheme} from '../utils.js';
2
2
 
3
- /** ASCII line theme. */
4
- export const lineTheme = {};
5
-
6
- const table11 = {t: '+++', m: '+++', b: '+++', v: '|||', h: '---'},
7
- table21 = {t: '+++', m: '+++', b: '+++', v: '|||', h: '==='};
8
-
9
- populateTheme(lineTheme, table11, 1, 1);
10
- populateTheme(lineTheme, table21, 2, 1);
3
+ export const lineTheme = makeLineTheme([
4
+ [{t: '+++', m: '+++', b: '+++', v: '|||', h: '---'}, 1, 1],
5
+ [{t: '+++', m: '+++', b: '+++', v: '|||', h: '==='}, 2, 1]
6
+ ]);
11
7
 
12
8
  export default lineTheme;
@@ -1,16 +1,10 @@
1
- import {populateTheme} from '../utils.js';
2
-
3
- /** Unicode bold box-drawing line theme. */
4
- export const lineTheme = {};
5
-
6
- const table11 = {t: '┌┬┐', m: '├┼┤', b: '└┴┘', v: '│││', h: '───'},
7
- table12 = {t: '┎┰┒', m: '┠╂┨', b: '┖┸┚', v: '┃┃┃', h: '───'},
8
- table21 = {t: '┍┯┑', m: '┝┿┥', b: '┕┷┙', v: '│││', h: '━━━'},
9
- table22 = {t: '┏┳┓', m: '┣╋┫', b: '┗┻┛', v: '┃┃┃', h: '━━━'};
10
-
11
- populateTheme(lineTheme, table11, 1, 1);
12
- populateTheme(lineTheme, table12, 1, 2);
13
- populateTheme(lineTheme, table21, 2, 1);
14
- populateTheme(lineTheme, table22, 2, 2);
1
+ import {makeLineTheme} from '../utils.js';
2
+
3
+ export const lineTheme = makeLineTheme([
4
+ [{t: '┌┬┐', m: '├┼┤', b: '└┴┘', v: '│││', h: '───'}, 1, 1],
5
+ [{t: '┎┰┒', m: '┠╂┨', b: '┖┸┚', v: '┃┃┃', h: '───'}, 1, 2],
6
+ [{t: '┍┯┑', m: '┝┿┥', b: '┕┷┙', v: '│││', h: '━━━'}, 2, 1],
7
+ [{t: '┏┳┓', m: '┣╋┫', b: '┗┻┛', v: '┃┃┃', h: '━━━'}, 2, 2]
8
+ ]);
15
9
 
16
10
  export default lineTheme;
@@ -1,16 +1,10 @@
1
- import {populateTheme} from '../utils.js';
2
-
3
- /** Unicode rounded box-drawing line theme. */
4
- export const lineTheme = {};
5
-
6
- const table11 = {t: '╭┬╮', m: '├┼┤', b: '╰┴╯', v: '│││', h: '───'},
7
- table12 = {t: '╓╥╖', m: '╟╫╢', b: '╙╨╜', v: '║║║', h: '───'},
8
- table21 = {t: '╒╤╕', m: '╞╪╡', b: '╘╧╛', v: '│││', h: '═══'},
9
- table22 = {t: '╔╦╗', m: '╠╬╣', b: '╚╩╝', v: '║║║', h: '═══'};
10
-
11
- populateTheme(lineTheme, table11, 1, 1);
12
- populateTheme(lineTheme, table12, 1, 2);
13
- populateTheme(lineTheme, table21, 2, 1);
14
- populateTheme(lineTheme, table22, 2, 2);
1
+ import {makeLineTheme} from '../utils.js';
2
+
3
+ export const lineTheme = makeLineTheme([
4
+ [{t: '╭┬╮', m: '├┼┤', b: '╰┴╯', v: '│││', h: '───'}, 1, 1],
5
+ [{t: '╓╥╖', m: '╟╫╢', b: '╙╨╜', v: '║║║', h: '───'}, 1, 2],
6
+ [{t: '╒╤╕', m: '╞╪╡', b: '╘╧╛', v: '│││', h: '═══'}, 2, 1],
7
+ [{t: '╔╦╗', m: '╠╬╣', b: '╚╩╝', v: '║║║', h: '═══'}, 2, 2]
8
+ ]);
15
9
 
16
10
  export default lineTheme;
@@ -1,16 +1,10 @@
1
- import {populateTheme} from '../utils.js';
2
-
3
- /** Unicode box-drawing line theme. */
4
- export const lineTheme = {};
5
-
6
- const table11 = {t: '┌┬┐', m: '├┼┤', b: '└┴┘', v: '│││', h: '───'},
7
- table12 = {t: '╓╥╖', m: '╟╫╢', b: '╙╨╜', v: '║║║', h: '───'},
8
- table21 = {t: '╒╤╕', m: '╞╪╡', b: '╘╧╛', v: '│││', h: '═══'},
9
- table22 = {t: '╔╦╗', m: '╠╬╣', b: '╚╩╝', v: '║║║', h: '═══'};
10
-
11
- populateTheme(lineTheme, table11, 1, 1);
12
- populateTheme(lineTheme, table12, 1, 2);
13
- populateTheme(lineTheme, table21, 2, 1);
14
- populateTheme(lineTheme, table22, 2, 2);
1
+ import {makeLineTheme} from '../utils.js';
2
+
3
+ export const lineTheme = makeLineTheme([
4
+ [{t: '┌┬┐', m: '├┼┤', b: '└┴┘', v: '│││', h: '───'}, 1, 1],
5
+ [{t: '╓╥╖', m: '╟╫╢', b: '╙╨╜', v: '║║║', h: '───'}, 1, 2],
6
+ [{t: '╒╤╕', m: '╞╪╡', b: '╘╧╛', v: '│││', h: '═══'}, 2, 1],
7
+ [{t: '╔╦╗', m: '╠╬╣', b: '╚╩╝', v: '║║║', h: '═══'}, 2, 2]
8
+ ]);
15
9
 
16
10
  export default lineTheme;
@@ -31,3 +31,9 @@ export function populateTheme(
31
31
  hTheme: number | string,
32
32
  vTheme: number | string
33
33
  ): void;
34
+
35
+ /** Builds a line theme from an array of `[tableDefinition, hTheme, vTheme]` entries.
36
+ * @param definitions - Array of populate-theme arguments.
37
+ * @returns A populated line theme.
38
+ */
39
+ export function makeLineTheme(definitions: Array<[TableDefinition, number | string, number | string]>): LineTheme;
@@ -10,13 +10,12 @@
10
10
 
11
11
  // The default value for 'w': 1
12
12
 
13
- /** Populates a line theme object from a table definition matrix.
14
- * Sets `t_`, `h_`, `v_`, `w_`, and `f` properties on the lineTheme.
15
- * @param {object} lineTheme - The line theme object to populate.
16
- * @param {object} tableDefinition - Definition with `t`, `m`, `b`, `v`, `h`, optional `w` and `f` properties.
17
- * @param {string|number} hTheme - Horizontal theme identifier.
18
- * @param {string|number} vTheme - Vertical theme identifier.
19
- */
13
+ export const makeLineTheme = definitions => {
14
+ const lineTheme = {};
15
+ for (const [table, hTheme, vTheme] of definitions) populateTheme(lineTheme, table, hTheme, vTheme);
16
+ return lineTheme;
17
+ };
18
+
20
19
  export const populateTheme = (lineTheme, tableDefinition, hTheme, vTheme) => {
21
20
  const w = tableDefinition.w || 1,
22
21
  s = [0, w, w << 1],
@@ -15,39 +15,47 @@ const getIndex = cell => {
15
15
  return {skipFlag, hTheme, vTheme, hIndex, vIndex};
16
16
  };
17
17
 
18
- /** Draws a Turtle's path as line art using a line theme.
19
- * @param {import('./turtle.js').Turtle} turtle - The turtle to draw.
20
- * @param {object} lineTheme - The line theme defining border characters.
21
- * @param {object} [options] - Options.
22
- * @param {string} [options.ignore=' '] - Character for empty cells.
23
- * @returns {import('../box.js').Box} A Box with the rendered line art.
24
- */
25
- export const draw = (turtle, lineTheme, {ignore = ' '} = {}) =>
26
- new Box(
18
+ export const draw = (turtle, lineTheme, {ignore = ' '} = {}) => {
19
+ const wCache = {},
20
+ vCache = {},
21
+ hCache = {},
22
+ tCache = {};
23
+ return new Box(
27
24
  turtle.cells.map(row =>
28
25
  row
29
26
  .map(cell => {
30
27
  const {skipFlag, hTheme, vTheme, hIndex, vIndex} = getIndex(cell);
31
28
  if (skipFlag) return ignore;
32
29
  if (!hTheme) {
33
- if (lineTheme['w_' + vTheme] !== 1)
30
+ let w = wCache[vTheme];
31
+ if (w === undefined) w = wCache[vTheme] = lineTheme['w_' + vTheme];
32
+ if (w !== 1)
34
33
  throw new TypeError(`Vertical theme "${vTheme}" should have width of 1 for all vertical elements`);
35
- if (!lineTheme['v_' + vTheme]) throw new TypeError(`Style has no "v_${vTheme}" property`);
36
- return lineTheme['v_' + vTheme][vIndex];
34
+ let v = vCache[vTheme];
35
+ if (v === undefined) v = vCache[vTheme] = lineTheme['v_' + vTheme];
36
+ if (!v) throw new TypeError(`Style has no "v_${vTheme}" property`);
37
+ return v[vIndex];
37
38
  }
38
39
  if (!vTheme) {
39
- if (!lineTheme['h_' + hTheme]) throw new TypeError(`Style has no "h_${hTheme}" property`);
40
- return lineTheme['h_' + hTheme][hIndex];
40
+ let h = hCache[hTheme];
41
+ if (h === undefined) h = hCache[hTheme] = lineTheme['h_' + hTheme];
42
+ if (!h) throw new TypeError(`Style has no "h_${hTheme}" property`);
43
+ return h[hIndex];
41
44
  }
42
- if (lineTheme['w_' + vTheme] !== 1)
45
+ let w = wCache[vTheme];
46
+ if (w === undefined) w = wCache[vTheme] = lineTheme['w_' + vTheme];
47
+ if (w !== 1)
43
48
  throw new TypeError(`Vertical theme "${vTheme}" should have width of 1 for all vertical elements`);
44
- if (!lineTheme['t_' + hTheme + '_' + vTheme])
45
- throw new TypeError(`Style has no "t_${hTheme}_${vTheme}" property`);
46
- return lineTheme['t_' + hTheme + '_' + vTheme][4 * hIndex + vIndex];
49
+ const tKey = hTheme + '_' + vTheme;
50
+ let t = tCache[tKey];
51
+ if (t === undefined) t = tCache[tKey] = lineTheme['t_' + hTheme + '_' + vTheme];
52
+ if (!t) throw new TypeError(`Style has no "t_${hTheme}_${vTheme}" property`);
53
+ return t[4 * hIndex + vIndex];
47
54
  })
48
55
  .join('')
49
56
  ),
50
57
  true
51
58
  );
59
+ };
52
60
 
53
61
  export default draw;
@@ -15,14 +15,6 @@ const arcs = {4: '╰', 12: '╭', 28: '╯', 36: '╮'};
15
15
 
16
16
  const getIndex = cell => (cell ? (((+cell.l || 0) * 3 + (+cell.d || 0)) * 3 + (+cell.r || 0)) * 3 + (+cell.u || 0) : 0);
17
17
 
18
- /** Draws a Turtle's path using Unicode box-drawing characters.
19
- * Supports themes 1 (thin) and 2 (thick), and optional arc characters for corners.
20
- * @param {import('./turtle.js').Turtle} turtle - The turtle to draw.
21
- * @param {object} [options] - Options.
22
- * @param {string} [options.ignore=' '] - Character for empty cells.
23
- * @param {boolean} [options.useArcs] - If true, use rounded arc characters for corners.
24
- * @returns {import('../box.js').Box} A Box with the rendered Unicode drawing.
25
- */
26
18
  export const draw = (turtle, {ignore = ' ', useArcs} = {}) =>
27
19
  new Box(
28
20
  turtle.cells.map(row =>
@@ -1,5 +1,5 @@
1
1
  import Turtle from './turtle.js';
2
- import {draw} from './draw-unicode.js';
2
+ import draw from './draw-unicode.js';
3
3
  import Box from '../box.js';
4
4
 
5
5
  declare module './turtle.js' {
@@ -1,17 +1,9 @@
1
1
  import Turtle from './turtle.js';
2
2
  import draw from './draw-unicode.js';
3
3
 
4
- /** Draws the turtle's path as a Box using Unicode box-drawing characters.
5
- * @param {object} [options] - Draw options.
6
- * @returns {import('../box.js').default}
7
- */
8
4
  Turtle.prototype.toBox = function (options) {
9
5
  return draw(this, options);
10
6
  };
11
- /** Draws the turtle's path as a string array using Unicode box-drawing characters.
12
- * @param {object} [options] - Draw options.
13
- * @returns {string[]}
14
- */
15
7
  Turtle.prototype.toStrings = function (options) {
16
8
  return this.toBox(options).toStrings();
17
9
  };
@@ -1,8 +1,5 @@
1
1
  import {addAliases} from '../meta.js';
2
2
 
3
- /** Turtle graphics on a grid. Supports directional movement, line drawing, state save/restore, and various aliases.
4
- * @see {@link https://github.com/uhop/console-toolkit/wiki/Package:-turtle}
5
- */
6
3
  export class Turtle {
7
4
  static RIGHT = 0;
8
5
  static DOWN = 1;
@@ -14,11 +11,6 @@ export class Turtle {
14
11
  static WEST = 2;
15
12
  static NORTH = 3;
16
13
 
17
- /** Creates a new Turtle on a grid of the given size.
18
- * @param {number} width - Grid width.
19
- * @param {number} height - Grid height.
20
- * @param {number} [theme=1] - The line theme/pen width.
21
- */
22
14
  constructor(width, height, theme = 1) {
23
15
  this.cells = new Array(height);
24
16
  for (let i = 0; i < height; ++i) {
@@ -33,136 +25,71 @@ export class Turtle {
33
25
  this.stack = [];
34
26
  }
35
27
 
36
- /** Resets the turtle position to (0, 0).
37
- * @returns {this}
38
- */
39
28
  reset() {
40
29
  this.position.x = this.position.y = 0;
41
30
  return this;
42
31
  }
43
- /** Sets the turtle position (clamped to grid bounds).
44
- * @param {number} x
45
- * @param {number} y
46
- * @returns {this}
47
- */
48
32
  set(x, y) {
49
33
  this.position.x = Math.max(0, Math.min(this.width - 1, x));
50
34
  this.position.y = Math.max(0, Math.min(this.height - 1, y));
51
35
  return this;
52
36
  }
53
- /** Sets the X coordinate.
54
- * @param {number} x
55
- * @returns {this}
56
- */
57
37
  setX(x) {
58
38
  this.position.x = Math.max(0, Math.min(this.width - 1, x));
59
39
  return this;
60
40
  }
61
- /** Sets the Y coordinate.
62
- * @param {number} y
63
- * @returns {this}
64
- */
65
41
  setY(y) {
66
42
  this.position.y = Math.max(0, Math.min(this.height - 1, y));
67
43
  return this;
68
44
  }
69
- /** Moves the turtle by a relative offset without drawing.
70
- * @param {number} dx - X offset.
71
- * @param {number} dy - Y offset.
72
- * @returns {this}
73
- */
74
45
  add(dx, dy) {
75
46
  return this.set(this.position.x + dx, this.position.y + dy);
76
47
  }
77
- /** Adds to the X coordinate.
78
- * @param {number} dx - X offset.
79
- * @returns {this}
80
- */
81
48
  addX(dx) {
82
49
  return this.setX(this.position.x + dx);
83
50
  }
84
- /** Adds to the Y coordinate.
85
- * @param {number} dy - Y offset.
86
- * @returns {this}
87
- */
88
51
  addY(dy) {
89
52
  return this.setY(this.position.y + dy);
90
53
  }
91
54
 
92
- /** Sets the line theme/pen width.
93
- * @param {number} theme
94
- * @returns {this}
95
- */
96
55
  setTheme(theme) {
97
56
  this.theme = theme;
98
57
  return this;
99
58
  }
100
59
 
101
- /** Sets the turtle direction (0=right, 1=down, 2=left, 3=up).
102
- * @param {number} direction
103
- * @returns {this}
104
- */
105
60
  setDirection(direction) {
106
61
  this.direction = direction % 4;
107
62
  return this;
108
63
  }
109
- /** Sets direction to up.
110
- * @returns {this}
111
- */
112
64
  setUp() {
113
65
  return this.setDirection(Turtle.UP);
114
66
  }
115
- /** Sets direction to down.
116
- * @returns {this}
117
- */
118
67
  setDown() {
119
68
  return this.setDirection(Turtle.DOWN);
120
69
  }
121
- /** Sets direction to left.
122
- * @returns {this}
123
- */
124
70
  setLeft() {
125
71
  return this.setDirection(Turtle.LEFT);
126
72
  }
127
- /** Sets direction to right.
128
- * @returns {this}
129
- */
130
73
  setRight() {
131
74
  return this.setDirection(Turtle.RIGHT);
132
75
  }
133
- /** Turns the turtle 90° to the left.
134
- * @returns {this}
135
- */
136
76
  left() {
137
77
  return this.setDirection((this.direction + 3) % 4);
138
78
  }
139
- /** Turns the turtle 90° to the right.
140
- * @returns {this}
141
- */
142
79
  right() {
143
80
  return this.setDirection((this.direction + 1) % 4);
144
81
  }
145
82
 
146
- /** Saves the current position, direction, and theme onto the stack.
147
- * @returns {this}
148
- */
149
83
  save() {
150
84
  this.stack.push([this.position.x, this.position.y, this.direction, this.theme]);
151
85
  return this;
152
86
  }
153
- /** Restores the position, direction, and theme from the stack.
154
- * @returns {this}
155
- */
156
87
  restore() {
157
88
  if (!this.stack.length) throw new ReferenceError('Unmatched restore');
158
89
  [this.position.x, this.position.y, this.direction, this.theme] = this.stack.pop();
159
90
  return this;
160
91
  }
161
92
 
162
- /** Moves the turtle up, drawing a line.
163
- * @param {number} distance - Number of cells to move.
164
- * @returns {this}
165
- */
166
93
  moveUp(distance) {
167
94
  if (!distance) return this;
168
95
  if (distance < 0) return this.moveDown(-distance);
@@ -189,10 +116,6 @@ export class Turtle {
189
116
  this.position.y = last;
190
117
  return this;
191
118
  }
192
- /** Moves the turtle down, drawing a line.
193
- * @param {number} distance - Number of cells to move.
194
- * @returns {this}
195
- */
196
119
  moveDown(distance) {
197
120
  if (!distance) return this;
198
121
  if (distance < 0) return this.moveUp(-distance);
@@ -219,10 +142,6 @@ export class Turtle {
219
142
  this.position.y = last;
220
143
  return this;
221
144
  }
222
- /** Moves the turtle left, drawing a line.
223
- * @param {number} distance - Number of cells to move.
224
- * @returns {this}
225
- */
226
145
  moveLeft(distance) {
227
146
  if (!distance) return this;
228
147
  if (distance < 0) return this.moveRight(-distance);
@@ -249,10 +168,6 @@ export class Turtle {
249
168
  this.position.x = last;
250
169
  return this;
251
170
  }
252
- /** Moves the turtle right, drawing a line.
253
- * @param {number} distance - Number of cells to move.
254
- * @returns {this}
255
- */
256
171
  moveRight(distance) {
257
172
  if (!distance) return this;
258
173
  if (distance < 0) return this.moveLeft(-distance);
@@ -279,11 +194,6 @@ export class Turtle {
279
194
  this.position.x = last;
280
195
  return this;
281
196
  }
282
- /** Moves the turtle in the given direction, drawing a line.
283
- * @param {number} direction - Direction (0=right, 1=down, 2=left, 3=up).
284
- * @param {number} distance - Number of cells to move.
285
- * @returns {this}
286
- */
287
197
  move(direction, distance) {
288
198
  switch (direction) {
289
199
  case Turtle.UP:
@@ -297,25 +207,13 @@ export class Turtle {
297
207
  }
298
208
  return this;
299
209
  }
300
- /** Moves the turtle forward in its current direction.
301
- * @param {number} distance - Number of cells to move.
302
- * @returns {this}
303
- */
304
210
  forward(distance) {
305
211
  return this.move(this.direction, distance);
306
212
  }
307
- /** Moves the turtle backward (opposite of current direction).
308
- * @param {number} distance - Number of cells to move.
309
- * @returns {this}
310
- */
311
213
  backward(distance) {
312
214
  return this.move((this.direction + 2) % 4, distance);
313
215
  }
314
216
 
315
- /** Marks a half-line from the center of the current cell in the given direction.
316
- * @param {number} direction - Direction (0=right, 1=down, 2=left, 3=up).
317
- * @returns {this}
318
- */
319
217
  markHalf(direction) {
320
218
  let cell = this.cells[this.position.y][this.position.x];
321
219
  if (!cell) cell = this.cells[this.position.y][this.position.x] = {};
@@ -335,39 +233,21 @@ export class Turtle {
335
233
  }
336
234
  return this;
337
235
  }
338
- /** Marks a half-step line forward.
339
- * @returns {this}
340
- */
341
236
  markHalfForward() {
342
237
  return this.markHalf(this.direction);
343
238
  }
344
- /** Marks a half-step line backward.
345
- * @returns {this}
346
- */
347
239
  markHalfBackward() {
348
240
  return this.markHalf((this.direction + 2) % 4);
349
241
  }
350
- /** Marks a half-step line up.
351
- * @returns {this}
352
- */
353
242
  markHalfUp() {
354
243
  return this.markHalf(Turtle.UP);
355
244
  }
356
- /** Marks a half-step line down.
357
- * @returns {this}
358
- */
359
245
  markHalfDown() {
360
246
  return this.markHalf(Turtle.DOWN);
361
247
  }
362
- /** Marks a half-step line left.
363
- * @returns {this}
364
- */
365
248
  markHalfLeft() {
366
249
  return this.markHalf(Turtle.LEFT);
367
250
  }
368
- /** Marks a half-step line right.
369
- * @returns {this}
370
- */
371
251
  markHalfRight() {
372
252
  return this.markHalf(Turtle.RIGHT);
373
253
  }