@iwascreatedtocreate/asciikit 0.1.2 → 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/README.md CHANGED
@@ -1,122 +1,196 @@
1
- # asciikit
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
-
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.
8
-
9
- ```bash
10
- npm i @iwascreatedtocreate/asciikit
11
- ```
12
-
13
- ```tsx
14
- import { Ascii } from '@iwascreatedtocreate/asciikit/react';
15
- import { Slant } from '@iwascreatedtocreate/asciikit/fonts';
16
-
17
- export default function Page() {
18
- return <Ascii text="Hello" font={Slant} border="rounded" />;
19
- }
20
- ```
21
-
22
- Live playground & font gallery: **https://asciikit.iwascreatedtocreate.com**
23
-
24
- ## Why
25
-
26
- - **Import fonts like icons** — `import { Slant, Doom, AnsiShadow } from '@iwascreatedtocreate/asciikit/fonts'`. Every font is its own module, so you only ship what you use.
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.
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.
29
- - **Effects** — borders (15 styles), shadow, fill, flip, rotate, scale, invert, join/stack/overlay, gradients, ANSI colors for terminals.
30
- - **Animations** — scramble, typewriter, reveal, fall, flicker, glitch, wave, rain. Respects `prefers-reduced-motion`.
31
- - **Image → ASCII** — ramps, braille, edge tracing, Floyd–Steinberg / Atkinson / ordered dithering, color.
32
- - **Framework-free core** — everything works in Node, Bun, Deno, edge runtimes and CLIs.
33
- - **Export** — `toSVG()` anywhere (OG images, READMEs), `toPNG()` / `toCanvas()` in the browser.
34
- - **CLI** — `npx @iwascreatedtocreate/asciikit "hello" -f slant -g sunset`.
35
- - **Wide characters** — emoji and CJK count as two columns, so borders and alignment stay straight.
36
- - **Zero dependencies.**
37
-
38
- ## CLI
39
-
40
- ```bash
41
- npx @iwascreatedtocreate/asciikit "deploy ok" -f slant -g sunset -b rounded
42
- echo "piped" | npx @iwascreatedtocreate/asciikit -f small
43
- npx @iwascreatedtocreate/asciikit --list --preview Hi # every font
44
- npx @iwascreatedtocreate/asciikit logo --svg logo.svg # also write an SVG
45
- ```
46
-
47
- Run `--help` for all options (fonts, width, align, layout, border, shadow, fill, gradient, color).
48
-
49
- ## Export
50
-
51
- ```ts
52
- import { ascii, toSVG, toPNG, downloadFile } from '@iwascreatedtocreate/asciikit';
53
-
54
- const art = ascii('Hello', { font: Slant });
55
- const svg = toSVG(art, { gradient: 'silver', background: '#000', fontSize: 20 }); // string, works on the server
56
- const png = await toPNG(art, { color: '#fff', background: '#000' }); // Blob, browser only
57
- downloadFile('hello.png', png);
58
- ```
59
-
60
- ## React
61
-
62
- ```tsx
63
- import { Ascii, AsciiImage, AsciiSpinner, AsciiBox, createAscii, useFont } from '@iwascreatedtocreate/asciikit/react';
64
-
65
- <Ascii text="Hello" /> // Standard built in
66
- <Ascii text="Hello" font={Slant} gradient="silver" glow />
67
- <Ascii text="Hi" font={Slant} border={{ style: 'double', title: 'v1' }} shadow />
68
- <Ascii text="Boot" font={AnsiShadow} animate={{ effect: 'scramble', trigger: 'visible' }} />
69
- <AsciiImage src="/me.jpg" columns={100} mode="braille" dither="atkinson" />
70
- <AsciiSpinner spinner="dots" text="loading" />
71
- <AsciiBox variant="rounded" title="note">{'multi\nline'}</AsciiBox>
72
-
73
- export const Logo = createAscii('ACME', { font: Slant }); // lucide-style factory
74
- const { font } = useFont('ansi-shadow'); // code-split loading
75
- ```
76
-
77
- ### `<Ascii>` props
78
-
79
- | prop | type |
80
- | --- | --- |
81
- | `text` / `children` | `string` |
82
- | `font` | `FontDefinition \| string` (registered name or raw `.flf`) |
83
- | `horizontalLayout`, `verticalLayout` | `'default' \| 'full' \| 'fitted' \| 'smush' \| 'universal-smush'` |
84
- | `horizontalRules`, `verticalRules` | toggle individual smushing rules |
85
- | `width`, `whitespaceBreak`, `align` | wrapping & alignment |
86
- | `letterSpacing`, `wordSpacing`, `lineGap`, `direction`, `trim` | spacing & direction |
87
- | `fill`, `replace`, `flip`, `rotate`, `scale`, `invert`, `shadow`, `border`, `padding`, `transform` | effects |
88
- | `color`, `gradient`, `gradientDirection`, `size`, `lineHeight`, `glow`, `fontFamily` | styling |
89
- | `animate` | effect name or `{ effect, duration, delay, loop, loopDelay, trigger, intensity, noise }` |
90
- | `as`, `label` | element & accessible label |
91
-
92
- ## Core
93
-
94
- ```ts
95
- import { render, ascii, pipe, box, shadow, fill, join, toAnsi, pixelsToAscii } from '@iwascreatedtocreate/asciikit';
96
- import { Standard } from '@iwascreatedtocreate/asciikit/fonts';
97
-
98
- render('Hello', { font: Standard, width: 60, align: 'center' });
99
- ascii('OK', { font: Standard, fill: '█', shadow: true, border: 'rounded' });
100
- console.log(toAnsi(render('deploy'), { gradient: 'sunset' }));
101
- ```
102
-
103
- ## Fonts
104
-
105
- ```ts
106
- import { Slant } from '@iwascreatedtocreate/asciikit/fonts'; // barrel (tree-shaken)
107
- import Ghost from '@iwascreatedtocreate/asciikit/fonts/ghost'; // direct path
108
- import { loadFont } from '@iwascreatedtocreate/asciikit/fonts/lazy'; // async by id or name
109
- import { fontList } from '@iwascreatedtocreate/asciikit/fonts/meta'; // metadata only
110
- import { parseFont, registerFont, setDefaultFont } from '@iwascreatedtocreate/asciikit';
111
- ```
112
-
113
- Tip for Next.js dev speed when importing many fonts from the barrel:
114
-
115
- ```js
116
- // next.config.js
117
- experimental: { optimizePackageImports: ['@iwascreatedtocreate/asciikit'] }
118
- ```
119
-
120
- ## License
121
-
122
- MIT. FIGlet/TOIlet fonts are © their respective authors and distributed under their original terms (bundled via the [figlet](https://github.com/patorjk/figlet.js) font collection).
1
+ # asciikit
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
+
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.
8
+
9
+ ```bash
10
+ npm i @iwascreatedtocreate/asciikit
11
+ ```
12
+
13
+ ```tsx
14
+ import { Ascii } from '@iwascreatedtocreate/asciikit/react';
15
+ import { Slant } from '@iwascreatedtocreate/asciikit/fonts';
16
+
17
+ export default function Page() {
18
+ return <Ascii text="Hello" font={Slant} border="rounded" />;
19
+ }
20
+ ```
21
+
22
+ Live playground & font gallery: **https://asciikit.iwascreatedtocreate.com**
23
+
24
+ ## Why
25
+
26
+ - **Import fonts like icons** — `import { Slant, Doom, AnsiShadow } from '@iwascreatedtocreate/asciikit/fonts'`. Every font is its own module, so you only ship what you use.
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.
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.
29
+ - **Effects** — borders (15 styles), shadow, fill, flip, rotate, scale, invert, join/stack/overlay, gradients, ANSI colors for terminals.
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.
35
+ - **Image → ASCII** — ramps, braille, edge tracing, Floyd–Steinberg / Atkinson / ordered dithering, color.
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.
127
+
128
+ ## React
129
+
130
+ ```tsx
131
+ import { Ascii, AsciiImage, AsciiSpinner, AsciiBox, AsciiTable, AsciiTree, AsciiChart, AsciiProgress, AsciiArt, createAscii, useFont } from '@iwascreatedtocreate/asciikit/react';
132
+
133
+ <Ascii text="Hello" /> // Standard built in
134
+ <Ascii text="Hello" font={Slant} gradient="silver" glow />
135
+ <Ascii text="Hi" font={Slant} border={{ style: 'double', title: 'v1' }} shadow />
136
+ <Ascii text="Boot" font={AnsiShadow} animate={{ effect: 'scramble', trigger: 'visible' }} />
137
+ <AsciiImage src="/me.jpg" columns={100} mode="braille" dither="atkinson" />
138
+ <AsciiSpinner spinner="dots" text="loading" />
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
146
+
147
+ export const Logo = createAscii('ACME', { font: Slant }); // lucide-style factory
148
+ const { font } = useFont('ansi-shadow'); // code-split loading
149
+ ```
150
+
151
+ ### `<Ascii>` props
152
+
153
+ | prop | type |
154
+ | --- | --- |
155
+ | `text` / `children` | `string` |
156
+ | `font` | `FontDefinition \| string` (registered name or raw `.flf`) |
157
+ | `horizontalLayout`, `verticalLayout` | `'default' \| 'full' \| 'fitted' \| 'smush' \| 'universal-smush'` |
158
+ | `horizontalRules`, `verticalRules` | toggle individual smushing rules |
159
+ | `width`, `whitespaceBreak`, `align` | wrapping & alignment |
160
+ | `letterSpacing`, `wordSpacing`, `lineGap`, `direction`, `trim` | spacing & direction |
161
+ | `fill`, `replace`, `flip`, `rotate`, `scale`, `invert`, `shadow`, `border`, `padding`, `transform` | effects |
162
+ | `color`, `gradient`, `gradientDirection`, `size`, `lineHeight`, `glow`, `fontFamily` | styling |
163
+ | `animate` | effect name or `{ effect, duration, delay, loop, loopDelay, trigger, intensity, noise }` |
164
+ | `as`, `label` | element & accessible label |
165
+
166
+ ## Core
167
+
168
+ ```ts
169
+ import { render, ascii, pipe, box, shadow, fill, join, toAnsi, pixelsToAscii } from '@iwascreatedtocreate/asciikit';
170
+ import { Standard } from '@iwascreatedtocreate/asciikit/fonts';
171
+
172
+ render('Hello', { font: Standard, width: 60, align: 'center' });
173
+ ascii('OK', { font: Standard, fill: '█', shadow: true, border: 'rounded' });
174
+ console.log(toAnsi(render('deploy'), { gradient: 'sunset' }));
175
+ ```
176
+
177
+ ## Fonts
178
+
179
+ ```ts
180
+ import { Slant } from '@iwascreatedtocreate/asciikit/fonts'; // barrel (tree-shaken)
181
+ import Ghost from '@iwascreatedtocreate/asciikit/fonts/ghost'; // direct path
182
+ import { loadFont } from '@iwascreatedtocreate/asciikit/fonts/lazy'; // async by id or name
183
+ import { fontList } from '@iwascreatedtocreate/asciikit/fonts/meta'; // metadata only
184
+ import { parseFont, registerFont, setDefaultFont } from '@iwascreatedtocreate/asciikit';
185
+ ```
186
+
187
+ Tip for Next.js dev speed when importing many fonts from the barrel:
188
+
189
+ ```js
190
+ // next.config.js
191
+ experimental: { optimizePackageImports: ['@iwascreatedtocreate/asciikit'] }
192
+ ```
193
+
194
+ ## License
195
+
196
+ MIT. FIGlet/TOIlet fonts are © their respective authors and distributed under their original terms (bundled via the [figlet](https://github.com/patorjk/figlet.js) font collection).
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,7 +1,7 @@
1
1
  import { normalize, toLines } from './effects.js';
2
2
  import { cells, fixCells } from './width.js';
3
3
  /** Effects that run forever by default (time based rather than progress based). */
4
- export const continuousEffects = ['glitch', 'wave', 'rain'];
4
+ export const continuousEffects = ['glitch', 'wave', 'rain', 'marquee', 'sparkle'];
5
5
  const DEFAULT_NOISE = '!<>-_\\/[]{}—=+*^?#________';
6
6
  function hash(a, b, c) {
7
7
  let h = (a * 374761393 + b * 668265263 + c * 2147483647) | 0;
@@ -96,6 +96,43 @@ export function animationFrame(art, effect, progress, options = {}) {
96
96
  return ch;
97
97
  });
98
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
+ }
99
136
  default:
100
137
  return map((ch) => ch);
101
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
+ }