@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 +196 -122
- package/dist/animate.d.ts +1 -1
- package/dist/animate.js +38 -1
- package/dist/canvas.d.ts +101 -0
- package/dist/canvas.js +321 -0
- package/dist/charts.d.ts +133 -0
- package/dist/charts.js +178 -0
- package/dist/cli.js +48 -30
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/layout.d.ts +307 -0
- package/dist/layout.js +194 -0
- package/dist/react/Ascii.d.ts +1 -1
- package/dist/react/AsciiImage.js +1 -1
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +1 -0
- package/dist/react/widgets.d.ts +56 -0
- package/dist/react/widgets.js +52 -0
- package/dist/text.d.ts +26 -0
- package/dist/text.js +230 -0
- package/package.json +3 -3
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { ElementType, HTMLAttributes } from 'react';
|
|
2
|
+
import { type BarChartOptions, type ChartData, type LineChartOptions, type ProgressStyle } from '../charts.js';
|
|
3
|
+
import { type TableCell, type TableOptions, type TreeInput, type TreeStyle } from '../layout.js';
|
|
4
|
+
import { type AsciiStyleProps } from './style.js';
|
|
5
|
+
type Base = AsciiStyleProps & Omit<HTMLAttributes<HTMLElement>, 'children' | 'color' | 'title'> & {
|
|
6
|
+
as?: ElementType;
|
|
7
|
+
};
|
|
8
|
+
export interface AsciiArtProps extends Base {
|
|
9
|
+
/** Any pre-made art string: from `ascii()`, `table()`, an `AsciiCanvas`, a file… */
|
|
10
|
+
art: string;
|
|
11
|
+
label?: string;
|
|
12
|
+
}
|
|
13
|
+
/** Show any art string with asciikit styling (gradient, glow, …). Server-component safe. */
|
|
14
|
+
export declare function AsciiArt({ art, label, ...props }: AsciiArtProps): import("react").JSX.Element;
|
|
15
|
+
export interface AsciiTableProps extends Base, Omit<TableOptions, 'style'> {
|
|
16
|
+
rows: readonly (readonly TableCell[])[];
|
|
17
|
+
variant?: TableOptions['style'];
|
|
18
|
+
}
|
|
19
|
+
/** Text-mode table. Server-component safe. */
|
|
20
|
+
export declare function AsciiTable({ rows, head, variant, align, padding, maxWidth, truncate, rowSeparators, title, ...props }: AsciiTableProps): import("react").JSX.Element;
|
|
21
|
+
export interface AsciiTreeProps extends Base {
|
|
22
|
+
data: TreeInput | readonly TreeInput[];
|
|
23
|
+
variant?: TreeStyle;
|
|
24
|
+
}
|
|
25
|
+
/** Tree diagram like the `tree` command. Server-component safe. */
|
|
26
|
+
export declare function AsciiTree({ data, variant, ...props }: AsciiTreeProps): import("react").JSX.Element;
|
|
27
|
+
export type AsciiChartProps = Base & {
|
|
28
|
+
label?: string;
|
|
29
|
+
} & (({
|
|
30
|
+
type: 'bar';
|
|
31
|
+
data: ChartData;
|
|
32
|
+
} & BarChartOptions) | ({
|
|
33
|
+
type: 'line';
|
|
34
|
+
data: readonly number[] | readonly (readonly number[])[];
|
|
35
|
+
} & LineChartOptions) | {
|
|
36
|
+
type: 'sparkline';
|
|
37
|
+
data: readonly (number | null | undefined)[];
|
|
38
|
+
min?: number;
|
|
39
|
+
max?: number;
|
|
40
|
+
});
|
|
41
|
+
/** Bar, line (braille) or sparkline chart. Server-component safe. */
|
|
42
|
+
export declare function AsciiChart(props: AsciiChartProps): import("react").JSX.Element;
|
|
43
|
+
export interface AsciiProgressProps extends Base {
|
|
44
|
+
/** 0…1 */
|
|
45
|
+
value: number;
|
|
46
|
+
/** Text before the bar. */
|
|
47
|
+
text?: string;
|
|
48
|
+
/** Bar width in columns (default 30). */
|
|
49
|
+
width?: number;
|
|
50
|
+
variant?: ProgressStyle;
|
|
51
|
+
/** Show the percentage (default true). */
|
|
52
|
+
showPercent?: boolean;
|
|
53
|
+
}
|
|
54
|
+
/** Text progress bar with progressbar semantics. Server-component safe. */
|
|
55
|
+
export declare function AsciiProgress({ value, width, variant, text, showPercent, ...props }: AsciiProgressProps): import("react").JSX.Element;
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { barChart, lineChart, progressBar, sparkline } from '../charts.js';
|
|
3
|
+
import { table, tree } from '../layout.js';
|
|
4
|
+
import { asciiStyle } from './style.js';
|
|
5
|
+
const STYLE_KEYS = ['color', 'gradient', 'gradientDirection', 'size', 'lineHeight', 'glow', 'fontFamily'];
|
|
6
|
+
// pulls the styling props out so the rest can go straight to the DOM
|
|
7
|
+
function Pre({ art, props, label, lineHeight = 1.2 }) {
|
|
8
|
+
const { as: Tag = 'pre', style, ...rest } = props;
|
|
9
|
+
const styleProps = {};
|
|
10
|
+
const dom = {};
|
|
11
|
+
for (const [k, v] of Object.entries(rest)) {
|
|
12
|
+
if (STYLE_KEYS.includes(k))
|
|
13
|
+
styleProps[k] = v;
|
|
14
|
+
else
|
|
15
|
+
dom[k] = v;
|
|
16
|
+
}
|
|
17
|
+
return (_jsx(Tag, { role: label ? 'img' : undefined, "aria-label": label, style: asciiStyle({ lineHeight, ...styleProps }, style), ...dom, children: art }));
|
|
18
|
+
}
|
|
19
|
+
/** Show any art string with asciikit styling (gradient, glow, …). Server-component safe. */
|
|
20
|
+
export function AsciiArt({ art, label, ...props }) {
|
|
21
|
+
return _jsx(Pre, { art: art, props: props, label: label, lineHeight: typeof props.lineHeight === 'number' ? props.lineHeight : 1 });
|
|
22
|
+
}
|
|
23
|
+
/** Text-mode table. Server-component safe. */
|
|
24
|
+
export function AsciiTable({ rows, head, variant, align, padding, maxWidth, truncate, rowSeparators, title, ...props }) {
|
|
25
|
+
const art = table(rows, { head, style: variant, align, padding, maxWidth, truncate, rowSeparators, title });
|
|
26
|
+
return _jsx(Pre, { art: art, props: props });
|
|
27
|
+
}
|
|
28
|
+
/** Tree diagram like the `tree` command. Server-component safe. */
|
|
29
|
+
export function AsciiTree({ data, variant, ...props }) {
|
|
30
|
+
return _jsx(Pre, { art: tree(data, { style: variant }), props: props });
|
|
31
|
+
}
|
|
32
|
+
/** Bar, line (braille) or sparkline chart. Server-component safe. */
|
|
33
|
+
export function AsciiChart(props) {
|
|
34
|
+
const { type, data, label, ...rest } = props;
|
|
35
|
+
const opts = {};
|
|
36
|
+
const dom = {};
|
|
37
|
+
const CHART_KEYS = ['width', 'height', 'direction', 'char', 'track', 'showValues', 'max', 'min', 'sort', 'format', 'barWidth', 'gap', 'axis'];
|
|
38
|
+
for (const [k, v] of Object.entries(rest))
|
|
39
|
+
(CHART_KEYS.includes(k) ? opts : dom)[k] = v;
|
|
40
|
+
const art = type === 'bar'
|
|
41
|
+
? barChart(data, opts)
|
|
42
|
+
: type === 'line'
|
|
43
|
+
? lineChart(data, opts)
|
|
44
|
+
: sparkline(data, opts);
|
|
45
|
+
return _jsx(Pre, { art: art, props: dom, label: label, lineHeight: type === 'line' ? 1 : 1.2 });
|
|
46
|
+
}
|
|
47
|
+
/** Text progress bar with progressbar semantics. Server-component safe. */
|
|
48
|
+
export function AsciiProgress({ value, width, variant, text, showPercent, ...props }) {
|
|
49
|
+
const v = Math.max(0, Math.min(1, Number.isFinite(value) ? value : 0));
|
|
50
|
+
const aria = { role: 'progressbar', 'aria-valuemin': 0, 'aria-valuemax': 100, 'aria-valuenow': Math.round(v * 100) };
|
|
51
|
+
return _jsx(Pre, { art: progressBar(v, { width, style: variant, showPercent, label: text }), props: { as: 'span', ...aria, ...props } });
|
|
52
|
+
}
|
package/dist/text.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface WrapOptions {
|
|
2
|
+
/** Break words longer than the width (default true). Otherwise they overflow. */
|
|
3
|
+
hard?: boolean;
|
|
4
|
+
/** Keep leading/trailing spaces of each line (default false). */
|
|
5
|
+
keepSpaces?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/** Word-wrap plain text to `width` columns. Emoji and CJK count as two columns. */
|
|
8
|
+
export declare function wrapText(text: string, width: number, options?: WrapOptions): string;
|
|
9
|
+
/** Cut text to at most `width` columns, ending with `ellipsis` when it was cut. */
|
|
10
|
+
export declare function truncate(text: string, width: number, ellipsis?: string): string;
|
|
11
|
+
declare const COMBINING: {
|
|
12
|
+
readonly strike: '̶';
|
|
13
|
+
readonly underline: '̲';
|
|
14
|
+
readonly doubleUnderline: '̳';
|
|
15
|
+
readonly overline: '̅';
|
|
16
|
+
readonly slash: '̸';
|
|
17
|
+
};
|
|
18
|
+
export declare const fancyStyles: readonly FancyStyle[];
|
|
19
|
+
export type FancyStyle = 'bold' | 'italic' | 'boldItalic' | 'script' | 'boldScript' | 'fraktur' | 'boldFraktur' | 'doubleStruck' | 'sans' | 'sansBold' | 'sansItalic' | 'sansBoldItalic' | 'monospace' | 'fullwidth' | 'circled' | 'circledNegative' | 'squared' | 'squaredNegative' | 'parenthesized' | 'smallCaps' | 'upsideDown' | keyof typeof COMBINING;
|
|
20
|
+
/**
|
|
21
|
+
* Restyle text with Unicode look-alike characters (𝐛𝐨𝐥𝐝, 𝔣𝔯𝔞𝔨𝔱𝔲𝔯, ⓒⓘⓡⓒⓛⓔⓓ, ꜱᴍᴀʟʟ ᴄᴀᴘꜱ, uʍop ǝpısdn…).
|
|
22
|
+
* Works anywhere plain text does: bios, titles, terminals. Pass several styles to combine
|
|
23
|
+
* a letter style with marks, e.g. `fancy('hi', ['bold', 'underline'])`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function fancy(text: string, style: FancyStyle | readonly FancyStyle[]): string;
|
|
26
|
+
export {};
|
package/dist/text.js
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { own } from './util.js';
|
|
2
|
+
import { cells, charWidth, graphemes, stringWidth } from './width.js';
|
|
3
|
+
/** Word-wrap plain text to `width` columns. Emoji and CJK count as two columns. */
|
|
4
|
+
export function wrapText(text, width, options = {}) {
|
|
5
|
+
const max = Math.max(1, Math.floor(width) || 1);
|
|
6
|
+
const hard = options.hard ?? true;
|
|
7
|
+
const out = [];
|
|
8
|
+
for (const para of String(text).split('\n')) {
|
|
9
|
+
const words = para.split(/(\s+)/).filter((w) => w !== '');
|
|
10
|
+
let line = '';
|
|
11
|
+
let lineW = 0;
|
|
12
|
+
const flush = () => {
|
|
13
|
+
out.push(options.keepSpaces ? line : line.trim());
|
|
14
|
+
line = '';
|
|
15
|
+
lineW = 0;
|
|
16
|
+
};
|
|
17
|
+
for (const word of words) {
|
|
18
|
+
const w = stringWidth(word);
|
|
19
|
+
if (/^\s+$/.test(word)) {
|
|
20
|
+
if (lineW && lineW + w <= max) {
|
|
21
|
+
line += word;
|
|
22
|
+
lineW += w;
|
|
23
|
+
}
|
|
24
|
+
else if (lineW)
|
|
25
|
+
flush();
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (lineW + w <= max) {
|
|
29
|
+
line += word;
|
|
30
|
+
lineW += w;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (lineW && line.trim())
|
|
34
|
+
flush();
|
|
35
|
+
else {
|
|
36
|
+
line = '';
|
|
37
|
+
lineW = 0;
|
|
38
|
+
}
|
|
39
|
+
if (w <= max || !hard) {
|
|
40
|
+
line = word;
|
|
41
|
+
lineW = w;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
// word is longer than a whole line: chop it into column-sized pieces
|
|
45
|
+
let piece = '';
|
|
46
|
+
let pieceW = 0;
|
|
47
|
+
for (const g of graphemes(word)) {
|
|
48
|
+
const gw = charWidth(g);
|
|
49
|
+
if (pieceW + gw > max && piece) {
|
|
50
|
+
out.push(piece);
|
|
51
|
+
piece = '';
|
|
52
|
+
pieceW = 0;
|
|
53
|
+
}
|
|
54
|
+
piece += g;
|
|
55
|
+
pieceW += gw;
|
|
56
|
+
}
|
|
57
|
+
line = piece;
|
|
58
|
+
lineW = pieceW;
|
|
59
|
+
}
|
|
60
|
+
flush();
|
|
61
|
+
}
|
|
62
|
+
return out.join('\n');
|
|
63
|
+
}
|
|
64
|
+
/** Cut text to at most `width` columns, ending with `ellipsis` when it was cut. */
|
|
65
|
+
export function truncate(text, width, ellipsis = '…') {
|
|
66
|
+
const max = Math.max(0, Math.floor(width) || 0);
|
|
67
|
+
if (stringWidth(text) <= max)
|
|
68
|
+
return text;
|
|
69
|
+
const room = max - stringWidth(ellipsis);
|
|
70
|
+
if (room <= 0)
|
|
71
|
+
return cells(ellipsis).slice(0, max).join('');
|
|
72
|
+
let out = '';
|
|
73
|
+
let w = 0;
|
|
74
|
+
for (const g of graphemes(text)) {
|
|
75
|
+
const gw = charWidth(g);
|
|
76
|
+
if (w + gw > room)
|
|
77
|
+
break;
|
|
78
|
+
out += g;
|
|
79
|
+
w += gw;
|
|
80
|
+
}
|
|
81
|
+
return out + ellipsis;
|
|
82
|
+
}
|
|
83
|
+
// ---------------------------------------------------------------------------
|
|
84
|
+
// fancy unicode text styles
|
|
85
|
+
const A = 65;
|
|
86
|
+
const a = 97;
|
|
87
|
+
const ZERO = 48;
|
|
88
|
+
const from = (cp) => String.fromCodePoint(cp);
|
|
89
|
+
// note: the math alphanumeric block has holes where letters already existed (ℎ, ℬ, ℭ…)
|
|
90
|
+
const MATH = {
|
|
91
|
+
bold: { upper: 0x1d400, lower: 0x1d41a, digits: 0x1d7ce },
|
|
92
|
+
italic: { upper: 0x1d434, lower: 0x1d44e, holes: { h: 0x210e } },
|
|
93
|
+
boldItalic: { upper: 0x1d468, lower: 0x1d482 },
|
|
94
|
+
script: {
|
|
95
|
+
upper: 0x1d49c,
|
|
96
|
+
lower: 0x1d4b6,
|
|
97
|
+
holes: { B: 0x212c, E: 0x2130, F: 0x2131, H: 0x210b, I: 0x2110, L: 0x2112, M: 0x2133, R: 0x211b, e: 0x212f, g: 0x210a, o: 0x2134 },
|
|
98
|
+
},
|
|
99
|
+
boldScript: { upper: 0x1d4d0, lower: 0x1d4ea },
|
|
100
|
+
fraktur: { upper: 0x1d504, lower: 0x1d51e, holes: { C: 0x212d, H: 0x210c, I: 0x2111, R: 0x211c, Z: 0x2128 } },
|
|
101
|
+
boldFraktur: { upper: 0x1d56c, lower: 0x1d586 },
|
|
102
|
+
doubleStruck: {
|
|
103
|
+
upper: 0x1d538,
|
|
104
|
+
lower: 0x1d552,
|
|
105
|
+
digits: 0x1d7d8,
|
|
106
|
+
holes: { C: 0x2102, H: 0x210d, N: 0x2115, P: 0x2119, Q: 0x211a, R: 0x211d, Z: 0x2124 },
|
|
107
|
+
},
|
|
108
|
+
sans: { upper: 0x1d5a0, lower: 0x1d5ba, digits: 0x1d7e2 },
|
|
109
|
+
sansBold: { upper: 0x1d5d4, lower: 0x1d5ee, digits: 0x1d7ec },
|
|
110
|
+
sansItalic: { upper: 0x1d608, lower: 0x1d622 },
|
|
111
|
+
sansBoldItalic: { upper: 0x1d63c, lower: 0x1d656 },
|
|
112
|
+
monospace: { upper: 0x1d670, lower: 0x1d68a, digits: 0x1d7f6 },
|
|
113
|
+
};
|
|
114
|
+
const SMALL_CAPS = 'ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ';
|
|
115
|
+
const UPSIDE_LO = 'ɐqɔpǝɟƃɥᴉɾʞlɯuodbɹsʇnʌʍxʎz';
|
|
116
|
+
const UPSIDE_UP = '∀ᗺƆᗡƎℲ⅁HIſꞰ˥WNOԀῸᴚS⊥∩ΛMX⅄Z';
|
|
117
|
+
const UPSIDE_DIGITS = '0ƖᘔƐᔭϛ9L86';
|
|
118
|
+
const UPSIDE_PUNCT = {
|
|
119
|
+
'.': '˙', ',': "'", "'": ',', '"': '„', '?': '¿', '!': '¡', '(': ')', ')': '(', '[': ']', ']': '[',
|
|
120
|
+
'{': '}', '}': '{', '<': '>', '>': '<', _: '‾', '&': '⅋', ';': '؛',
|
|
121
|
+
};
|
|
122
|
+
const COMBINING = {
|
|
123
|
+
strike: '̶',
|
|
124
|
+
underline: '̲',
|
|
125
|
+
doubleUnderline: '̳',
|
|
126
|
+
overline: '̅',
|
|
127
|
+
slash: '̸',
|
|
128
|
+
};
|
|
129
|
+
export const fancyStyles = [
|
|
130
|
+
...Object.keys(MATH),
|
|
131
|
+
'fullwidth',
|
|
132
|
+
'circled',
|
|
133
|
+
'circledNegative',
|
|
134
|
+
'squared',
|
|
135
|
+
'squaredNegative',
|
|
136
|
+
'parenthesized',
|
|
137
|
+
'smallCaps',
|
|
138
|
+
'upsideDown',
|
|
139
|
+
...Object.keys(COMBINING),
|
|
140
|
+
];
|
|
141
|
+
function mapChar(ch, style) {
|
|
142
|
+
const cp = ch.codePointAt(0);
|
|
143
|
+
const up = ch >= 'A' && ch <= 'Z';
|
|
144
|
+
const lo = ch >= 'a' && ch <= 'z';
|
|
145
|
+
const dig = ch >= '0' && ch <= '9';
|
|
146
|
+
const math = own(MATH, style);
|
|
147
|
+
if (math) {
|
|
148
|
+
const hole = math.holes && own(math.holes, ch);
|
|
149
|
+
if (hole)
|
|
150
|
+
return from(hole);
|
|
151
|
+
if (up)
|
|
152
|
+
return from(math.upper + cp - A);
|
|
153
|
+
if (lo && math.lower)
|
|
154
|
+
return from(math.lower + cp - a);
|
|
155
|
+
if (dig && math.digits)
|
|
156
|
+
return from(math.digits + cp - ZERO);
|
|
157
|
+
return ch;
|
|
158
|
+
}
|
|
159
|
+
switch (style) {
|
|
160
|
+
case 'fullwidth':
|
|
161
|
+
if (ch === ' ')
|
|
162
|
+
return ' ';
|
|
163
|
+
return cp > 0x20 && cp < 0x7f ? from(cp + 0xfee0) : ch;
|
|
164
|
+
case 'circled':
|
|
165
|
+
if (up)
|
|
166
|
+
return from(0x24b6 + cp - A);
|
|
167
|
+
if (lo)
|
|
168
|
+
return from(0x24d0 + cp - a);
|
|
169
|
+
if (ch === '0')
|
|
170
|
+
return '⓪';
|
|
171
|
+
if (dig)
|
|
172
|
+
return from(0x2460 + cp - ZERO - 1);
|
|
173
|
+
return ch;
|
|
174
|
+
case 'circledNegative':
|
|
175
|
+
if (up || lo)
|
|
176
|
+
return from(0x1f150 + ch.toUpperCase().charCodeAt(0) - A);
|
|
177
|
+
if (ch === '0')
|
|
178
|
+
return '⓿';
|
|
179
|
+
if (dig)
|
|
180
|
+
return from(0x2776 + cp - ZERO - 1);
|
|
181
|
+
return ch;
|
|
182
|
+
case 'squared':
|
|
183
|
+
return up || lo ? from(0x1f130 + ch.toUpperCase().charCodeAt(0) - A) : ch;
|
|
184
|
+
case 'squaredNegative':
|
|
185
|
+
return up || lo ? from(0x1f170 + ch.toUpperCase().charCodeAt(0) - A) : ch;
|
|
186
|
+
case 'parenthesized':
|
|
187
|
+
if (up || lo)
|
|
188
|
+
return from(0x249c + ch.toLowerCase().charCodeAt(0) - a);
|
|
189
|
+
if (dig && ch !== '0')
|
|
190
|
+
return from(0x2474 + cp - ZERO - 1);
|
|
191
|
+
return ch;
|
|
192
|
+
case 'smallCaps':
|
|
193
|
+
return up || lo ? SMALL_CAPS[ch.toLowerCase().charCodeAt(0) - a] : ch;
|
|
194
|
+
case 'upsideDown':
|
|
195
|
+
if (lo)
|
|
196
|
+
return [...UPSIDE_LO][cp - a];
|
|
197
|
+
if (up)
|
|
198
|
+
return [...UPSIDE_UP][cp - A];
|
|
199
|
+
if (dig)
|
|
200
|
+
return [...UPSIDE_DIGITS][cp - ZERO];
|
|
201
|
+
return own(UPSIDE_PUNCT, ch) ?? ch;
|
|
202
|
+
default: {
|
|
203
|
+
const mark = own(COMBINING, style);
|
|
204
|
+
return mark && ch !== ' ' && ch !== '\n' ? ch + mark : ch;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Restyle text with Unicode look-alike characters (𝐛𝐨𝐥𝐝, 𝔣𝔯𝔞𝔨𝔱𝔲𝔯, ⓒⓘⓡⓒⓛⓔⓓ, ꜱᴍᴀʟʟ ᴄᴀᴘꜱ, uʍop ǝpısdn…).
|
|
210
|
+
* Works anywhere plain text does: bios, titles, terminals. Pass several styles to combine
|
|
211
|
+
* a letter style with marks, e.g. `fancy('hi', ['bold', 'underline'])`.
|
|
212
|
+
*/
|
|
213
|
+
export function fancy(text, style) {
|
|
214
|
+
const styles = typeof style === 'string' ? [style] : style;
|
|
215
|
+
let out = String(text);
|
|
216
|
+
for (const s of styles) {
|
|
217
|
+
out = out
|
|
218
|
+
.split('\n')
|
|
219
|
+
.map((line) => {
|
|
220
|
+
// map the base char only, so accents and other marks stay attached
|
|
221
|
+
const mapped = graphemes(line).map((g) => {
|
|
222
|
+
const base = String.fromCodePoint(g.codePointAt(0));
|
|
223
|
+
return mapChar(base, s) + g.slice(base.length);
|
|
224
|
+
});
|
|
225
|
+
return (s === 'upsideDown' ? mapped.reverse() : mapped).join('');
|
|
226
|
+
})
|
|
227
|
+
.join('\n');
|
|
228
|
+
}
|
|
229
|
+
return out;
|
|
230
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iwascreatedtocreate/asciikit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "The advanced ASCII art toolkit for React & Next.js — 300+ FIGlet fonts, full smushing engine, effects, animations and image-to-ASCII. Import fonts like icons.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ascii",
|
|
@@ -72,11 +72,11 @@
|
|
|
72
72
|
}
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"@types/node": "^
|
|
75
|
+
"@types/node": "^24.19.4",
|
|
76
76
|
"@types/react": "^19.3.3",
|
|
77
77
|
"figlet": "^1.13.0",
|
|
78
78
|
"react": "^19.3.1",
|
|
79
|
-
"typescript": "^
|
|
79
|
+
"typescript": "^7.0.2"
|
|
80
80
|
},
|
|
81
81
|
"bin": {
|
|
82
82
|
"asciikit": "./dist/cli.js"
|