@thi.ng/text-canvas 1.1.4 → 2.0.4

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/api.js CHANGED
@@ -14,49 +14,6 @@ export var Border;
14
14
  Border[Border["FRAME_H"] = 5] = "FRAME_H";
15
15
  Border[Border["FRAME_V"] = 6] = "FRAME_V";
16
16
  })(Border || (Border = {}));
17
- // bits 0-3: fg
18
- // bit 4: bright fg
19
- // bits 5-8: bg
20
- // bit 9: bright bg
21
- // bit 10: bold
22
- // bit 11: dim
23
- // bit 12: underline
24
- export const NONE = 0;
25
- export const FG_BLACK = 1;
26
- export const FG_RED = 2;
27
- export const FG_GREEN = 3;
28
- export const FG_YELLOW = 4;
29
- export const FG_BLUE = 5;
30
- export const FG_MAGENTA = 6;
31
- export const FG_CYAN = 7;
32
- export const FG_LIGHT_GRAY = 8;
33
- export const FG_GRAY = 0x11;
34
- export const FG_LIGHT_RED = 0x12;
35
- export const FG_LIGHT_GREEN = 0x13;
36
- export const FG_LIGHT_YELLOW = 0x14;
37
- export const FG_LIGHT_BLUE = 0x15;
38
- export const FG_LIGHT_MAGENTA = 0x16;
39
- export const FG_LIGHT_CYAN = 0x17;
40
- export const FG_WHITE = 0x18;
41
- export const BG_BLACK = 0x20;
42
- export const BG_RED = 0x40;
43
- export const BG_GREEN = 0x60;
44
- export const BG_YELLOW = 0x80;
45
- export const BG_BLUE = 0xa0;
46
- export const BG_MAGENTA = 0xc0;
47
- export const BG_CYAN = 0xe0;
48
- export const BG_LIGHT_GRAY = 0x100;
49
- export const BG_GRAY = 0x220;
50
- export const BG_LIGHT_RED = 0x240;
51
- export const BG_LIGHT_GREEN = 0x260;
52
- export const BG_LIGHT_YELLOW = 0x280;
53
- export const BG_LIGHT_BLUE = 0x2a0;
54
- export const BG_LIGHT_MAGENTA = 0x2c0;
55
- export const BG_LIGHT_CYAN = 0x2e0;
56
- export const BG_WHITE = 0x300;
57
- export const BOLD = 0x400;
58
- export const DIM = 0x800;
59
- export const UNDERLINE = 0x1000;
60
17
  // https://en.wikipedia.org/wiki/Box-drawing_character
61
18
  export const STYLE_ASCII = {
62
19
  hl: "-",
@@ -86,9 +43,25 @@ export const STYLE_THIN = {
86
43
  jct: "┼",
87
44
  dot: "•",
88
45
  };
89
- export const STYLE_THIN_ROUNDED = Object.assign(Object.assign({}, STYLE_THIN), { tl: "╭", tr: "╮", bl: "╰", br: "╯" });
90
- export const STYLE_DASHED = Object.assign(Object.assign({}, STYLE_THIN), { hl: "╌", vl: "┆" });
91
- export const STYLE_DASHED_ROUNDED = Object.assign(Object.assign({}, STYLE_DASHED), { tl: "╭", tr: "╮", bl: "╰", br: "╯" });
46
+ export const STYLE_THIN_ROUNDED = {
47
+ ...STYLE_THIN,
48
+ tl: "╭",
49
+ tr: "╮",
50
+ bl: "╰",
51
+ br: "╯",
52
+ };
53
+ export const STYLE_DASHED = {
54
+ ...STYLE_THIN,
55
+ hl: "╌",
56
+ vl: "┆",
57
+ };
58
+ export const STYLE_DASHED_ROUNDED = {
59
+ ...STYLE_DASHED,
60
+ tl: "╭",
61
+ tr: "╮",
62
+ bl: "╰",
63
+ br: "╯",
64
+ };
92
65
  export const STYLE_DOUBLE = {
93
66
  hl: "═",
94
67
  vl: "║",
package/bars.js CHANGED
@@ -1,7 +1,10 @@
1
- import { fitClamped, fract } from "@thi.ng/math";
2
- import { padLeft, padRight, repeat } from "@thi.ng/strings";
3
- import { map } from "@thi.ng/transducers";
4
- import { BARS_H, BARS_V } from "./api";
1
+ import { fitClamped } from "@thi.ng/math/fit";
2
+ import { fract } from "@thi.ng/math/prec";
3
+ import { padLeft } from "@thi.ng/strings/pad-left";
4
+ import { padRight } from "@thi.ng/strings/pad-right";
5
+ import { repeat } from "@thi.ng/strings/repeat";
6
+ import { map } from "@thi.ng/transducers/map";
7
+ import { BARS_H, BARS_V } from "./api.js";
5
8
  export const barChartHLines = (height, vals, min = 0, max = 1) => {
6
9
  const bars = [...map((x) => barVertical(height, x, min, max, ""), vals)];
7
10
  const num = bars.length;
package/canvas.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Fn0, NumOrString } from "@thi.ng/api";
2
- import { ClipRect, StrokeStyle } from "./api";
2
+ import { ClipRect, StrokeStyle } from "./api.js";
3
3
  export declare class Canvas {
4
4
  buf: Uint32Array;
5
5
  width: number;
package/canvas.js CHANGED
@@ -1,7 +1,8 @@
1
- import { peek } from "@thi.ng/arrays";
2
- import { clamp } from "@thi.ng/math";
3
- import { NONE, STYLE_ASCII } from "./api";
4
- import { charCode, intersectRect } from "./utils";
1
+ import { peek } from "@thi.ng/arrays/peek";
2
+ import { clamp } from "@thi.ng/math/interval";
3
+ import { NONE } from "@thi.ng/text-format/api";
4
+ import { STYLE_ASCII } from "./api.js";
5
+ import { charCode, intersectRect } from "./utils.js";
5
6
  export class Canvas {
6
7
  constructor(width, height, format = NONE, style = STYLE_ASCII) {
7
8
  this.width = width;
package/circle.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { NumOrString } from "@thi.ng/api";
2
- import type { Canvas } from "./canvas";
2
+ import type { Canvas } from "./canvas.js";
3
3
  /**
4
4
  * Draws a circle (filled or outline) at given center position and
5
5
  * radius and taking the current clip rect and format into account. If
package/circle.js CHANGED
@@ -1,6 +1,6 @@
1
- import { peek } from "@thi.ng/arrays";
2
- import { hline } from "./hvline";
3
- import { charCode, intersectRectCircle } from "./utils";
1
+ import { peek } from "@thi.ng/arrays/peek";
2
+ import { hline } from "./hvline.js";
3
+ import { charCode, intersectRectCircle } from "./utils.js";
4
4
  /**
5
5
  * Draws a circle (filled or outline) at given center position and
6
6
  * radius and taking the current clip rect and format into account. If
package/format.d.ts CHANGED
@@ -1,104 +1,12 @@
1
- import type { HtmlFormatOpts, StringFormat } from "./api";
1
+ import type { StringFormat } from "@thi.ng/text-format";
2
+ import type { Canvas } from "./canvas.js";
2
3
  /**
3
- * String format preset, translating canvas format info to ANSI 4bit
4
- * control sequences.
4
+ * Returns string representation of canvas, optionally using given string
5
+ * formatter. If none is given, returns plain string representation, ignoring
6
+ * any character format data.
5
7
  *
6
- * https://stackoverflow.com/a/33206814/294515
8
+ * @param canvas
9
+ * @param format
7
10
  */
8
- export declare const FMT_ANSI16: StringFormat;
9
- /**
10
- * String format preset, translating canvas format info to ANSI 8bit control
11
- * sequences. Only foreground/background colors are supported, no other
12
- * formatting (e.g. bold etc.).
13
- *
14
- * @remarks
15
- * https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
16
- *
17
- * Also see {@link format256}.
18
- */
19
- export declare const FMT_ANSI256: StringFormat;
20
- /**
21
- * String format preset, interpreting the canvas 16bit format info as text color
22
- * and translating it into ANSI 24bit control sequences. No other formatting
23
- * (e.g. bold etc.) supported in this mode.
24
- *
25
- * @remarks
26
- * This mode is intended for image displays, e.g. using thi.ng/pixel and
27
- * {@link imageRaw}. Also see {@link format556} and {@link format565_8bit}.
28
- *
29
- * https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
30
- */
31
- export declare const FMT_ANSI565: StringFormat;
32
- /**
33
- * Takes 2 ANSI256 values and returns a combined 16bit format ID.
34
- *
35
- * @remarks
36
- * https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
37
- *
38
- * @param fg
39
- * @param bg
40
- */
41
- export declare const format256: (fg: number, bg?: number) => number;
42
- /**
43
- * Takes _normalized_ RGB values ([0..1] range) and converts them into an RGB565
44
- * value for later use with {@link FMT_ANSI565} or {@link FMT_HTML_565}. Does
45
- * NOT perform clipping!
46
- *
47
- * @param r
48
- * @param g
49
- * @param b
50
- */
51
- export declare const format565: (r: number, g: number, b: number) => number;
52
- /**
53
- * Converts RGB (8bit channels) into a 16bit RGB565 value for later use with
54
- * {@link FMT_ANSI565} or {@link FMT_HTML_565}. Does NOT perform clipping!
55
- *
56
- * @param r
57
- * @param g
58
- * @param b
59
- */
60
- export declare const format565_8bit: (r: number, g: number, b: number) => number;
61
- /**
62
- * Syntax sugar for `defFormat(FMT_ANSI16, ...)`
63
- *
64
- * @param col
65
- */
66
- export declare const defAnsi16: (col: number) => (x: any) => string;
67
- /**
68
- * Syntax sugar for `defFormat(FMT_ANSI256, ...)`
69
- *
70
- * @param col
71
- */
72
- export declare const defAnsi256: (col: number) => (x: any) => string;
73
- /**
74
- * Syntax sugar for `defFormat(FMT_ANSI565, ...)`
75
- *
76
- * @param col
77
- */
78
- export declare const defAnsi565: (col: number) => (x: any) => string;
79
- /**
80
- * Constructs an HTML formatter using given config options and for use w/
81
- * default format IDs only.
82
- *
83
- * @param opts
84
- */
85
- export declare const formatHtml: ({ colors, attrib, delim, fg, bg, bold, dim, underline, }: HtmlFormatOpts) => StringFormat;
86
- /**
87
- * Preset HTML string formatter for use w/ default format IDs, generating
88
- * `<span>` elements with inline CSS.
89
- */
90
- export declare const FMT_HTML_INLINE_CSS: StringFormat;
91
- /**
92
- * Preset HTML formatter for use w/ default format IDs, generating `<span>`
93
- * elements with Tachyons CSS classes.
94
- */
95
- export declare const FMT_HTML_TACHYONS: StringFormat;
96
- /**
97
- * Higher order custom HTML formatter for 16bit (RGB565) colors (without
98
- * additional formatting flags). By default assigns text color, but can be
99
- * assigned to any CSS property via given `prop` argument.
100
- *
101
- * @param prop
102
- */
103
- export declare const FMT_HTML565: (prop?: string) => StringFormat;
11
+ export declare const formatCanvas: (canvas: Canvas, format?: StringFormat | undefined) => string;
104
12
  //# sourceMappingURL=format.d.ts.map
package/format.js CHANGED
@@ -1,207 +1,43 @@
1
- import { memoize1 } from "@thi.ng/memoize";
2
- import { U8 } from "@thi.ng/strings";
3
- import { defFormat } from "./string";
4
- const ANSI_RESET = `\x1b[0m`;
5
- const ANSI_FLAGS = ["", "1", "2", "1;2", "4", "1;4", "2;4", "1;2;4"];
6
1
  /**
7
- * String format preset, translating canvas format info to ANSI 4bit
8
- * control sequences.
9
- *
10
- * https://stackoverflow.com/a/33206814/294515
11
- */
12
- export const FMT_ANSI16 = {
13
- start: memoize1((x) => {
14
- let res = [];
15
- let y = x & 0xf;
16
- y && res.push(29 + ((x >> 4) & 1) * 60 + y);
17
- y = (x >> 5) & 0xf;
18
- y && res.push(39 + ((x >> 9) & 1) * 60 + y);
19
- y = x >> 10;
20
- y && res.push(ANSI_FLAGS[y]);
21
- return "\x1b[" + res.join(";") + "m";
22
- }),
23
- end: ANSI_RESET,
24
- prefix: ANSI_RESET,
25
- suffix: "\n",
2
+ * Returns string representation of canvas, optionally using given string
3
+ * formatter. If none is given, returns plain string representation, ignoring
4
+ * any character format data.
5
+ *
6
+ * @param canvas
7
+ * @param format
8
+ */
9
+ export const formatCanvas = (canvas, format) => {
10
+ const { buf, width, height } = canvas;
11
+ const res = [];
12
+ if (format) {
13
+ const { start, end, prefix, suffix, zero } = format;
14
+ let prevID, ch, id;
15
+ const check = zero ? () => prevID !== -1 : () => prevID !== 0;
16
+ for (let y = 0, i = 0; y < height; y++) {
17
+ prevID = zero ? -1 : 0;
18
+ res.push(prefix);
19
+ for (let x = 0; x < width; x++, i++) {
20
+ ch = buf[i];
21
+ id = ch >>> 16;
22
+ if (id != prevID) {
23
+ check() && res.push(end);
24
+ (zero || id) && res.push(start(id));
25
+ prevID = id;
26
+ }
27
+ res.push(String.fromCharCode(ch & 0xffff));
28
+ }
29
+ check() && res.push(end);
30
+ res.push(suffix);
31
+ }
32
+ return res.join("");
33
+ }
34
+ else {
35
+ for (let y = 0, i = 0; y < height; y++) {
36
+ for (let x = 0; x < width; x++, i++) {
37
+ res.push(String.fromCharCode(buf[i] & 0xffff));
38
+ }
39
+ res.push("\n");
40
+ }
41
+ return res.join("");
42
+ }
26
43
  };
27
- /**
28
- * String format preset, translating canvas format info to ANSI 8bit control
29
- * sequences. Only foreground/background colors are supported, no other
30
- * formatting (e.g. bold etc.).
31
- *
32
- * @remarks
33
- * https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
34
- *
35
- * Also see {@link format256}.
36
- */
37
- export const FMT_ANSI256 = {
38
- start: (x) => `\x1b[38;5;${x & 0xff};48;5;${x >>> 8}m`,
39
- end: ANSI_RESET,
40
- prefix: ANSI_RESET,
41
- suffix: "\n",
42
- zero: true,
43
- };
44
- const F5 = 255 / 31;
45
- const F6 = 255 / 63;
46
- /**
47
- * String format preset, interpreting the canvas 16bit format info as text color
48
- * and translating it into ANSI 24bit control sequences. No other formatting
49
- * (e.g. bold etc.) supported in this mode.
50
- *
51
- * @remarks
52
- * This mode is intended for image displays, e.g. using thi.ng/pixel and
53
- * {@link imageRaw}. Also see {@link format556} and {@link format565_8bit}.
54
- *
55
- * https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
56
- */
57
- export const FMT_ANSI565 = {
58
- start: (x) => `\x1b[38;2;${(((x >> 11) & 31) * F5) | 0};${(((x >> 5) & 63) * F6) | 0};${((x & 31) * F5) | 0}m`,
59
- end: ANSI_RESET,
60
- prefix: ANSI_RESET,
61
- suffix: "\n",
62
- zero: true,
63
- };
64
- /**
65
- * Takes 2 ANSI256 values and returns a combined 16bit format ID.
66
- *
67
- * @remarks
68
- * https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
69
- *
70
- * @param fg
71
- * @param bg
72
- */
73
- export const format256 = (fg, bg = 0) => ((bg & 0xff) << 8) | (fg & 0xff);
74
- /**
75
- * Takes _normalized_ RGB values ([0..1] range) and converts them into an RGB565
76
- * value for later use with {@link FMT_ANSI565} or {@link FMT_HTML_565}. Does
77
- * NOT perform clipping!
78
- *
79
- * @param r
80
- * @param g
81
- * @param b
82
- */
83
- export const format565 = (r, g, b) => ((r * 0x1f) << 11) | ((g * 0x3f) << 5) | (b * 0x1f);
84
- /**
85
- * Converts RGB (8bit channels) into a 16bit RGB565 value for later use with
86
- * {@link FMT_ANSI565} or {@link FMT_HTML_565}. Does NOT perform clipping!
87
- *
88
- * @param r
89
- * @param g
90
- * @param b
91
- */
92
- export const format565_8bit = (r, g, b) => ((r << 8) & 0xf800) | ((g << 3) & 0x7e0) | (b >> 3);
93
- /**
94
- * Syntax sugar for `defFormat(FMT_ANSI16, ...)`
95
- *
96
- * @param col
97
- */
98
- export const defAnsi16 = (col) => defFormat(FMT_ANSI16, col);
99
- /**
100
- * Syntax sugar for `defFormat(FMT_ANSI256, ...)`
101
- *
102
- * @param col
103
- */
104
- export const defAnsi256 = (col) => defFormat(FMT_ANSI256, col);
105
- /**
106
- * Syntax sugar for `defFormat(FMT_ANSI565, ...)`
107
- *
108
- * @param col
109
- */
110
- export const defAnsi565 = (col) => defFormat(FMT_ANSI565, col);
111
- /**
112
- * Constructs an HTML formatter using given config options and for use w/
113
- * default format IDs only.
114
- *
115
- * @param opts
116
- */
117
- export const formatHtml = ({ colors, attrib, delim, fg, bg, bold, dim, underline, }) => ({
118
- start: memoize1((x) => {
119
- let y = x & 0xf;
120
- let res = `<span ${attrib}="${fg}${colors[(y - 1) | ((x >> 1) & 0x8)]}${delim}`;
121
- y = (x >> 5) & 0x0f;
122
- y && (res += `${bg}${colors[(y - 1) | ((x >> 6) & 0x8)]}${delim}`);
123
- x & 0x400 && (res += bold + delim);
124
- x & 0x800 && (res += dim + delim);
125
- x & 0x1000 && (res += underline + delim);
126
- return res + '">';
127
- }),
128
- end: "</span>",
129
- prefix: "",
130
- suffix: "<br/>",
131
- });
132
- /**
133
- * Preset HTML string formatter for use w/ default format IDs, generating
134
- * `<span>` elements with inline CSS.
135
- */
136
- export const FMT_HTML_INLINE_CSS = formatHtml({
137
- colors: [
138
- "#000",
139
- "#a00",
140
- "#0a0",
141
- "#aa0",
142
- "#00a",
143
- "#a0a",
144
- "#0aa",
145
- "#aaa",
146
- "#555",
147
- "#f55",
148
- "#5f5",
149
- "#ff5",
150
- "#55f",
151
- "#f5f",
152
- "#5ff",
153
- "#fff",
154
- ],
155
- attrib: "style",
156
- delim: ";",
157
- fg: "color:",
158
- bg: "background:",
159
- bold: "font-weight:bold",
160
- dim: "opacity:0.5",
161
- underline: "text-decoration:underline",
162
- });
163
- /**
164
- * Preset HTML formatter for use w/ default format IDs, generating `<span>`
165
- * elements with Tachyons CSS classes.
166
- */
167
- export const FMT_HTML_TACHYONS = formatHtml({
168
- colors: [
169
- "black",
170
- "dark-red",
171
- "dark-green",
172
- "gold",
173
- "dark-blue",
174
- "dark-pink",
175
- "light-blue",
176
- "moon-gray",
177
- "mid-gray",
178
- "red",
179
- "green",
180
- "yellow",
181
- "blue",
182
- "hot-pink",
183
- "lightest-blue",
184
- "white",
185
- ],
186
- attrib: "class",
187
- delim: " ",
188
- fg: "",
189
- bg: "bg-",
190
- bold: "b",
191
- dim: "o-50",
192
- underline: "underline",
193
- });
194
- /**
195
- * Higher order custom HTML formatter for 16bit (RGB565) colors (without
196
- * additional formatting flags). By default assigns text color, but can be
197
- * assigned to any CSS property via given `prop` argument.
198
- *
199
- * @param prop
200
- */
201
- export const FMT_HTML565 = (prop = "color") => ({
202
- start: memoize1((x) => `<span style="${prop}:#${U8((x >> 11) * F5)}${U8(((x >> 5) & 0x3f) * F6)}${U8((x & 0x1f) * F5)}">`),
203
- end: "</span>",
204
- prefix: "",
205
- suffix: "<br/>",
206
- zero: true,
207
- });
package/hvline.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { NumOrString } from "@thi.ng/api";
2
- import type { Canvas } from "./canvas";
2
+ import type { Canvas } from "./canvas.js";
3
3
  /**
4
4
  * Draws horizontal line from `x`,`y`, taking the current clip rect,
5
5
  * format and style into account. The optional `s`, `e` (line endings)
package/hvline.js CHANGED
@@ -1,5 +1,5 @@
1
- import { peek } from "@thi.ng/arrays";
2
- import { charCode } from "./utils";
1
+ import { peek } from "@thi.ng/arrays/peek";
2
+ import { charCode } from "./utils.js";
3
3
  /**
4
4
  * Draws horizontal line from `x`,`y`, taking the current clip rect,
5
5
  * format and style into account. The optional `s`, `e` (line endings)
package/image.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { UIntArray } from "@thi.ng/api";
2
- import { ImageOpts } from "./api";
3
- import { Canvas } from "./canvas";
2
+ import { ImageOpts } from "./api.js";
3
+ import { Canvas } from "./canvas.js";
4
4
  export declare const blit: (canvas: Canvas, x: number, y: number, src: Canvas) => void;
5
5
  export declare const resize: (canvas: Canvas, newWidth: number, newHeight: number) => void;
6
6
  export declare const extract: (canvas: Canvas, x: number, y: number, w: number, h: number) => Canvas;
@@ -46,7 +46,7 @@ export declare const imageRaw: (canvas: Canvas, x: number, y: number, w: number,
46
46
  *
47
47
  * @remarks
48
48
  * For best results, it's recommended to pre-dither the image (e.g. using
49
- * thi.ng/pixel or other dither tools).
49
+ * thi.ng/pixel-dither or other dither tools).
50
50
  *
51
51
  * Reference:
52
52
  * https://en.wikipedia.org/wiki/Braille_Patterns#Identifying.2C_naming_and_ordering
@@ -114,5 +114,5 @@ export declare const imageString565: (src: {
114
114
  width: number;
115
115
  height: number;
116
116
  pixels: UIntArray;
117
- }, char?: string | undefined) => string;
117
+ }, char?: string | undefined, fmt?: import("@thi.ng/text-format").StringFormat) => string;
118
118
  //# sourceMappingURL=image.d.ts.map
package/image.js CHANGED
@@ -1,11 +1,11 @@
1
- import { peek } from "@thi.ng/arrays";
2
- import { isNumber } from "@thi.ng/checks";
3
- import { clamp0 } from "@thi.ng/math";
4
- import { SHADES_BLOCK } from "./api";
5
- import { canvas, Canvas } from "./canvas";
6
- import { FMT_ANSI565 } from "./format";
7
- import { toString } from "./string";
8
- import { charCode, intersectRect } from "./utils";
1
+ import { peek } from "@thi.ng/arrays/peek";
2
+ import { isNumber } from "@thi.ng/checks/is-number";
3
+ import { clamp0 } from "@thi.ng/math/interval";
4
+ import { FMT_ANSI565 } from "@thi.ng/text-format/ansi";
5
+ import { SHADES_BLOCK } from "./api.js";
6
+ import { canvas, Canvas } from "./canvas.js";
7
+ import { formatCanvas } from "./format.js";
8
+ import { charCode, intersectRect } from "./utils.js";
9
9
  export const blit = (canvas, x, y, src) => {
10
10
  x |= 0;
11
11
  y |= 0;
@@ -88,7 +88,14 @@ export const image = (canvas, x, y, w, h, pixels, opts) => {
88
88
  const { x1, y1, x2, y2, sx, sy, w: iw, h: ih, } = imgRect(canvas, x, y, w, h);
89
89
  if (!iw || !ih)
90
90
  return;
91
- const { chars, format, gamma, invert, bits } = Object.assign({ chars: SHADES_BLOCK, format: canvas.format, gamma: 1, invert: false, bits: 8 }, opts);
91
+ const { chars, format, gamma, invert, bits } = {
92
+ chars: SHADES_BLOCK,
93
+ format: canvas.format,
94
+ gamma: 1,
95
+ invert: false,
96
+ bits: 8,
97
+ ...opts,
98
+ };
92
99
  const fmt = isNumber(format) ? () => format : format;
93
100
  const max = (1 << bits) - 1;
94
101
  const mask = invert ? max : 0;
@@ -141,7 +148,7 @@ export const imageRaw = (canvas, x, y, w, h, pixels, char = "█") => {
141
148
  *
142
149
  * @remarks
143
150
  * For best results, it's recommended to pre-dither the image (e.g. using
144
- * thi.ng/pixel or other dither tools).
151
+ * thi.ng/pixel-dither or other dither tools).
145
152
  *
146
153
  * Reference:
147
154
  * https://en.wikipedia.org/wiki/Braille_Patterns#Identifying.2C_naming_and_ordering
@@ -208,7 +215,7 @@ export const imageCanvasBraille = (src, thresh, format = 0) => {
208
215
  * @param src
209
216
  * @param thresh
210
217
  */
211
- export const imageStringBraille = (src, thresh) => toString(imageCanvasBraille(src, thresh, 0));
218
+ export const imageStringBraille = (src, thresh) => formatCanvas(imageCanvasBraille(src, thresh, 0));
212
219
  /**
213
220
  * Syntax sugar for {@link imageRaw}. Takes a thi.ng/pixel compatible 16bit
214
221
  * pixel buffer in RGB565 format and converts it into a new {@link canvas}. The
@@ -229,7 +236,7 @@ export const imageCanvas565 = (src, char) => {
229
236
  * @param src
230
237
  * @param char
231
238
  */
232
- export const imageString565 = (src, char) => toString(imageCanvas565(src, char), FMT_ANSI565);
239
+ export const imageString565 = (src, char, fmt = FMT_ANSI565) => formatCanvas(imageCanvas565(src, char), fmt);
233
240
  const imgRect = (canvas, x, y, w, h) => {
234
241
  const rect = (intersectRect({ x1: x, y1: y, x2: x + w, y2: y + h, w, h }, peek(canvas.clipRects)));
235
242
  rect.sx = clamp0(rect.x1 - x);
package/index.d.ts CHANGED
@@ -1,14 +1,13 @@
1
- export * from "./api";
2
- export * from "./bars";
3
- export * from "./canvas";
4
- export * from "./circle";
5
- export * from "./format";
6
- export * from "./hvline";
7
- export * from "./image";
8
- export * from "./line";
9
- export * from "./rect";
10
- export * from "./string";
11
- export * from "./table";
12
- export * from "./text";
13
- export * from "./utils";
1
+ export * from "./api.js";
2
+ export * from "./bars.js";
3
+ export * from "./canvas.js";
4
+ export * from "./circle.js";
5
+ export * from "./format.js";
6
+ export * from "./hvline.js";
7
+ export * from "./image.js";
8
+ export * from "./line.js";
9
+ export * from "./rect.js";
10
+ export * from "./table.js";
11
+ export * from "./text.js";
12
+ export * from "./utils.js";
14
13
  //# sourceMappingURL=index.d.ts.map
package/index.js CHANGED
@@ -1,13 +1,12 @@
1
- export * from "./api";
2
- export * from "./bars";
3
- export * from "./canvas";
4
- export * from "./circle";
5
- export * from "./format";
6
- export * from "./hvline";
7
- export * from "./image";
8
- export * from "./line";
9
- export * from "./rect";
10
- export * from "./string";
11
- export * from "./table";
12
- export * from "./text";
13
- export * from "./utils";
1
+ export * from "./api.js";
2
+ export * from "./bars.js";
3
+ export * from "./canvas.js";
4
+ export * from "./circle.js";
5
+ export * from "./format.js";
6
+ export * from "./hvline.js";
7
+ export * from "./image.js";
8
+ export * from "./line.js";
9
+ export * from "./rect.js";
10
+ export * from "./table.js";
11
+ export * from "./text.js";
12
+ export * from "./utils.js";
package/line.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { NumOrString } from "@thi.ng/api";
2
- import type { Canvas } from "./canvas";
2
+ import type { Canvas } from "./canvas.js";
3
3
  /**
4
4
  * Draws a line between `ax`,`ay` and `bx`,`by`, using `char` and taking
5
5
  * the current clip rect and format into account. If `char` is not