@thi.ng/text-canvas 2.3.7 → 2.3.8
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 +1 -1
- package/format.d.ts +2 -2
- package/format.js +9 -28
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2022-06-
|
|
3
|
+
- **Last updated**: 2022-06-28T13:48:51Z
|
|
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.8](https://github.com/thi-ng/umbrella/tree/@thi.ng/text-canvas@2.3.8) (2022-06-28)
|
|
13
|
+
|
|
14
|
+
#### ♻️ Refactoring
|
|
15
|
+
|
|
16
|
+
- update/simplify formatCanvas() ([e2f3ab9](https://github.com/thi-ng/umbrella/commit/e2f3ab9))
|
|
17
|
+
- re-use new single-line formatting fns from [@thi.ng/text-format](https://github.com/thi-ng/umbrella/tree/main/packages/text-format)
|
|
18
|
+
|
|
12
19
|
## [2.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/text-canvas@2.3.0) (2022-04-07)
|
|
13
20
|
|
|
14
21
|
#### 🚀 Features
|
package/README.md
CHANGED
package/format.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { Canvas } from "./canvas.js";
|
|
|
6
6
|
* any character format data.
|
|
7
7
|
*
|
|
8
8
|
* @param canvas -
|
|
9
|
-
* @param
|
|
9
|
+
* @param fmt -
|
|
10
10
|
*/
|
|
11
|
-
export declare const formatCanvas: (canvas: Canvas,
|
|
11
|
+
export declare const formatCanvas: (canvas: Canvas, fmt?: StringFormat) => string;
|
|
12
12
|
//# sourceMappingURL=format.d.ts.map
|
package/format.js
CHANGED
|
@@ -1,43 +1,24 @@
|
|
|
1
|
+
import { format, formatNone } from "@thi.ng/text-format/format";
|
|
1
2
|
/**
|
|
2
3
|
* Returns string representation of canvas, optionally using given string
|
|
3
4
|
* formatter. If none is given, returns plain string representation, ignoring
|
|
4
5
|
* any character format data.
|
|
5
6
|
*
|
|
6
7
|
* @param canvas -
|
|
7
|
-
* @param
|
|
8
|
+
* @param fmt -
|
|
8
9
|
*/
|
|
9
|
-
export const formatCanvas = (canvas,
|
|
10
|
+
export const formatCanvas = (canvas, fmt) => {
|
|
10
11
|
const { data, width, height } = canvas;
|
|
11
12
|
const res = [];
|
|
12
|
-
if (
|
|
13
|
-
|
|
14
|
-
|
|
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 = data[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);
|
|
13
|
+
if (fmt) {
|
|
14
|
+
for (let y = 0; y < height; y++) {
|
|
15
|
+
res.push(format(fmt, data, width, y * width));
|
|
31
16
|
}
|
|
32
|
-
return res.join("");
|
|
33
17
|
}
|
|
34
18
|
else {
|
|
35
|
-
for (let y = 0
|
|
36
|
-
|
|
37
|
-
res.push(String.fromCharCode(data[i] & 0xffff));
|
|
38
|
-
}
|
|
39
|
-
res.push("\n");
|
|
19
|
+
for (let y = 0; y < height; y++) {
|
|
20
|
+
res.push(formatNone(data, width, y * width));
|
|
40
21
|
}
|
|
41
|
-
return res.join("");
|
|
42
22
|
}
|
|
23
|
+
return res.join("");
|
|
43
24
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/text-canvas",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.8",
|
|
4
4
|
"description": "Text based canvas, drawing, tables with arbitrary formatting (incl. ANSI/HTML)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"@thi.ng/api": "^8.3.7",
|
|
38
38
|
"@thi.ng/arrays": "^2.2.5",
|
|
39
39
|
"@thi.ng/checks": "^3.2.1",
|
|
40
|
-
"@thi.ng/geom-clip-line": "^2.1.
|
|
40
|
+
"@thi.ng/geom-clip-line": "^2.1.17",
|
|
41
41
|
"@thi.ng/math": "^5.3.3",
|
|
42
42
|
"@thi.ng/strings": "^3.3.5",
|
|
43
|
-
"@thi.ng/text-format": "^1.
|
|
43
|
+
"@thi.ng/text-format": "^1.2.0",
|
|
44
44
|
"@thi.ng/transducers": "^8.3.5"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
@@ -138,5 +138,5 @@
|
|
|
138
138
|
],
|
|
139
139
|
"year": 2020
|
|
140
140
|
},
|
|
141
|
-
"gitHead": "
|
|
141
|
+
"gitHead": "207404f1e1fcfd3596780322d9218156aeaac3dd\n"
|
|
142
142
|
}
|