@thi.ng/text-canvas 3.0.21 → 3.0.23
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 +1 -1
- package/README.md +1 -1
- package/canvas.js +2 -4
- package/circle.js +2 -4
- package/hvline.js +2 -4
- package/image.js +9 -18
- package/line.js +2 -4
- package/package.json +15 -15
- package/plot.js +3 -6
- package/rect.js +3 -6
- package/text.js +2 -4
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
package/canvas.js
CHANGED
|
@@ -5,8 +5,7 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
5
5
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
6
|
if (decorator = decorators[i])
|
|
7
7
|
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
-
if (kind && result)
|
|
9
|
-
__defProp(target, key, result);
|
|
8
|
+
if (kind && result) __defProp(target, key, result);
|
|
10
9
|
return result;
|
|
11
10
|
};
|
|
12
11
|
import {
|
|
@@ -171,8 +170,7 @@ const setAt = (canvas2, x, y, code, format = canvas2.format) => {
|
|
|
171
170
|
x |= 0;
|
|
172
171
|
y |= 0;
|
|
173
172
|
const { x1, y1, x2, y2 } = peek(canvas2.clipRects);
|
|
174
|
-
if (x < x1 || y < y1 || x >= x2 || y >= y2)
|
|
175
|
-
return;
|
|
173
|
+
if (x < x1 || y < y1 || x >= x2 || y >= y2) return;
|
|
176
174
|
canvas2.data[x + y * canvas2.width] = charCode(code, format);
|
|
177
175
|
};
|
|
178
176
|
export {
|
package/circle.js
CHANGED
|
@@ -2,14 +2,12 @@ import { peek } from "@thi.ng/arrays/peek";
|
|
|
2
2
|
import { hline } from "./hvline.js";
|
|
3
3
|
import { charCode, intersectRectCircle } from "./utils.js";
|
|
4
4
|
const circle = (canvas, cx, cy, r, char, fill = false, format = canvas.format) => {
|
|
5
|
-
if (r < 1)
|
|
6
|
-
return;
|
|
5
|
+
if (r < 1) return;
|
|
7
6
|
cx |= 0;
|
|
8
7
|
cy |= 0;
|
|
9
8
|
r |= 0;
|
|
10
9
|
const { x1, y1, x2, y2, w: clipw, h: cliph } = peek(canvas.clipRects);
|
|
11
|
-
if (!intersectRectCircle(x1, y1, clipw, cliph, cx, cy, r))
|
|
12
|
-
return;
|
|
10
|
+
if (!intersectRectCircle(x1, y1, clipw, cliph, cx, cy, r)) return;
|
|
13
11
|
char = charCode(
|
|
14
12
|
char !== void 0 ? char : peek(canvas.styles).dot,
|
|
15
13
|
format
|
package/hvline.js
CHANGED
|
@@ -2,8 +2,7 @@ import { peek } from "@thi.ng/arrays/peek";
|
|
|
2
2
|
import { charCode } from "./utils.js";
|
|
3
3
|
const hline = (canvas, x, y, len, s, e, m, format = canvas.format) => {
|
|
4
4
|
const { x1, y1, x2, y2 } = peek(canvas.clipRects);
|
|
5
|
-
if (len < 1 || y < y1 || y >= y2 || x >= x2)
|
|
6
|
-
return;
|
|
5
|
+
if (len < 1 || y < y1 || y >= y2 || x >= x2) return;
|
|
7
6
|
_hvline(
|
|
8
7
|
canvas.data,
|
|
9
8
|
x,
|
|
@@ -22,8 +21,7 @@ const hline = (canvas, x, y, len, s, e, m, format = canvas.format) => {
|
|
|
22
21
|
};
|
|
23
22
|
const vline = (canvas, x, y, len, s, e, m, format = canvas.format) => {
|
|
24
23
|
const { x1, x2, y1, y2 } = peek(canvas.clipRects);
|
|
25
|
-
if (len < 1 || x < x1 || x >= x2 || y >= y2)
|
|
26
|
-
return;
|
|
24
|
+
if (len < 1 || x < x1 || x >= x2 || y >= y2) return;
|
|
27
25
|
_hvline(
|
|
28
26
|
canvas.data,
|
|
29
27
|
y,
|
package/image.js
CHANGED
|
@@ -41,16 +41,14 @@ const __initBlit = (dest, x, y, src) => {
|
|
|
41
41
|
{ x1: x, y1: y, x2: x + sw, y2: y + sh, w: sw, h: sh },
|
|
42
42
|
peek(dest.clipRects)
|
|
43
43
|
);
|
|
44
|
-
if (!iw || !ih)
|
|
45
|
-
return;
|
|
44
|
+
if (!iw || !ih) return;
|
|
46
45
|
const sx = clamp0(x1 - x);
|
|
47
46
|
const sy = clamp0(y1 - y);
|
|
48
47
|
return { sbuf, dbuf, sw, dw, x, y, x1, y1, y2, iw, ih, sx, sy };
|
|
49
48
|
};
|
|
50
49
|
const blit = (dest, src, x = 0, y = 0) => {
|
|
51
50
|
const state = __initBlit(dest, x, y, src);
|
|
52
|
-
if (!state)
|
|
53
|
-
return;
|
|
51
|
+
if (!state) return;
|
|
54
52
|
const { sbuf, dbuf, x1, y1, y2, sx, sy, iw, sw, dw } = state;
|
|
55
53
|
for (let yy = sy, dy = y1; dy < y2; yy++, dy++) {
|
|
56
54
|
let sidx = sx + yy * sw;
|
|
@@ -60,8 +58,7 @@ const blit = (dest, src, x = 0, y = 0) => {
|
|
|
60
58
|
};
|
|
61
59
|
const blitMask = (dest, src, x = 0, y = 0, mask = 32) => {
|
|
62
60
|
const state = __initBlit(dest, x, y, src);
|
|
63
|
-
if (!state)
|
|
64
|
-
return;
|
|
61
|
+
if (!state) return;
|
|
65
62
|
const { sbuf, dbuf, x1, y1, y2, sx, sy, iw, sw, dw } = state;
|
|
66
63
|
mask = charCode(mask, 0);
|
|
67
64
|
for (let yy = sy, dy = y1; dy < y2; yy++, dy++) {
|
|
@@ -72,8 +69,7 @@ const blitMask = (dest, src, x = 0, y = 0, mask = 32) => {
|
|
|
72
69
|
};
|
|
73
70
|
const blitBarsV = (dest, src, x = 0, y = 0, blend = blendBarsVAdd) => {
|
|
74
71
|
const state = __initBlit(dest, x, y, src);
|
|
75
|
-
if (!state)
|
|
76
|
-
return;
|
|
72
|
+
if (!state) return;
|
|
77
73
|
const { sbuf, dbuf, x1, y1, y2, sx, sy, iw, sw, dw } = state;
|
|
78
74
|
for (let yy = sy, dy = y1; dy < y2; yy++, dy++) {
|
|
79
75
|
let sidx = sx + yy * sw;
|
|
@@ -251,8 +247,7 @@ const BLEND_ADD = {
|
|
|
251
247
|
}
|
|
252
248
|
};
|
|
253
249
|
const resize = (canvas2, newWidth, newHeight) => {
|
|
254
|
-
if (canvas2.width === newWidth && canvas2.height === newHeight)
|
|
255
|
-
return;
|
|
250
|
+
if (canvas2.width === newWidth && canvas2.height === newHeight) return;
|
|
256
251
|
const dest = new Canvas(newWidth, newHeight);
|
|
257
252
|
dest.data.fill(charCode(32, canvas2.format));
|
|
258
253
|
blit(dest, canvas2);
|
|
@@ -303,8 +298,7 @@ const image = (canvas2, x, y, w, h, pixels, opts = {}) => {
|
|
|
303
298
|
w: iw,
|
|
304
299
|
h: ih
|
|
305
300
|
} = imgRect(canvas2, x, y, w, h);
|
|
306
|
-
if (!iw || !ih)
|
|
307
|
-
return;
|
|
301
|
+
if (!iw || !ih) return;
|
|
308
302
|
const {
|
|
309
303
|
chars = SHADES_BLOCK,
|
|
310
304
|
format = canvas2.format,
|
|
@@ -342,8 +336,7 @@ const imageRaw = (canvas2, x, y, w, h, pixels, char = "\u2588") => {
|
|
|
342
336
|
w: iw,
|
|
343
337
|
h: ih
|
|
344
338
|
} = imgRect(canvas2, x, y, w, h);
|
|
345
|
-
if (!iw || !ih)
|
|
346
|
-
return;
|
|
339
|
+
if (!iw || !ih) return;
|
|
347
340
|
const code = char.charCodeAt(0);
|
|
348
341
|
for (let yy = sy, dy = y1; dy < y2; yy++, dy++) {
|
|
349
342
|
let sidx = sx + yy * w;
|
|
@@ -369,8 +362,7 @@ const imageRawFmtOnly = (canvas2, x, y, w, h, pixels) => {
|
|
|
369
362
|
w: iw,
|
|
370
363
|
h: ih
|
|
371
364
|
} = imgRect(canvas2, x, y, w, h);
|
|
372
|
-
if (!iw || !ih)
|
|
373
|
-
return;
|
|
365
|
+
if (!iw || !ih) return;
|
|
374
366
|
for (let yy = sy, dy = y1; dy < y2; yy++, dy++) {
|
|
375
367
|
let sidx = sx + yy * w;
|
|
376
368
|
let didx = x1 + dy * width;
|
|
@@ -397,8 +389,7 @@ const imageBraille = (canvas2, x, y, w, h, pixels, thresh, format) => {
|
|
|
397
389
|
w: iw,
|
|
398
390
|
h: ih
|
|
399
391
|
} = imgRect(canvas2, x, y, w >> 1, h >> 2);
|
|
400
|
-
if (!iw || !ih)
|
|
401
|
-
return;
|
|
392
|
+
if (!iw || !ih) return;
|
|
402
393
|
const w2 = w * 2;
|
|
403
394
|
const w3 = w * 3;
|
|
404
395
|
const braille = (i) => (pixels[i] >= thresh ? 1 : 0) | (pixels[i + w] >= thresh ? 2 : 0) | (pixels[i + w2] >= thresh ? 4 : 0) | (pixels[i + w3] >= thresh ? 8 : 0) | (pixels[i + 1] >= thresh ? 16 : 0) | (pixels[i + w + 1] >= thresh ? 32 : 0) | (pixels[i + w2 + 1] >= thresh ? 64 : 0) | (pixels[i + w3 + 1] >= thresh ? 128 : 0) | 10240;
|
package/line.js
CHANGED
|
@@ -5,8 +5,7 @@ import { charCode } from "./utils.js";
|
|
|
5
5
|
const line = (canvas, ax, ay, bx, by, char, format = canvas.format) => {
|
|
6
6
|
const { x1, y1, x2, y2 } = peek(canvas.clipRects);
|
|
7
7
|
const clipped = liangBarsky2Raw(ax, ay, bx, by, x1, y1, x2, y2);
|
|
8
|
-
if (!clipped)
|
|
9
|
-
return;
|
|
8
|
+
if (!clipped) return;
|
|
10
9
|
ax = clipped[0] | 0;
|
|
11
10
|
ay = clipped[1] | 0;
|
|
12
11
|
bx = clipped[2] | 0;
|
|
@@ -23,8 +22,7 @@ const line = (canvas, ax, ay, bx, by, char, format = canvas.format) => {
|
|
|
23
22
|
);
|
|
24
23
|
while (true) {
|
|
25
24
|
canvas.data[ax + ay * w] = char;
|
|
26
|
-
if (ax === bx && ay === by)
|
|
27
|
-
return;
|
|
25
|
+
if (ax === bx && ay === by) return;
|
|
28
26
|
let t = err << 1;
|
|
29
27
|
if (t < dx) {
|
|
30
28
|
err += dx;
|
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.23",
|
|
4
4
|
"description": "Text based canvas, drawing, plotting, tables with arbitrary formatting (incl. ANSI/HTML)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -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.10.
|
|
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.2",
|
|
40
|
+
"@thi.ng/arrays": "^2.9.6",
|
|
41
|
+
"@thi.ng/checks": "^3.6.4",
|
|
42
|
+
"@thi.ng/errors": "^2.5.7",
|
|
43
|
+
"@thi.ng/geom-clip-line": "^2.3.89",
|
|
44
|
+
"@thi.ng/math": "^5.10.13",
|
|
45
|
+
"@thi.ng/strings": "^3.7.33",
|
|
46
|
+
"@thi.ng/text-format": "^2.2.5",
|
|
47
|
+
"@thi.ng/transducers": "^9.0.5"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@microsoft/api-extractor": "^7.43.
|
|
51
|
-
"esbuild": "^0.
|
|
50
|
+
"@microsoft/api-extractor": "^7.43.2",
|
|
51
|
+
"esbuild": "^0.21.1",
|
|
52
52
|
"tslib": "^2.6.2",
|
|
53
|
-
"typedoc": "^0.25.
|
|
54
|
-
"typescript": "^5.4.
|
|
53
|
+
"typedoc": "^0.25.13",
|
|
54
|
+
"typescript": "^5.4.5"
|
|
55
55
|
},
|
|
56
56
|
"keywords": [
|
|
57
57
|
"4bit",
|
|
@@ -147,5 +147,5 @@
|
|
|
147
147
|
],
|
|
148
148
|
"year": 2020
|
|
149
149
|
},
|
|
150
|
-
"gitHead": "
|
|
150
|
+
"gitHead": "df34b4a9e650cc7323575356de207d78933bdcf3\n"
|
|
151
151
|
}
|
package/plot.js
CHANGED
|
@@ -34,18 +34,15 @@ const plotLineChart = (canvas, x, y, height, vals, min, max, format = canvas.for
|
|
|
34
34
|
const { x1, x2 } = peek(canvas.clipRects);
|
|
35
35
|
for (let i = 0, n = $vals.length - 1; i < n; i++) {
|
|
36
36
|
const xx = x + i;
|
|
37
|
-
if (xx < x1)
|
|
38
|
-
|
|
39
|
-
if (xx > x2)
|
|
40
|
-
break;
|
|
37
|
+
if (xx < x1) continue;
|
|
38
|
+
if (xx > x2) break;
|
|
41
39
|
const ya = Math.round(fitClamped($vals[i], min, max, height, 0)) + y;
|
|
42
40
|
const yb = Math.round(fitClamped($vals[i + 1], min, max, height, 0)) + y;
|
|
43
41
|
if (ya === yb) {
|
|
44
42
|
canvas.setAt(xx, ya, 9472 | format);
|
|
45
43
|
} else {
|
|
46
44
|
let [y1, y2] = minMax(ya, yb);
|
|
47
|
-
while (++y1 < y2)
|
|
48
|
-
canvas.setAt(xx, y1, 9474 | format);
|
|
45
|
+
while (++y1 < y2) canvas.setAt(xx, y1, 9474 | format);
|
|
49
46
|
canvas.setAt(xx, ya, (ya < yb ? 9582 : 9583) | format);
|
|
50
47
|
canvas.setAt(xx, yb, (ya < yb ? 9584 : 9581) | format);
|
|
51
48
|
}
|
package/rect.js
CHANGED
|
@@ -18,8 +18,7 @@ const clear = (canvas, reset = false, code = 32) => {
|
|
|
18
18
|
};
|
|
19
19
|
const clearFormat = ({ data }, format = NONE) => {
|
|
20
20
|
format <<= 16;
|
|
21
|
-
for (let i = data.length; i-- > 0; )
|
|
22
|
-
data[i] = data[i] & 65535 | format;
|
|
21
|
+
for (let i = data.length; i-- > 0; ) data[i] = data[i] & 65535 | format;
|
|
23
22
|
};
|
|
24
23
|
const fillRect = (canvas, x, y, w, h, char, format = canvas.format) => {
|
|
25
24
|
x |= 0;
|
|
@@ -36,8 +35,7 @@ const fillRect = (canvas, x, y, w, h, char, format = canvas.format) => {
|
|
|
36
35
|
y = y1;
|
|
37
36
|
}
|
|
38
37
|
const { data, width } = canvas;
|
|
39
|
-
if (w < 1 || h < 1 || x >= x2 || y >= y2)
|
|
40
|
-
return;
|
|
38
|
+
if (w < 1 || h < 1 || x >= x2 || y >= y2) return;
|
|
41
39
|
w = Math.min(w, x2 - x);
|
|
42
40
|
h = Math.min(h, y2 - y);
|
|
43
41
|
char = charCode(char, format);
|
|
@@ -49,8 +47,7 @@ const fillRect = (canvas, x, y, w, h, char, format = canvas.format) => {
|
|
|
49
47
|
const strokeRect = (canvas, x, y, w, h, format = canvas.format) => {
|
|
50
48
|
w |= 0;
|
|
51
49
|
h |= 0;
|
|
52
|
-
if (w < 2 || h < 2)
|
|
53
|
-
return;
|
|
50
|
+
if (w < 2 || h < 2) return;
|
|
54
51
|
const style = peek(canvas.styles);
|
|
55
52
|
hline(canvas, x, y, w, style.tl, style.tr, style.hl, format);
|
|
56
53
|
hline(canvas, x, y + h - 1, w, style.bl, style.br, style.hl, format);
|
package/text.js
CHANGED
|
@@ -12,8 +12,7 @@ const textLine = (canvas, x, y, line, format = canvas.format) => {
|
|
|
12
12
|
x |= 0;
|
|
13
13
|
y |= 0;
|
|
14
14
|
const { x1, y1, x2, y2 } = peek(canvas.clipRects);
|
|
15
|
-
if (y < y1 || y >= y2 || x >= x2)
|
|
16
|
-
return;
|
|
15
|
+
if (y < y1 || y >= y2 || x >= x2) return;
|
|
17
16
|
let i = 0;
|
|
18
17
|
if (x < x1) {
|
|
19
18
|
i = x1 - x;
|
|
@@ -41,8 +40,7 @@ const textColumn = (canvas, x, y, width, txt, format = canvas.format, hard = fal
|
|
|
41
40
|
for (let line of wordWrapLines(txt, { width, hard })) {
|
|
42
41
|
textLine(canvas, x, y, line.toString(), format);
|
|
43
42
|
y++;
|
|
44
|
-
if (y >= height)
|
|
45
|
-
break;
|
|
43
|
+
if (y >= height) break;
|
|
46
44
|
}
|
|
47
45
|
return y;
|
|
48
46
|
};
|