textmode.js 0.7.1 → 0.8.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 (54) hide show
  1. package/dist/textmode.esm.js +2042 -2108
  2. package/dist/textmode.umd.js +16 -16
  3. package/dist/types/Textmode.d.ts +11 -11
  4. package/dist/types/errors/index.d.ts +1 -1
  5. package/dist/types/index.d.ts +11 -3
  6. package/dist/types/rendering/webgl/core/Framebuffer.d.ts +0 -6
  7. package/dist/types/rendering/webgl/core/Renderer.d.ts +7 -6
  8. package/dist/types/rendering/webgl/core/interfaces/IFramebuffer.d.ts +6 -6
  9. package/dist/types/rendering/webgl/core/interfaces/IRenderer.d.ts +3 -3
  10. package/dist/types/rendering/webgl/index.d.ts +2 -2
  11. package/dist/types/rendering/webgl/pipeline/MaterialBatchPipeline.d.ts +1 -1
  12. package/dist/types/textmode/Canvas.d.ts +2 -2
  13. package/dist/types/textmode/Grid.d.ts +32 -3
  14. package/dist/types/textmode/Textmodifier.d.ts +14 -72
  15. package/dist/types/textmode/conversion/ConversionManager.d.ts +73 -0
  16. package/dist/types/textmode/conversion/ConversionRegistry.d.ts +61 -18
  17. package/dist/types/textmode/conversion/index.d.ts +3 -1
  18. package/dist/types/textmode/filters/FilterManager.d.ts +0 -4
  19. package/dist/types/textmode/filters/index.d.ts +1 -1
  20. package/dist/types/textmode/interfaces/ITextmodifier.d.ts +165 -50
  21. package/dist/types/textmode/layers/Layer2DCompositor.d.ts +13 -20
  22. package/dist/types/textmode/layers/LayerManager.d.ts +31 -20
  23. package/dist/types/textmode/layers/TextmodeLayer.d.ts +58 -20
  24. package/dist/types/textmode/layers/interfaces/ILayerManager.d.ts +7 -0
  25. package/dist/types/textmode/layers/interfaces/ITextmodeLayer.d.ts +49 -28
  26. package/dist/types/textmode/layers/types.d.ts +16 -21
  27. package/dist/types/textmode/loadables/ITextmodeSource.d.ts +123 -0
  28. package/dist/types/textmode/loadables/TextmodeImage.d.ts +2 -2
  29. package/dist/types/textmode/loadables/TextmodeSource.d.ts +10 -118
  30. package/dist/types/textmode/loadables/font/CharacterExtractor.d.ts +1 -1
  31. package/dist/types/textmode/loadables/font/TextmodeFont.d.ts +3 -0
  32. package/dist/types/textmode/loadables/font/index.d.ts +2 -2
  33. package/dist/types/textmode/loadables/index.d.ts +0 -2
  34. package/dist/types/textmode/loadables/video/ITextmodeVideo.d.ts +75 -0
  35. package/dist/types/textmode/loadables/video/TextmodeVideo.d.ts +23 -126
  36. package/dist/types/textmode/loading/LoadingPhase.d.ts +26 -0
  37. package/dist/types/textmode/loading/LoadingScreenManager.d.ts +91 -93
  38. package/dist/types/textmode/loading/index.d.ts +3 -2
  39. package/dist/types/textmode/loading/types.d.ts +57 -57
  40. package/dist/types/textmode/managers/MouseManager.d.ts +24 -14
  41. package/dist/types/textmode/managers/TouchManager.d.ts +25 -13
  42. package/dist/types/textmode/mixins/index.d.ts +1 -2
  43. package/dist/types/textmode/mixins/interfaces/IAnimationMixin.d.ts +87 -87
  44. package/dist/types/textmode/mixins/interfaces/IKeyboardMixin.d.ts +128 -128
  45. package/dist/types/textmode/mixins/interfaces/IMouseMixin.d.ts +96 -105
  46. package/dist/types/textmode/mixins/interfaces/IRenderingMixin.d.ts +271 -370
  47. package/dist/types/textmode/mixins/interfaces/ITouchMixin.d.ts +1 -1
  48. package/dist/types/textmode/types.d.ts +2 -6
  49. package/package.json +5 -2
  50. package/dist/types/textmode/layers/filters/index.d.ts +0 -6
  51. package/dist/types/textmode/loadables/video/TextmodeVideoPreloader.d.ts +0 -29
  52. package/dist/types/textmode/loadables/video/types.d.ts +0 -43
  53. package/dist/types/textmode/mixins/FontMixin.d.ts +0 -8
  54. package/dist/types/textmode/mixins/interfaces/IFontMixin.d.ts +0 -46
@@ -1,4 +1,5 @@
1
1
  import type { GLFramebuffer } from '../../../rendering';
2
+ import type { TextmodeFont } from '../../loadables/font';
2
3
  import type { TextmodeLayerBlendMode } from '../types';
3
4
  import type { FilterName, BuiltInFilterName, BuiltInFilterParams } from '../../filters';
4
5
  /**
@@ -38,11 +39,13 @@ export interface ITextmodeLayer {
38
39
  * If the layer is not yet initialized, returns undefined.
39
40
  */
40
41
  readonly drawFramebuffer: GLFramebuffer | undefined;
42
+ /** The font used by this layer. */
43
+ readonly font: TextmodeFont;
41
44
  /**
42
45
  * Define this layer's draw callback. The callback is executed each frame
43
46
  * and should contain all drawing commands for this layer.
44
47
  *
45
- * Inside the callback, use `t` (your textmode instance) to access drawing
48
+ * Inside the callback, use `t` (your `Textmodifier` instance) to access drawing
46
49
  * methods like `char()`, `charColor()`, `translate()`, and `rect()`.
47
50
  *
48
51
  * @param callback The function to call when drawing this layer.
@@ -118,6 +121,24 @@ export interface ITextmodeLayer {
118
121
  * ```
119
122
  */
120
123
  draw(callback: () => void): void;
124
+ /** Get or set the font size for this layer. */
125
+ fontSize(size?: number): number | void;
126
+ /**
127
+ * Load a font from the given source into this layer.
128
+ *
129
+ * @param fontSource The URL or path to the font file.
130
+ * @returns The loaded TextmodeFont instance.
131
+ *
132
+ * @example
133
+ * ```javascript
134
+ * const layer = t.layers.add();
135
+ *
136
+ * t.setup(async () => {
137
+ * await layer.loadFont('./fonts/custom.ttf');
138
+ * });
139
+ * ```
140
+ */
141
+ loadFont(fontSource: string | TextmodeFont): Promise<TextmodeFont>;
121
142
  /**
122
143
  * Show this layer for rendering.
123
144
  */
@@ -138,7 +159,7 @@ export interface ITextmodeLayer {
138
159
  * @param mode The blend mode to set.
139
160
  * @returns The current blend mode if no parameter is provided.
140
161
  *
141
- * **Available Blend Modes:**
162
+ * **Available blend modes:**
142
163
  * - `'normal'` - Standard alpha compositing
143
164
  * - `'additive'` - Adds colors together (great for glow/energy effects)
144
165
  * - `'multiply'` - Darkens by multiplying colors
@@ -279,32 +300,32 @@ export interface ITextmodeLayer {
279
300
  * @param z The rotation angle in degrees. Positive values rotate clockwise.
280
301
  * @returns The current rotation in degrees if no parameter is provided.
281
302
  *
282
- * @example
283
- * ```typescript
284
- * import { textmode } from 'textmode.js';
285
- *
286
- * const t = textmode.create();
287
- *
288
- * const rotatingLayer = t.layers.add({ blendMode: 'difference', opacity: 1.0 });
289
- *
290
- * rotatingLayer.draw(() => {
291
- * t.clear();
292
- * t.charColor(255, 200, 100);
293
- * t.char('#');
294
- * t.rect(10, 5);
295
- * });
296
- *
297
- * t.draw(() => {
298
- * t.background(20, 20, 40);
299
- *
300
- * // Rotate the layer over time
301
- * rotatingLayer.rotateZ(t.frameCount * 2);
302
- *
303
- * t.charColor(100, 200, 255);
304
- * t.char('-');
305
- * t.rect(t.grid.cols, t.grid.rows);
306
- * });
307
- * ```
303
+ * @example
304
+ * ```typescript
305
+ * import { textmode } from 'textmode.js';
306
+ *
307
+ * const t = textmode.create();
308
+ *
309
+ * const rotatingLayer = t.layers.add({ blendMode: 'difference', opacity: 1.0 });
310
+ *
311
+ * rotatingLayer.draw(() => {
312
+ * t.clear();
313
+ * t.charColor(255, 200, 100);
314
+ * t.char('#');
315
+ * t.rect(10, 5);
316
+ * });
317
+ *
318
+ * t.draw(() => {
319
+ * t.background(20, 20, 40);
320
+ *
321
+ * // Rotate the layer over time
322
+ * rotatingLayer.rotateZ(t.frameCount * 2);
323
+ *
324
+ * t.charColor(100, 200, 255);
325
+ * t.char('-');
326
+ * t.rect(t.grid.cols, t.grid.rows);
327
+ * });
328
+ * ```
308
329
  */
309
330
  rotateZ(z?: number): number | void;
310
331
  /**
@@ -1,8 +1,8 @@
1
1
  import type { GLFramebuffer } from '../../rendering';
2
- import type { TextmodeGrid } from '../Grid';
3
2
  import type { GLRenderer } from '../../rendering/webgl/core/Renderer';
4
- import type { TextmodeFont } from '../loadables/font';
5
3
  import type { TextmodeFilterManager } from '../filters';
4
+ import type { TextmodeCanvas } from '../Canvas';
5
+ import type { TextmodeFont } from '../loadables';
6
6
  /**
7
7
  * Blend modes available for {@link TextmodeLayer} compositing in 2D mode.
8
8
  *
@@ -50,6 +50,16 @@ export interface TextmodeLayerOptions {
50
50
  * The rotation of the layer in degrees around its center. Default is `0`.
51
51
  */
52
52
  rotation?: number;
53
+ /**
54
+ * The font size for the layer's text. Default is `16`.
55
+ */
56
+ fontSize?: number;
57
+ /**
58
+ * Source for the font to use in this layer.
59
+ *
60
+ * Can be a URL/path to a font file, or an existing TextmodeFont instance.
61
+ */
62
+ fontSource?: string | TextmodeFont;
53
63
  }
54
64
  /**
55
65
  * Dependencies required by a TextmodeLayer to function.
@@ -57,27 +67,12 @@ export interface TextmodeLayerOptions {
57
67
  */
58
68
  export interface LayerDependencies {
59
69
  renderer: GLRenderer;
60
- grid: TextmodeGrid;
61
- font: TextmodeFont;
62
- createFramebuffer: (width: number, height: number, attachments?: number) => GLFramebuffer;
70
+ canvas: TextmodeCanvas;
71
+ createFramebuffer: (width: number, height: number, attachments?: number, options?: {
72
+ depth?: boolean;
73
+ }) => GLFramebuffer;
63
74
  /**
64
75
  * The shared filter manager for applying post-ASCII filters.
65
76
  */
66
77
  filterManager: TextmodeFilterManager;
67
- /**
68
- * Ping-pong buffers for layer filter chain processing (grid-sized).
69
- * Shared across all layers within the LayerManager.
70
- */
71
- layerPingPongBuffers: [GLFramebuffer, GLFramebuffer];
72
- /**
73
- * Optional external draw framebuffer. When provided, the layer will use this
74
- * instead of creating its own. Used for the base layer which shares the
75
- * main textmode draw framebuffer.
76
- */
77
- externalDrawFramebuffer?: GLFramebuffer;
78
- /**
79
- * Optional external ASCII framebuffer. When provided, the layer will use this
80
- * instead of creating its own. Used for the base layer.
81
- */
82
- externalAsciiFramebuffer?: GLFramebuffer;
83
78
  }
@@ -0,0 +1,123 @@
1
+ import type { Material } from '../../rendering/webgl/materials/Material';
2
+ import type { TextmodeConversionMode } from '../conversion';
3
+ import type { TextmodeColor } from '../TextmodeColor';
4
+ import type { TextmodeFont } from './font/TextmodeFont';
5
+ /**
6
+ * Base interface for drawable textmode sources (images, videos, canvas, etc.).
7
+ * Handles shared WebGL texture state, material creation, and color/character settings.
8
+ */
9
+ export interface ITextmodeSource {
10
+ /**
11
+ * Select the conversion mode for this source.
12
+ *
13
+ * `textmode.js` includes only a single built-in conversion strategy `'brightness'`.
14
+ *
15
+ * Additional conversion strategies may be provided via add-on libraries.
16
+ *
17
+ * @param mode Conversion mode to use.
18
+ */
19
+ conversionMode(mode: TextmodeConversionMode): this;
20
+ /**
21
+ * Dispose of the underlying WebGL texture. Subclasses may extend for additional cleanup.
22
+ * @ignore
23
+ */
24
+ $dispose(): void;
25
+ /**
26
+ * Set the invert flag, swapping character and cell colors when enabled.
27
+ * @param v Invert flag
28
+ * @returns This instance for chaining.
29
+ */
30
+ invert(v?: boolean | number): this;
31
+ /**
32
+ * Set horizontal flip indicator flag.
33
+ * @param v Flip flag
34
+ * @returns This instance for chaining.
35
+ */
36
+ flipX(v?: boolean | number): this;
37
+ /**
38
+ * Set vertical flip indicator flag.
39
+ * @param v Flip flag
40
+ * @returns This instance for chaining.
41
+ */
42
+ flipY(v?: boolean | number): this;
43
+ /**
44
+ * Set the character rotation in degrees (0-360).
45
+ * @param degrees Rotation in degrees
46
+ * @returns This instance for chaining.
47
+ */
48
+ charRotation(degrees: number): this;
49
+ /**
50
+ * Set character color mode: `'sampled'` *(from source)* or `'fixed'`.
51
+ * @param mode The character color mode
52
+ * @returns This instance for chaining.
53
+ */
54
+ charColorMode(mode: 'sampled' | 'fixed'): this;
55
+ /**
56
+ * Set cell color mode: `'sampled'` *(from source)* or `'fixed'`.
57
+ * @param mode The cell color mode
58
+ * @returns This instance for chaining.
59
+ */
60
+ cellColorMode(mode: 'sampled' | 'fixed'): this;
61
+ /**
62
+ * Defines the character color when {@link charColorMode} is `'fixed'`.
63
+ * @param colorOrGray A grayscale value (0-255), hex string ('#RGB', '#RRGGBB', '#RRGGBBAA'), or TextmodeColor instance
64
+ * @param g Green component (0-255) if using RGB format
65
+ * @param b Blue component (0-255) if using RGB format
66
+ * @param a Alpha component (0-255) if using RGBA format
67
+ * @returns This instance for chaining.
68
+ */
69
+ charColor(colorOrGray: number | string | TextmodeColor, g?: number, b?: number, a?: number): this;
70
+ /**
71
+ * Defines the cell color when {@link cellColorMode} is `'fixed'`.
72
+ * @param colorOrGray A grayscale value (0-255), hex string ('#RGB', '#RRGGBB', '#RRGGBBAA'), or TextmodeColor instance
73
+ * @param g Green component (0-255) if using RGB format
74
+ * @param b Blue component (0-255) if using RGB format
75
+ * @param a Alpha component (0-255) if using RGBA format
76
+ * @returns This instance for chaining.
77
+ */
78
+ cellColor(colorOrGray: number | string | TextmodeColor, g?: number, b?: number, a?: number): this;
79
+ /**
80
+ * Defines the background color used for transparent pixels.
81
+ * @param colorOrGray A grayscale value (0-255), hex string ('#RGB', '#RRGGBB', '#RRGGBBAA'), or TextmodeColor instance
82
+ * @param g Green component (0-255) if using RGB format
83
+ * @param b Blue component (0-255) if using RGB format
84
+ * @param a Alpha component (0-255) if using RGBA format
85
+ * @returns This instance for chaining.
86
+ */
87
+ background(colorOrGray: number | TextmodeColor | string, g?: number, b?: number, a?: number): this;
88
+ /**
89
+ * Define the characters to use for brightness mapping as a string.
90
+ * Maximum length is 255; excess characters are ignored.
91
+ * @param chars String of characters to map
92
+ * @returns This instance for chaining.
93
+ */
94
+ characters(chars: string): this;
95
+ /**
96
+ * Set the active font for the current render pass.
97
+ * Called by the renderer before getMaterial() to ensure the source uses the correct layer's font.
98
+ * @param font The font to use for this render
99
+ * @ignore
100
+ */
101
+ $setActiveFont(font: TextmodeFont): void;
102
+ /** Return the WebGL texture currently backing this source. */
103
+ readonly texture: WebGLTexture;
104
+ /** Ideal width in grid cells. */
105
+ readonly width: number;
106
+ /** Ideal height in grid cells. */
107
+ readonly height: number;
108
+ /** Original pixel width. */
109
+ readonly originalWidth: number;
110
+ /** Original pixel height. */
111
+ readonly originalHeight: number;
112
+ /**
113
+ * Get or create the material for rendering this source.
114
+ * @ignore
115
+ */
116
+ $getMaterial(): Material;
117
+ /**
118
+ * Create base conversion uniforms shared across all strategies.
119
+ * @returns Uniforms object
120
+ * @ignore
121
+ */
122
+ createBaseConversionUniforms(): Record<string, any>;
123
+ }
@@ -1,6 +1,6 @@
1
1
  import type { GLRenderer } from '../../rendering/webgl/core/Renderer';
2
- import type { TextmodeFont } from './font/TextmodeFont';
3
2
  import { TextmodeSource } from './TextmodeSource';
3
+ import type { TextmodeConversionManager } from '../conversion';
4
4
  /**
5
5
  * Represents an image uploaded for textmode rendering via {@link Textmodifier.loadImage}.
6
6
  *
@@ -43,6 +43,6 @@ export declare class TextmodeImage extends TextmodeSource {
43
43
  * Texture parameters use NEAREST and CLAMP to align with grid sampling.
44
44
  * @ignore
45
45
  */
46
- static $fromSource(renderer: GLRenderer, font: TextmodeFont, source: HTMLImageElement | HTMLCanvasElement | HTMLVideoElement, gridCols: number, gridRows: number): TextmodeImage;
46
+ static $fromSource(renderer: GLRenderer, conversionManager: TextmodeConversionManager, source: HTMLImageElement | HTMLCanvasElement | HTMLVideoElement, gridCols: number, gridRows: number): TextmodeImage;
47
47
  protected $getActiveTexture(): WebGLTexture;
48
48
  }
@@ -2,13 +2,10 @@ import type { GLRenderer } from '../../rendering/webgl/core/Renderer';
2
2
  import type { Material } from '../../rendering/webgl/materials/Material';
3
3
  import { TextmodeColor } from '../TextmodeColor';
4
4
  import type { TextmodeFont } from './font/TextmodeFont';
5
- import { type TextmodeConversionMode } from '../conversion';
5
+ import type { ITextmodeSource } from './ITextmodeSource';
6
+ import type { TextmodeConversionMode, TextmodeConversionManager } from '../conversion';
6
7
  type GlyphColor = [number, number, number];
7
- /**
8
- * Base class for drawable textmode sources (images, videos, canvas, etc.).
9
- * Handles shared WebGL texture state, material creation, and color/character settings.
10
- */
11
- export declare abstract class TextmodeSource {
8
+ export declare abstract class TextmodeSource implements ITextmodeSource {
12
9
  protected _gl: WebGL2RenderingContext;
13
10
  protected _renderer: GLRenderer;
14
11
  protected _texture: WebGLTexture;
@@ -17,9 +14,10 @@ export declare abstract class TextmodeSource {
17
14
  protected _width: number;
18
15
  protected _height: number;
19
16
  protected _material: Material | null;
20
- protected _font: TextmodeFont;
17
+ protected _activeFont: TextmodeFont | null;
21
18
  protected _conversionMode: TextmodeConversionMode;
22
19
  private _cachedConversionStrategy;
20
+ private _conversionManager;
23
21
  protected _invert: number;
24
22
  protected _flipX: number;
25
23
  protected _flipY: number;
@@ -31,143 +29,37 @@ export declare abstract class TextmodeSource {
31
29
  protected _backgroundColor: [number, number, number, number];
32
30
  protected _glyphColors: GlyphColor[];
33
31
  private _characterString;
34
- private _disposeListeners;
35
- private _colorFilterPalette;
36
- private _colorFilterSize;
37
- protected constructor(gl: WebGL2RenderingContext, renderer: GLRenderer, texture: WebGLTexture, font: TextmodeFont, originalWidth: number, originalHeight: number, width: number, height: number);
38
- /**
39
- * Select the conversion mode for this source.
40
- *
41
- * `textmode.js` includes only a single built-in conversion strategy `'brightness'`.
42
- *
43
- * Additional conversion strategies may be provided via add-on libraries.
44
- *
45
- * @param mode Conversion mode to use.
46
- */
32
+ protected constructor(gl: WebGL2RenderingContext, renderer: GLRenderer, texture: WebGLTexture, conversionManager: TextmodeConversionManager, originalWidth: number, originalHeight: number, width: number, height: number);
47
33
  conversionMode(mode: TextmodeConversionMode): this;
48
- /**
49
- * Dispose of the underlying WebGL texture. Subclasses may extend for additional cleanup.
50
- * @ignore
51
- */
52
34
  $dispose(): void;
53
- /**
54
- * Register a callback to be invoked when this source is disposed.
55
- * @param callback The callback function to register
56
- * @ignore
57
- */
58
- $onDispose(callback: () => void): void;
59
- /**
60
- * Set the invert flag, swapping character and cell colors when enabled.
61
- * @param v Invert flag
62
- * @returns This instance for chaining.
63
- */
64
35
  invert(v?: boolean | number): this;
65
- /**
66
- * Set horizontal flip indicator flag.
67
- * @param v Flip flag
68
- * @returns This instance for chaining.
69
- */
70
36
  flipX(v?: boolean | number): this;
71
- /**
72
- * Set vertical flip indicator flag.
73
- * @param v Flip flag
74
- * @returns This instance for chaining.
75
- */
76
37
  flipY(v?: boolean | number): this;
77
- /**
78
- * Set the character rotation in degrees (0-360).
79
- * @param degrees Rotation in degrees
80
- * @returns This instance for chaining.
81
- */
82
38
  charRotation(degrees: number): this;
83
- /**
84
- * Set character color mode: `'sampled'` *(from source)* or `'fixed'`.
85
- * @param mode The character color mode
86
- * @returns This instance for chaining.
87
- */
88
39
  charColorMode(mode: 'sampled' | 'fixed'): this;
89
- /**
90
- * Set cell color mode: `'sampled'` *(from source)* or `'fixed'`.
91
- * @param mode The cell color mode
92
- * @returns This instance for chaining.
93
- */
94
40
  cellColorMode(mode: 'sampled' | 'fixed'): this;
95
- /**
96
- * Defines the character color when {@link charColorMode} is `'fixed'`.
97
- * @param colorOrGray A grayscale value (0-255), hex string ('#RGB', '#RRGGBB', '#RRGGBBAA'), or TextmodeColor instance
98
- * @param g Green component (0-255) if using RGB format
99
- * @param b Blue component (0-255) if using RGB format
100
- * @param a Alpha component (0-255) if using RGBA format
101
- * @returns This instance for chaining.
102
- */
103
41
  charColor(colorOrGray: number | string | TextmodeColor, g?: number, b?: number, a?: number): this;
104
- /**
105
- * Defines the cell color when {@link cellColorMode} is `'fixed'`.
106
- * @param colorOrGray A grayscale value (0-255), hex string ('#RGB', '#RRGGBB', '#RRGGBBAA'), or TextmodeColor instance
107
- * @param g Green component (0-255) if using RGB format
108
- * @param b Blue component (0-255) if using RGB format
109
- * @param a Alpha component (0-255) if using RGBA format
110
- * @returns This instance for chaining.
111
- */
112
42
  cellColor(colorOrGray: number | string | TextmodeColor, g?: number, b?: number, a?: number): this;
113
- /**
114
- * Defines the background color used for transparent pixels.
115
- * @param colorOrGray A grayscale value (0-255), hex string ('#RGB', '#RRGGBB', '#RRGGBBAA'), or TextmodeColor instance
116
- * @param g Green component (0-255) if using RGB format
117
- * @param b Blue component (0-255) if using RGB format
118
- * @param a Alpha component (0-255) if using RGBA format
119
- * @returns This instance for chaining.
120
- */
121
43
  background(colorOrGray: number | TextmodeColor | string, g?: number, b?: number, a?: number): this;
122
- /**
123
- * Applies an optional color filter palette before MRT conversion.
124
- * When a palette is provided, all sampled pixels are quantized to the closest palette color
125
- * prior to character/color analysis.
126
- *
127
- * @param palette A list of colors defined as {@link TextmodeColor} instances, hex strings, or RGBA tuples (0-255).
128
- * Providing an empty array or `null` disables the filter.
129
- */
130
- colorFilter(palette?: TextmodeColor[] | string[] | [number, number, number][] | [number, number, number, number][] | null): this;
131
- /**
132
- * Define the characters to use for brightness mapping as a string.
133
- * Maximum length is 255; excess characters are ignored.
134
- * @param chars String of characters to map
135
- * @returns This instance for chaining.
136
- */
137
44
  characters(chars: string): this;
138
45
  /**
139
- * Handle font change notification from the Textmodifier.
140
- * @param font The new font
46
+ * Set the active font for the current render pass.
47
+ * Called by the renderer before getMaterial() to ensure the source uses the correct layer's font.
48
+ * @param font The font to use for this render
141
49
  * @ignore
142
50
  */
143
- $handleFontChange(font: TextmodeFont): void;
144
- /** Return the WebGL texture currently backing this source. */
51
+ $setActiveFont(font: TextmodeFont): void;
145
52
  get texture(): WebGLTexture;
146
- /** Ideal width in grid cells. */
147
53
  get width(): number;
148
- /** Ideal height in grid cells. */
149
54
  get height(): number;
150
- /** Original pixel width. */
151
55
  get originalWidth(): number;
152
- /** Original pixel height. */
153
56
  get originalHeight(): number;
154
- /**
155
- * Get or create the material for rendering this source.
156
- * @ignore
157
- */
158
57
  $getMaterial(): Material;
159
- /** Hook for subclasses to run logic before material updates (e.g., upload latest frame). */
160
58
  protected $beforeMaterialUpdate(): void;
161
- /** Subclasses must supply the active texture handle to bind as u_image. */
162
59
  protected abstract $getActiveTexture(): WebGLTexture;
163
60
  private _updateMaterial;
164
61
  private _setColor;
165
62
  private _applyCharacterPalette;
166
- /**
167
- * Create base conversion uniforms shared across all strategies.
168
- * @returns Uniforms object
169
- * @ignore
170
- */
171
63
  createBaseConversionUniforms(): Record<string, any>;
172
64
  private _getActiveConversionStrategy;
173
65
  private _createConversionContext;
@@ -3,7 +3,7 @@ import type { TyprFont } from './typr/types.ts';
3
3
  * Handles extraction of characters from font cmap tables.
4
4
  * This class encapsulates the complex logic for reading different cmap table formats.
5
5
  */
6
- export declare class CharacterExtraction {
6
+ export declare class CharacterExtractor {
7
7
  /**
8
8
  * Extracts all available characters from a font's cmap tables.
9
9
  * @param font The parsed font object from Typr
@@ -25,6 +25,7 @@ export declare class TextmodeFont {
25
25
  private _textureAtlas;
26
26
  private _metricsCalculator;
27
27
  private _characterColorMapper;
28
+ private _isInitialized;
28
29
  /**
29
30
  * Creates a new TextmodeFont instance.
30
31
  * @param renderer Renderer instance for texture creation
@@ -81,6 +82,8 @@ export declare class TextmodeFont {
81
82
  * @ignore
82
83
  */
83
84
  $dispose(): void;
85
+ /** Returns whether this font has been initialized. @ignore */
86
+ get $isInitialized(): boolean;
84
87
  /** Returns the WebGL framebuffer containing the font texture atlas. */
85
88
  get fontFramebuffer(): GLFramebuffer;
86
89
  /** Returns the character map for O(1) lookups. */
@@ -1,8 +1,8 @@
1
1
  export { TextmodeFont } from './TextmodeFont.ts';
2
2
  export type { TextmodeCharacter, GlyphDimensions } from './types.ts';
3
- export type { TyprFont, CmapTable, CmapTableFormat4, CmapTableFormat12, HeadTable, HheaTable, HmtxTable, MaxpTable, CmapData, GlyphData, LocaTable, TyprStatic } from './typr/types.ts';
3
+ export type { TyprFont, CmapTable, CmapTableFormat4, CmapTableFormat12, HeadTable, HheaTable, HmtxTable, MaxpTable, CmapData, GlyphData, LocaTable, TyprStatic, } from './typr/types.ts';
4
4
  export { default as Typr } from './typr/Typr.ts';
5
- export { CharacterExtraction } from './CharacterExtractor.ts';
5
+ export { CharacterExtractor } from './CharacterExtractor.ts';
6
6
  export { TextureAtlas as TextureAtlasCreation } from './TextureAtlas.ts';
7
7
  export { FontMetricsCalculator as MetricsCalculation } from './MetricsCalculator.ts';
8
8
  export { CharacterColorMapper as CharacterColorMapping } from './CharacterColorMapper.ts';
@@ -2,5 +2,3 @@ export { TextmodeImage } from './TextmodeImage';
2
2
  export { TextmodeVideo } from './video/TextmodeVideo';
3
3
  export { TextmodeFont } from './font/TextmodeFont';
4
4
  export type { TextmodeCharacter } from './font/types';
5
- export type { TextmodeVideoOptions } from './video/TextmodeVideo';
6
- export type { TextmodeConversionMode } from '../conversion';
@@ -0,0 +1,75 @@
1
+ import type { Material } from '../../../rendering/webgl/materials/Material';
2
+ import type { ITextmodeSource } from '../ITextmodeSource';
3
+ export interface ITextmodeVideo extends ITextmodeSource {
4
+ /**
5
+ * Dispose of GPU resources and cleanup video element.
6
+ * @ignore
7
+ */
8
+ $dispose(): void;
9
+ /**
10
+ * Update the texture with the current video frame if needed.
11
+ * For preloaded videos, this returns the appropriate frame texture.
12
+ * For live videos, this updates the texture with current video data.
13
+ * @ignore
14
+ */
15
+ $updateTexture(): void;
16
+ /**
17
+ * Get or create the material for rendering this video.
18
+ * Always updates the material to ensure the latest video frame is used.
19
+ * @ignore
20
+ */
21
+ $getMaterial(): Material;
22
+ /**
23
+ * Play the video.
24
+ * @returns Promise that resolves when playback starts
25
+ */
26
+ play(): Promise<void>;
27
+ /**
28
+ * Pause the video.
29
+ */
30
+ pause(): void;
31
+ /**
32
+ * Stop the video and reset to beginning.
33
+ */
34
+ stop(): void;
35
+ /**
36
+ * Set the playback speed.
37
+ * @param rate Playback rate (1.0 = normal speed)
38
+ */
39
+ speed(rate: number): this;
40
+ /**
41
+ * Set whether the video should loop.
42
+ * @param shouldLoop Whether to loop (defaults to true)
43
+ */
44
+ loop(shouldLoop?: boolean): this;
45
+ /**
46
+ * Set the current time position in the video.
47
+ * @param seconds Time in seconds
48
+ */
49
+ time(seconds: number): this;
50
+ /**
51
+ * Set the volume.
52
+ * @param level Volume level (0.0-1.0)
53
+ */
54
+ volume(level: number): this;
55
+ /**
56
+ * WebGL texture handle containing the current video frame.
57
+ */
58
+ readonly texture: WebGLTexture;
59
+ /**
60
+ * The underlying HTML video element.
61
+ */
62
+ readonly videoElement: HTMLVideoElement;
63
+ /**
64
+ * Current playback time in seconds.
65
+ */
66
+ readonly currentTime: number;
67
+ /**
68
+ * Total duration of the video in seconds.
69
+ */
70
+ readonly duration: number;
71
+ /**
72
+ * Whether the video is currently playing.
73
+ */
74
+ readonly isPlaying: boolean;
75
+ }