@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2022-06-09T16:14:01Z
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
@@ -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.36 KB
73
+ Package sizes (gzipped, pre-treeshake): ESM: 5.24 KB
74
74
 
75
75
  ## Dependencies
76
76
 
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 format -
9
+ * @param fmt -
10
10
  */
11
- export declare const formatCanvas: (canvas: Canvas, format?: StringFormat) => string;
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 format -
8
+ * @param fmt -
8
9
  */
9
- export const formatCanvas = (canvas, format) => {
10
+ export const formatCanvas = (canvas, fmt) => {
10
11
  const { data, width, height } = canvas;
11
12
  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 = 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, i = 0; y < height; y++) {
36
- for (let x = 0; x < width; x++, i++) {
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.7",
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.16",
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.1.7",
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": "73139849c7b46c0451693d994e14a34bc2434280\n"
141
+ "gitHead": "207404f1e1fcfd3596780322d9218156aeaac3dd\n"
142
142
  }