@iwascreatedtocreate/asciikit 0.1.1 → 0.2.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.
package/LICENSE CHANGED
@@ -1,24 +1,24 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 iwascreatedtocreate
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
22
-
23
- FIGlet and TOIlet fonts included in dist/fonts are the work of their respective
24
- authors and are distributed under their original terms.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 sia!
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ FIGlet and TOIlet fonts included in dist/fonts are the work of their respective
24
+ authors and are distributed under their original terms.
package/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # asciikit
2
2
 
3
+ [![npm](https://img.shields.io/npm/v/@iwascreatedtocreate/asciikit?color=black)](https://www.npmjs.com/package/@iwascreatedtocreate/asciikit)
4
+ [![downloads](https://img.shields.io/npm/dm/@iwascreatedtocreate/asciikit?color=black)](https://www.npmjs.com/package/@iwascreatedtocreate/asciikit)
5
+ [![ci](https://github.com/iwascreatedtocreate/asciikit/actions/workflows/ci.yml/badge.svg)](https://github.com/iwascreatedtocreate/asciikit/actions/workflows/ci.yml)
6
+
3
7
  ASCII art for React & Next.js. **332 FIGlet fonts you import like icons**, a full FIGfont smushing engine, borders, shadows, gradients, animations and image-to-ASCII.
4
8
 
5
9
  ```bash
@@ -23,14 +27,108 @@ Live playground & font gallery: **https://asciikit.iwascreatedtocreate.com**
23
27
  - **Server Components first** — `<Ascii>` renders on the server with zero client JS. When you animate, only the final string goes to the browser, never the font.
24
28
  - **A real FIGlet engine** — full width, fitting, all 6 horizontal + 5 vertical smushing rules, universal smushing, word wrap, alignment, RTL, FIGlet & TOIlet (`.flf` / `.tlf`) fonts. Output matches figlet.js / TAAG for 97%+ of fonts.
25
29
  - **Effects** — borders (15 styles), shadow, fill, flip, rotate, scale, invert, join/stack/overlay, gradients, ANSI colors for terminals.
26
- - **Animations** — scramble, typewriter, reveal, fall, flicker, glitch, wave, rain. Respects `prefers-reduced-motion`.
30
+ - **Animations** — scramble, typewriter, reveal, fade, slide, fall, flicker, glitch, wave, rain, marquee, sparkle. Respects `prefers-reduced-motion`.
31
+ - **Text widgets** — tables (9 styles, markdown too), trees, dividers, speech bubbles with little critters.
32
+ - **Charts** — sparklines, bar charts (horizontal / vertical, smooth eighth-blocks), braille line charts, progress bars.
33
+ - **Drawing canvas** — lines, boxes that merge into proper `┼ ├ ┬` junctions, circles, text; plus a braille pixel canvas with 8× resolution.
34
+ - **Fancy Unicode text** — 𝐛𝐨𝐥𝐝, 𝔣𝔯𝔞𝔨𝔱𝔲𝔯, 𝓈𝒸𝓇𝒾𝓅𝓉, ⓒⓘⓡⓒⓛⓔⓓ, ꜱᴍᴀʟʟ ᴄᴀᴘꜱ, uʍop ǝpısdn and 20 more styles.
27
35
  - **Image → ASCII** — ramps, braille, edge tracing, Floyd–Steinberg / Atkinson / ordered dithering, color.
28
36
  - **Framework-free core** — everything works in Node, Bun, Deno, edge runtimes and CLIs.
37
+ - **Export** — `toSVG()` anywhere (OG images, READMEs), `toPNG()` / `toCanvas()` in the browser.
38
+ - **CLI** — `npx @iwascreatedtocreate/asciikit "hello" -f slant -g sunset`.
39
+ - **Wide characters** — emoji and CJK count as two columns, so borders and alignment stay straight.
40
+ - **Zero dependencies.**
41
+
42
+ ## CLI
43
+
44
+ ```bash
45
+ npx @iwascreatedtocreate/asciikit "deploy ok" -f slant -g sunset -b rounded
46
+ echo "piped" | npx @iwascreatedtocreate/asciikit -f small
47
+ npx @iwascreatedtocreate/asciikit --list --preview Hi # every font
48
+ npx @iwascreatedtocreate/asciikit logo --svg logo.svg # also write an SVG
49
+ npx @iwascreatedtocreate/asciikit "ship it" --say robot # speech bubble
50
+ npx @iwascreatedtocreate/asciikit hello --fancy fraktur # 𝔥𝔢𝔩𝔩𝔬
51
+ ```
52
+
53
+ Run `--help` for all options (fonts, width, align, layout, border, shadow, fill, gradient, color).
54
+
55
+ ## Export
56
+
57
+ ```ts
58
+ import { ascii, toSVG, toPNG, downloadFile } from '@iwascreatedtocreate/asciikit';
59
+
60
+ const art = ascii('Hello', { font: Slant });
61
+ const svg = toSVG(art, { gradient: 'silver', background: '#000', fontSize: 20 }); // string, works on the server
62
+ const png = await toPNG(art, { color: '#fff', background: '#000' }); // Blob, browser only
63
+ downloadFile('hello.png', png);
64
+ ```
65
+
66
+ ## Tables, trees and bubbles
67
+
68
+ ```ts
69
+ import { table, tree, divider, say, fancy } from '@iwascreatedtocreate/asciikit';
70
+
71
+ table([['asciikit', '332 fonts'], ['日本語', 'wide chars line up']], { head: ['name', 'notes'], style: 'rounded' });
72
+ // ╭──────────┬────────────────────╮
73
+ // │ name │ notes │
74
+ // ├──────────┼────────────────────┤
75
+ // │ asciikit │ 332 fonts │
76
+ // │ 日本語 │ wide chars line up │
77
+ // ╰──────────┴────────────────────╯
78
+
79
+ tree({ app: { src: ['index.ts', 'cli.ts'], 'package.json': null } });
80
+ // app
81
+ // ├── src
82
+ // │ ├── index.ts
83
+ // │ └── cli.ts
84
+ // └── package.json
85
+
86
+ divider('Section'); // ────────── Section ──────────
87
+ say('ship it', 'robot'); // bubble + robot (cat, robot, ghost, blob, bird, computer, or your own art)
88
+ fancy('hello', 'fraktur'); // 𝔥𝔢𝔩𝔩𝔬 (bold, script, doubleStruck, circled, smallCaps, upsideDown, strike…)
89
+ ```
90
+
91
+ Tables take `align`, `maxWidth` (cells wrap or `truncate`), `rowSeparators`, `title`, `padding` and the styles `single`, `double`, `rounded`, `heavy`, `dashed`, `ascii`, `minimal`, `markdown`, `none`. Cells can be multi-line, even ASCII art.
92
+
93
+ ## Charts
94
+
95
+ ```ts
96
+ import { sparkline, barChart, lineChart, progressBar } from '@iwascreatedtocreate/asciikit';
97
+
98
+ sparkline([1, 5, 2, 8, 3, 7]); // ▁▅▂█▃▇
99
+ barChart({ react: 92, vue: 61, svelte: 40 }, { width: 30 });
100
+ // react │██████████████████████████████ 92
101
+ // vue │███████████████████▉ 61
102
+ // svelte │█████████████ 40
103
+ barChart(data, { direction: 'vertical', height: 8 });
104
+ lineChart([3, 7, 4, 9, 12, 8, 15], { width: 40, height: 8 }); // braille dots, several series allowed
105
+ progressBar(0.42, { style: 'ascii' }); // [============> ] 42%
106
+ ```
107
+
108
+ ## Drawing canvas
109
+
110
+ ```ts
111
+ import { AsciiCanvas, BrailleCanvas } from '@iwascreatedtocreate/asciikit';
112
+
113
+ const c = new AsciiCanvas(32, 5);
114
+ c.rect(0, 0, 14, 5, { title: 'api' }).rect(18, 0, 14, 5, { title: 'db' }).line(13, 2, 18, 2);
115
+ c.toString();
116
+ // ┌─ api ──────┐ ┌─ db ───────┐
117
+ // │ │ │ │
118
+ // │ ├────┤ │
119
+ // │ │ │ │
120
+ // └────────────┘ └────────────┘
121
+
122
+ const b = new BrailleCanvas(40, 10); // 80×40 dots
123
+ b.circle(40, 20, 18).plot(Math.sin, { xMin: 0, xMax: 6.28, yMin: -1, yMax: 1 });
124
+ ```
125
+
126
+ `AsciiCanvas` also has `set`, `text`, `circle` (aspect-corrected), `draw(art, x, y)` and `clear`. Lines pick `─ │ / \` from their slope.
29
127
 
30
128
  ## React
31
129
 
32
130
  ```tsx
33
- import { Ascii, AsciiImage, AsciiSpinner, AsciiBox, createAscii, useFont } from '@iwascreatedtocreate/asciikit/react';
131
+ import { Ascii, AsciiImage, AsciiSpinner, AsciiBox, AsciiTable, AsciiTree, AsciiChart, AsciiProgress, AsciiArt, createAscii, useFont } from '@iwascreatedtocreate/asciikit/react';
34
132
 
35
133
  <Ascii text="Hello" /> // Standard built in
36
134
  <Ascii text="Hello" font={Slant} gradient="silver" glow />
@@ -39,6 +137,12 @@ import { Ascii, AsciiImage, AsciiSpinner, AsciiBox, createAscii, useFont } from
39
137
  <AsciiImage src="/me.jpg" columns={100} mode="braille" dither="atkinson" />
40
138
  <AsciiSpinner spinner="dots" text="loading" />
41
139
  <AsciiBox variant="rounded" title="note">{'multi\nline'}</AsciiBox>
140
+ <AsciiTable rows={[['a', 1]]} head={['k', 'v']} variant="rounded" />
141
+ <AsciiTree data={{ src: ['index.ts'] }} />
142
+ <AsciiChart type="bar" data={{ react: 92, vue: 61 }} width={30} gradient="sunset" />
143
+ <AsciiChart type="line" data={[3, 7, 4, 9]} height={6} />
144
+ <AsciiProgress value={0.42} variant="blocks" text="build" />
145
+ <AsciiArt art={canvas.toString()} glow /> // any pre-made art string
42
146
 
43
147
  export const Logo = createAscii('ACME', { font: Slant }); // lucide-style factory
44
148
  const { font } = useFont('ansi-shadow'); // code-split loading
package/dist/animate.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type Art } from './effects.js';
2
- export type AnimationEffect = 'typewriter' | 'reveal' | 'scramble' | 'glitch' | 'wave' | 'fall' | 'flicker' | 'rain';
2
+ export type AnimationEffect = 'typewriter' | 'reveal' | 'scramble' | 'glitch' | 'wave' | 'fall' | 'flicker' | 'rain' | 'fade' | 'slide' | 'marquee' | 'sparkle';
3
3
  /** Effects that run forever by default (time based rather than progress based). */
4
4
  export declare const continuousEffects: readonly AnimationEffect[];
5
5
  export interface FrameOptions {
package/dist/animate.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { normalize, toLines } from './effects.js';
2
+ import { cells, fixCells } from './width.js';
2
3
  /** Effects that run forever by default (time based rather than progress based). */
3
- export const continuousEffects = ['glitch', 'wave', 'rain'];
4
+ export const continuousEffects = ['glitch', 'wave', 'rain', 'marquee', 'sparkle'];
4
5
  const DEFAULT_NOISE = '!<>-_\\/[]{}—=+*^?#________';
5
6
  function hash(a, b, c) {
6
7
  let h = (a * 374761393 + b * 668265263 + c * 2147483647) | 0;
@@ -16,7 +17,7 @@ const ease = (t) => 1 - Math.pow(1 - Math.max(0, Math.min(1, t)), 3);
16
17
  * @param progress 0…1 for one-shot effects. Ignored by continuous effects (use `time`).
17
18
  */
18
19
  export function animationFrame(art, effect, progress, options = {}) {
19
- const grid = toLines(normalize(art)).map((l) => Array.from(l));
20
+ const grid = toLines(normalize(art)).map((l) => cells(l));
20
21
  const h = grid.length;
21
22
  const w = grid[0]?.length ?? 0;
22
23
  const p = Math.max(0, Math.min(1, progress));
@@ -27,7 +28,7 @@ export function animationFrame(art, effect, progress, options = {}) {
27
28
  const tick = Math.floor(time / 50);
28
29
  const rnd = (r, c, k = 0) => hash(r + seed * 31, c + k * 7919, seed);
29
30
  const noiseChar = (r, c, k) => noise[Math.floor(hash(r, c, k + seed) * noise.length)];
30
- const map = (fn) => grid.map((row, r) => row.map((ch, c) => fn(ch, r, c)).join('')).join('\n');
31
+ const map = (fn) => grid.map((row, r) => fixCells(row.map((ch, c) => fn(ch, r, c))).join('')).join('\n');
31
32
  switch (effect) {
32
33
  case 'typewriter': {
33
34
  const edge = p * (w + 1);
@@ -65,8 +66,8 @@ export function animationFrame(art, effect, progress, options = {}) {
65
66
  return grid
66
67
  .map((row, r) => {
67
68
  const off = Math.round(amp * Math.sin(time / 180 + r * 0.7));
68
- const line = row.join('');
69
- return off >= 0 ? (' '.repeat(off) + line).slice(0, w + amp) : line.slice(-off);
69
+ const shifted = off >= 0 ? [...Array(off).fill(' '), ...row].slice(0, w + amp) : row.slice(-off);
70
+ return fixCells(shifted).join('');
70
71
  })
71
72
  .join('\n');
72
73
  }
@@ -79,7 +80,7 @@ export function animationFrame(art, effect, progress, options = {}) {
79
80
  const shift = Math.round((hash(r, tick, 3) - 0.5) * 6 * intensity);
80
81
  line = shift > 0 ? [...Array(shift).fill(' '), ...line].slice(0, w) : line.slice(-shift).concat(Array(-shift).fill(' '));
81
82
  }
82
- return line.join('');
83
+ return fixCells(line).join('');
83
84
  })
84
85
  .join('\n');
85
86
  }
@@ -95,6 +96,43 @@ export function animationFrame(art, effect, progress, options = {}) {
95
96
  return ch;
96
97
  });
97
98
  }
99
+ case 'fade': {
100
+ // each char climbs a density ramp before landing on its final glyph
101
+ const ramp = [' ', '.', ':', '-', '=', '+', '*', '#'];
102
+ return map((ch, r, c) => {
103
+ if (ch === ' ')
104
+ return ch;
105
+ const local = (p - rnd(r, c, 2) * 0.5) / 0.5;
106
+ if (local >= 1)
107
+ return ch;
108
+ if (local <= 0)
109
+ return ' ';
110
+ return ramp[Math.min(ramp.length - 1, Math.floor(local * ramp.length))];
111
+ });
112
+ }
113
+ case 'slide': {
114
+ // rows arrive from the left one after another
115
+ return map((_ch, r, c) => {
116
+ const local = ease((p - (r / Math.max(1, h)) * 0.3) / 0.7);
117
+ const off = Math.round((1 - local) * w);
118
+ return grid[r][c - off] ?? ' ';
119
+ });
120
+ }
121
+ case 'marquee': {
122
+ const gap = Math.max(4, Math.round(w * 0.3));
123
+ const span = w + gap;
124
+ const off = Math.floor(time / (90 - intensity * 70)) % span;
125
+ return map((_ch, r, c) => grid[r][(c + off) % span] ?? ' ');
126
+ }
127
+ case 'sparkle': {
128
+ const stars = ['*', '+', '·', '.'];
129
+ return map((ch, r, c) => {
130
+ if (ch === ' ')
131
+ return ch;
132
+ const t = rnd(r, c, tick);
133
+ return t < intensity * 0.06 ? stars[Math.floor(t * 1000) % stars.length] : ch;
134
+ });
135
+ }
98
136
  default:
99
137
  return map((ch) => ch);
100
138
  }
@@ -0,0 +1,101 @@
1
+ import { type Art, type BoxChars, type BoxStyle } from './effects.js';
2
+ export interface RectOptions {
3
+ /** Border style (default `single`). Single/rounded borders merge where they cross. */
4
+ style?: BoxStyle | BoxChars;
5
+ /** Fill the inside with this character. */
6
+ fill?: string;
7
+ /** Title written into the top edge. */
8
+ title?: string;
9
+ }
10
+ /**
11
+ * A fixed-size character grid you can draw on: text, lines, boxes, circles and other art.
12
+ * Light box lines that touch merge into proper junctions (┼ ├ ┬ …).
13
+ *
14
+ * ```ts
15
+ * const c = new AsciiCanvas(30, 8);
16
+ * c.rect(0, 0, 14, 5, { title: 'api' }).rect(16, 0, 14, 5, { title: 'db' }).line(14, 2, 16, 2, '─');
17
+ * c.toString();
18
+ * ```
19
+ */
20
+ export declare class AsciiCanvas {
21
+ readonly width: number;
22
+ readonly height: number;
23
+ private grid;
24
+ constructor(width: number, height: number, background?: string);
25
+ /** Read the character at a cell ('' for the right half of a wide char). */
26
+ get(x: number, y: number): string | undefined;
27
+ /** Put one character. Light box chars merge with what's already there unless `merge` is false. */
28
+ set(x: number, y: number, ch: string, merge?: boolean): this;
29
+ /** Write a string starting at (x, y). Newlines start a new row at the same x. */
30
+ text(x: number, y: number, str: string): this;
31
+ /**
32
+ * Draw a straight line (Bresenham). Without `ch` the character follows the slope:
33
+ * `─ │` for straight lines and `/ \` for diagonals.
34
+ */
35
+ line(x0: number, y0: number, x1: number, y1: number, ch?: string): this;
36
+ /** Draw a box. Width and height include the border. */
37
+ rect(x: number, y: number, w: number, h: number, options?: RectOptions): this;
38
+ /**
39
+ * Draw an ellipse outline (or a filled one with `fill`). `ry` defaults to half of `rx`
40
+ * because character cells are about twice as tall as they are wide.
41
+ */
42
+ circle(cx: number, cy: number, rx: number, options?: {
43
+ ry?: number;
44
+ char?: string;
45
+ fill?: string;
46
+ }): this;
47
+ /** Paste art at (x, y). Spaces are transparent unless `opaque` is set. */
48
+ draw(art: Art, x: number, y: number, options?: {
49
+ opaque?: boolean;
50
+ }): this;
51
+ /** Fill every cell with `ch`. */
52
+ clear(ch?: string): this;
53
+ /** The drawing as a string. Trailing spaces are removed unless `keepSpaces` is set. */
54
+ toString(options?: {
55
+ keepSpaces?: boolean;
56
+ }): string;
57
+ }
58
+ /**
59
+ * A pixel canvas drawn with braille characters (2×4 dots per character). Great for
60
+ * plots, curves and small drawings.
61
+ *
62
+ * ```ts
63
+ * const b = new BrailleCanvas(40, 10); // 80×40 dots
64
+ * b.circle(40, 20, 18).line(0, 39, 79, 0);
65
+ * b.toString();
66
+ * ```
67
+ */
68
+ export declare class BrailleCanvas {
69
+ /** Size in characters. */
70
+ readonly columns: number;
71
+ readonly rows: number;
72
+ /** Size in dots. */
73
+ readonly width: number;
74
+ readonly height: number;
75
+ private bits;
76
+ constructor(columns: number, rows: number);
77
+ private at;
78
+ set(x: number, y: number): this;
79
+ unset(x: number, y: number): this;
80
+ toggle(x: number, y: number): this;
81
+ get(x: number, y: number): boolean;
82
+ line(x0: number, y0: number, x1: number, y1: number): this;
83
+ rect(x: number, y: number, w: number, h: number, fill?: boolean): this;
84
+ /** Circle (dots are square-ish, so no aspect correction needed). `ry` makes an ellipse. */
85
+ circle(cx: number, cy: number, r: number, options?: {
86
+ ry?: number;
87
+ fill?: boolean;
88
+ }): this;
89
+ /** Plot y = fn(x) across the canvas. `fn` gets x in [xMin, xMax] and returns y in [yMin, yMax]. */
90
+ plot(fn: (x: number) => number, range?: {
91
+ xMin?: number;
92
+ xMax?: number;
93
+ yMin?: number;
94
+ yMax?: number;
95
+ }): this;
96
+ clear(): this;
97
+ /** Empty cells become spaces unless `blank` is set (U+2800 keeps width in some fonts). */
98
+ toString(options?: {
99
+ blank?: boolean;
100
+ }): string;
101
+ }