textmode.js 0.1.9 → 0.2.0-beta.2

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.
Files changed (63) hide show
  1. package/README.md +4 -4
  2. package/dist/textmode.esm.js +1418 -1481
  3. package/dist/textmode.esm.min.js +1500 -1563
  4. package/dist/textmode.umd.js +19 -56
  5. package/dist/textmode.umd.min.js +20 -57
  6. package/dist/types/Textmode.d.ts +10 -38
  7. package/dist/types/export/base/DataExtractor.d.ts +3 -3
  8. package/dist/types/export/image/ImageExporter.d.ts +4 -11
  9. package/dist/types/export/image/types.d.ts +2 -3
  10. package/dist/types/export/svg/SVGExporter.d.ts +1 -1
  11. package/dist/types/export/svg/types.d.ts +1 -0
  12. package/dist/types/export/txt/TXTExporter.d.ts +1 -1
  13. package/dist/types/export/txt/types.d.ts +2 -2
  14. package/dist/types/index.d.ts +1 -7
  15. package/dist/types/rendering/index.d.ts +0 -1
  16. package/dist/types/rendering/webgl/DrawQueue.d.ts +26 -0
  17. package/dist/types/rendering/webgl/Framebuffer.d.ts +41 -40
  18. package/dist/types/rendering/webgl/InstanceBatch.d.ts +91 -0
  19. package/dist/types/rendering/webgl/InstanceData.d.ts +65 -0
  20. package/dist/types/rendering/webgl/RenderPipeline.d.ts +15 -0
  21. package/dist/types/rendering/webgl/RenderState.d.ts +71 -0
  22. package/dist/types/rendering/webgl/Renderer.d.ts +54 -81
  23. package/dist/types/rendering/webgl/Shader.d.ts +11 -16
  24. package/dist/types/rendering/webgl/VAOManager.d.ts +15 -0
  25. package/dist/types/rendering/webgl/geometries/Arc.d.ts +16 -0
  26. package/dist/types/rendering/webgl/geometries/BaseGeometry.d.ts +35 -29
  27. package/dist/types/rendering/webgl/geometries/BezierCurve.d.ts +22 -0
  28. package/dist/types/rendering/webgl/geometries/Ellipse.d.ts +20 -0
  29. package/dist/types/rendering/webgl/geometries/Line.d.ts +13 -4
  30. package/dist/types/rendering/webgl/geometries/Rectangle.d.ts +13 -8
  31. package/dist/types/rendering/webgl/geometries/Triangle.d.ts +20 -0
  32. package/dist/types/rendering/webgl/geometries/index.d.ts +4 -1
  33. package/dist/types/rendering/webgl/index.d.ts +17 -1
  34. package/dist/types/rendering/webgl/types/DrawCommand.d.ts +9 -0
  35. package/dist/types/rendering/webgl/types/GeometryTypes.d.ts +144 -0
  36. package/dist/types/rendering/webgl/types/RenderTypes.d.ts +12 -0
  37. package/dist/types/textmode/AnimationController.d.ts +81 -0
  38. package/dist/types/textmode/Canvas.d.ts +18 -19
  39. package/dist/types/textmode/Grid.d.ts +1 -34
  40. package/dist/types/textmode/Textmodifier.d.ts +36 -277
  41. package/dist/types/textmode/font/CharacterColorMapper.d.ts +3 -3
  42. package/dist/types/textmode/font/TextmodeFont.d.ts +6 -11
  43. package/dist/types/textmode/font/types.d.ts +1 -1
  44. package/dist/types/textmode/font/typr/types.d.ts +1 -1
  45. package/dist/types/textmode/font/utils/index.d.ts +0 -1
  46. package/dist/types/textmode/mixins/AnimationMixin.d.ts +120 -0
  47. package/dist/types/textmode/mixins/ExportMixin.d.ts +4 -6
  48. package/dist/types/textmode/mixins/FontMixin.d.ts +4 -10
  49. package/dist/types/textmode/mixins/RenderingMixin.d.ts +224 -246
  50. package/dist/types/textmode/mixins/TextmodifierMixin.d.ts +13 -4
  51. package/dist/types/textmode/mixins/index.d.ts +2 -2
  52. package/package.json +1 -1
  53. package/dist/types/ColorPalette.d.ts +0 -35
  54. package/dist/types/rendering/core/Framebuffer.d.ts +0 -140
  55. package/dist/types/rendering/core/Shader.d.ts +0 -59
  56. package/dist/types/rendering/core/index.d.ts +0 -2
  57. package/dist/types/textmode/ConversionPipeline.d.ts +0 -110
  58. package/dist/types/textmode/converters/BrightnessConverter.d.ts +0 -58
  59. package/dist/types/textmode/converters/Converter.d.ts +0 -69
  60. package/dist/types/textmode/converters/FeatureConverter.d.ts +0 -128
  61. package/dist/types/textmode/converters/index.d.ts +0 -3
  62. package/dist/types/textmode/font/utils/FontConstants.d.ts +0 -60
  63. package/dist/types/textmode/mixins/ConversionMixin.d.ts +0 -62
@@ -2,34 +2,26 @@ import { GLRenderer } from '../rendering/webgl/Renderer';
2
2
  import { TextmodeFont } from './font';
3
3
  import { TextmodeGrid } from './Grid';
4
4
  import { TextmodeCanvas } from './Canvas';
5
- import { TextmodeConversionPipeline } from './ConversionPipeline';
5
+ import { AnimationController } from './AnimationController';
6
6
  import { type TextmodifierContext } from './mixins';
7
7
  import type { RenderingCapabilities } from './mixins/RenderingMixin';
8
8
  import type { ExportCapabilities } from './mixins/ExportMixin';
9
9
  import type { FontCapabilities } from './mixins/FontMixin';
10
- import type { ConversionCapabilities } from './mixins/ConversionMixin';
11
- /**
12
- * Supported capture sources for textmode rendering.
13
- * @ignore
14
- */
15
- export type TextmodeCaptureSource = HTMLCanvasElement | HTMLVideoElement;
10
+ import type { AnimationCapabilities } from './mixins/AnimationMixin';
11
+ import type { GLFramebuffer, Shader } from '../rendering';
16
12
  /**
17
13
  * Options for creating a {@link Textmodifier} instance.
18
14
  */
19
15
  export type TextmodeOptions = {
16
+ /** An existing HTMLCanvasElement to use instead of creating a new one. */
17
+ canvas?: HTMLCanvasElement;
20
18
  /** The font size to use for text rendering. Defaults to 16. */
21
19
  fontSize?: number;
22
- /**
23
- * Automatic rendering mode. Defaults to 'auto'.
24
- * - `'manual'`: Requires manual `render()` calls
25
- * - `'auto'`: Automatically renders using [requestAnimationFrame](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame)
26
- */
27
- renderMode?: 'manual' | 'auto';
28
20
  /** Maximum frames per second for auto rendering. Defaults to 60. */
29
21
  frameRate?: number;
30
- /** The width of the canvas in `standalone` mode. Defaults to 800. */
22
+ /** The width of the canvas when creating a new canvas. Defaults to 800. */
31
23
  width?: number;
32
- /** The height of the canvas in `standalone` mode. Defaults to 600. */
24
+ /** The height of the canvas when creating a new canvas. Defaults to 600. */
33
25
  height?: number;
34
26
  /**
35
27
  * URL or path to a custom font file *(.otf/.ttf)*.
@@ -39,279 +31,61 @@ export type TextmodeOptions = {
39
31
  fontSource?: string;
40
32
  };
41
33
  /**
42
- * Base class for mixin application
34
+ * Base class for mixin application.
43
35
  */
44
36
  declare class TextmodifierCore implements TextmodifierContext {
45
37
  _renderer: GLRenderer;
46
38
  _font: TextmodeFont;
47
- _pipeline: TextmodeConversionPipeline;
48
39
  _canvas: TextmodeCanvas;
49
40
  _grid: TextmodeGrid;
41
+ _animationController: AnimationController;
42
+ _textmodeDrawShader: Shader;
43
+ _textmodeDrawFramebuffer: GLFramebuffer;
44
+ _textmodeConversionShader: Shader;
45
+ $render(): void;
50
46
  }
51
47
  declare const Textmodifier_base: typeof TextmodifierCore;
52
48
  /**
53
- * Manages textmode rendering on a canvas or video element.
54
- *
55
- * Each `Textmodifier` instance applies a `HTMLCanvasElement` with custom WebGL rendering on top of the original content.
49
+ * Manages textmode rendering on a `HTMLCanvasElement` and provides methods for drawing,
50
+ * exporting, font management, and animation control.
56
51
  *
57
- * If the `Textmodifier` instance is created in `standalone` mode without a capture source,
58
- * it simply creates a new `HTMLCanvasElement` to draw on using the `textmode.js` drawing API.
52
+ * If the `Textmodifier` instance is created without a canvas parameter,
53
+ * it creates a new `HTMLCanvasElement` to draw on using the `textmode.js` drawing API.
54
+ * If a canvas is provided, it will use that canvas instead.
59
55
  */
60
56
  export declare class Textmodifier extends Textmodifier_base {
61
- /** The element to capture content from (optional for standalone mode) */
62
- private _captureSource;
63
- /** Canvas framebuffer for capturing source content */
64
- private _canvasFramebuffer;
65
- private _resizeObserver;
66
- private _mode;
67
- private _frameRateLimit;
68
- private _animationFrameId;
69
- private _lastFrameTime;
70
- private _frameInterval;
71
- private _isLooping;
72
- private _frameRate;
73
- private _lastRenderTime;
74
- private _frameCount;
75
- private _frameTimeHistory;
76
- private _frameTimeHistorySize;
77
57
  private _isDisposed;
78
- private _standalone;
79
58
  private _drawCallback;
80
59
  private _resizedCallback;
81
60
  private _windowResizeListener;
82
61
  /**
83
62
  * Creates an instance of Textmodifier.
84
- * @param source The HTML canvas or video element to capture content from. Pass `null` for standalone mode.
85
63
  * @param opts Optional configuration options for the Textmodifier instance.
86
64
  * @ignore
87
65
  */
88
- constructor(source?: TextmodeCaptureSource | null, opts?: TextmodeOptions);
66
+ constructor(opts?: TextmodeOptions);
89
67
  /**
90
68
  * Static factory method for creating and initializing a Textmodifier instance.
91
- * @param source The HTML canvas or video element to capture content from. Pass `null` for standalone mode.
92
69
  * @param opts Optional configuration options for the `Textmodifier` instance.
93
70
  * @ignore
94
71
  */
95
- static create(source?: TextmodeCaptureSource | null, opts?: TextmodeOptions): Promise<Textmodifier>;
72
+ static create(opts?: TextmodeOptions): Promise<Textmodifier>;
96
73
  /**
97
74
  * Setup event listeners for resize handling.
98
75
  * @ignore
99
76
  */
100
77
  $setupEventListeners(): void;
101
78
  /**
102
- * Apply textmode rendering to the canvas.
103
- *
104
- * **Note:** In `'auto'` mode, this is called automatically.
105
- * In `'manual'` mode, you need to call this method when you want to update the textmode rendering.
106
- *
107
- * @example
108
- * ```javascript
109
- * // p5.js example
110
- *
111
- * let textmodifier;
112
- *
113
- * // p5.js setup function
114
- * async function setup() {
115
- *
116
- * // Create a p5.js canvas
117
- * const canvas = createCanvas(800, 600);
118
- *
119
- * // Create a Textmodifier instance
120
- * textmodifier = await textmode.create(canvas.elt);
121
- *
122
- * // Update the rendering mode to 'manual'
123
- * textmodifier.renderMode('manual');
124
- * }
125
- *
126
- * // p5.js draw function
127
- * function draw() {
128
- *
129
- * // Draw something on the p5.js canvas
130
- * background(220);
131
- * fill(255, 0, 0);
132
- * rect(50, 50, 100, 100);
133
- *
134
- * // Apply textmode rendering
135
- * textmodifier.render();
136
- * }
137
- * ```
138
- */
139
- render(): void;
140
- private _resize;
141
- /**
142
- * Start automatic rendering
143
- */
144
- private _startAutoRendering;
145
- /**
146
- * Update FPS measurement - works for both auto and manual modes
147
- * Uses a rolling average for smoother frame rate reporting
148
- */
149
- private _measureFrameRate;
150
- /**
151
- * Stop automatic rendering
152
- */
153
- private _stopAutoRendering;
154
- /**
155
- * Update the rendering mode.
156
- *
157
- * - `'manual'`: Requires manual [render](#render) calls
158
- * - `'auto'`: Automatically renders using [requestAnimationFrame](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame)
159
- *
160
- * @param mode The new rendering mode to set.
161
- *
162
- * @example
163
- * ```javascript
164
- * // Fetch a canvas element to apply textmode rendering to
165
- * const canvas = document.querySelector('canvas#myCanvas');
166
- *
167
- * // Create a Textmodifier instance
168
- * const textmodifier = await textmode.create(canvas);
169
- *
170
- * // Update the rendering mode to 'manual'
171
- * textmodifier.renderMode('manual');
172
- *
173
- * // Now you need to call textmodifier.render() manually in your animation loop
174
- * ```
175
- */
176
- renderMode(mode: 'manual' | 'auto'): void;
177
- /**
178
- * Set the maximum frame rate for auto rendering. If called without arguments, returns the current measured frame rate.
179
- * @param fps The maximum frames per second for auto rendering.
180
- *
181
- * @example
182
- * ```javascript
183
- * // Fetch a canvas element to apply textmode rendering to
184
- * const canvas = document.querySelector('canvas#myCanvas');
185
- *
186
- * // Create a Textmodifier instance
187
- * const textmodifier = await textmode.create(canvas);
188
- *
189
- * // Set the maximum frame rate to 30 FPS
190
- * textmodifier.frameRate(30);
191
- * ```
192
- */
193
- frameRate(fps?: number): number | void;
194
- /**
195
- * Stop the automatic rendering loop while keeping the render mode as 'auto'.
196
- *
197
- * This method pauses the render loop without changing the render mode, allowing
198
- * it to be resumed later with {@link loop}. This is useful for temporarily pausing
199
- * animation while maintaining the ability to restart it.
200
- *
201
- * **Note:** This only affects rendering when in `'auto'` mode. In `'manual'` mode,
202
- * this method has no effect since rendering is already controlled manually.
203
- *
204
- * @example
205
- * ```javascript
206
- * // Create a textmodifier instance in auto mode
207
- * const textmodifier = await textmode.create(canvas);
208
- *
209
- * // The render loop is running automatically
210
- * console.log(textmodifier.isLooping()); // true
211
- *
212
- * // Stop the automatic rendering loop
213
- * textmodifier.noLoop();
214
- * console.log(textmodifier.isLooping()); // false
215
- *
216
- * // Resume the automatic rendering loop
217
- * textmodifier.loop();
218
- * console.log(textmodifier.isLooping()); // true
219
- * ```
220
- */
221
- noLoop(): void;
222
- /**
223
- * Resume the automatic rendering loop if it was stopped by {@link noLoop}.
224
- *
225
- * This method restarts the render loop when in `'auto'` mode. If the render mode
226
- * is `'manual'`, the loop state will be set but automatic rendering will not start
227
- * until the mode is changed back to `'auto'`.
228
- *
229
- * @example
230
- * ```javascript
231
- * // Create a textmodifier instance
232
- * const textmodifier = await textmode.create(canvas);
233
- *
234
- * // Stop the loop
235
- * textmodifier.noLoop();
236
- *
237
- * // Resume the loop
238
- * textmodifier.loop();
239
- *
240
- * // You can also use this pattern for conditional animation
241
- * if (someCondition) {
242
- * textmodifier.loop();
243
- * } else {
244
- * textmodifier.noLoop();
245
- * }
246
- * ```
247
- */
248
- loop(): void;
249
- /**
250
- * Execute the render function a specified number of times.
251
- *
252
- * This method is useful when the render loop has been stopped with {@link noLoop}
253
- * or when in `'manual'` mode, allowing you to trigger rendering on demand.
254
- * Similar to p5.js's `redraw()` function.
255
- *
256
- * @param n The number of times to execute the render function. Defaults to 1.
257
- *
258
- * @example
259
- * ```javascript
260
- * // Create a textmodifier instance
261
- * const textmodifier = await textmode.create(canvas, { renderMode: 'manual' });
262
- *
263
- * // Set up drawing
264
- * textmodifier.draw(() => {
265
- * textmodifier.background(0);
266
- * textmodifier.fill(255, 0, 0);
267
- * textmodifier.rect(100, 100, 200, 150);
268
- * });
269
- *
270
- * // Render once manually
271
- * textmodifier.redraw();
272
- *
273
- * // Render 5 times
274
- * textmodifier.redraw(5);
275
- *
276
- * // Also useful when loop is stopped
277
- * textmodifier.noLoop();
278
- * textmodifier.redraw(3); // Render 3 times despite loop being stopped
279
- * ```
79
+ * Renders the current frame.
80
+ * @returns void
81
+ * @ignore
280
82
  */
281
- redraw(n?: number): void;
83
+ $render(): void;
282
84
  /**
283
- * Check whether the textmodifier is currently running the automatic render loop.
284
- *
285
- * Returns `true` when both the render mode is `'auto'` AND the loop is active.
286
- * Returns `false` when in `'manual'` mode or when {@link noLoop} has been called.
287
- *
288
- * @returns True if the automatic render loop is currently active, false otherwise.
289
- *
290
- * @example
291
- * ```javascript
292
- * const textmodifier = await textmode.create(canvas);
293
- *
294
- * // Check loop status in different states
295
- * console.log(textmodifier.isLooping()); // true (auto mode, looping)
296
- *
297
- * textmodifier.noLoop();
298
- * console.log(textmodifier.isLooping()); // false (auto mode, not looping)
299
- *
300
- * textmodifier.renderMode('manual');
301
- * console.log(textmodifier.isLooping()); // false (manual mode)
85
+ * Set a draw callback function that will be executed before each render.
302
86
  *
303
- * textmodifier.renderMode('auto');
304
- * console.log(textmodifier.isLooping()); // false (auto mode, but loop was stopped)
87
+ * This callback function is where all drawing commands should be placed for textmode rendering.
305
88
  *
306
- * textmodifier.loop();
307
- * console.log(textmodifier.isLooping()); // true (auto mode, looping)
308
- * ```
309
- */
310
- isLooping(): boolean;
311
- /**
312
- * Set a draw callback function that will be executed before each render.
313
- * This method is primarily useful for standalone textmodifier instances,
314
- * but can also be used to draw on top of the captured video or canvas.
315
89
  * @param callback The function to call before each render
316
90
  *
317
91
  * @example
@@ -327,9 +101,8 @@ export declare class Textmodifier extends Textmodifier_base {
327
101
  * // Set background color
328
102
  * t.background(128);
329
103
  *
330
- * // Draw some content
331
- * t.fill(255, 0, 0); // Set fill color to red
332
- * t.rect(50, 50, 100, 100);
104
+ * // Draw a textmode rectangle with default settings
105
+ * t.rect(0, 0, 16, 16);
333
106
  * });
334
107
  * ```
335
108
  */
@@ -351,9 +124,7 @@ export declare class Textmodifier extends Textmodifier_base {
351
124
  * // Set background color
352
125
  * t.background(128);
353
126
  *
354
- * // Draw some content
355
- * t.fill(255, 0, 0); // Set fill color to red
356
- * t.rect(50, 50, 100, 100);
127
+ * // todo...
357
128
  * });
358
129
  *
359
130
  * // Set up window resize callback
@@ -365,9 +136,8 @@ export declare class Textmodifier extends Textmodifier_base {
365
136
  */
366
137
  windowResized(callback: () => void): void;
367
138
  /**
368
- * Resize the `textmode.js` canvas.
139
+ * Resize the canvas and adjust all related components accordingly.
369
140
  *
370
- * Can only be used in `standalone` mode since the textmode canvas otherwise automatically adjusts to the video/canvas size.
371
141
  * @param width The new width of the canvas.
372
142
  * @param height The new height of the canvas.
373
143
  */
@@ -377,15 +147,12 @@ export declare class Textmodifier extends Textmodifier_base {
377
147
  *
378
148
  * After calling this method, the instance should not be used and will be eligible for garbage collection.
379
149
  *
380
- * This method is idempotent and safe to call multiple times.
381
- *
382
150
  * @example
383
151
  * ```javascript
384
152
  * // Create a textmodifier instance
385
- * const textmodifier = await textmode.create(canvas);
153
+ * const textmodifier = await textmode.create();
386
154
  *
387
- * // Use it for rendering
388
- * textmodifier.render();
155
+ * // ...
389
156
  *
390
157
  * // When done, completely clean up
391
158
  * textmodifier.destroy();
@@ -398,25 +165,17 @@ export declare class Textmodifier extends Textmodifier_base {
398
165
  get grid(): TextmodeGrid;
399
166
  /** Get the current font object used for rendering. */
400
167
  get font(): TextmodeFont;
401
- /** Get the current rendering mode.*/
402
- get mode(): 'manual' | 'auto';
403
- /** Get the current textmode conversion pipeline. */
404
- get pipeline(): TextmodeConversionPipeline;
405
- /** Get the current frame count. */
406
- get frameCount(): number;
407
- /** Get the WebGL renderer. */
408
- get renderer(): GLRenderer;
409
- /** Set the current frame count. */
410
- set frameCount(value: number);
411
168
  /** Get the width of the canvas. */
412
169
  get width(): number;
413
170
  /** Get the height of the canvas. */
414
171
  get height(): number;
415
172
  /** Get the textmodifier canvas containing the rendered output. */
416
- get canvas(): TextmodeCanvas;
173
+ get canvas(): HTMLCanvasElement;
417
174
  /** Check if the instance has been disposed/destroyed. */
418
175
  get isDisposed(): boolean;
176
+ /** Get the draw framebuffer used for offscreen rendering. @ignore */
177
+ get drawFramebuffer(): any;
419
178
  }
420
- export interface Textmodifier extends RenderingCapabilities, ExportCapabilities, FontCapabilities, ConversionCapabilities {
179
+ export interface Textmodifier extends RenderingCapabilities, ExportCapabilities, FontCapabilities, AnimationCapabilities {
421
180
  }
422
181
  export {};
@@ -17,7 +17,7 @@ export declare class CharacterColorMapper {
17
17
  /**
18
18
  * Generates a unique RGB color for a character based on its index.
19
19
  * @param index The index of the character
20
- * @returns RGB color as a tuple [r, g, b]
20
+ * @returns RGB color as a tuple [r, g, b] with values from 0-1 for shader use
21
21
  */
22
22
  private _generateCharacterColor;
23
23
  /**
@@ -26,12 +26,12 @@ export declare class CharacterColorMapper {
26
26
  * @param characters Array of TextmodeCharacter objects
27
27
  * @returns RGB color as a tuple [r, g, b], or [0, 0, 0] if not found
28
28
  */
29
- getCharacterColor(character: string, characters: TextmodeCharacter[]): [number, number, number];
29
+ $getCharacterColor(character: string, characters: TextmodeCharacter[]): [number, number, number];
30
30
  /**
31
31
  * Gets colors for multiple characters.
32
32
  * @param characterString String of characters to get colors for
33
33
  * @param characters Array of TextmodeCharacter objects
34
34
  * @returns Array of RGB colors for each character
35
35
  */
36
- getCharacterColors(characterString: string, characters: TextmodeCharacter[]): [number, number, number][];
36
+ $getCharacterColors(characterString: string, characters: TextmodeCharacter[]): [number, number, number][];
37
37
  }
@@ -3,10 +3,10 @@ import type { GLFramebuffer } from '../../rendering/webgl/Framebuffer.ts';
3
3
  import type { TextmodeCharacter } from './types.ts';
4
4
  import type { TyprFont } from './typr/types.ts';
5
5
  /**
6
- * Manages the textmode font used for rendering characters.
6
+ * Manages the font used for rendering characters.
7
7
  *
8
8
  * This class coordinates font loading, character extraction, texture atlas creation,
9
- * and provides character color information. It acts as a facade for the font system.
9
+ * and provides character information.
10
10
  */
11
11
  export declare class TextmodeFont {
12
12
  private _font;
@@ -17,7 +17,6 @@ export declare class TextmodeFont {
17
17
  private _textureRows;
18
18
  private _maxGlyphDimensions;
19
19
  private _fontFace;
20
- private _fontFamilyName;
21
20
  private _characterExtractor;
22
21
  private _textureAtlas;
23
22
  private _metricsCalculator;
@@ -62,21 +61,17 @@ export declare class TextmodeFont {
62
61
  * Get the color associated with a character.
63
62
  * @param character The character to get the color for.
64
63
  * @returns The RGB color as an array `[r, g, b]`.
64
+ * @ignore
65
65
  */
66
- getCharacterColor(character: string): [number, number, number];
66
+ $getCharacterColor(character: string): [number, number, number];
67
67
  /**
68
68
  * Get the colors associated with a string of characters.
69
69
  * @param characters The string of characters to get colors for.
70
70
  * @returns An array of RGB colors for each character in the string.
71
71
  * Each color is represented as an array `[r, g, b]`.
72
+ * @ignore
72
73
  */
73
- getCharacterColors(characters: string): [number, number, number][];
74
- /**
75
- * Checks if all characters in the given string exist in the font.
76
- * @param str The string to check.
77
- * @returns `true` if all characters exist in the font, `false` otherwise.
78
- */
79
- hasAllCharacters(str: string): boolean;
74
+ $getCharacterColors(characters: string): [number, number, number][];
80
75
  /**
81
76
  * Dispose of all resources used by this font manager.
82
77
  * @ignore
@@ -6,7 +6,7 @@ export type TextmodeCharacter = {
6
6
  character: string;
7
7
  /** The Unicode code point of the character. */
8
8
  unicode: number;
9
- /** The RGB color associated with the character for identification. */
9
+ /** The shader color associated with the character. */
10
10
  color: [number, number, number];
11
11
  /** The advance width of the character. @ignore */
12
12
  advanceWidth: number;
@@ -171,7 +171,7 @@ export interface GlyphData {
171
171
  * Each table parser implements this interface
172
172
  */
173
173
  export interface TableParser<T = any> {
174
- parseTab: (data: Uint8Array, offset: number, length: number, font?: TyprFont) => T;
174
+ parseTab: (data: Uint8Array, offset: number, length: number, font: TyprFont) => T;
175
175
  }
176
176
  /**
177
177
  * Extended cmap parser with format-specific methods
@@ -6,4 +6,3 @@
6
6
  */
7
7
  export { FontTableReader } from './FontTableReader.ts';
8
8
  export { CmapParser } from './CmapParser.ts';
9
- export * from './FontConstants.ts';
@@ -0,0 +1,120 @@
1
+ import type { Mixin } from './TextmodifierMixin';
2
+ /**
3
+ * Interface for animation capabilities that will be mixed into Textmodifier
4
+ */
5
+ export interface AnimationCapabilities {
6
+ /**
7
+ * Get or set the current frame count.
8
+ */
9
+ frameCount: number;
10
+ /**
11
+ * Set the maximum frame rate. If called without arguments, returns the current measured frame rate.
12
+ * @param fps The maximum frames per second for rendering.
13
+ *
14
+ * @example
15
+ * ```javascript
16
+ * // Create a Textmodifier instance
17
+ * const textmodifier = await textmode.create();
18
+ *
19
+ * // Set the maximum frame rate to 30 FPS
20
+ * textmodifier.frameRate(30);
21
+ * ```
22
+ */
23
+ frameRate(fps?: number): number | void;
24
+ /**
25
+ * Stop the automatic rendering loop.
26
+ *
27
+ * This method pauses the render loop without, allowing
28
+ * it to be resumed later with {@link loop}. This is useful for temporarily pausing
29
+ * animation while maintaining the ability to continue it.
30
+ *
31
+ * @example
32
+ * ```javascript
33
+ * // Create a textmodifier instance in auto mode
34
+ * const textmodifier = await textmode.create();
35
+ *
36
+ * // The render loop is running by default
37
+ * console.log(textmodifier.isLooping()); // true
38
+ *
39
+ * // Stop the automatic rendering loop
40
+ * textmodifier.noLoop();
41
+ * console.log(textmodifier.isLooping()); // false
42
+ *
43
+ * // Resume the rendering loop
44
+ * textmodifier.loop();
45
+ * console.log(textmodifier.isLooping()); // true
46
+ * ```
47
+ */
48
+ noLoop(): void;
49
+ /**
50
+ * Resume the rendering loop if it was stopped by {@link noLoop}.
51
+ *
52
+ * @example
53
+ * ```javascript
54
+ * // Create a textmodifier instance
55
+ * const textmodifier = await textmode.create();
56
+ *
57
+ * // Stop the loop
58
+ * textmodifier.noLoop();
59
+ *
60
+ * // Resume the loop
61
+ * textmodifier.loop();
62
+ *
63
+ * // You can also use this pattern for conditional animation
64
+ * if (someCondition) {
65
+ * textmodifier.loop();
66
+ * } else {
67
+ * textmodifier.noLoop();
68
+ * }
69
+ * ```
70
+ */
71
+ loop(): void;
72
+ /**
73
+ * Execute the render function a specified number of times.
74
+ *
75
+ * This method is useful when the render loop has been stopped with {@link noLoop},
76
+ * allowing you to trigger rendering on demand.
77
+ *
78
+ * @param n The number of times to execute the render function. Defaults to 1.
79
+ *
80
+ * @example
81
+ * ```javascript
82
+ * // Create a textmodifier instance
83
+ * const textmodifier = await textmode.create();
84
+ *
85
+ * // Set up drawing
86
+ * textmodifier.draw(() => {
87
+ * // todo...
88
+ * });
89
+ *
90
+ * textmodifier.noLoop();
91
+ * textmodifier.redraw(3); // Render 3 times despite loop being stopped
92
+ * ```
93
+ */
94
+ redraw(n?: number): void;
95
+ /**
96
+ * Check whether the textmodifier is currently running the automatic render loop.
97
+ * @returns True if the render loop is currently active, false otherwise.
98
+ *
99
+ * @example
100
+ * ```javascript
101
+ * const textmodifier = await textmode.create(canvas);
102
+ *
103
+ * // Check loop status in different states
104
+ * console.log(textmodifier.isLooping()); // true (looping)
105
+ *
106
+ * textmodifier.noLoop();
107
+ * console.log(textmodifier.isLooping()); // false (not looping)
108
+ *
109
+ * textmodifier.loop();
110
+ * console.log(textmodifier.isLooping()); // true (alooping)
111
+ * ```
112
+ */
113
+ isLooping(): boolean;
114
+ }
115
+ /**
116
+ * Mixin that adds animation capabilities to a class
117
+ * @param Base The base class to extend
118
+ * @returns Extended class with animation capabilities
119
+ */
120
+ export declare const AnimationMixin: Mixin<AnimationCapabilities>;
@@ -32,7 +32,7 @@ export interface ExportCapabilities {
32
32
  * console.log(textString);
33
33
  * ```
34
34
  */
35
- toString(options?: Omit<TXTExportOptions, 'filename'>): string;
35
+ toString(options?: TXTExportOptions): string;
36
36
  /**
37
37
  * Export the current textmode rendering to a TXT file.
38
38
  * @param options Options for TXT export
@@ -82,7 +82,7 @@ export interface ExportCapabilities {
82
82
  * console.log(svgString);
83
83
  * ```
84
84
  */
85
- toSVG(options?: Omit<SVGExportOptions, 'filename'>): string;
85
+ toSVG(options?: SVGExportOptions): string;
86
86
  /**
87
87
  * Export the current textmode rendering to an SVG file.
88
88
  * @param options Options for SVG export
@@ -107,9 +107,7 @@ export interface ExportCapabilities {
107
107
  saveSVG(options?: SVGExportOptions): void;
108
108
  /**
109
109
  * Export the current textmode rendering to an image file.
110
- * @param filename The filename (without extension) to save the image as
111
- * @param format The image format ('png', 'jpg', or 'webp')
112
- * @param options Additional options for image export
110
+ * @param options Options for image export
113
111
  *
114
112
  * @example
115
113
  * ```javascript
@@ -133,7 +131,7 @@ export interface ExportCapabilities {
133
131
  * });
134
132
  * ```
135
133
  */
136
- saveCanvas(filename: string, format?: 'png' | 'jpg' | 'webp', options?: Omit<ImageExportOptions, 'filename' | 'format'>): Promise<void>;
134
+ saveCanvas(options?: ImageExportOptions): Promise<void>;
137
135
  }
138
136
  /**
139
137
  * Mixin that adds export capabilities to a class