@thi.ng/text-canvas 1.1.4 → 2.0.4

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
@@ -3,7 +3,7 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [1.1.4](https://github.com/thi-ng/umbrella/compare/@thi.ng/text-canvas@1.1.3...@thi.ng/text-canvas@1.1.4) (2021-09-03)
6
+ ## [2.0.4](https://github.com/thi-ng/umbrella/compare/@thi.ng/text-canvas@2.0.3...@thi.ng/text-canvas@2.0.4) (2021-10-25)
7
7
 
8
8
  **Note:** Version bump only for package @thi.ng/text-canvas
9
9
 
@@ -11,146 +11,123 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
11
11
 
12
12
 
13
13
 
14
- # [1.1.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/text-canvas@1.0.3...@thi.ng/text-canvas@1.1.0) (2021-08-13)
14
+ ## [2.0.3](https://github.com/thi-ng/umbrella/compare/@thi.ng/text-canvas@2.0.2...@thi.ng/text-canvas@2.0.3) (2021-10-15)
15
15
 
16
-
17
- ### Features
18
-
19
- * **text-canvas:** add image -> braille functions ([8201ad2](https://github.com/thi-ng/umbrella/commit/8201ad2c83f32522fcb6fbf0d3d46925491aacc8))
20
-
21
-
22
-
23
-
24
-
25
- ## [0.7.14](https://github.com/thi-ng/umbrella/compare/@thi.ng/text-canvas@0.7.13...@thi.ng/text-canvas@0.7.14) (2021-08-07)
26
-
27
-
28
- ### Bug Fixes
29
-
30
- * **text-canvas:** fix ImageOpts.chars type ([0ae7855](https://github.com/thi-ng/umbrella/commit/0ae78552be39f543e98f8716dc239c3ce9c50b7b))
31
-
32
-
33
-
34
-
35
-
36
- ## [0.7.4](https://github.com/thi-ng/umbrella/compare/@thi.ng/text-canvas@0.7.3...@thi.ng/text-canvas@0.7.4) (2021-03-30)
16
+ **Note:** Version bump only for package @thi.ng/text-canvas
37
17
 
38
18
 
39
- ### Bug Fixes
40
19
 
41
- * **text-canvas:** fix FMT_NONE suffix, export format preset types ([e7a9ff7](https://github.com/thi-ng/umbrella/commit/e7a9ff7391b2d30ead4b40fced9b76a089be632e))
42
20
 
43
21
 
22
+ ## [2.0.2](https://github.com/thi-ng/umbrella/compare/@thi.ng/text-canvas@2.0.1...@thi.ng/text-canvas@2.0.2) (2021-10-15)
44
23
 
24
+ **Note:** Version bump only for package @thi.ng/text-canvas
45
25
 
46
26
 
47
- # [0.7.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/text-canvas@0.6.0...@thi.ng/text-canvas@0.7.0) (2021-03-26)
48
27
 
49
28
 
50
- ### Features
51
29
 
52
- * **text-canvas:** update table cell wordwrap handling ([f19f925](https://github.com/thi-ng/umbrella/commit/f19f9251443bc609a28fe5776399c162bc75b9b8))
30
+ ## [2.0.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/text-canvas@2.0.0...@thi.ng/text-canvas@2.0.1) (2021-10-13)
53
31
 
32
+ **Note:** Version bump only for package @thi.ng/text-canvas
54
33
 
55
34
 
56
35
 
57
36
 
58
- # [0.6.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/text-canvas@0.5.1...@thi.ng/text-canvas@0.6.0) (2021-03-24)
59
37
 
38
+ # [2.0.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/text-canvas@1.1.4...@thi.ng/text-canvas@2.0.0) (2021-10-12)
60
39
 
61
- ### Bug Fixes
62
40
 
63
- * **text-canvas:** fix format start/end handling in toString() ([5100222](https://github.com/thi-ng/umbrella/commit/5100222a874ce57ef1cd6892bf4e51faebf62dd1))
41
+ ### Build System
64
42
 
43
+ * major update of ALL pkgs (export maps, ESM only) ([0d1d6ea](https://github.com/thi-ng/umbrella/commit/0d1d6ea9fab2a645d6c5f2bf2591459b939c09b6))
65
44
 
66
- ### Features
67
45
 
68
- * **text-canvas:** add FMT_ANSI565, update StringFormat ([3bf5b47](https://github.com/thi-ng/umbrella/commit/3bf5b475cd75c9046804c81fb80b5f9e6d056fd0))
69
- * **text-canvas:** add imageCanvas/String565() fns ([6e254eb](https://github.com/thi-ng/umbrella/commit/6e254ebf7acf6520551caf99aef3a0b93d06a519))
46
+ ### Code Refactoring
70
47
 
48
+ * **text-canvas:** update to use thi.ng/text-format ([aa67a5a](https://github.com/thi-ng/umbrella/commit/aa67a5a27197b4c751bb5959cdcd2a238af2a825))
71
49
 
72
50
 
51
+ ### BREAKING CHANGES
73
52
 
53
+ * **text-canvas:** migrate formatting consts/functions to new pkg
74
54
 
75
- # [0.5.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/text-canvas@0.4.12...@thi.ng/text-canvas@0.5.0) (2021-03-24)
55
+ - see 8c28655d1 for details
56
+ - rename `toString()` => `formatCanvas()`
57
+ - update dependencies
58
+ * discontinue CommonJS & UMD versions
76
59
 
60
+ - only ESM modules will be published from now on
61
+ - CJS obsolete due to ESM support in recent versions of node:
62
+ - i.e. launch NodeJS via:
63
+ - `node --experimental-specifier-resolution=node --experimental-repl-await`
64
+ - in the node REPL use `await import(...)` instead of `require()`
65
+ - UMD obsolete due to widespread browser support for ESM
77
66
 
78
- ### Features
67
+ Also:
68
+ - normalize/restructure/reorg all package.json files
69
+ - cleanup all build scripts, remove obsolete
70
+ - switch from mocha to @thi.ng/testament for all tests
79
71
 
80
- * **text-canvas:** add FMT_NONE dummy formatter ([0b1f3bd](https://github.com/thi-ng/umbrella/commit/0b1f3bd88405aa89fdf344513bb43f7ac8a95e84))
81
- * **text-canvas:** add hardwrapped text support ([4e171db](https://github.com/thi-ng/umbrella/commit/4e171db1e77269604578495170b05a5e0bfcbc95))
82
72
 
83
73
 
84
74
 
85
75
 
86
76
 
87
- ## [0.4.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/text-canvas@0.4.0...@thi.ng/text-canvas@0.4.1) (2021-01-10)
77
+ # [1.1.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/text-canvas@1.0.3...@thi.ng/text-canvas@1.1.0) (2021-08-13)
88
78
 
79
+ ### Features
89
80
 
90
- ### Bug Fixes
81
+ - **text-canvas:** add image -> braille functions ([8201ad2](https://github.com/thi-ng/umbrella/commit/8201ad2c83f32522fcb6fbf0d3d46925491aacc8))
91
82
 
92
- * **text-canvas:** fix FMT_ANSI256 bg bitshift ([b50a0f9](https://github.com/thi-ng/umbrella/commit/b50a0f9c0464774f3b62888d718da89381b3014c))
83
+ ## [0.7.14](https://github.com/thi-ng/umbrella/compare/@thi.ng/text-canvas@0.7.13...@thi.ng/text-canvas@0.7.14) (2021-08-07)
93
84
 
85
+ ### Bug Fixes
94
86
 
87
+ - **text-canvas:** fix ImageOpts.chars type ([0ae7855](https://github.com/thi-ng/umbrella/commit/0ae78552be39f543e98f8716dc239c3ce9c50b7b))
95
88
 
89
+ ## [0.7.4](https://github.com/thi-ng/umbrella/compare/@thi.ng/text-canvas@0.7.3...@thi.ng/text-canvas@0.7.4) (2021-03-30)
96
90
 
91
+ ### Bug Fixes
97
92
 
98
- # [0.4.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/text-canvas@0.3.0...@thi.ng/text-canvas@0.4.0) (2021-01-05)
93
+ - **text-canvas:** fix FMT_NONE suffix, export format preset types ([e7a9ff7](https://github.com/thi-ng/umbrella/commit/e7a9ff7391b2d30ead4b40fced9b76a089be632e))
99
94
 
95
+ # [0.7.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/text-canvas@0.6.0...@thi.ng/text-canvas@0.7.0) (2021-03-26)
100
96
 
101
97
  ### Features
102
98
 
103
- * **text-canvas:** add formatter fns/utils ([fb4470d](https://github.com/thi-ng/umbrella/commit/fb4470d5a708e3d1f700bab5274463f754489940))
104
-
105
-
106
-
99
+ - **text-canvas:** update table cell wordwrap handling ([f19f925](https://github.com/thi-ng/umbrella/commit/f19f9251443bc609a28fe5776399c162bc75b9b8))
107
100
 
101
+ # [0.6.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/text-canvas@0.5.1...@thi.ng/text-canvas@0.6.0) (2021-03-24)
108
102
 
109
- # [0.3.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/text-canvas@0.2.36...@thi.ng/text-canvas@0.3.0) (2021-01-02)
103
+ ### Bug Fixes
110
104
 
105
+ - **text-canvas:** fix format start/end handling in toString() ([5100222](https://github.com/thi-ng/umbrella/commit/5100222a874ce57ef1cd6892bf4e51faebf62dd1))
111
106
 
112
107
  ### Features
113
108
 
114
- * **text-canvas:** add ANSI256 & HTML_565 formatters ([1f2d35b](https://github.com/thi-ng/umbrella/commit/1f2d35b306c30bfecd168f25abd0ead18e2fdf2a))
115
- * **text-canvas:** add imageRaw(), update image() ([34037ad](https://github.com/thi-ng/umbrella/commit/34037ad4ec87027779c72b683c3a4194f1995e79))
116
-
109
+ - **text-canvas:** add FMT_ANSI565, update StringFormat ([3bf5b47](https://github.com/thi-ng/umbrella/commit/3bf5b475cd75c9046804c81fb80b5f9e6d056fd0))
110
+ - **text-canvas:** add imageCanvas/String565() fns ([6e254eb](https://github.com/thi-ng/umbrella/commit/6e254ebf7acf6520551caf99aef3a0b93d06a519))
117
111
 
112
+ # [0.5.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/text-canvas@0.4.12...@thi.ng/text-canvas@0.5.0) (2021-03-24)
118
113
 
114
+ ### Features
119
115
 
116
+ - **text-canvas:** add FMT_NONE dummy formatter ([0b1f3bd](https://github.com/thi-ng/umbrella/commit/0b1f3bd88405aa89fdf344513bb43f7ac8a95e84))
117
+ - **text-canvas:** add hardwrapped text support ([4e171db](https://github.com/thi-ng/umbrella/commit/4e171db1e77269604578495170b05a5e0bfcbc95))
120
118
 
121
- # [0.2.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/text-canvas@0.1.2...@thi.ng/text-canvas@0.2.0) (2020-03-01)
122
-
123
-
124
- ### Features
125
-
126
- * **text-canvas:** add tableCanvas() ([13ee370](https://github.com/thi-ng/umbrella/commit/13ee370f03cc34305058265bff46e2ef23cecb2d))
127
-
119
+ ## [0.4.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/text-canvas@0.4.0...@thi.ng/text-canvas@0.4.1) (2021-01-10)
128
120
 
121
+ ### Bug Fixes
129
122
 
123
+ - **text-canvas:** fix FMT_ANSI256 bg bitshift ([b50a0f9](https://github.com/thi-ng/umbrella/commit/b50a0f9c0464774f3b62888d718da89381b3014c))
130
124
 
125
+ # [0.4.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/text-canvas@0.3.0...@thi.ng/text-canvas@0.4.0) (2021-01-05)
131
126
 
132
- # 0.1.0 (2020-02-25)
127
+ ### Features
133
128
 
129
+ - **text-canvas:** add formatter fns/utils ([fb4470d](https://github.com/thi-ng/umbrella/commit/fb4470d5a708e3d1f700bab5274463f754489940))
134
130
 
135
- ### Features
131
+ # [0.3.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/text-canvas@0.2.36...@thi.ng/text-canvas@0.3.0) (2021-01-02)
136
132
 
137
- * **text-canvas:** add bar chart & image fns ([3130fe4](https://github.com/thi-ng/umbrella/commit/3130fe4ae10d6e579298d1b330c80d2e01d0a3ff))
138
- * **text-canvas:** add blit(), getAt(), fix table() arg type ([b5c9eb4](https://github.com/thi-ng/umbrella/commit/b5c9eb4e77c956e01d76f247a84ceb46d57498d4))
139
- * **text-canvas:** add bresenham line & circle fns, force int coords ([0587a66](https://github.com/thi-ng/umbrella/commit/0587a66529a179235e52e0ea4430376a850d8a15))
140
- * **text-canvas:** add canvas() factory fn ([3baeb31](https://github.com/thi-ng/umbrella/commit/3baeb31c96b033479e09eb77fdd1a5055359a5be))
141
- * **text-canvas:** add derived style fns (horizontalOnly, verticalOnly) ([dc1cb05](https://github.com/thi-ng/umbrella/commit/dc1cb054545456384a3502e91b7cba2022cce305))
142
- * **text-canvas:** add ImageOpts, update image(), add resize(), extract() ([73f941a](https://github.com/thi-ng/umbrella/commit/73f941add71eba7dbb535d0ae553e504cccbe553))
143
- * **text-canvas:** add inverted image draw opt ([08cb56a](https://github.com/thi-ng/umbrella/commit/08cb56a42abee49aaa28effc3a8cea0997231d13))
144
- * **text-canvas:** add more border consts ([05247a0](https://github.com/thi-ng/umbrella/commit/05247a0806b932936eb044ccc82ef9cae0518423))
145
- * **text-canvas:** add opt cell height config support ([d162a1c](https://github.com/thi-ng/umbrella/commit/d162a1c0e4da9a66ab5a7beeaaf4f0172b5b9e3a))
146
- * **text-canvas:** add scrollV() ([135258e](https://github.com/thi-ng/umbrella/commit/135258e9992dad502ea9b0b9efb276e086bd4e08))
147
- * **text-canvas:** add support for table cell format overrides ([8909ce0](https://github.com/thi-ng/umbrella/commit/8909ce07a14e61416f9deb45f1f1f7f4279c4e81))
148
- * **text-canvas:** add table support & options ([8983ad6](https://github.com/thi-ng/umbrella/commit/8983ad6083e0802a3ba003cca684869284c69c9e))
149
- * **text-canvas:** add textBox, update format enums & handling ([c922e14](https://github.com/thi-ng/umbrella/commit/c922e140992963d5fb4318e2a6dade02d4779905))
150
- * **text-canvas:** add textLines(), wordWrappedLines() ([0f13fe2](https://github.com/thi-ng/umbrella/commit/0f13fe27ffc720fb246e49c8487bb58077be275f))
151
- * **text-canvas:** add withClip/Format/Style() HOFs ([369909c](https://github.com/thi-ng/umbrella/commit/369909c62755453e3709bf469e9f74fdd1301493))
152
- * **text-canvas:** add wrappedText(), update draw fns & clip rect handling ([ba66aee](https://github.com/thi-ng/umbrella/commit/ba66aee98024b0ba9e58fed02a255dc7eeb28ae4))
153
- * **text-canvas:** add/update/rename consts, toString() ([254f3d7](https://github.com/thi-ng/umbrella/commit/254f3d7f06ada232b002d0e708101e9f8289b21f))
154
- * **text-canvas:** initial import as new pkg ([fd084bf](https://github.com/thi-ng/umbrella/commit/fd084bfd59adc2482a84ec11247db1cc027fad71))
155
- * **text-canvas:** major update/rewrite, format support ([57a7487](https://github.com/thi-ng/umbrella/commit/57a7487389294197265f58717d3c942191bad2cf))
156
- * **text-canvas:** update StrokeStyle ([d5bdcc8](https://github.com/thi-ng/umbrella/commit/d5bdcc8cb202d6ece879526f8a5f40e0d913e38b))
133
+ ### Features
package/README.md CHANGED
@@ -11,6 +11,7 @@ This project is part of the
11
11
 
12
12
  - [About](#about)
13
13
  - [Status](#status)
14
+ - [Related packages](#related-packages)
14
15
  - [Installation](#installation)
15
16
  - [Dependencies](#dependencies)
16
17
  - [Usage examples](#usage-examples)
@@ -21,9 +22,6 @@ This project is part of the
21
22
  - [Variations](#variations)
22
23
  - [Combined formats](#combined-formats)
23
24
  - [String conversion format presets](#string-conversion-format-presets)
24
- - [256 color ANSI format](#256-color-ansi-format)
25
- - [16bit color ANSI & HTML formats](#16bit-color-ansi--html-formats)
26
- - [Ad-hoc formatting of strings](#ad-hoc-formatting-of-strings)
27
25
  - [Stroke styles](#stroke-styles)
28
26
  - [Clipping](#clipping)
29
27
  - [Drawing functions](#drawing-functions)
@@ -45,21 +43,34 @@ Text based canvas, drawing, tables with arbitrary formatting (incl. ANSI/HTML).
45
43
 
46
44
  [Search or submit any issues for this package](https://github.com/thi-ng/umbrella/issues?q=%5Btext-canvas%5D+in%3Atitle)
47
45
 
46
+ ### Related packages
47
+
48
+ - [@thi.ng/text-format](https://github.com/thi-ng/umbrella/tree/develop/packages/text-format) - Customizable color text formatting with presets for ANSI & HTML
49
+
48
50
  ## Installation
49
51
 
50
52
  ```bash
51
53
  yarn add @thi.ng/text-canvas
52
54
  ```
53
55
 
56
+ ES module import:
57
+
54
58
  ```html
55
- // ES module
56
- <script type="module" src="https://unpkg.com/@thi.ng/text-canvas?module" crossorigin></script>
59
+ <script type="module" src="https://cdn.skypack.dev/@thi.ng/text-canvas"></script>
60
+ ```
61
+
62
+ [Skypack documentation](https://docs.skypack.dev/)
57
63
 
58
- // UMD
59
- <script src="https://unpkg.com/@thi.ng/text-canvas/lib/index.umd.js" crossorigin></script>
64
+ For Node.js REPL:
65
+
66
+ ```text
67
+ # with flag only for < v16
68
+ node --experimental-repl-await
69
+
70
+ > const textCanvas = await import("@thi.ng/text-canvas");
60
71
  ```
61
72
 
62
- Package sizes (gzipped, pre-treeshake): ESM: 6.27 KB / CJS: 6.63 KB / UMD: 6.34 KB
73
+ Package sizes (gzipped, pre-treeshake): ESM: 4.97 KB
63
74
 
64
75
  ## Dependencies
65
76
 
@@ -68,8 +79,8 @@ Package sizes (gzipped, pre-treeshake): ESM: 6.27 KB / CJS: 6.63 KB / UMD: 6.34
68
79
  - [@thi.ng/checks](https://github.com/thi-ng/umbrella/tree/develop/packages/checks)
69
80
  - [@thi.ng/geom-clip-line](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-clip-line)
70
81
  - [@thi.ng/math](https://github.com/thi-ng/umbrella/tree/develop/packages/math)
71
- - [@thi.ng/memoize](https://github.com/thi-ng/umbrella/tree/develop/packages/memoize)
72
82
  - [@thi.ng/strings](https://github.com/thi-ng/umbrella/tree/develop/packages/strings)
83
+ - [@thi.ng/text-format](https://github.com/thi-ng/umbrella/tree/develop/packages/text-format)
73
84
  - [@thi.ng/transducers](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers)
74
85
 
75
86
  ## Usage examples
@@ -99,29 +110,30 @@ const c = canvas(width, height, format?, style?);
99
110
 
100
111
  The text canvas stores all characters in a `Uint32Array` with the lower 16 bits
101
112
  used for the UTF-16 code and the upper 16 bits for **abitrary** formatting data.
102
- The package [provides its own format
103
- IDs](https://github.com/thi-ng/umbrella/blob/develop/packages/text-canvas/src/api.ts#L146)
104
- which are tailored for the bundled ANSI & HTML formatters, but users are free to
113
+ The package utilizes [format identifier constants and formatters from the
114
+ @thi.ng/text-format
115
+ package](https://github.com/thi-ng/umbrella/blob/develop/packages/text-format/),
116
+ which are tailored for the included ANSI & HTML formatters, but users are free to
105
117
  choose use any other system (but then will also need to implement a custom
106
118
  string formatter impl).
107
119
 
108
- The default format ID layout is as shown:
120
+ The default format ID layout used by text canvas is as shown:
109
121
 
110
122
  ![format bit layout](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/text-canvas/format-layout.png)
111
123
 
112
124
  Most drawing functions accept an optional `format` arg, but a default
113
125
  format can also be set via `setFormat(canvas, formatID)`.
114
126
 
115
- The following built-in format IDs are only compatible with these formatters:
127
+ The format IDs defined in @thi.ng/text-format are only compatible with these
128
+ formatters (also supplied by that package):
116
129
 
117
130
  - `FMT_ANSI16`
118
131
  - `FMT_HTML_INLINE_CSS`
119
132
  - `FMT_HTML_TACHYONS`
120
133
 
121
- Custom formatters are discussed further below:
122
-
123
- - [`FMT_ANSI256`](#256-color-ansi-format)
124
- - [`FMT_HTML_565`](#16bit-color-html-format)
134
+ **All constants and other formatters are also discussed in detail in the
135
+ [@thi.ng/text-format
136
+ readme](https://github.com/thi-ng/umbrella/blob/develop/packages/text-format/README.md).**
125
137
 
126
138
  #### Colors
127
139
 
@@ -162,101 +174,31 @@ setFormat(canvas, FG_BLACK | BG_LIGHT_CYAN | BOLD | UNDERLINE);
162
174
  ### String conversion format presets
163
175
 
164
176
  Canvas-to-string conversion is completely customizable via the [`StringFormat`
165
- interface](https://github.com/thi-ng/umbrella/blob/develop/packages/text-canvas/src/api.ts#L78)
166
- and the following presets are supplied:
177
+ interface](https://docs.thi.ng/umbrella/text-format/interfaces/StringFormat.html).
178
+ Currently the following presets are supplied (in the
179
+ [@thi.ng/text-format](https://github.com/thi-ng/umbrella/tree/develop/packages/text-format)
180
+ package):
167
181
 
168
- - `FMT_ANSI16` - translate built-in format IDs to 4bit ANSI escape sequences
182
+ - `FMT_ANSI16` - translate built-in format IDs to 4-bit ANSI escape sequences
169
183
  - `FMT_ANSI256` - uses all 16 format bits for fg & bg colors (ANSI esc sequences)
184
+ - `FMT_ANSI565` - uses all 16 format bits for RGB565 fg colors (ANSI esc sequences)
170
185
  - `FMT_ANSI_RAW` - verbatim use of format IDs to ANSI sequences
171
186
  - `FMT_HTML_INLINE_CSS` - HTML `<span>` elements with inline CSS
172
187
  - `FMT_HTML_TACHYONS` - HTML `<span>` elements with [Tachyons
173
188
  CSS](http://tachyons.io/) class names
189
+ - `FMT_HTML565` - HTML `<span>` elements with RGB565 color coding
174
190
  - `FMT_NONE` - dummy formatter outputting plain text only (all format
175
- information discarded)
191
+ information discarded, e.g. for [`NO_COLOR`](https://no-color.org/) support)
176
192
 
177
193
  ```ts
178
194
  // Terminal
179
- console.log(toString(canvas, FMT_ANSI16));
195
+ console.log(formatCanvas(canvas, FMT_ANSI16));
180
196
  // or
181
- console.log(toString(canvas, FMT_ANSI256));
197
+ console.log(formatCanvas(canvas, FMT_ANSI256));
182
198
 
183
199
  // Browser
184
200
  const el = document.createElement("pre");
185
- el.innerHTML = toString(canvas, FMT_HTML_TACHYONS);
186
- ```
187
-
188
- ### 256 color ANSI format
189
-
190
- If targeting this output format, all 16 bits available for formatting
191
- information are used to encode 2x 8bit foreground/background colors. Therefore,
192
- none of the above mentioned preset color names and/or any additional formatting
193
- flags (e.g. bold, underline etc.) **cannot be used**. Instead, use the
194
- `format256()` function to compute a format ID based on given FG, BG colors.
195
-
196
- ```ts
197
- // deep purple on yellow bg
198
- textLine(canvas, 1, 1, "hello color!", format256(19, 226));
199
- ```
200
-
201
- ![ANSI256 color pallette](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/text-canvas/ansi256.png)
202
-
203
- Source: [Wikipedia](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit)
204
-
205
- ### 16bit color ANSI & HTML formats
206
-
207
- Similar to the above custom ANSI format, here all available 16 bits are used to
208
- store color information, in the standard [RGB565
209
- format](https://en.wikipedia.org/wiki/High_color) (5bits red, 6bits green, 5bits
210
- blue). This also means, only either the text or background color<sup>(1)</sup> can be
211
- controlled and no other formatting flag (bold, underline etc.) are available.
212
-
213
- <sup>(1)</sup> In the ANSI version it's always only the text color.
214
-
215
- ```ts
216
- const el = document.createElement("pre");
217
- // format and assign text colors
218
- el.innerHTML = toString(canvas, FMT_HTML565());
219
-
220
- // assign bg colors
221
- el.innerHTML = toString(canvas, FMT_HTML565("background"));
222
- ```
223
-
224
- These formats are primarily intended for image display, see
225
- [section](#image-functions) below for examples...
226
-
227
- ### Ad-hoc formatting of strings
228
-
229
- String formatters can also be used in an ad-hoc manner, without requiring any of
230
- the other text canvas functionality.
231
-
232
- ```ts
233
- // create & use a HTML formatter
234
- defFormat(FMT_HTML_INLINE_CSS, FG_LIGHT_RED | BG_GRAY)("hello")
235
- // "<span style="color:#f55;background:#555;">hello</span>"
236
-
237
- // create & use an ANSI formatter
238
- defFormat(FMT_ANSI16, FG_LIGHT_RED | BG_GRAY)("hello")
239
- // "\x1B[91;100mhello\x1B[0m"
240
-
241
- // ANSI syntax sugar (same result as above)
242
- defAnsi16(FG_LIGHT_RED | BG_GRAY)("hello")
243
- // "\x1B[91;100mhello\x1B[0m"
244
- ```
245
-
246
- Furthermore, `defFormatPresets()` can be used to create formatting functions for
247
- all 16 preset [foreground color IDs](#colors) for a given string format
248
- strategy:
249
-
250
- ```ts
251
- const ansi = defFormatPresets(FMT_ANSI16);
252
-
253
- `${ansi.green("hello")} ${ansi.lightRed("world")}!`;
254
- // '\x1B[32mhello\x1B[0m \x1B[91mworld\x1B[0m!'
255
-
256
- const html = defFormatPresets(FMT_HTML_TACHYONS);
257
-
258
- `${html.green("hello")} ${html.lightRed("world")}!`;
259
- // '<span class="dark-green ">hello</span> <span class="red ">world</span>!'
201
+ el.innerHTML = formatCanvas(canvas, FMT_HTML_TACHYONS);
260
202
  ```
261
203
 
262
204
  ### Stroke styles
@@ -371,6 +313,7 @@ enabling the `hard` option (see example below).
371
313
  ```ts
372
314
  import { repeatedly } from "@thi.ng/transducers";
373
315
  import * as tc from "@thi.ng/text-canvas";
316
+ import * as tf from "@thi.ng/text-format";
374
317
 
375
318
  // generate 20 random values
376
319
  const data = repeatedly(() => Math.random(), 20)
@@ -389,9 +332,9 @@ tc.table(
389
332
  // column defs
390
333
  cols: [{ width: 4 }, { width: 20 }, { width: 8 }],
391
334
  // default cell format
392
- format: tc.FG_BLACK | tc.BG_LIGHT_CYAN,
335
+ format: tf.FG_BLACK | tf.BG_LIGHT_CYAN,
393
336
  // default format for header cells (1st row)
394
- formatHead: tc.FG_RED | tc.BG_LIGHT_CYAN | tc.BOLD | tc.UNDERLINE,
337
+ formatHead: tf.FG_RED | tf.BG_LIGHT_CYAN | tf.BOLD | tf.UNDERLINE,
395
338
  // border line style
396
339
  style: tc.STYLE_DASHED_ROUNDED,
397
340
  // border mode
@@ -407,7 +350,7 @@ tc.table(
407
350
  ["ID", "Main", "Comment"],
408
351
  [
409
352
  "0001",
410
- { body: chart, format: tc.FG_BLUE | tc.BG_LIGHT_CYAN },
353
+ { body: chart, format: tf.FG_BLUE | tf.BG_LIGHT_CYAN },
411
354
  "This is a test!"
412
355
  ],
413
356
  ["0002", "Random data plot", "Word wrapped content"],
@@ -416,14 +359,14 @@ tc.table(
416
359
  );
417
360
 
418
361
  // output as ANSI formatted string
419
- console.log(tc.toString(canvas, tc.FMT_ANSI16));
362
+ console.log(tc.formatCanvas(canvas, tf.FMT_ANSI16));
420
363
  ```
421
364
 
422
365
  For even more detailed control, tables can also be pre-initialized prior
423
366
  to creation of the canvas via
424
- [`initTable()`](https://github.com/thi-ng/umbrella/blob/develop/packages/text-canvas/src/table.ts#L20)
367
+ [`initTable()`](https://github.com/thi-ng/umbrella/blob/develop/packages/text-canvas/src/table.ts#L29)
425
368
  and then drawn via
426
- [`drawTable()`](https://github.com/thi-ng/umbrella/blob/develop/packages/text-canvas/src/table.ts#L80).
369
+ [`drawTable()`](https://github.com/thi-ng/umbrella/blob/develop/packages/text-canvas/src/table.ts#L97).
427
370
  The `initTable` function returns an object also containing the computed
428
371
  table size (`width`, `height` keys) which can then be used to create a
429
372
  canvas with the required size...
@@ -475,12 +418,13 @@ Code for this above example output (CLI version):
475
418
  import * as geom from "@thi.ng/geom";
476
419
  import * as mat from "@thi.ng/matrices";
477
420
  import * as tc from "@thi.ng/text-canvas";
421
+ import * as tf from "@thi.ng/text-format";
478
422
 
479
423
  const W = 64;
480
424
  const H = 32;
481
425
 
482
426
  // create text canvas
483
- const canvas = new tc.Canvas(W, H, tc.BG_BLACK, tc.STYLE_THIN);
427
+ const canvas = new tc.Canvas(W, H, tf.BG_BLACK, tf.STYLE_THIN);
484
428
 
485
429
  // cube corner vertices
486
430
  const cube = geom.vertices(geom.center(geom.aabb(1))!);
@@ -517,10 +461,10 @@ setInterval(() => {
517
461
  for (let e of edges) {
518
462
  const a = pts[e[0]];
519
463
  const b = pts[e[1]];
520
- tc.line(canvas, a[0], a[1], b[0], b[1], "+", tc.FG_WHITE | tc.BG_RED);
464
+ tc.line(canvas, a[0], a[1], b[0], b[1], "+", tf.FG_WHITE | tf.BG_RED);
521
465
  }
522
466
  // draw vertex labels
523
- canvas.format = tc.FG_WHITE | tc.BG_BLUE;
467
+ canvas.format = tf.FG_WHITE | tf.BG_BLUE;
524
468
  for (let i = 0; i < 8; i++) {
525
469
  const p = pts[i];
526
470
  tc.textBox(canvas, p[0] - 1, p[1] - 1, 5, 3, ` ${i} `);
@@ -530,16 +474,16 @@ setInterval(() => {
530
474
  2, 1, 24, -1,
531
475
  `@thi.ng/text-canvas wireframe cube\n\nx: ${rotx.toFixed(2)}\ny: ${roty.toFixed(2)}`,
532
476
  {
533
- format: tc.FG_BLACK | tc.BG_LIGHT_CYAN,
477
+ format: tf.FG_BLACK | tf.BG_LIGHT_CYAN,
534
478
  padding: [1, 0]
535
479
  }
536
480
  );
537
481
  // draw canvas
538
482
  console.clear();
539
483
  // output as ANSI formatted string
540
- console.log(tc.toString(canvas, tc.FMT_ANSI16));
484
+ console.log(tc.formatCanvas(canvas, tf.FMT_ANSI16));
541
485
  // output as plain text
542
- // console.log(tc.toString(canvas));
486
+ // console.log(tc.formatCanvas(canvas));
543
487
  }, 15);
544
488
  ```
545
489
 
package/api.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Fn, FnN, NumOrString } from "@thi.ng/api";
1
+ import type { FnN, NumOrString } from "@thi.ng/api";
2
2
  export declare enum Align {
3
3
  LEFT = 0,
4
4
  RIGHT = 1,
@@ -72,111 +72,6 @@ export interface ClipRect {
72
72
  w: number;
73
73
  h: number;
74
74
  }
75
- export interface StringFormat {
76
- /**
77
- * Function translating canvas character format codes to the actual
78
- * output format. This function will only be called when needed,
79
- * i.e. when a character's format is different than that of the
80
- * previous.
81
- */
82
- start: Fn<number, string>;
83
- /**
84
- * Format end string (e.g. to ANSI reset or `</span>`).
85
- */
86
- end: string;
87
- /**
88
- * Prefix for each canvas row / line result string
89
- */
90
- prefix: string;
91
- /**
92
- * Suffix for each canvas row / line result string (e.g. linebreak)
93
- */
94
- suffix: string;
95
- /**
96
- * If true, DON'T skip 0-valued format IDs during formatting.
97
- *
98
- * @remarks
99
- * This is needed for various custom color-only formats, e.g. in order to
100
- * reproduce black in `FMT_ANSI565`. In the default format, a zero refers to
101
- * the default format of the target.
102
- *
103
- * @defaultValue false
104
- */
105
- zero?: boolean;
106
- }
107
- export interface HtmlFormatOpts {
108
- /**
109
- * Array of 16 color strings, in this order: black, red, green,
110
- * yellow, blue, magenta, cyan, white, then repeated as bright
111
- * versions.
112
- */
113
- colors: string[];
114
- /**
115
- * HTML attrib name.
116
- */
117
- attrib: string;
118
- /**
119
- * Delimiter between individual formatting terms (e.g. `;` for CSS
120
- * rules or ` ` for CSS class names).
121
- */
122
- delim: string;
123
- /**
124
- * Prefix string for foreground colors
125
- */
126
- fg: string;
127
- /**
128
- * Prefix string for background colors
129
- */
130
- bg: string;
131
- /**
132
- * Bold format string
133
- */
134
- bold: string;
135
- /**
136
- * Dimmed format string
137
- */
138
- dim: string;
139
- /**
140
- * Underline format string
141
- */
142
- underline: string;
143
- }
144
- export declare const NONE = 0;
145
- export declare const FG_BLACK = 1;
146
- export declare const FG_RED = 2;
147
- export declare const FG_GREEN = 3;
148
- export declare const FG_YELLOW = 4;
149
- export declare const FG_BLUE = 5;
150
- export declare const FG_MAGENTA = 6;
151
- export declare const FG_CYAN = 7;
152
- export declare const FG_LIGHT_GRAY = 8;
153
- export declare const FG_GRAY = 17;
154
- export declare const FG_LIGHT_RED = 18;
155
- export declare const FG_LIGHT_GREEN = 19;
156
- export declare const FG_LIGHT_YELLOW = 20;
157
- export declare const FG_LIGHT_BLUE = 21;
158
- export declare const FG_LIGHT_MAGENTA = 22;
159
- export declare const FG_LIGHT_CYAN = 23;
160
- export declare const FG_WHITE = 24;
161
- export declare const BG_BLACK = 32;
162
- export declare const BG_RED = 64;
163
- export declare const BG_GREEN = 96;
164
- export declare const BG_YELLOW = 128;
165
- export declare const BG_BLUE = 160;
166
- export declare const BG_MAGENTA = 192;
167
- export declare const BG_CYAN = 224;
168
- export declare const BG_LIGHT_GRAY = 256;
169
- export declare const BG_GRAY = 544;
170
- export declare const BG_LIGHT_RED = 576;
171
- export declare const BG_LIGHT_GREEN = 608;
172
- export declare const BG_LIGHT_YELLOW = 640;
173
- export declare const BG_LIGHT_BLUE = 672;
174
- export declare const BG_LIGHT_MAGENTA = 704;
175
- export declare const BG_LIGHT_CYAN = 736;
176
- export declare const BG_WHITE = 768;
177
- export declare const BOLD = 1024;
178
- export declare const DIM = 2048;
179
- export declare const UNDERLINE = 4096;
180
75
  export interface StrokeStyle {
181
76
  hl: string;
182
77
  vl: string;