@thi.ng/text-canvas 3.0.23 → 3.0.24
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 +7 -1
- package/README.md +1 -1
- package/bars.js +3 -3
- package/canvas.js +3 -3
- package/image.d.ts +7 -5
- package/image.js +5 -5
- package/package.json +16 -16
- package/utils.js +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-
|
|
3
|
+
- **Last updated**: 2024-06-21T19:34:38Z
|
|
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,12 @@ 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
|
+
### [3.0.24](https://github.com/thi-ng/umbrella/tree/@thi.ng/text-canvas@3.0.24) (2024-06-21)
|
|
13
|
+
|
|
14
|
+
#### ♻️ Refactoring
|
|
15
|
+
|
|
16
|
+
- enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
|
|
17
|
+
|
|
12
18
|
### [3.0.3](https://github.com/thi-ng/umbrella/tree/@thi.ng/text-canvas@3.0.3) (2024-02-22)
|
|
13
19
|
|
|
14
20
|
#### ♻️ Refactoring
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://mastodon.thi.ng/@toxi)
|
|
8
8
|
|
|
9
9
|
> [!NOTE]
|
|
10
|
-
> This is one of
|
|
10
|
+
> This is one of 193 standalone projects, maintained as part
|
|
11
11
|
> of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
|
|
12
12
|
> and anti-framework.
|
|
13
13
|
>
|
package/bars.js
CHANGED
|
@@ -32,9 +32,9 @@ const barChartHLines = (width, vals, min, max) => {
|
|
|
32
32
|
return [...map((x) => barHorizontal(width, x, min, max), $vals)];
|
|
33
33
|
};
|
|
34
34
|
const barChartHStr = (width, vals, min, max) => barChartHLines(width, vals, min, max).join("\n");
|
|
35
|
-
const barHorizontal = (width, x, min = 0, max = 1) =>
|
|
36
|
-
const barVertical = (height, x, min = 0, max = 1, delim = "\n") =>
|
|
37
|
-
const
|
|
35
|
+
const barHorizontal = (width, x, min = 0, max = 1) => __bar(BARS_H, width, false, x, min, max, "");
|
|
36
|
+
const barVertical = (height, x, min = 0, max = 1, delim = "\n") => __bar(BARS_V, height, true, x, min, max, delim);
|
|
37
|
+
const __bar = (chars, size, left, x, min, max, delim) => {
|
|
38
38
|
x = fitClamped(x, min, max, 0, size);
|
|
39
39
|
const f = fract(x) * 9 | 0;
|
|
40
40
|
const full = repeat(chars[8] + delim, x | 0);
|
package/canvas.js
CHANGED
|
@@ -138,8 +138,8 @@ const beginClip = (canvas2, x, y, w, h) => {
|
|
|
138
138
|
)
|
|
139
139
|
);
|
|
140
140
|
};
|
|
141
|
-
const
|
|
142
|
-
const endClip = (canvas2) =>
|
|
141
|
+
const __pop = (stack) => stack.length > 1 && stack.pop();
|
|
142
|
+
const endClip = (canvas2) => __pop(canvas2.clipRects);
|
|
143
143
|
const withClip = (canvas2, x, y, w, h, fn) => {
|
|
144
144
|
beginClip(canvas2, x, y, w, h);
|
|
145
145
|
fn();
|
|
@@ -148,7 +148,7 @@ const withClip = (canvas2, x, y, w, h, fn) => {
|
|
|
148
148
|
const beginStyle = (canvas2, style) => {
|
|
149
149
|
canvas2.styles.push(style);
|
|
150
150
|
};
|
|
151
|
-
const endStyle = (canvas2) =>
|
|
151
|
+
const endStyle = (canvas2) => __pop(canvas2.styles);
|
|
152
152
|
const withStyle = (canvas2, style, fn) => {
|
|
153
153
|
canvas2.styles.push(style);
|
|
154
154
|
fn();
|
package/image.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare const blit: (dest: Canvas, src: Canvas, x?: number, y?: number) =
|
|
|
16
16
|
* pixels/chars will be copied. Supports region clipping.
|
|
17
17
|
*
|
|
18
18
|
* @example
|
|
19
|
-
* ```ts
|
|
19
|
+
* ```ts tangle:../export/blit-mask.ts
|
|
20
20
|
* import {
|
|
21
21
|
* blitMask, canvas, canvasFromText, clear, formatCanvas
|
|
22
22
|
* } from "@thi.ng/text-canvas";
|
|
@@ -30,17 +30,19 @@ export declare const blit: (dest: Canvas, src: Canvas, x?: number, y?: number) =
|
|
|
30
30
|
* "###==###",
|
|
31
31
|
* ]);
|
|
32
32
|
*
|
|
33
|
+
* console.log(formatCanvas(a));
|
|
34
|
+
*
|
|
33
35
|
* // destination canvas (filled w/ "-")
|
|
34
36
|
* const b = canvas(12,7);
|
|
35
37
|
* clear(b, true, "-");
|
|
36
38
|
*
|
|
37
39
|
* // paste `a` several times into `b` using "#" as mask
|
|
38
|
-
* blitMask(b, -4, -2,
|
|
39
|
-
* blitMask(b, 2, 1,
|
|
40
|
-
* blitMask(b, 8, 4,
|
|
40
|
+
* blitMask(b, a, -4, -2, "#"); // top-left (partially outside)
|
|
41
|
+
* blitMask(b, a, 2, 1, "#"); // center
|
|
42
|
+
* blitMask(b, a, 8, 4, "#"); // bottom-right (part outside)
|
|
41
43
|
*
|
|
42
44
|
* // show result
|
|
43
|
-
* console.log(formatCanvas(b))
|
|
45
|
+
* console.log(formatCanvas(b));
|
|
44
46
|
* // ===---------
|
|
45
47
|
* // ==---==-----
|
|
46
48
|
* // =---====----
|
package/image.js
CHANGED
|
@@ -297,7 +297,7 @@ const image = (canvas2, x, y, w, h, pixels, opts = {}) => {
|
|
|
297
297
|
sy,
|
|
298
298
|
w: iw,
|
|
299
299
|
h: ih
|
|
300
|
-
} =
|
|
300
|
+
} = __imgRect(canvas2, x, y, w, h);
|
|
301
301
|
if (!iw || !ih) return;
|
|
302
302
|
const {
|
|
303
303
|
chars = SHADES_BLOCK,
|
|
@@ -335,7 +335,7 @@ const imageRaw = (canvas2, x, y, w, h, pixels, char = "\u2588") => {
|
|
|
335
335
|
sy,
|
|
336
336
|
w: iw,
|
|
337
337
|
h: ih
|
|
338
|
-
} =
|
|
338
|
+
} = __imgRect(canvas2, x, y, w, h);
|
|
339
339
|
if (!iw || !ih) return;
|
|
340
340
|
const code = char.charCodeAt(0);
|
|
341
341
|
for (let yy = sy, dy = y1; dy < y2; yy++, dy++) {
|
|
@@ -361,7 +361,7 @@ const imageRawFmtOnly = (canvas2, x, y, w, h, pixels) => {
|
|
|
361
361
|
sy,
|
|
362
362
|
w: iw,
|
|
363
363
|
h: ih
|
|
364
|
-
} =
|
|
364
|
+
} = __imgRect(canvas2, x, y, w, h);
|
|
365
365
|
if (!iw || !ih) return;
|
|
366
366
|
for (let yy = sy, dy = y1; dy < y2; yy++, dy++) {
|
|
367
367
|
let sidx = sx + yy * w;
|
|
@@ -388,7 +388,7 @@ const imageBraille = (canvas2, x, y, w, h, pixels, thresh, format) => {
|
|
|
388
388
|
sy,
|
|
389
389
|
w: iw,
|
|
390
390
|
h: ih
|
|
391
|
-
} =
|
|
391
|
+
} = __imgRect(canvas2, x, y, w >> 1, h >> 2);
|
|
392
392
|
if (!iw || !ih) return;
|
|
393
393
|
const w2 = w * 2;
|
|
394
394
|
const w3 = w * 3;
|
|
@@ -413,7 +413,7 @@ const imageCanvas565 = (src, char) => {
|
|
|
413
413
|
return dest;
|
|
414
414
|
};
|
|
415
415
|
const imageString565 = (src, char, fmt = FMT_ANSI565) => formatCanvas(imageCanvas565(src, char), fmt);
|
|
416
|
-
const
|
|
416
|
+
const __imgRect = (canvas2, x, y, w, h) => {
|
|
417
417
|
const rect = intersectRect(
|
|
418
418
|
{ x1: x, y1: y, x2: x + w, y2: y + h, w, h },
|
|
419
419
|
peek(canvas2.clipRects)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/text-canvas",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.24",
|
|
4
4
|
"description": "Text based canvas, drawing, plotting, tables with arbitrary formatting (incl. ANSI/HTML)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/thi-ng/umbrella.git"
|
|
12
12
|
},
|
|
13
|
-
"homepage": "https://
|
|
13
|
+
"homepage": "https://thi.ng/text-canvas",
|
|
14
14
|
"funding": [
|
|
15
15
|
{
|
|
16
16
|
"type": "github",
|
|
@@ -36,22 +36,22 @@
|
|
|
36
36
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@thi.ng/api": "^8.11.
|
|
40
|
-
"@thi.ng/arrays": "^2.9.
|
|
41
|
-
"@thi.ng/checks": "^3.6.
|
|
42
|
-
"@thi.ng/errors": "^2.5.
|
|
43
|
-
"@thi.ng/geom-clip-line": "^2.3.
|
|
44
|
-
"@thi.ng/math": "^5.
|
|
45
|
-
"@thi.ng/strings": "^3.7.
|
|
46
|
-
"@thi.ng/text-format": "^2.2.
|
|
47
|
-
"@thi.ng/transducers": "^9.0.
|
|
39
|
+
"@thi.ng/api": "^8.11.3",
|
|
40
|
+
"@thi.ng/arrays": "^2.9.7",
|
|
41
|
+
"@thi.ng/checks": "^3.6.5",
|
|
42
|
+
"@thi.ng/errors": "^2.5.8",
|
|
43
|
+
"@thi.ng/geom-clip-line": "^2.3.90",
|
|
44
|
+
"@thi.ng/math": "^5.11.0",
|
|
45
|
+
"@thi.ng/strings": "^3.7.34",
|
|
46
|
+
"@thi.ng/text-format": "^2.2.6",
|
|
47
|
+
"@thi.ng/transducers": "^9.0.6"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@microsoft/api-extractor": "^7.
|
|
51
|
-
"esbuild": "^0.21.
|
|
52
|
-
"tslib": "^2.6.
|
|
50
|
+
"@microsoft/api-extractor": "^7.47.0",
|
|
51
|
+
"esbuild": "^0.21.5",
|
|
52
|
+
"tslib": "^2.6.3",
|
|
53
53
|
"typedoc": "^0.25.13",
|
|
54
|
-
"typescript": "^5.
|
|
54
|
+
"typescript": "^5.5.2"
|
|
55
55
|
},
|
|
56
56
|
"keywords": [
|
|
57
57
|
"4bit",
|
|
@@ -147,5 +147,5 @@
|
|
|
147
147
|
],
|
|
148
148
|
"year": 2020
|
|
149
149
|
},
|
|
150
|
-
"gitHead": "
|
|
150
|
+
"gitHead": "154c95cf9d6bab32174498ec3b5b5d87e42be7f9\n"
|
|
151
151
|
}
|
package/utils.js
CHANGED
|
@@ -6,8 +6,8 @@ const intersectRect = (a, b) => {
|
|
|
6
6
|
const y2 = Math.min(a.y2, b.y2);
|
|
7
7
|
return { x1, y1, x2, y2, w: Math.max(x2 - x1, 0), h: Math.max(y2 - y1, 0) };
|
|
8
8
|
};
|
|
9
|
-
const
|
|
10
|
-
const intersectRectCircle = (x, y, w, h, cx, cy, r) =>
|
|
9
|
+
const __axis = (a, b, c) => (a < b ? a - b : a > b + c ? a - b - c : 0) ** 2;
|
|
10
|
+
const intersectRectCircle = (x, y, w, h, cx, cy, r) => __axis(cx, x, w) + __axis(cy, y, h) <= r * r;
|
|
11
11
|
export {
|
|
12
12
|
charCode,
|
|
13
13
|
intersectRect,
|