ansimax 1.3.1 → 1.3.2

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.
package/dist/index.d.ts CHANGED
@@ -960,7 +960,82 @@ interface RenderOptions$1 {
960
960
  /** Use braille (2×4 sub-char resolution). Overrides halfBlock. */
961
961
  braille?: boolean;
962
962
  }
963
+ /**
964
+ * Render a 2D grid of pixels (`{r, g, b, a?}` objects) as terminal output
965
+ * using half-block characters (`▀`) to fit two vertical pixels per row.
966
+ * This doubles vertical resolution compared to one-character-per-pixel.
967
+ *
968
+ * @param pixels - 2D grid of pixel objects.
969
+ * @param opts - Render options (scale, background, etc.).
970
+ *
971
+ * @example basic pixel art
972
+ * ```js
973
+ * import { renderPixelArt } from 'ansimax';
974
+ *
975
+ * const heart = [
976
+ * [null, {r:255,g:0,b:0}, null, {r:255,g:0,b:0}, null],
977
+ * [{r:255,g:0,b:0}, {r:255,g:0,b:0}, {r:255,g:0,b:0}, {r:255,g:0,b:0}, {r:255,g:0,b:0}],
978
+ * [{r:255,g:0,b:0}, {r:255,g:0,b:0}, {r:255,g:0,b:0}, {r:255,g:0,b:0}, {r:255,g:0,b:0}],
979
+ * [null, {r:255,g:0,b:0}, {r:255,g:0,b:0}, {r:255,g:0,b:0}, null],
980
+ * [null, null, {r:255,g:0,b:0}, null, null],
981
+ * ];
982
+ *
983
+ * console.log(renderPixelArt(heart));
984
+ * ```
985
+ *
986
+ * @example with scale (each pixel rendered as multiple chars)
987
+ * ```js
988
+ * console.log(renderPixelArt(myPixels, { scale: 2 }));
989
+ * // Each pixel becomes 2x2 in the output
990
+ * ```
991
+ *
992
+ * @example with background color (transparent pixels show through)
993
+ * ```js
994
+ * console.log(renderPixelArt(myPixels, {
995
+ * background: { r: 30, g: 30, b: 30 },
996
+ * }));
997
+ * ```
998
+ *
999
+ * @example combined with a sprite from SPRITES
1000
+ * ```js
1001
+ * import { renderPixelArt, SPRITES } from 'ansimax';
1002
+ *
1003
+ * console.log(renderPixelArt(SPRITES.heart.pixels, { scale: 3 }));
1004
+ * ```
1005
+ */
963
1006
  declare const renderPixelArt: (pixels: PixelGrid, opts?: RenderOptions$1) => string;
1007
+ /**
1008
+ * Built-in sprite library — small pre-defined pixel art ready for use.
1009
+ *
1010
+ * Each entry has a `pixels` property containing a `PixelGrid`.
1011
+ *
1012
+ * Currently available: `heart`, `star`, `arrow`, `check`, `x`, `bell`,
1013
+ * `gear`, `bolt`, `flag`, `crown`.
1014
+ *
1015
+ * @example render a built-in sprite
1016
+ * ```js
1017
+ * import { renderPixelArt, SPRITES } from 'ansimax';
1018
+ *
1019
+ * console.log(renderPixelArt(SPRITES.heart.pixels));
1020
+ * console.log(renderPixelArt(SPRITES.star.pixels, { scale: 2 }));
1021
+ * ```
1022
+ *
1023
+ * @example list all available sprites
1024
+ * ```js
1025
+ * console.log('Available sprites:', Object.keys(SPRITES).join(', '));
1026
+ * ```
1027
+ *
1028
+ * @example compose sprites on a canvas
1029
+ * ```js
1030
+ * import { createCanvas, SPRITES } from 'ansimax';
1031
+ *
1032
+ * const canvas = createCanvas(30, 10);
1033
+ * canvas.drawSprite(2, 2, SPRITES.heart.pixels);
1034
+ * canvas.drawSprite(10, 2, SPRITES.star.pixels);
1035
+ * canvas.drawSprite(18, 2, SPRITES.crown.pixels);
1036
+ * canvas.print();
1037
+ * ```
1038
+ */
964
1039
  declare const SPRITES: Record<string, {
965
1040
  pixels: PixelGrid;
966
1041
  }>;
@@ -985,6 +1060,78 @@ interface GradientRectOptions {
985
1060
  /** Render in braille mode for 2× horizontal × 4× vertical resolution. */
986
1061
  braille?: boolean;
987
1062
  }
1063
+ /**
1064
+ * Render a rectangle filled with a multi-color gradient. Supports horizontal,
1065
+ * vertical, diagonal, arbitrary-angle, radial, and conic gradient styles.
1066
+ *
1067
+ * @param opts - Configuration: dimensions, colors, style, dithering.
1068
+ *
1069
+ * @example horizontal gradient (default)
1070
+ * ```js
1071
+ * import { gradientRect } from 'ansimax';
1072
+ *
1073
+ * console.log(gradientRect({
1074
+ * width: 40, height: 10,
1075
+ * colors: ['#ff0000', '#0000ff'],
1076
+ * }));
1077
+ * ```
1078
+ *
1079
+ * @example vertical gradient with multiple stops
1080
+ * ```js
1081
+ * console.log(gradientRect({
1082
+ * width: 30, height: 15,
1083
+ * colors: ['#ff0000', '#ffff00', '#00ff00', '#0000ff'],
1084
+ * style: 'vertical',
1085
+ * }));
1086
+ * ```
1087
+ *
1088
+ * @example arbitrary angle (45° = bottom-left to top-right)
1089
+ * ```js
1090
+ * console.log(gradientRect({
1091
+ * width: 40, height: 20,
1092
+ * colors: ['#bd93f9', '#ff79c6'],
1093
+ * style: 'diagonal',
1094
+ * angle: 45,
1095
+ * }));
1096
+ * ```
1097
+ *
1098
+ * @example radial gradient (center to edge)
1099
+ * ```js
1100
+ * console.log(gradientRect({
1101
+ * width: 30, height: 15,
1102
+ * colors: ['#ffffff', '#000000'],
1103
+ * style: 'radial',
1104
+ * }));
1105
+ * ```
1106
+ *
1107
+ * @example conic (rainbow wheel) — v1.2.0+
1108
+ * ```js
1109
+ * console.log(gradientRect({
1110
+ * width: 30, height: 15,
1111
+ * colors: ['#ff0000', '#ffff00', '#00ff00', '#00ffff', '#0000ff', '#ff00ff', '#ff0000'],
1112
+ * style: 'conic',
1113
+ * startAngle: 0,
1114
+ * }));
1115
+ * ```
1116
+ *
1117
+ * @example with Bayer dithering for smoother tonal transitions
1118
+ * ```js
1119
+ * console.log(gradientRect({
1120
+ * width: 60, height: 20,
1121
+ * colors: ['#000033', '#ffcc00'],
1122
+ * dither: 'bayer',
1123
+ * }));
1124
+ * ```
1125
+ *
1126
+ * @example braille mode (4× vertical resolution per cell)
1127
+ * ```js
1128
+ * console.log(gradientRect({
1129
+ * width: 60, height: 30,
1130
+ * colors: ['#ff0000', '#0000ff'],
1131
+ * braille: true,
1132
+ * }));
1133
+ * ```
1134
+ */
988
1135
  declare const gradientRect: (opts?: GradientRectOptions) => string;
989
1136
  interface CanvasRenderOptions extends RenderOptions$1 {
990
1137
  /** Render only the dirty region instead of the whole canvas. Default: false. */
@@ -1011,6 +1158,61 @@ interface Canvas {
1011
1158
  /** Deep copy of the current pixel grid. Mutations don't affect the canvas. */
1012
1159
  pixels: PixelGrid;
1013
1160
  }
1161
+ /**
1162
+ * Create a mutable in-memory canvas with drawing primitives (line, rect,
1163
+ * circle, sprite). The canvas tracks dirty regions so subsequent renders
1164
+ * can update only changed pixels (useful for animation).
1165
+ *
1166
+ * @param width - Canvas width in pixels (1 to MAX_DIMENSION).
1167
+ * @param height - Canvas height in pixels (1 to MAX_DIMENSION).
1168
+ * @param fillColor - Initial fill (`null` for transparent). Default `null`.
1169
+ * @returns A Canvas object with drawing methods.
1170
+ *
1171
+ * @example draw and render a simple scene
1172
+ * ```js
1173
+ * import { createCanvas } from 'ansimax';
1174
+ *
1175
+ * const canvas = createCanvas(40, 20, { r: 20, g: 20, b: 30 });
1176
+ *
1177
+ * canvas.drawRect(5, 5, 30, 10, { r: 100, g: 200, b: 255 }, true);
1178
+ * canvas.drawCircle(20, 10, 4, { r: 255, g: 200, b: 0 }, true);
1179
+ * canvas.drawLine(0, 0, 39, 19, { r: 255, g: 0, b: 100 });
1180
+ *
1181
+ * canvas.print(); // render and write to stdout
1182
+ * ```
1183
+ *
1184
+ * @example animated frame with dirty-region tracking
1185
+ * ```js
1186
+ * const canvas = createCanvas(60, 30);
1187
+ *
1188
+ * for (let frame = 0; frame < 100; frame++) {
1189
+ * canvas.setPixel(frame % 60, 15, { r: 255, g: 0, b: 0 });
1190
+ *
1191
+ * // Only re-render changed pixels (much faster than full redraw)
1192
+ * process.stdout.write(canvas.render({ dirtyOnly: true }));
1193
+ * await new Promise(r => setTimeout(r, 50));
1194
+ * }
1195
+ * ```
1196
+ *
1197
+ * @example composite sprites
1198
+ * ```js
1199
+ * import { createCanvas, SPRITES } from 'ansimax';
1200
+ *
1201
+ * const canvas = createCanvas(40, 20);
1202
+ * canvas.drawSprite(5, 5, SPRITES.heart.pixels);
1203
+ * canvas.drawSprite(20, 5, SPRITES.star.pixels);
1204
+ * canvas.print();
1205
+ * ```
1206
+ *
1207
+ * @example resize while preserving content
1208
+ * ```js
1209
+ * const canvas = createCanvas(20, 10, { r: 50, g: 50, b: 50 });
1210
+ * canvas.drawCircle(10, 5, 3, { r: 255, g: 0, b: 0 });
1211
+ *
1212
+ * canvas.resize(40, 20); // existing pixels remain in upper-left
1213
+ * canvas.print();
1214
+ * ```
1215
+ */
1014
1216
  declare const createCanvas: (width: number, height: number, fillColor?: Pixel) => Canvas;
1015
1217
  declare const images: {
1016
1218
  render: (pixels: PixelGrid, opts?: RenderOptions$1) => string;
package/docs/README.md ADDED
@@ -0,0 +1,110 @@
1
+ <div align="center">
2
+
3
+ # 📚 ansimax — Documentation
4
+
5
+ Detailed examples covering every module in **ansimax**, with copy-paste runnable code in three formats.
6
+
7
+ </div>
8
+
9
+ ---
10
+
11
+ ## 📖 Where to start
12
+
13
+ Pick the document that matches your project setup:
14
+
15
+ | File | Format | Use when… |
16
+ |---|---|---|
17
+ | [`examples-ts.md`](./examples-ts.md) | **TypeScript** (`.ts`) | Your project uses TypeScript (with `ts-node`, `tsx`, or compiled output) |
18
+ | [`examples-mjs.md`](./examples-mjs.md) | **JavaScript ESM** (`.mjs` / `"type":"module"`) | Modern JavaScript with `import`/`export` |
19
+ | [`examples-cjs.md`](./examples-cjs.md) | **JavaScript CommonJS** (`.cjs` / classic Node) | Legacy or simple Node scripts with `require()` |
20
+ | [`showcase.md`](./showcase.md) | **Complete app** | A single end-to-end JavaScript app combining all modules |
21
+
22
+ Each `examples-*.md` file covers **all 11 modules** with **3 runnable examples each** (33 examples per file).
23
+
24
+ ---
25
+
26
+ ## 🧩 Modules covered in every file
27
+
28
+ Each examples file is organized in this order:
29
+
30
+ 1. **`color`** — basic colors, ANSI styling, gradients
31
+ 2. **`gradient`** — multi-stop, animated, eased, conic gradients
32
+ 3. **`ascii`** — boxes, banners (figlet), image-to-ASCII
33
+ 4. **`animations`** — typewriter, fadeIn, fadeOut
34
+ 5. **`loaders`** — spinners, tasks, progress bars
35
+ 6. **`components`** — table, badge, status, timeline
36
+ 7. **`themes`** — built-in themes, custom themes, registry
37
+ 8. **`trees`** — hierarchical rendering, max-depth, cycles
38
+ 9. **`frames`** — frame-by-frame animation, morphing
39
+ 10. **`images`** — pixel art, canvas, gradient rectangles
40
+ 11. **`panels`** + **`json`** — split layouts + pretty-printing (v1.3.0+)
41
+
42
+ ---
43
+
44
+ ## 💡 Running the examples
45
+
46
+ ### TypeScript (`examples-ts.md`)
47
+
48
+ ```bash
49
+ # Quickest: tsx (no compile step)
50
+ npx tsx my-example.ts
51
+
52
+ # Or with ts-node
53
+ npx ts-node my-example.ts
54
+
55
+ # Or compile then run
56
+ npx tsc my-example.ts && node my-example.js
57
+ ```
58
+
59
+ ### JavaScript ESM (`examples-mjs.md`)
60
+
61
+ Either:
62
+ - Save the file with `.mjs` extension, OR
63
+ - Set `"type": "module"` in your `package.json` and use `.js`
64
+
65
+ ```bash
66
+ node my-example.mjs
67
+ ```
68
+
69
+ ### JavaScript CommonJS (`examples-cjs.md`)
70
+
71
+ ```bash
72
+ node my-example.cjs
73
+ ```
74
+
75
+ ### Showcase (`showcase.md`)
76
+
77
+ A complete demo app. Save as `.mjs`, run with `node`. Demonstrates how multiple modules compose in a real CLI.
78
+
79
+ ---
80
+
81
+ ## ⚙️ Project setup
82
+
83
+ For any of these, your `package.json` needs:
84
+
85
+ ```json
86
+ {
87
+ "dependencies": {
88
+ "ansimax": "^1.3.2"
89
+ }
90
+ }
91
+ ```
92
+
93
+ Then `npm install` and pick an example.
94
+
95
+ ---
96
+
97
+ ## 🔗 More resources
98
+
99
+ - [Main README](../README.md) — overview, badges, comparison table, roadmap
100
+ - [CHANGELOG](../CHANGELOG.md) — version history
101
+ - [npm package](https://www.npmjs.com/package/ansimax)
102
+ - [GitHub](https://github.com/Brashkie/ansimax)
103
+
104
+ ---
105
+
106
+ <div align="center">
107
+
108
+ If any example doesn't work, [open an issue](https://github.com/Brashkie/ansimax/issues) — we'll fix it.
109
+
110
+ </div>