textmode.js 0.2.0-beta.5 → 0.2.1-beta.1
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/README.md +114 -63
- package/dist/textmode.esm.js +1141 -903
- package/dist/textmode.esm.min.js +1387 -1149
- package/dist/textmode.umd.js +20 -20
- package/dist/textmode.umd.min.js +18 -18
- package/dist/types/Textmode.d.ts +2 -6
- package/dist/types/textmode/Textmodifier.d.ts +16 -8
- package/dist/types/textmode/keyboard/KeyboardManager.d.ts +123 -0
- package/dist/types/textmode/keyboard/index.d.ts +2 -0
- package/dist/types/textmode/mixins/AnimationMixin.d.ts +10 -6
- package/dist/types/textmode/mixins/ExportMixin.d.ts +5 -5
- package/dist/types/textmode/mixins/FontMixin.d.ts +1 -1
- package/dist/types/textmode/mixins/KeyboardMixin.d.ts +39 -0
- package/dist/types/textmode/mixins/MouseMixin.d.ts +27 -0
- package/dist/types/textmode/mixins/RenderingMixin.d.ts +70 -39
- package/dist/types/textmode/mixins/TextmodifierMixin.d.ts +6 -0
- package/dist/types/textmode/mixins/index.d.ts +4 -0
- package/dist/types/textmode/mouse/MouseManager.d.ts +130 -0
- package/dist/types/textmode/mouse/index.d.ts +2 -0
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -10,32 +10,36 @@
|
|
|
10
10
|
|
|
11
11
|
</div>
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
textmode.js is a lightweight creative-coding library for real‑time ASCII and textmode graphics in the browser. It combines a grid‑based API with a modern `WebGL2` pipeline, multiple render targets, and aggressive instanced rendering to deliver smooth, high‑performance rendering.
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
The library is designed to be easy to use and accessible to developers of all skill levels. Whether you're a seasoned developer or just starting out, `textmode.js` provides a simple and intuitive API that makes it easy to create stunning textmode art and animations.
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
The library powers live coding performances, interactive installations, and digital art projects worldwide, bringing the nostalgic aesthetic of textmode art into modern web development.
|
|
17
|
+
Key ideas in one sentence: you draw with simple shape calls; under the hood we batch instances and write to a special framebuffer with five render targets; a conversion pass maps those buffers to a crisp grid of characters on the canvas.
|
|
20
18
|
|
|
21
19
|
## Features
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
29
|
-
-
|
|
20
|
+
- Real‑time* ASCII/textmode rendering with a simple drawing API
|
|
21
|
+
- `WebGL2` pipeline with [Multiple Render Targets (MRT)](https://en.wikipedia.org/wiki/Multiple_Render_Targets) for rich per‑cell data
|
|
22
|
+
- Instanced rendering and batching for low draw call counts
|
|
23
|
+
- Font system with runtime font loading and dynamic sizing
|
|
24
|
+
- Author custom filter shaders in [`GLSL ES 3.00`](https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf) for advanced effects
|
|
25
|
+
- Flexible exporting: TXT, SVG, and raster images *(PNG/JPG/WebP)*
|
|
26
|
+
- Animation loop control: `frameRate`, `loop`/`noLoop`, `redraw`, `frameCount`, etc.
|
|
27
|
+
- Zero dependencies, written in TypeScript, with comprehensive type definitions
|
|
28
|
+
|
|
29
|
+
> [!NOTE]
|
|
30
|
+
> *Performance depends on the complexity of your scene and device capabilities. Consider authoring filter shaders for complex effects at low cost.
|
|
30
31
|
|
|
31
32
|
## Installation
|
|
32
33
|
|
|
33
34
|
### Prerequisites
|
|
34
35
|
|
|
35
36
|
To get started with `textmode.js`, you'll need:
|
|
36
|
-
- A **modern web browser** with `
|
|
37
|
-
- A `<canvas>`
|
|
38
|
-
-
|
|
37
|
+
- A **modern web browser** with `WebGL2` support *(Chrome, Firefox, Safari, Edge, etc.)*
|
|
38
|
+
- A [`<canvas>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas) in your project *(optional, otherwise the library will create one for you)*
|
|
39
|
+
- [Node.js 16+](https://nodejs.org/) and `npm` *(optional, for ESM installation)*
|
|
40
|
+
|
|
41
|
+
> [!IMPORTANT]
|
|
42
|
+
> `textmode.js` is currently fully dependent on `WebGL2`. Ensure your target browsers support it. You can check compatibility on [caniuse.com](https://caniuse.com/webgl2).
|
|
39
43
|
|
|
40
44
|
### Importing `textmode.js`
|
|
41
45
|
|
|
@@ -43,28 +47,31 @@ To get started with `textmode.js`, you'll need:
|
|
|
43
47
|
|
|
44
48
|
| Bundle type | File size | Font included? | Best for |
|
|
45
49
|
|-------------|-----------|---------------|----------|
|
|
46
|
-
| **Standard UMD
|
|
47
|
-
| **Standard ESM
|
|
48
|
-
| **Minified UMD
|
|
49
|
-
| **Minified ESM
|
|
50
|
+
| **Standard UMD** (`textmode.umd.js`) | ~112kB | ✅ [UrsaFont](https://ursafrank.itch.io/ursafont) embedded | Quick setup, prototyping |
|
|
51
|
+
| **Standard ESM** (`textmode.esm.js`) | ~130kB | ✅ [UrsaFont](https://ursafrank.itch.io/ursafont) embedded | Quick setup, prototyping |
|
|
52
|
+
| **Minified UMD** (`textmode.umd.min.js`) | ~65kB | ❌ Requires external font | Custom fonts |
|
|
53
|
+
| **Minified ESM** (`textmode.esm.min.js`) | ~84kB | ❌ Requires external font | Custom fonts |
|
|
50
54
|
|
|
51
55
|
**Choose standard bundles for:**
|
|
52
56
|
- Quick setup with no additional configuration
|
|
53
|
-
-
|
|
54
|
-
- Getting started without worrying about fonts
|
|
57
|
+
- Production applications that use the embedded font
|
|
55
58
|
|
|
56
59
|
**Choose minified bundles for:**
|
|
57
60
|
- Production applications that don't use the embedded font
|
|
58
61
|
|
|
59
|
-
|
|
62
|
+
> [!NOTE]
|
|
63
|
+
> Apart from the font inclusion, both bundle types are functionally identical and equally minified.
|
|
64
|
+
|
|
65
|
+
### UMD
|
|
60
66
|
|
|
61
67
|
To use `textmode.js` in a UMD environment, download the latest `umd` build from the [**GitHub releases page**](https://github.com/humanbydefinition/textmode.js/releases/) or import it directly from a CDN like [**jsDelivr**](https://www.jsdelivr.com/package/npm/textmode.js). The library is distributed as a single JavaScript file, which you can include in your project by adding the following script tag to your HTML file:
|
|
62
68
|
|
|
63
69
|
```html
|
|
70
|
+
<!-- index.html -->
|
|
64
71
|
<!DOCTYPE html>
|
|
65
72
|
<html>
|
|
66
73
|
<head>
|
|
67
|
-
<title>textmode.js
|
|
74
|
+
<title>textmode.js sketch</title>
|
|
68
75
|
|
|
69
76
|
<!-- Standard bundle (with embedded UrsaFont) -->
|
|
70
77
|
<script src="https://cdn.jsdelivr.net/npm/textmode.js@latest/dist/textmode.umd.js"></script>
|
|
@@ -73,26 +80,40 @@ To use `textmode.js` in a UMD environment, download the latest `umd` build from
|
|
|
73
80
|
<!-- <script src="https://cdn.jsdelivr.net/npm/textmode.js@latest/dist/textmode.umd.min.js"></script> -->
|
|
74
81
|
</head>
|
|
75
82
|
<body>
|
|
76
|
-
<
|
|
77
|
-
<script>
|
|
78
|
-
(async () => {
|
|
79
|
-
// Reference your existing canvas element
|
|
80
|
-
const canvas = document.querySelector('canvas#myCanvas');
|
|
81
|
-
|
|
82
|
-
// Standard bundle - no font configuration needed
|
|
83
|
-
const textmodifier = await textmode.create(canvas);
|
|
84
|
-
|
|
85
|
-
// Minified bundle - font required
|
|
86
|
-
// const textmodifier = await textmode.create(canvas, {
|
|
87
|
-
// fontSource: './path/to/your/font.ttf'
|
|
88
|
-
// });
|
|
89
|
-
})();
|
|
90
|
-
</script>
|
|
83
|
+
<script src="sketch.js"></script>
|
|
91
84
|
</body>
|
|
92
85
|
</html>
|
|
93
86
|
```
|
|
94
87
|
|
|
95
|
-
|
|
88
|
+
```javascript
|
|
89
|
+
// sketch.js
|
|
90
|
+
const t = textmode.create({
|
|
91
|
+
width: window.innerWidth,
|
|
92
|
+
height: window.innerHeight,
|
|
93
|
+
fontSize: 16,
|
|
94
|
+
frameRate: 60
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
t.setup(() => {
|
|
98
|
+
// Optional setup code here (e.g., load fonts/shaders, initialize variables that access 't')
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
t.draw(() => {
|
|
102
|
+
t.background(32); // Dark gray background
|
|
103
|
+
|
|
104
|
+
t.char('A');
|
|
105
|
+
t.charColor(255, 0, 0); // Cover the top-left quarter of the grid with a rectangle of red 'A's
|
|
106
|
+
t.rect(0, 0, t.grid.cols / 2, t.grid.rows / 2);
|
|
107
|
+
|
|
108
|
+
// ...add your drawing code here!
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
t.windowResized(() => {
|
|
112
|
+
t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
113
|
+
});
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### ESM
|
|
96
117
|
|
|
97
118
|
To use `textmode.js` in an ESM environment, you can install it via `npm`:
|
|
98
119
|
|
|
@@ -102,43 +123,73 @@ npm install textmode.js
|
|
|
102
123
|
|
|
103
124
|
Then, you can import it in your JavaScript or TypeScript files:
|
|
104
125
|
|
|
126
|
+
```html
|
|
127
|
+
<!-- index.html -->
|
|
128
|
+
<!DOCTYPE html>
|
|
129
|
+
<html lang="en">
|
|
130
|
+
<head>
|
|
131
|
+
<meta charset="utf-8">
|
|
132
|
+
<title>textmode.js sketch</title>
|
|
133
|
+
</head>
|
|
134
|
+
<body>
|
|
135
|
+
<script type="module" src="./sketch.js"></script>
|
|
136
|
+
</body>
|
|
137
|
+
</html>
|
|
138
|
+
```
|
|
139
|
+
|
|
105
140
|
```javascript
|
|
141
|
+
// sketch.js
|
|
106
142
|
// Standard bundle (with embedded UrsaFont)
|
|
107
143
|
import { textmode } from 'textmode.js';
|
|
108
144
|
|
|
109
145
|
// OR Minified bundle (requires external font)
|
|
110
146
|
// import { textmode } from 'textmode.js/min';
|
|
111
147
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
//
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
148
|
+
const t = textmode.create({
|
|
149
|
+
width: window.innerWidth,
|
|
150
|
+
height: window.innerHeight,
|
|
151
|
+
fontSize: 16,
|
|
152
|
+
frameRate: 60
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
t.setup(() => {
|
|
156
|
+
// Optional setup code here (e.g., load fonts/shaders, initialize variables that access 't')
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
t.draw(() => {
|
|
160
|
+
t.background(32); // Dark gray background
|
|
161
|
+
|
|
162
|
+
t.char('A');
|
|
163
|
+
t.charColor(255, 0, 0); // Cover the top-left quarter of the grid with a rectangle of red 'A's
|
|
164
|
+
t.rect(0, 0, t.grid.cols / 2, t.grid.rows / 2);
|
|
165
|
+
|
|
166
|
+
// ...add your drawing code here!
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
t.windowResized(() => {
|
|
170
|
+
t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
171
|
+
});
|
|
124
172
|
```
|
|
125
173
|
|
|
126
|
-
|
|
174
|
+
## Verification
|
|
175
|
+
|
|
176
|
+
To verify your installation is working correctly, try this simple test:
|
|
177
|
+
|
|
178
|
+
```javascript
|
|
179
|
+
// Test if textmode.js is available
|
|
180
|
+
console.log('textmode.js version:', textmode.version);
|
|
181
|
+
```
|
|
127
182
|
|
|
128
|
-
|
|
183
|
+
> [!NOTE]
|
|
184
|
+
> If you see the version number printed in the console, your installation was successful!
|
|
129
185
|
|
|
130
|
-
##
|
|
186
|
+
## Next steps
|
|
131
187
|
|
|
132
|
-
|
|
188
|
+
Now that you have `textmode.js` set up, you can start creating your textmode art projects! Going forward, here are some resources to help you get the most out of the library:
|
|
133
189
|
|
|
134
|
-
|
|
135
|
-
- Detailed guides
|
|
136
|
-
- Interactive examples
|
|
137
|
-
- Complete API reference
|
|
138
|
-
- Tips and tricks
|
|
139
|
-
- ... and much more!
|
|
190
|
+
📚 **[Visit the Official Documentation](https://code.textmode.art/)** for detailed guides, interactive examples, complete API reference, tips and tricks, and much more to unlock the full potential of `textmode.js` in your creative coding projects.
|
|
140
191
|
|
|
141
|
-
|
|
192
|
+
🎨 **[Try the Web Editor](https://editor.textmode.art)** to experiment with `textmode.js` without setting up a local environment.
|
|
142
193
|
|
|
143
194
|
## Acknowledgements
|
|
144
195
|
|