textmode.js 0.6.0-beta.3 → 0.6.0-beta.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/README.md +59 -19
- package/dist/textmode.esm.js +1669 -1594
- package/dist/textmode.umd.js +10 -10
- package/dist/types/index.d.ts +3 -1
- package/dist/types/rendering/webgl/core/Renderer.d.ts +4 -2
- package/dist/types/textmode/TextmodeColor.d.ts +16 -1
- package/dist/types/textmode/Textmodifier.d.ts +4 -0
- package/dist/types/textmode/conversion/ConversionRegistry.d.ts +21 -0
- package/dist/types/textmode/conversion/index.d.ts +1 -0
- package/dist/types/textmode/conversion/strategies/brightness.d.ts +2 -0
- package/dist/types/textmode/interfaces/ITextmodifier.d.ts +5 -0
- package/dist/types/textmode/loadables/TextmodeImage.d.ts +2 -1
- package/dist/types/textmode/loadables/TextmodeSource.d.ts +36 -5
- package/dist/types/textmode/loadables/TextmodeVideo.d.ts +3 -2
- package/dist/types/textmode/loadables/index.d.ts +3 -0
- package/dist/types/textmode/mixins/interfaces/IRenderingMixin.d.ts +3 -2
- package/dist/types/utils/color.d.ts +1 -0
- package/package.json +2 -3
- package/dist/textmode.esm.min.js +0 -3490
- package/dist/textmode.umd.min.js +0 -14
package/README.md
CHANGED
|
@@ -58,25 +58,6 @@ To get started with `textmode.js`, you'll need:
|
|
|
58
58
|
|
|
59
59
|
### Importing `textmode.js`
|
|
60
60
|
|
|
61
|
-
`textmode.js` is available in multiple bundle variants to suit different project needs:
|
|
62
|
-
|
|
63
|
-
| Bundle type | File size | Font included? | Best for |
|
|
64
|
-
|-------------|-----------|---------------|----------|
|
|
65
|
-
| **Standard UMD** (`textmode.umd.js`) | ~87kB | ✅ [UrsaFont](https://ursafrank.itch.io/ursafont) embedded | Quick setup, prototyping |
|
|
66
|
-
| **Standard ESM** (`textmode.esm.js`) | ~111kB | ✅ [UrsaFont](https://ursafrank.itch.io/ursafont) embedded | Quick setup, prototyping |
|
|
67
|
-
| **Minified UMD** (`textmode.umd.min.js`) | ~79kB | ❌ Requires external font | Custom fonts |
|
|
68
|
-
| **Minified ESM** (`textmode.esm.min.js`) | ~103kB | ❌ Requires external font | Custom fonts |
|
|
69
|
-
|
|
70
|
-
**Choose standard bundles for:**
|
|
71
|
-
- Quick setup with no additional configuration
|
|
72
|
-
- Production applications that use the embedded font
|
|
73
|
-
|
|
74
|
-
**Choose minified bundles for:**
|
|
75
|
-
- Production applications that don't use the embedded font
|
|
76
|
-
|
|
77
|
-
> [!NOTE]
|
|
78
|
-
> Apart from the font inclusion, both bundle types are functionally identical and equally minified.
|
|
79
|
-
|
|
80
61
|
#### UMD
|
|
81
62
|
|
|
82
63
|
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:
|
|
@@ -186,6 +167,65 @@ t.windowResized(() => {
|
|
|
186
167
|
});
|
|
187
168
|
```
|
|
188
169
|
|
|
170
|
+
## Conversion strategies & add-ons
|
|
171
|
+
|
|
172
|
+
`textmode.js` now exposes a pluggable conversion pipeline so you can swap out how images, videos, and other sources translate into ASCII cells. The core bundle ships with the classic brightness-based converter, and you can register additional strategies at runtime—either from your own code or from official/community add-ons.
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
import {
|
|
176
|
+
registerConversionStrategy,
|
|
177
|
+
Shader,
|
|
178
|
+
type TextmodeConversionStrategy,
|
|
179
|
+
} from 'textmode.js';
|
|
180
|
+
|
|
181
|
+
import fragmentSource from './my-custom-image-to-mrt.frag';
|
|
182
|
+
import vertexSource from './my-shared-instanced.vert';
|
|
183
|
+
|
|
184
|
+
const customStrategy: TextmodeConversionStrategy = {
|
|
185
|
+
id: 'posterize',
|
|
186
|
+
createShader({ gl }) {
|
|
187
|
+
return new Shader(gl, vertexSource, fragmentSource);
|
|
188
|
+
},
|
|
189
|
+
createUniforms({ source }) {
|
|
190
|
+
return {
|
|
191
|
+
...source.createBaseConversionUniforms(),
|
|
192
|
+
u_levels: 6,
|
|
193
|
+
};
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
registerConversionStrategy(customStrategy);
|
|
198
|
+
|
|
199
|
+
// Later in your sketch
|
|
200
|
+
image.conversionMode('posterize');
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Accurate conversion add-on
|
|
204
|
+
|
|
205
|
+
The heavy multi-sample “accurate” converter now lives in a standalone add-on so you only pay for it when you need it:
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
npm install textmode.accurate.js
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
```ts
|
|
212
|
+
import { textmode } from 'textmode.js';
|
|
213
|
+
import { createAccurateConversionPlugin } from 'textmode.accurate.js';
|
|
214
|
+
|
|
215
|
+
const t = textmode.create({
|
|
216
|
+
width: 1024,
|
|
217
|
+
height: 576,
|
|
218
|
+
plugins: [createAccurateConversionPlugin()],
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
t.setup(async () => {
|
|
222
|
+
const img = await t.loadImage('https://example.com/image.jpg');
|
|
223
|
+
img.conversionMode('accurate', { sampleRate: 12 });
|
|
224
|
+
});
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
If you call `conversionMode('accurate')` without the add-on installed, `textmode.js` will throw a clear runtime error explaining how to enable it.
|
|
228
|
+
|
|
189
229
|
## Next steps
|
|
190
230
|
|
|
191
231
|
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:
|