@thi.ng/text-canvas 2.2.7 → 2.3.1
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/CHANGELOG.md +8 -1
- package/README.md +2 -2
- package/canvas.d.ts +2 -2
- package/canvas.js +10 -2
- package/circle.d.ts +6 -6
- package/circle.js +6 -6
- package/format.d.ts +2 -2
- package/format.js +2 -2
- package/hvline.d.ts +14 -14
- package/hvline.js +14 -14
- package/image.d.ts +34 -34
- package/image.js +34 -34
- package/line.d.ts +6 -6
- package/line.js +6 -6
- package/package.json +27 -27
- package/rect.d.ts +14 -14
- package/rect.js +14 -14
- package/text.d.ts +18 -18
- package/text.js +18 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**:
|
|
3
|
+
- **Last updated**: 2022-04-07T14:17:30Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,13 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
## [2.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/text-canvas@2.3.0) (2022-04-07)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- update Canvas.setAt() ([7df033f](https://github.com/thi-ng/umbrella/commit/7df033f))
|
|
17
|
+
- allow pixel value to be number or string
|
|
18
|
+
|
|
12
19
|
## [2.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/text-canvas@2.2.0) (2021-11-17)
|
|
13
20
|
|
|
14
21
|
#### 🚀 Features
|
package/README.md
CHANGED
|
@@ -70,7 +70,7 @@ node --experimental-repl-await
|
|
|
70
70
|
> const textCanvas = await import("@thi.ng/text-canvas");
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
-
Package sizes (gzipped, pre-treeshake): ESM: 5.
|
|
73
|
+
Package sizes (gzipped, pre-treeshake): ESM: 5.36 KB
|
|
74
74
|
|
|
75
75
|
## Dependencies
|
|
76
76
|
|
|
@@ -504,4 +504,4 @@ If this project contributes to an academic publication, please cite it as:
|
|
|
504
504
|
|
|
505
505
|
## License
|
|
506
506
|
|
|
507
|
-
© 2020 -
|
|
507
|
+
© 2020 - 2022 Karsten Schmidt // Apache Software License 2.0
|
package/canvas.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Fn0, IGrid2D, NumOrString } from "@thi.ng/api";
|
|
2
2
|
import { ClipRect, StrokeStyle } from "./api.js";
|
|
3
3
|
export declare class Canvas implements IGrid2D<Uint32Array, number> {
|
|
4
4
|
data: Uint32Array;
|
|
@@ -19,7 +19,7 @@ export declare class Canvas implements IGrid2D<Uint32Array, number> {
|
|
|
19
19
|
indexAtUnsafe(d0: number, d1: number): number;
|
|
20
20
|
getAt(x: number, y: number): number;
|
|
21
21
|
getAtUnsafe(x: number, y: number): number;
|
|
22
|
-
setAt(x: number, y: number,
|
|
22
|
+
setAt(x: number, y: number, val: NumOrString): boolean;
|
|
23
23
|
setAtUnsafe(x: number, y: number, col: number): boolean;
|
|
24
24
|
}
|
|
25
25
|
export declare const canvas: (width: number, height: number, format?: number | undefined, style?: StrokeStyle | undefined) => Canvas;
|
package/canvas.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
|
+
import { nomixin } from "@thi.ng/api";
|
|
2
3
|
import { IGrid2DMixin } from "@thi.ng/api/mixins/igrid";
|
|
3
4
|
import { peek } from "@thi.ng/arrays/peek";
|
|
4
5
|
import { clamp } from "@thi.ng/math/interval";
|
|
@@ -40,11 +41,18 @@ let Canvas = class Canvas {
|
|
|
40
41
|
getAt(x, y) { }
|
|
41
42
|
// @ts-ignore mixin
|
|
42
43
|
getAtUnsafe(x, y) { }
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
setAt(x, y, val) {
|
|
45
|
+
return this.includes(x, y)
|
|
46
|
+
? ((this.data[this.indexAtUnsafe(x, y)] = charCode(val, this.format)),
|
|
47
|
+
true)
|
|
48
|
+
: false;
|
|
49
|
+
}
|
|
45
50
|
// @ts-ignore mixin
|
|
46
51
|
setAtUnsafe(x, y, col) { }
|
|
47
52
|
};
|
|
53
|
+
__decorate([
|
|
54
|
+
nomixin
|
|
55
|
+
], Canvas.prototype, "setAt", null);
|
|
48
56
|
Canvas = __decorate([
|
|
49
57
|
IGrid2DMixin
|
|
50
58
|
], Canvas);
|
package/circle.d.ts
CHANGED
|
@@ -5,12 +5,12 @@ import type { Canvas } from "./canvas.js";
|
|
|
5
5
|
* radius and taking the current clip rect and format into account. If
|
|
6
6
|
* `char` is not given, uses current style's `dot` char.
|
|
7
7
|
*
|
|
8
|
-
* @param canvas
|
|
9
|
-
* @param cx
|
|
10
|
-
* @param cy
|
|
11
|
-
* @param r
|
|
12
|
-
* @param char
|
|
13
|
-
* @param fill
|
|
8
|
+
* @param canvas -
|
|
9
|
+
* @param cx -
|
|
10
|
+
* @param cy -
|
|
11
|
+
* @param r -
|
|
12
|
+
* @param char -
|
|
13
|
+
* @param fill -
|
|
14
14
|
*/
|
|
15
15
|
export declare const circle: (canvas: Canvas, cx: number, cy: number, r: number, char?: NumOrString | undefined, fill?: boolean, format?: number) => void;
|
|
16
16
|
//# sourceMappingURL=circle.d.ts.map
|
package/circle.js
CHANGED
|
@@ -6,12 +6,12 @@ import { charCode, intersectRectCircle } from "./utils.js";
|
|
|
6
6
|
* radius and taking the current clip rect and format into account. If
|
|
7
7
|
* `char` is not given, uses current style's `dot` char.
|
|
8
8
|
*
|
|
9
|
-
* @param canvas
|
|
10
|
-
* @param cx
|
|
11
|
-
* @param cy
|
|
12
|
-
* @param r
|
|
13
|
-
* @param char
|
|
14
|
-
* @param fill
|
|
9
|
+
* @param canvas -
|
|
10
|
+
* @param cx -
|
|
11
|
+
* @param cy -
|
|
12
|
+
* @param r -
|
|
13
|
+
* @param char -
|
|
14
|
+
* @param fill -
|
|
15
15
|
*/
|
|
16
16
|
export const circle = (canvas, cx, cy, r, char, fill = false, format = canvas.format) => {
|
|
17
17
|
if (r < 1)
|
package/format.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ import type { Canvas } from "./canvas.js";
|
|
|
5
5
|
* formatter. If none is given, returns plain string representation, ignoring
|
|
6
6
|
* any character format data.
|
|
7
7
|
*
|
|
8
|
-
* @param canvas
|
|
9
|
-
* @param format
|
|
8
|
+
* @param canvas -
|
|
9
|
+
* @param format -
|
|
10
10
|
*/
|
|
11
11
|
export declare const formatCanvas: (canvas: Canvas, format?: StringFormat | undefined) => string;
|
|
12
12
|
//# sourceMappingURL=format.d.ts.map
|
package/format.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* formatter. If none is given, returns plain string representation, ignoring
|
|
4
4
|
* any character format data.
|
|
5
5
|
*
|
|
6
|
-
* @param canvas
|
|
7
|
-
* @param format
|
|
6
|
+
* @param canvas -
|
|
7
|
+
* @param format -
|
|
8
8
|
*/
|
|
9
9
|
export const formatCanvas = (canvas, format) => {
|
|
10
10
|
const { data, width, height } = canvas;
|
package/hvline.d.ts
CHANGED
|
@@ -6,13 +6,13 @@ import type { Canvas } from "./canvas.js";
|
|
|
6
6
|
* and `m` (line middle) chars can be used to override the currently
|
|
7
7
|
* active style.
|
|
8
8
|
*
|
|
9
|
-
* @param canvas
|
|
10
|
-
* @param x
|
|
11
|
-
* @param y
|
|
12
|
-
* @param len
|
|
13
|
-
* @param s
|
|
14
|
-
* @param e
|
|
15
|
-
* @param m
|
|
9
|
+
* @param canvas -
|
|
10
|
+
* @param x -
|
|
11
|
+
* @param y -
|
|
12
|
+
* @param len -
|
|
13
|
+
* @param s -
|
|
14
|
+
* @param e -
|
|
15
|
+
* @param m -
|
|
16
16
|
*/
|
|
17
17
|
export declare const hline: (canvas: Canvas, x: number, y: number, len: number, s?: NumOrString | undefined, e?: NumOrString | undefined, m?: NumOrString | undefined, format?: number) => void;
|
|
18
18
|
/**
|
|
@@ -21,13 +21,13 @@ export declare const hline: (canvas: Canvas, x: number, y: number, len: number,
|
|
|
21
21
|
* and `m` (line middle) chars can be used to override the currently
|
|
22
22
|
* active style.
|
|
23
23
|
*
|
|
24
|
-
* @param canvas
|
|
25
|
-
* @param x
|
|
26
|
-
* @param y
|
|
27
|
-
* @param len
|
|
28
|
-
* @param s
|
|
29
|
-
* @param e
|
|
30
|
-
* @param m
|
|
24
|
+
* @param canvas -
|
|
25
|
+
* @param x -
|
|
26
|
+
* @param y -
|
|
27
|
+
* @param len -
|
|
28
|
+
* @param s -
|
|
29
|
+
* @param e -
|
|
30
|
+
* @param m -
|
|
31
31
|
*/
|
|
32
32
|
export declare const vline: (canvas: Canvas, x: number, y: number, len: number, s?: NumOrString | undefined, e?: NumOrString | undefined, m?: NumOrString | undefined, format?: number) => void;
|
|
33
33
|
//# sourceMappingURL=hvline.d.ts.map
|
package/hvline.js
CHANGED
|
@@ -6,13 +6,13 @@ import { charCode } from "./utils.js";
|
|
|
6
6
|
* and `m` (line middle) chars can be used to override the currently
|
|
7
7
|
* active style.
|
|
8
8
|
*
|
|
9
|
-
* @param canvas
|
|
10
|
-
* @param x
|
|
11
|
-
* @param y
|
|
12
|
-
* @param len
|
|
13
|
-
* @param s
|
|
14
|
-
* @param e
|
|
15
|
-
* @param m
|
|
9
|
+
* @param canvas -
|
|
10
|
+
* @param x -
|
|
11
|
+
* @param y -
|
|
12
|
+
* @param len -
|
|
13
|
+
* @param s -
|
|
14
|
+
* @param e -
|
|
15
|
+
* @param m -
|
|
16
16
|
*/
|
|
17
17
|
export const hline = (canvas, x, y, len, s, e, m, format = canvas.format) => {
|
|
18
18
|
const { x1, y1, x2, y2 } = peek(canvas.clipRects);
|
|
@@ -26,13 +26,13 @@ export const hline = (canvas, x, y, len, s, e, m, format = canvas.format) => {
|
|
|
26
26
|
* and `m` (line middle) chars can be used to override the currently
|
|
27
27
|
* active style.
|
|
28
28
|
*
|
|
29
|
-
* @param canvas
|
|
30
|
-
* @param x
|
|
31
|
-
* @param y
|
|
32
|
-
* @param len
|
|
33
|
-
* @param s
|
|
34
|
-
* @param e
|
|
35
|
-
* @param m
|
|
29
|
+
* @param canvas -
|
|
30
|
+
* @param x -
|
|
31
|
+
* @param y -
|
|
32
|
+
* @param len -
|
|
33
|
+
* @param s -
|
|
34
|
+
* @param e -
|
|
35
|
+
* @param m -
|
|
36
36
|
*/
|
|
37
37
|
export const vline = (canvas, x, y, len, s, e, m, format = canvas.format) => {
|
|
38
38
|
const { x1, x2, y1, y2 } = peek(canvas.clipRects);
|
package/image.d.ts
CHANGED
|
@@ -9,33 +9,33 @@ export declare const extract: (canvas: Canvas, x: number, y: number, w: number,
|
|
|
9
9
|
* upward, if `dy < 0` downward. The new empty space will be filled with
|
|
10
10
|
* `clear` char (default: ` `).
|
|
11
11
|
*
|
|
12
|
-
* @param canvas
|
|
13
|
-
* @param dy
|
|
14
|
-
* @param clear
|
|
12
|
+
* @param canvas -
|
|
13
|
+
* @param dy -
|
|
14
|
+
* @param clear -
|
|
15
15
|
*/
|
|
16
16
|
export declare const scrollV: (canvas: Canvas, dy: number, clear?: number) => void;
|
|
17
17
|
/**
|
|
18
18
|
*
|
|
19
|
-
* @param canvas
|
|
20
|
-
* @param x
|
|
21
|
-
* @param y
|
|
22
|
-
* @param w
|
|
23
|
-
* @param h
|
|
24
|
-
* @param pixels
|
|
25
|
-
* @param opts
|
|
19
|
+
* @param canvas -
|
|
20
|
+
* @param x -
|
|
21
|
+
* @param y -
|
|
22
|
+
* @param w -
|
|
23
|
+
* @param h -
|
|
24
|
+
* @param pixels -
|
|
25
|
+
* @param opts -
|
|
26
26
|
*/
|
|
27
27
|
export declare const image: (canvas: Canvas, x: number, y: number, w: number, h: number, pixels: ArrayLike<number>, opts?: Partial<ImageOpts> | undefined) => void;
|
|
28
28
|
/**
|
|
29
29
|
* Optimized version of {@link image}, which only uses a single char for all
|
|
30
30
|
* pixels and applies pixel values directly as formatting data (for each pixel).
|
|
31
31
|
*
|
|
32
|
-
* @param canvas
|
|
33
|
-
* @param x
|
|
34
|
-
* @param y
|
|
35
|
-
* @param w
|
|
36
|
-
* @param h
|
|
37
|
-
* @param pixels
|
|
38
|
-
* @param char
|
|
32
|
+
* @param canvas -
|
|
33
|
+
* @param x -
|
|
34
|
+
* @param y -
|
|
35
|
+
* @param w -
|
|
36
|
+
* @param h -
|
|
37
|
+
* @param pixels -
|
|
38
|
+
* @param char -
|
|
39
39
|
*/
|
|
40
40
|
export declare const imageRaw: (canvas: Canvas, x: number, y: number, w: number, h: number, pixels: ArrayLike<number>, char?: string) => void;
|
|
41
41
|
/**
|
|
@@ -51,14 +51,14 @@ export declare const imageRaw: (canvas: Canvas, x: number, y: number, w: number,
|
|
|
51
51
|
* Reference:
|
|
52
52
|
* https://en.wikipedia.org/wiki/Braille_Patterns#Identifying.2C_naming_and_ordering
|
|
53
53
|
*
|
|
54
|
-
* @param canvas
|
|
55
|
-
* @param x
|
|
56
|
-
* @param y
|
|
57
|
-
* @param w
|
|
58
|
-
* @param h
|
|
59
|
-
* @param pixels
|
|
60
|
-
* @param thresh
|
|
61
|
-
* @param format
|
|
54
|
+
* @param canvas -
|
|
55
|
+
* @param x -
|
|
56
|
+
* @param y -
|
|
57
|
+
* @param w -
|
|
58
|
+
* @param h -
|
|
59
|
+
* @param pixels -
|
|
60
|
+
* @param thresh -
|
|
61
|
+
* @param format -
|
|
62
62
|
*/
|
|
63
63
|
export declare const imageBraille: (canvas: Canvas, x: number, y: number, w: number, h: number, pixels: ArrayLike<number>, thresh: number, format?: number | undefined) => void;
|
|
64
64
|
/**
|
|
@@ -69,9 +69,9 @@ export declare const imageBraille: (canvas: Canvas, x: number, y: number, w: num
|
|
|
69
69
|
* The returned canvas will have 50% width and 25% height of the original image
|
|
70
70
|
* (due to each Braille character encoding 2x4 pixels).
|
|
71
71
|
*
|
|
72
|
-
* @param src
|
|
73
|
-
* @param thresh
|
|
74
|
-
* @param format
|
|
72
|
+
* @param src -
|
|
73
|
+
* @param thresh -
|
|
74
|
+
* @param format -
|
|
75
75
|
*/
|
|
76
76
|
export declare const imageCanvasBraille: (src: {
|
|
77
77
|
width: number;
|
|
@@ -82,8 +82,8 @@ export declare const imageCanvasBraille: (src: {
|
|
|
82
82
|
* Same as {@link imageCanvasBrailler}, but returns resulting canvas as plain
|
|
83
83
|
* string (of Unicode Braille characters).
|
|
84
84
|
*
|
|
85
|
-
* @param src
|
|
86
|
-
* @param thresh
|
|
85
|
+
* @param src -
|
|
86
|
+
* @param thresh -
|
|
87
87
|
*/
|
|
88
88
|
export declare const imageStringBraille: (src: {
|
|
89
89
|
width: number;
|
|
@@ -95,8 +95,8 @@ export declare const imageStringBraille: (src: {
|
|
|
95
95
|
* pixel buffer in RGB565 format and converts it into a new {@link canvas}. The
|
|
96
96
|
* optional `char` will be used as character for each pixel.
|
|
97
97
|
*
|
|
98
|
-
* @param src
|
|
99
|
-
* @param char
|
|
98
|
+
* @param src -
|
|
99
|
+
* @param char -
|
|
100
100
|
*/
|
|
101
101
|
export declare const imageCanvas565: (src: {
|
|
102
102
|
width: number;
|
|
@@ -107,8 +107,8 @@ export declare const imageCanvas565: (src: {
|
|
|
107
107
|
* Same as {@link imageCanvas565}, but returns resulting canvas as 24bit ANSI
|
|
108
108
|
* string.
|
|
109
109
|
*
|
|
110
|
-
* @param src
|
|
111
|
-
* @param char
|
|
110
|
+
* @param src -
|
|
111
|
+
* @param char -
|
|
112
112
|
*/
|
|
113
113
|
export declare const imageString565: (src: {
|
|
114
114
|
width: number;
|
package/image.js
CHANGED
|
@@ -52,9 +52,9 @@ export const extract = (canvas, x, y, w, h) => {
|
|
|
52
52
|
* upward, if `dy < 0` downward. The new empty space will be filled with
|
|
53
53
|
* `clear` char (default: ` `).
|
|
54
54
|
*
|
|
55
|
-
* @param canvas
|
|
56
|
-
* @param dy
|
|
57
|
-
* @param clear
|
|
55
|
+
* @param canvas -
|
|
56
|
+
* @param dy -
|
|
57
|
+
* @param clear -
|
|
58
58
|
*/
|
|
59
59
|
export const scrollV = (canvas, dy, clear = 0x20) => {
|
|
60
60
|
const { data, width } = canvas;
|
|
@@ -71,13 +71,13 @@ export const scrollV = (canvas, dy, clear = 0x20) => {
|
|
|
71
71
|
};
|
|
72
72
|
/**
|
|
73
73
|
*
|
|
74
|
-
* @param canvas
|
|
75
|
-
* @param x
|
|
76
|
-
* @param y
|
|
77
|
-
* @param w
|
|
78
|
-
* @param h
|
|
79
|
-
* @param pixels
|
|
80
|
-
* @param opts
|
|
74
|
+
* @param canvas -
|
|
75
|
+
* @param x -
|
|
76
|
+
* @param y -
|
|
77
|
+
* @param w -
|
|
78
|
+
* @param h -
|
|
79
|
+
* @param pixels -
|
|
80
|
+
* @param opts -
|
|
81
81
|
*/
|
|
82
82
|
export const image = (canvas, x, y, w, h, pixels, opts) => {
|
|
83
83
|
x |= 0;
|
|
@@ -114,13 +114,13 @@ export const image = (canvas, x, y, w, h, pixels, opts) => {
|
|
|
114
114
|
* Optimized version of {@link image}, which only uses a single char for all
|
|
115
115
|
* pixels and applies pixel values directly as formatting data (for each pixel).
|
|
116
116
|
*
|
|
117
|
-
* @param canvas
|
|
118
|
-
* @param x
|
|
119
|
-
* @param y
|
|
120
|
-
* @param w
|
|
121
|
-
* @param h
|
|
122
|
-
* @param pixels
|
|
123
|
-
* @param char
|
|
117
|
+
* @param canvas -
|
|
118
|
+
* @param x -
|
|
119
|
+
* @param y -
|
|
120
|
+
* @param w -
|
|
121
|
+
* @param h -
|
|
122
|
+
* @param pixels -
|
|
123
|
+
* @param char -
|
|
124
124
|
*/
|
|
125
125
|
export const imageRaw = (canvas, x, y, w, h, pixels, char = "█") => {
|
|
126
126
|
x |= 0;
|
|
@@ -153,14 +153,14 @@ export const imageRaw = (canvas, x, y, w, h, pixels, char = "█") => {
|
|
|
153
153
|
* Reference:
|
|
154
154
|
* https://en.wikipedia.org/wiki/Braille_Patterns#Identifying.2C_naming_and_ordering
|
|
155
155
|
*
|
|
156
|
-
* @param canvas
|
|
157
|
-
* @param x
|
|
158
|
-
* @param y
|
|
159
|
-
* @param w
|
|
160
|
-
* @param h
|
|
161
|
-
* @param pixels
|
|
162
|
-
* @param thresh
|
|
163
|
-
* @param format
|
|
156
|
+
* @param canvas -
|
|
157
|
+
* @param x -
|
|
158
|
+
* @param y -
|
|
159
|
+
* @param w -
|
|
160
|
+
* @param h -
|
|
161
|
+
* @param pixels -
|
|
162
|
+
* @param thresh -
|
|
163
|
+
* @param format -
|
|
164
164
|
*/
|
|
165
165
|
export const imageBraille = (canvas, x, y, w, h, pixels, thresh, format) => {
|
|
166
166
|
x |= 0;
|
|
@@ -199,9 +199,9 @@ export const imageBraille = (canvas, x, y, w, h, pixels, thresh, format) => {
|
|
|
199
199
|
* The returned canvas will have 50% width and 25% height of the original image
|
|
200
200
|
* (due to each Braille character encoding 2x4 pixels).
|
|
201
201
|
*
|
|
202
|
-
* @param src
|
|
203
|
-
* @param thresh
|
|
204
|
-
* @param format
|
|
202
|
+
* @param src -
|
|
203
|
+
* @param thresh -
|
|
204
|
+
* @param format -
|
|
205
205
|
*/
|
|
206
206
|
export const imageCanvasBraille = (src, thresh, format = 0) => {
|
|
207
207
|
const dest = canvas(src.width >> 1, src.height >> 2);
|
|
@@ -212,8 +212,8 @@ export const imageCanvasBraille = (src, thresh, format = 0) => {
|
|
|
212
212
|
* Same as {@link imageCanvasBrailler}, but returns resulting canvas as plain
|
|
213
213
|
* string (of Unicode Braille characters).
|
|
214
214
|
*
|
|
215
|
-
* @param src
|
|
216
|
-
* @param thresh
|
|
215
|
+
* @param src -
|
|
216
|
+
* @param thresh -
|
|
217
217
|
*/
|
|
218
218
|
export const imageStringBraille = (src, thresh) => formatCanvas(imageCanvasBraille(src, thresh, 0));
|
|
219
219
|
/**
|
|
@@ -221,8 +221,8 @@ export const imageStringBraille = (src, thresh) => formatCanvas(imageCanvasBrail
|
|
|
221
221
|
* pixel buffer in RGB565 format and converts it into a new {@link canvas}. The
|
|
222
222
|
* optional `char` will be used as character for each pixel.
|
|
223
223
|
*
|
|
224
|
-
* @param src
|
|
225
|
-
* @param char
|
|
224
|
+
* @param src -
|
|
225
|
+
* @param char -
|
|
226
226
|
*/
|
|
227
227
|
export const imageCanvas565 = (src, char) => {
|
|
228
228
|
const dest = canvas(src.width, src.height);
|
|
@@ -233,8 +233,8 @@ export const imageCanvas565 = (src, char) => {
|
|
|
233
233
|
* Same as {@link imageCanvas565}, but returns resulting canvas as 24bit ANSI
|
|
234
234
|
* string.
|
|
235
235
|
*
|
|
236
|
-
* @param src
|
|
237
|
-
* @param char
|
|
236
|
+
* @param src -
|
|
237
|
+
* @param char -
|
|
238
238
|
*/
|
|
239
239
|
export const imageString565 = (src, char, fmt = FMT_ANSI565) => formatCanvas(imageCanvas565(src, char), fmt);
|
|
240
240
|
const imgRect = (canvas, x, y, w, h) => {
|
package/line.d.ts
CHANGED
|
@@ -5,12 +5,12 @@ import type { Canvas } from "./canvas.js";
|
|
|
5
5
|
* the current clip rect and format into account. If `char` is not
|
|
6
6
|
* given, uses current style's `dot` char.
|
|
7
7
|
*
|
|
8
|
-
* @param canvas
|
|
9
|
-
* @param ax
|
|
10
|
-
* @param ay
|
|
11
|
-
* @param bx
|
|
12
|
-
* @param by
|
|
13
|
-
* @param char
|
|
8
|
+
* @param canvas -
|
|
9
|
+
* @param ax -
|
|
10
|
+
* @param ay -
|
|
11
|
+
* @param bx -
|
|
12
|
+
* @param by -
|
|
13
|
+
* @param char -
|
|
14
14
|
*/
|
|
15
15
|
export declare const line: (canvas: Canvas, ax: number, ay: number, bx: number, by: number, char?: NumOrString | undefined, format?: number) => void;
|
|
16
16
|
//# sourceMappingURL=line.d.ts.map
|
package/line.js
CHANGED
|
@@ -6,12 +6,12 @@ import { charCode } from "./utils.js";
|
|
|
6
6
|
* the current clip rect and format into account. If `char` is not
|
|
7
7
|
* given, uses current style's `dot` char.
|
|
8
8
|
*
|
|
9
|
-
* @param canvas
|
|
10
|
-
* @param ax
|
|
11
|
-
* @param ay
|
|
12
|
-
* @param bx
|
|
13
|
-
* @param by
|
|
14
|
-
* @param char
|
|
9
|
+
* @param canvas -
|
|
10
|
+
* @param ax -
|
|
11
|
+
* @param ay -
|
|
12
|
+
* @param bx -
|
|
13
|
+
* @param by -
|
|
14
|
+
* @param char -
|
|
15
15
|
*/
|
|
16
16
|
export const line = (canvas, ax, ay, bx, by, char, format = canvas.format) => {
|
|
17
17
|
const { x1, y1, x2, y2 } = peek(canvas.clipRects);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/text-canvas",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"description": "Text based canvas, drawing, tables with arbitrary formatting (incl. ANSI/HTML)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -34,23 +34,23 @@
|
|
|
34
34
|
"test": "testament test"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@thi.ng/api": "^8.3.
|
|
38
|
-
"@thi.ng/arrays": "^2.1
|
|
39
|
-
"@thi.ng/checks": "^3.1.
|
|
40
|
-
"@thi.ng/geom-clip-line": "^2.1.
|
|
41
|
-
"@thi.ng/math": "^5.
|
|
42
|
-
"@thi.ng/strings": "^3.3.
|
|
43
|
-
"@thi.ng/text-format": "^1.1.
|
|
44
|
-
"@thi.ng/transducers": "^8.
|
|
37
|
+
"@thi.ng/api": "^8.3.5",
|
|
38
|
+
"@thi.ng/arrays": "^2.2.1",
|
|
39
|
+
"@thi.ng/checks": "^3.1.5",
|
|
40
|
+
"@thi.ng/geom-clip-line": "^2.1.10",
|
|
41
|
+
"@thi.ng/math": "^5.3.1",
|
|
42
|
+
"@thi.ng/strings": "^3.3.3",
|
|
43
|
+
"@thi.ng/text-format": "^1.1.5",
|
|
44
|
+
"@thi.ng/transducers": "^8.3.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@microsoft/api-extractor": "^7.19.
|
|
48
|
-
"@thi.ng/testament": "^0.2.
|
|
47
|
+
"@microsoft/api-extractor": "^7.19.4",
|
|
48
|
+
"@thi.ng/testament": "^0.2.5",
|
|
49
49
|
"rimraf": "^3.0.2",
|
|
50
50
|
"tools": "^0.0.1",
|
|
51
51
|
"tslib": "^2.3.1",
|
|
52
|
-
"typedoc": "^0.22.
|
|
53
|
-
"typescript": "^4.
|
|
52
|
+
"typedoc": "^0.22.13",
|
|
53
|
+
"typescript": "^4.6.2"
|
|
54
54
|
},
|
|
55
55
|
"keywords": [
|
|
56
56
|
"4bit",
|
|
@@ -93,43 +93,43 @@
|
|
|
93
93
|
],
|
|
94
94
|
"exports": {
|
|
95
95
|
".": {
|
|
96
|
-
"
|
|
96
|
+
"default": "./index.js"
|
|
97
97
|
},
|
|
98
98
|
"./api": {
|
|
99
|
-
"
|
|
99
|
+
"default": "./api.js"
|
|
100
100
|
},
|
|
101
101
|
"./bars": {
|
|
102
|
-
"
|
|
102
|
+
"default": "./bars.js"
|
|
103
103
|
},
|
|
104
104
|
"./canvas": {
|
|
105
|
-
"
|
|
105
|
+
"default": "./canvas.js"
|
|
106
106
|
},
|
|
107
107
|
"./circle": {
|
|
108
|
-
"
|
|
108
|
+
"default": "./circle.js"
|
|
109
109
|
},
|
|
110
110
|
"./format": {
|
|
111
|
-
"
|
|
111
|
+
"default": "./format.js"
|
|
112
112
|
},
|
|
113
113
|
"./hvline": {
|
|
114
|
-
"
|
|
114
|
+
"default": "./hvline.js"
|
|
115
115
|
},
|
|
116
116
|
"./image": {
|
|
117
|
-
"
|
|
117
|
+
"default": "./image.js"
|
|
118
118
|
},
|
|
119
119
|
"./line": {
|
|
120
|
-
"
|
|
120
|
+
"default": "./line.js"
|
|
121
121
|
},
|
|
122
122
|
"./rect": {
|
|
123
|
-
"
|
|
123
|
+
"default": "./rect.js"
|
|
124
124
|
},
|
|
125
125
|
"./style": {
|
|
126
|
-
"
|
|
126
|
+
"default": "./style.js"
|
|
127
127
|
},
|
|
128
128
|
"./table": {
|
|
129
|
-
"
|
|
129
|
+
"default": "./table.js"
|
|
130
130
|
},
|
|
131
131
|
"./text": {
|
|
132
|
-
"
|
|
132
|
+
"default": "./text.js"
|
|
133
133
|
}
|
|
134
134
|
},
|
|
135
135
|
"thi.ng": {
|
|
@@ -138,5 +138,5 @@
|
|
|
138
138
|
],
|
|
139
139
|
"year": 2020
|
|
140
140
|
},
|
|
141
|
-
"gitHead": "
|
|
141
|
+
"gitHead": "542bf14bd0c7a56b4e6297718189eea772a824b7\n"
|
|
142
142
|
}
|
package/rect.d.ts
CHANGED
|
@@ -5,32 +5,32 @@ import type { Canvas } from "./canvas.js";
|
|
|
5
5
|
* 0x20 / space). If `reset` is true, first resets all internal state
|
|
6
6
|
* (clipping, format, style), so that entire canvas will be cleared.
|
|
7
7
|
*
|
|
8
|
-
* @param canvas
|
|
9
|
-
* @param reset
|
|
10
|
-
* @param code
|
|
8
|
+
* @param canvas -
|
|
9
|
+
* @param reset -
|
|
10
|
+
* @param code -
|
|
11
11
|
*/
|
|
12
12
|
export declare const clear: (canvas: Canvas, reset?: boolean, code?: NumOrString) => void;
|
|
13
13
|
/**
|
|
14
14
|
* Fills given rect with char, taking currect clip rect and format into
|
|
15
15
|
* account.
|
|
16
16
|
*
|
|
17
|
-
* @param canvas
|
|
18
|
-
* @param x
|
|
19
|
-
* @param y
|
|
20
|
-
* @param w
|
|
21
|
-
* @param h
|
|
22
|
-
* @param char
|
|
17
|
+
* @param canvas -
|
|
18
|
+
* @param x -
|
|
19
|
+
* @param y -
|
|
20
|
+
* @param w -
|
|
21
|
+
* @param h -
|
|
22
|
+
* @param char -
|
|
23
23
|
*/
|
|
24
24
|
export declare const fillRect: (canvas: Canvas, x: number, y: number, w: number, h: number, char: NumOrString, format?: number) => void;
|
|
25
25
|
/**
|
|
26
26
|
* Draws an outline of given rect, taking the current clip rect, format
|
|
27
27
|
* and style into account.
|
|
28
28
|
*
|
|
29
|
-
* @param canvas
|
|
30
|
-
* @param x
|
|
31
|
-
* @param y
|
|
32
|
-
* @param w
|
|
33
|
-
* @param h
|
|
29
|
+
* @param canvas -
|
|
30
|
+
* @param x -
|
|
31
|
+
* @param y -
|
|
32
|
+
* @param w -
|
|
33
|
+
* @param h -
|
|
34
34
|
*/
|
|
35
35
|
export declare const strokeRect: (canvas: Canvas, x: number, y: number, w: number, h: number, format?: number) => void;
|
|
36
36
|
//# sourceMappingURL=rect.d.ts.map
|
package/rect.js
CHANGED
|
@@ -6,9 +6,9 @@ import { charCode } from "./utils.js";
|
|
|
6
6
|
* 0x20 / space). If `reset` is true, first resets all internal state
|
|
7
7
|
* (clipping, format, style), so that entire canvas will be cleared.
|
|
8
8
|
*
|
|
9
|
-
* @param canvas
|
|
10
|
-
* @param reset
|
|
11
|
-
* @param code
|
|
9
|
+
* @param canvas -
|
|
10
|
+
* @param reset -
|
|
11
|
+
* @param code -
|
|
12
12
|
*/
|
|
13
13
|
export const clear = (canvas, reset = false, code = 0x20) => {
|
|
14
14
|
const rects = canvas.clipRects;
|
|
@@ -29,12 +29,12 @@ export const clear = (canvas, reset = false, code = 0x20) => {
|
|
|
29
29
|
* Fills given rect with char, taking currect clip rect and format into
|
|
30
30
|
* account.
|
|
31
31
|
*
|
|
32
|
-
* @param canvas
|
|
33
|
-
* @param x
|
|
34
|
-
* @param y
|
|
35
|
-
* @param w
|
|
36
|
-
* @param h
|
|
37
|
-
* @param char
|
|
32
|
+
* @param canvas -
|
|
33
|
+
* @param x -
|
|
34
|
+
* @param y -
|
|
35
|
+
* @param w -
|
|
36
|
+
* @param h -
|
|
37
|
+
* @param char -
|
|
38
38
|
*/
|
|
39
39
|
export const fillRect = (canvas, x, y, w, h, char, format = canvas.format) => {
|
|
40
40
|
x |= 0;
|
|
@@ -65,11 +65,11 @@ export const fillRect = (canvas, x, y, w, h, char, format = canvas.format) => {
|
|
|
65
65
|
* Draws an outline of given rect, taking the current clip rect, format
|
|
66
66
|
* and style into account.
|
|
67
67
|
*
|
|
68
|
-
* @param canvas
|
|
69
|
-
* @param x
|
|
70
|
-
* @param y
|
|
71
|
-
* @param w
|
|
72
|
-
* @param h
|
|
68
|
+
* @param canvas -
|
|
69
|
+
* @param x -
|
|
70
|
+
* @param y -
|
|
71
|
+
* @param w -
|
|
72
|
+
* @param h -
|
|
73
73
|
*/
|
|
74
74
|
export const strokeRect = (canvas, x, y, w, h, format = canvas.format) => {
|
|
75
75
|
w |= 0;
|
package/text.d.ts
CHANGED
|
@@ -5,10 +5,10 @@ import { Canvas } from "./canvas.js";
|
|
|
5
5
|
* and format into account. The string MUST not include linebreaks or
|
|
6
6
|
* other control chars.
|
|
7
7
|
*
|
|
8
|
-
* @param canvas
|
|
9
|
-
* @param x
|
|
10
|
-
* @param y
|
|
11
|
-
* @param line
|
|
8
|
+
* @param canvas -
|
|
9
|
+
* @param x -
|
|
10
|
+
* @param y -
|
|
11
|
+
* @param line -
|
|
12
12
|
*/
|
|
13
13
|
export declare const textLine: (canvas: Canvas, x: number, y: number, line: string, format?: number) => void;
|
|
14
14
|
export declare const textLines: (canvas: Canvas, x: number, y: number, lines: string[], format?: number) => number;
|
|
@@ -17,13 +17,13 @@ export declare const textLines: (canvas: Canvas, x: number, y: number, lines: st
|
|
|
17
17
|
* also taking the current clip rect and format into account. Applies
|
|
18
18
|
* word wrapping.
|
|
19
19
|
*
|
|
20
|
-
* @param canvas
|
|
21
|
-
* @param x
|
|
22
|
-
* @param y
|
|
23
|
-
* @param width
|
|
24
|
-
* @param txt
|
|
25
|
-
* @param format
|
|
26
|
-
* @param hardWrap
|
|
20
|
+
* @param canvas -
|
|
21
|
+
* @param x -
|
|
22
|
+
* @param y -
|
|
23
|
+
* @param width -
|
|
24
|
+
* @param txt -
|
|
25
|
+
* @param format -
|
|
26
|
+
* @param hardWrap -
|
|
27
27
|
*/
|
|
28
28
|
export declare const textColumn: (canvas: Canvas, x: number, y: number, width: number, txt: string, format?: number, hard?: boolean) => number;
|
|
29
29
|
/**
|
|
@@ -34,13 +34,13 @@ export declare const textColumn: (canvas: Canvas, x: number, y: number, width: n
|
|
|
34
34
|
* @remarks
|
|
35
35
|
* The width and height will include any configured padding and the box frame.
|
|
36
36
|
*
|
|
37
|
-
* @param canvas
|
|
38
|
-
* @param x
|
|
39
|
-
* @param y
|
|
40
|
-
* @param width
|
|
41
|
-
* @param height
|
|
42
|
-
* @param txt
|
|
43
|
-
* @param opts
|
|
37
|
+
* @param canvas -
|
|
38
|
+
* @param x -
|
|
39
|
+
* @param y -
|
|
40
|
+
* @param width -
|
|
41
|
+
* @param height -
|
|
42
|
+
* @param txt -
|
|
43
|
+
* @param opts -
|
|
44
44
|
*/
|
|
45
45
|
export declare const textBox: (canvas: Canvas, x: number, y: number, width: number, height: number, txt: string, opts?: Partial<TextBoxOpts> | undefined) => number;
|
|
46
46
|
//# sourceMappingURL=text.d.ts.map
|
package/text.js
CHANGED
|
@@ -8,10 +8,10 @@ import { fillRect, strokeRect } from "./rect.js";
|
|
|
8
8
|
* and format into account. The string MUST not include linebreaks or
|
|
9
9
|
* other control chars.
|
|
10
10
|
*
|
|
11
|
-
* @param canvas
|
|
12
|
-
* @param x
|
|
13
|
-
* @param y
|
|
14
|
-
* @param line
|
|
11
|
+
* @param canvas -
|
|
12
|
+
* @param x -
|
|
13
|
+
* @param y -
|
|
14
|
+
* @param line -
|
|
15
15
|
*/
|
|
16
16
|
export const textLine = (canvas, x, y, line, format = canvas.format) => {
|
|
17
17
|
x |= 0;
|
|
@@ -43,13 +43,13 @@ export const textLines = (canvas, x, y, lines, format = canvas.format) => {
|
|
|
43
43
|
* also taking the current clip rect and format into account. Applies
|
|
44
44
|
* word wrapping.
|
|
45
45
|
*
|
|
46
|
-
* @param canvas
|
|
47
|
-
* @param x
|
|
48
|
-
* @param y
|
|
49
|
-
* @param width
|
|
50
|
-
* @param txt
|
|
51
|
-
* @param format
|
|
52
|
-
* @param hardWrap
|
|
46
|
+
* @param canvas -
|
|
47
|
+
* @param x -
|
|
48
|
+
* @param y -
|
|
49
|
+
* @param width -
|
|
50
|
+
* @param txt -
|
|
51
|
+
* @param format -
|
|
52
|
+
* @param hardWrap -
|
|
53
53
|
*/
|
|
54
54
|
export const textColumn = (canvas, x, y, width, txt, format = canvas.format, hard = false) => {
|
|
55
55
|
x |= 0;
|
|
@@ -72,13 +72,13 @@ export const textColumn = (canvas, x, y, width, txt, format = canvas.format, har
|
|
|
72
72
|
* @remarks
|
|
73
73
|
* The width and height will include any configured padding and the box frame.
|
|
74
74
|
*
|
|
75
|
-
* @param canvas
|
|
76
|
-
* @param x
|
|
77
|
-
* @param y
|
|
78
|
-
* @param width
|
|
79
|
-
* @param height
|
|
80
|
-
* @param txt
|
|
81
|
-
* @param opts
|
|
75
|
+
* @param canvas -
|
|
76
|
+
* @param x -
|
|
77
|
+
* @param y -
|
|
78
|
+
* @param width -
|
|
79
|
+
* @param height -
|
|
80
|
+
* @param txt -
|
|
81
|
+
* @param opts -
|
|
82
82
|
*/
|
|
83
83
|
export const textBox = (canvas, x, y, width, height, txt, opts) => {
|
|
84
84
|
const { format, style, padding: [padX, padY], hard, } = {
|