textmode.js 0.4.0 → 0.6.0-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.
Files changed (105) hide show
  1. package/dist/textmode.esm.js +2868 -2164
  2. package/dist/textmode.esm.min.js +2863 -2159
  3. package/dist/textmode.umd.js +11 -8
  4. package/dist/textmode.umd.min.js +11 -8
  5. package/dist/types/Textmode.d.ts +13 -22
  6. package/dist/types/index.d.ts +8 -6
  7. package/dist/types/rendering/index.d.ts +3 -3
  8. package/dist/types/rendering/webgl/batching/DrawQueue.d.ts +89 -0
  9. package/dist/types/rendering/webgl/{VAOManager.d.ts → batching/GeometryAttributeCache.d.ts} +4 -4
  10. package/dist/types/rendering/webgl/batching/InstanceAttributeBinder.d.ts +87 -0
  11. package/dist/types/rendering/webgl/{InstanceBatch.d.ts → batching/InstanceBatch.d.ts} +25 -34
  12. package/dist/types/rendering/webgl/batching/InstanceBuffer.d.ts +78 -0
  13. package/dist/types/rendering/webgl/{InstanceData.d.ts → batching/InstanceData.d.ts} +11 -18
  14. package/dist/types/rendering/webgl/batching/InstanceWriter.d.ts +70 -0
  15. package/dist/types/rendering/webgl/{Framebuffer.d.ts → core/Framebuffer.d.ts} +37 -39
  16. package/dist/types/rendering/webgl/core/Renderer.d.ts +64 -0
  17. package/dist/types/rendering/webgl/{Shader.d.ts → core/Shader.d.ts} +2 -23
  18. package/dist/types/rendering/webgl/core/interfaces/IFramebuffer.d.ts +103 -0
  19. package/dist/types/rendering/webgl/core/interfaces/IRenderer.d.ts +210 -0
  20. package/dist/types/rendering/webgl/geometries/{Arc.d.ts → 2d/Arc.d.ts} +5 -4
  21. package/dist/types/rendering/webgl/geometries/{BezierCurve.d.ts → 2d/BezierCurve.d.ts} +5 -4
  22. package/dist/types/rendering/webgl/geometries/{Ellipse.d.ts → 2d/Ellipse.d.ts} +6 -5
  23. package/dist/types/rendering/webgl/geometries/{Line.d.ts → 2d/Line.d.ts} +5 -4
  24. package/dist/types/rendering/webgl/geometries/{Rectangle.d.ts → 2d/Rectangle.d.ts} +5 -4
  25. package/dist/types/rendering/webgl/geometries/{Triangle.d.ts → 2d/Triangle.d.ts} +5 -4
  26. package/dist/types/rendering/webgl/geometries/BaseGeometry.d.ts +30 -26
  27. package/dist/types/rendering/webgl/geometries/immediate/ImmediateQuad.d.ts +33 -0
  28. package/dist/types/rendering/webgl/geometries/index.d.ts +6 -6
  29. package/dist/types/rendering/webgl/geometries/utils/GeometryDescriptors.d.ts +31 -0
  30. package/dist/types/rendering/webgl/geometries/utils/GeometryGenerator.d.ts +16 -0
  31. package/dist/types/rendering/webgl/index.d.ts +15 -14
  32. package/dist/types/rendering/webgl/materials/Material.d.ts +26 -0
  33. package/dist/types/rendering/webgl/materials/MaterialManager.d.ts +63 -0
  34. package/dist/types/rendering/webgl/materials/index.d.ts +2 -0
  35. package/dist/types/rendering/webgl/pipeline/MaterialBatchPipeline.d.ts +63 -0
  36. package/dist/types/rendering/webgl/pipeline/index.d.ts +7 -0
  37. package/dist/types/rendering/webgl/state/RenderState.d.ts +143 -0
  38. package/dist/types/rendering/webgl/types/DrawCommand.d.ts +5 -3
  39. package/dist/types/rendering/webgl/types/GeometryTypes.d.ts +10 -10
  40. package/dist/types/rendering/webgl/types/RenderTypes.d.ts +1 -1
  41. package/dist/types/rendering/webgl/utils/GLUtils.d.ts +45 -0
  42. package/dist/types/rendering/webgl/utils/hash.d.ts +118 -0
  43. package/dist/types/textmode/AnimationController.d.ts +11 -21
  44. package/dist/types/textmode/Canvas.d.ts +10 -2
  45. package/dist/types/textmode/Grid.d.ts +2 -0
  46. package/dist/types/textmode/TextmodeColor.d.ts +57 -0
  47. package/dist/types/textmode/Textmodifier.d.ts +40 -212
  48. package/dist/types/textmode/interfaces/ITextmodifier.d.ts +272 -0
  49. package/dist/types/textmode/interfaces/index.d.ts +1 -0
  50. package/dist/types/textmode/loadables/TextmodeImage.d.ts +21 -0
  51. package/dist/types/textmode/loadables/TextmodeSource.d.ts +130 -0
  52. package/dist/types/textmode/loadables/TextmodeVideo.d.ts +237 -0
  53. package/dist/types/textmode/{font → loadables/font}/CharacterColorMapper.d.ts +1 -1
  54. package/dist/types/textmode/{font → loadables/font}/CharacterExtractor.d.ts +0 -10
  55. package/dist/types/textmode/{font → loadables/font}/TextmodeFont.d.ts +6 -3
  56. package/dist/types/textmode/{font → loadables/font}/TextureAtlas.d.ts +4 -11
  57. package/dist/types/textmode/{font → loadables/font}/typr/types.d.ts +0 -6
  58. package/dist/types/textmode/loadables/index.d.ts +5 -0
  59. package/dist/types/textmode/loading/LoadingPhaseTracker.d.ts +20 -0
  60. package/dist/types/textmode/loading/LoadingScreenManager.d.ts +170 -0
  61. package/dist/types/textmode/loading/LoadingScreenState.d.ts +22 -0
  62. package/dist/types/textmode/loading/LoadingScreenTheme.d.ts +26 -0
  63. package/dist/types/textmode/loading/LoadingScreenTransition.d.ts +17 -0
  64. package/dist/types/textmode/loading/index.d.ts +6 -0
  65. package/dist/types/textmode/loading/templates/SpinnerTemplate.d.ts +2 -0
  66. package/dist/types/textmode/loading/templates/index.d.ts +1 -0
  67. package/dist/types/textmode/loading/types.d.ts +251 -0
  68. package/dist/types/textmode/managers/KeyboardManager.d.ts +2 -3
  69. package/dist/types/textmode/managers/MouseManager.d.ts +1 -1
  70. package/dist/types/textmode/{plugins → managers}/PluginManager.d.ts +12 -15
  71. package/dist/types/textmode/managers/TouchManager.d.ts +0 -2
  72. package/dist/types/textmode/mixins/AnimationMixin.d.ts +2 -122
  73. package/dist/types/textmode/mixins/FontMixin.d.ts +2 -77
  74. package/dist/types/textmode/mixins/KeyboardMixin.d.ts +3 -85
  75. package/dist/types/textmode/mixins/MouseMixin.d.ts +3 -130
  76. package/dist/types/textmode/mixins/RenderingMixin.d.ts +2 -749
  77. package/dist/types/textmode/mixins/TextmodifierMixin.d.ts +2 -44
  78. package/dist/types/textmode/mixins/TouchMixin.d.ts +2 -187
  79. package/dist/types/textmode/mixins/index.d.ts +8 -8
  80. package/dist/types/textmode/mixins/interfaces/IAnimationMixin.d.ts +167 -0
  81. package/dist/types/textmode/mixins/interfaces/IFontMixin.d.ts +46 -0
  82. package/dist/types/textmode/mixins/interfaces/IKeyboardMixin.d.ts +235 -0
  83. package/dist/types/textmode/mixins/interfaces/IMouseMixin.d.ts +457 -0
  84. package/dist/types/textmode/mixins/interfaces/IRenderingMixin.d.ts +1085 -0
  85. package/dist/types/textmode/mixins/interfaces/ITouchMixin.d.ts +186 -0
  86. package/dist/types/textmode/types.d.ts +49 -0
  87. package/dist/types/textmode/utils/cssColor.d.ts +8 -0
  88. package/dist/types/utils/array.d.ts +34 -0
  89. package/dist/types/utils/math.d.ts +69 -0
  90. package/package.json +1 -1
  91. package/dist/types/rendering/webgl/DrawQueue.d.ts +0 -30
  92. package/dist/types/rendering/webgl/RenderPipeline.d.ts +0 -30
  93. package/dist/types/rendering/webgl/RenderState.d.ts +0 -73
  94. package/dist/types/rendering/webgl/Renderer.d.ts +0 -158
  95. package/dist/types/rendering/webgl/ShaderManager.d.ts +0 -66
  96. package/dist/types/rendering/webgl/geometries/NoiseGrid.d.ts +0 -1
  97. package/dist/types/textmode/TextmodeImage.d.ts +0 -161
  98. package/dist/types/textmode/mixins/ShaderMixin.d.ts +0 -1
  99. /package/dist/types/rendering/webgl/{StateCache.d.ts → utils/ViewportCache.d.ts} +0 -0
  100. /package/dist/types/textmode/{font → loadables/font}/MetricsCalculator.d.ts +0 -0
  101. /package/dist/types/textmode/{font → loadables/font}/index.d.ts +0 -0
  102. /package/dist/types/textmode/{font → loadables/font}/types.d.ts +0 -0
  103. /package/dist/types/textmode/{font → loadables/font}/typr/Typr.d.ts +0 -0
  104. /package/dist/types/textmode/{font → loadables/font}/utils/FontTableReader.d.ts +0 -0
  105. /package/dist/types/textmode/{font → loadables/font}/utils/index.d.ts +0 -0
@@ -1,4 +1,5 @@
1
- import type { TextmodeOptions } from "./Textmodifier";
1
+ import type { TextmodeOptions } from "./types";
2
+ import { type RGBA } from "./utils/cssColor";
2
3
  /**
3
4
  * Manages a `HTMLCanvasElement` for textmode rendering.
4
5
  * @ignore
@@ -7,7 +8,6 @@ export declare class TextmodeCanvas {
7
8
  private _canvas;
8
9
  private _targetCanvas;
9
10
  private _isOverlay;
10
- private _resizeObserver?;
11
11
  private _canvasCreatedByUs;
12
12
  /**
13
13
  * Creates a new TextmodeCanvas instance.
@@ -18,6 +18,13 @@ export declare class TextmodeCanvas {
18
18
  private _createCanvas;
19
19
  private _createOverlayCanvas;
20
20
  private _setupOverlayPositioning;
21
+ private _collectBackgroundSources;
22
+ /**
23
+ * Attempts to detect the background color behind the textmode canvas.
24
+ * Used internally for theming transparent UI elements like the loading screen.
25
+ * @ignore
26
+ */
27
+ $sampleBackgroundColor(): RGBA | null;
21
28
  private _positionOverlayCanvas;
22
29
  /**
23
30
  * Resize the canvas to the specified width and height.
@@ -38,6 +45,7 @@ export declare class TextmodeCanvas {
38
45
  * @ignore
39
46
  */
40
47
  $dispose(): void;
48
+ /** Getters */
41
49
  get canvas(): HTMLCanvasElement;
42
50
  get targetCanvas(): HTMLCanvasElement | HTMLVideoElement | null;
43
51
  get width(): number;
@@ -1,5 +1,7 @@
1
1
  /**
2
2
  * Manages the grid of a {@link Textmodifier} instance.
3
+ *
4
+ * Can be accessed via {@link Textmodifier.grid}.
3
5
  */
4
6
  export declare class TextmodeGrid {
5
7
  /** The number of columns in the grid. */
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Represents a color in the `textmode.js` rendering system.
3
+ *
4
+ * Values are stored as `0-255` integers for compatibility with public APIs,
5
+ * while normalized versions are derived on demand for shader uploads.
6
+ *
7
+ * Use {@link Textmodifier.color} to create colors.
8
+ */
9
+ export declare class TextmodeColor {
10
+ private readonly _rgba;
11
+ private readonly _normalized;
12
+ private readonly _character?;
13
+ /** Red component *(0-255)* */
14
+ readonly r: number;
15
+ /** Green component *(0-255)* */
16
+ readonly g: number;
17
+ /** Blue component *(0-255)* */
18
+ readonly b: number;
19
+ /** Alpha component *(0-255)* */
20
+ readonly a: number;
21
+ private constructor();
22
+ /**
23
+ * Create a color from RGB or RGBA components (0-255 range).
24
+ * @ignore
25
+ */
26
+ static $fromRGBA(r: number, g: number, b: number, a?: number): TextmodeColor;
27
+ /**
28
+ * Create a grayscale color. Optional alpha can be provided.
29
+ * @ignore
30
+ */
31
+ static $fromGray(gray: number, alpha?: number): TextmodeColor;
32
+ /**
33
+ * Create a color from a CSS-style hex string.
34
+ * @ignore
35
+ */
36
+ static $fromHex(hex: string): TextmodeColor;
37
+ /**
38
+ * Create a color representing a textmode character encoded as RGB triplet
39
+ * (values already normalized 0-1 for shader usage).
40
+ * @ignore
41
+ */
42
+ static $fromCharacter(characterColor: [number, number, number]): TextmodeColor;
43
+ /** Returns a plain RGB array with integer components. */
44
+ get rgb(): [number, number, number];
45
+ /** Returns a plain RGBA array with integer components. */
46
+ get rgba(): [number, number, number, number];
47
+ /** Returns the normalized *(0-1)* RGBA array. */
48
+ get normalized(): [number, number, number, number];
49
+ /** Returns the character encoding *(0-1 range)* if this color was created from a glyph. */
50
+ get character(): [number, number, number] | undefined;
51
+ /**
52
+ * Runtime type guard.
53
+ * @ignore
54
+ */
55
+ static $isColor(value: unknown): value is TextmodeColor;
56
+ }
57
+ export type ColorLike = TextmodeColor | [number, number, number] | [number, number, number, number];
@@ -1,97 +1,56 @@
1
- import { GLRenderer } from '../rendering/webgl/Renderer';
2
- import { TextmodeFont } from './font';
1
+ import { GLRenderer } from '../rendering/webgl/core/Renderer';
2
+ import { TextmodeFont } from './loadables/font';
3
3
  import { TextmodeGrid } from './Grid';
4
4
  import { TextmodeCanvas } from './Canvas';
5
- import { TextmodeImage } from './TextmodeImage';
5
+ import { TextmodeImage } from './loadables/TextmodeImage';
6
6
  import { AnimationController } from './AnimationController';
7
7
  import { MouseManager } from './managers/MouseManager';
8
8
  import { KeyboardManager } from './managers/KeyboardManager';
9
9
  import { TouchManager } from './managers/TouchManager';
10
- import { type TextmodifierContext } from './mixins';
11
- import { type TextmodePlugin, type TextmodePluginContext } from './plugins/PluginManager';
12
- import type { RenderingCapabilities } from './mixins/RenderingMixin';
13
- import type { FontCapabilities } from './mixins/FontMixin';
14
- import type { AnimationCapabilities } from './mixins/AnimationMixin';
15
- import type { MouseCapabilities } from './mixins/MouseMixin';
16
- import type { TouchCapabilities } from './mixins/TouchMixin';
17
- import type { KeyboardCapabilities } from './mixins/KeyboardMixin';
10
+ import type { ITextmodifier } from './interfaces';
18
11
  import type { GLFramebuffer, Shader } from '../rendering';
19
- /**
20
- * Options for creating a {@link Textmodifier} instance.
21
- */
22
- export type TextmodeOptions = {
23
- /**
24
- * An existing [HTMLCanvasElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement) to use instead of creating a new one.
25
- *
26
- * **Note:**
27
- * If using `overlay` mode, this should be the target canvas or video element to overlay on.
28
- * `textmode.js` will create its own canvas applied on top of the target element, always matching its size and position.
29
- */
30
- canvas?: HTMLCanvasElement;
31
- /** The font size to use for text rendering. Defaults to 16. */
32
- fontSize?: number;
33
- /** Maximum frames per second for auto rendering. Defaults to 60. */
34
- frameRate?: number;
35
- /** The width of the canvas when creating a new canvas. Defaults to 800. */
36
- width?: number;
37
- /** The height of the canvas when creating a new canvas. Defaults to 600. */
38
- height?: number;
39
- /**
40
- * URL or path to a custom font file *(.otf/.ttf)*.
41
- *
42
- * Required when using minified builds that don't include a default font.
43
- *
44
- * Optional for full builds *(will override embedded font if provided)*.
45
- */
46
- fontSource?: string;
47
- /**
48
- * Use `textmode.js` in overlay mode,
49
- * which sets up the textmode `<canvas>` on top of an existing HTMLCanvasElement or HTMLVideoElement,
50
- * automatically resizing and positioning it to match the target element.
51
- *
52
- * In this mode `textmode.js` fetches the content of the target element and applies it with adjustable textmode conversion
53
- * as a first layer to the textmode canvas.
54
- *
55
- * Useful for applying textmode conversion to p5.js sketches, YouTube videos, and sooo much more.
56
- *
57
- * All functionality of `textmode.js` remains available, including drawing additional content on top of the converted source.
58
- *
59
- */
60
- overlay?: boolean;
61
- /** List of plugins to install when the Textmodifier instance is created. */
62
- plugins?: TextmodePlugin[];
12
+ import type { TextmodeOptions } from './types';
13
+ import type { IAnimationMixin } from './mixins/interfaces/IAnimationMixin';
14
+ import type { IFontMixin } from './mixins/interfaces/IFontMixin';
15
+ import type { IRenderingMixin } from './mixins/interfaces/IRenderingMixin';
16
+ import type { IKeyboardMixin } from './mixins/interfaces/IKeyboardMixin';
17
+ import type { ITouchMixin } from './mixins/interfaces/ITouchMixin';
18
+ import type { IMouseMixin } from './mixins/interfaces/IMouseMixin';
19
+ import { LoadingScreenManager } from './loading/LoadingScreenManager';
20
+ declare const Textmodifier_base: {
21
+ new (): {};
63
22
  };
64
23
  /**
65
- * Base class for mixin application.
24
+ * Manages textmode rendering on a [`HTMLCanvasElement`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement) and provides methods for drawing,
25
+ * font management, event handling, and animation control.
26
+ *
27
+ * If the `Textmodifier` instance is created without a canvas parameter,
28
+ * it creates a new `HTMLCanvasElement` to draw on using the `textmode.js` drawing API.
29
+ * If a canvas is provided, it will use that canvas instead.
66
30
  */
67
- declare class TextmodifierCore implements TextmodifierContext {
31
+ export declare class Textmodifier extends Textmodifier_base implements ITextmodifier {
68
32
  _renderer: GLRenderer;
69
33
  _font: TextmodeFont;
34
+ _loadingFont: TextmodeFont;
70
35
  _canvas: TextmodeCanvas;
71
36
  _grid: TextmodeGrid;
37
+ _loadingGrid: TextmodeGrid;
72
38
  _animationController: AnimationController;
73
39
  _mouseManager: MouseManager;
74
40
  _touchManager: TouchManager;
75
41
  _keyboardManager: KeyboardManager;
76
- _textmodeDrawShader: Shader;
77
42
  _textmodeDrawFramebuffer: GLFramebuffer;
43
+ _loadingDrawFramebuffer: GLFramebuffer;
78
44
  _textmodeConversionShader: Shader;
79
- _asciiColorFramebuffer: GLFramebuffer;
45
+ _textmodeFramebuffer: GLFramebuffer;
46
+ _loadingFramebuffer: GLFramebuffer;
80
47
  _presentShader: Shader;
81
- $render(): void;
82
- }
83
- declare const Textmodifier_base: typeof TextmodifierCore;
84
- /**
85
- * Manages textmode rendering on a [`HTMLCanvasElement`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement) and provides methods for drawing,
86
- * exporting, font management, event handling, and animation control.
87
- *
88
- * If the `Textmodifier` instance is created without a canvas parameter,
89
- * it creates a new `HTMLCanvasElement` to draw on using the `textmode.js` drawing API.
90
- * If a canvas is provided, it will use that canvas instead.
91
- */
92
- export declare class Textmodifier extends Textmodifier_base {
93
48
  private _pluginManager;
49
+ _loading: LoadingScreenManager;
50
+ private _destroyRequested;
51
+ private _isRenderingFrame;
94
52
  private _isDisposed;
53
+ private _setupComplete;
95
54
  private _setupCallback;
96
55
  private _drawCallback;
97
56
  private _resizedCallback;
@@ -100,166 +59,35 @@ export declare class Textmodifier extends Textmodifier_base {
100
59
  private _isOverlay;
101
60
  private _targetCanvasImage?;
102
61
  /**
103
- * Creates an instance of Textmodifier.
104
- * @param opts Optional configuration options for the Textmodifier instance.
62
+ * Create a new Textmodifier instance.
63
+ * @param opts Configuration options for the Textmodifier instance.
105
64
  * @ignore
106
65
  */
107
66
  constructor(opts?: TextmodeOptions);
108
- /**
109
- * Internal async initialization method.
110
- * @param opts Configuration options
111
- */
112
67
  private _initialize;
113
68
  /**
114
- * Provide plugins with a minimal API surface so they can interact with the renderer safely.
115
- */
116
- $getPluginContext(): TextmodePluginContext;
117
- /**
118
- * Setup event listeners for resize handling.
69
+ * Setup event listeners for window resize and input handling.
119
70
  * @ignore
120
71
  */
121
72
  $setupEventListeners(): void;
122
- /**
123
- * Renders the current frame.
124
- * @returns void
125
- * @ignore
126
- */
127
73
  $render(): void;
128
- /**
129
- * Set a setup callback function that will be executed once when initialization is complete.
130
- *
131
- * This callback is called after font loading and grid initialization, allowing access to
132
- * properties like `textmodifier.grid.cols` for calculating layout or setup variables.
133
- *
134
- * @param callback The function to call when setup is complete
135
- *
136
- * @example
137
- * ```javascript
138
- * const textmodifier = textmode.create({
139
- * width: 800,
140
- * height: 600,
141
- * fontSize: 16
142
- * });
143
- *
144
- * // Setup callback - called once when ready
145
- * textmodifier.setup(() => {
146
- * // Now you can access grid properties
147
- * const cols = textmodifier.grid.cols;
148
- * const rows = textmodifier.grid.rows;
149
- *
150
- * // Initialize any variables that depend on grid size
151
- * cellWidth = Math.floor(cols / 3);
152
- * cellHeight = Math.floor(rows / 2);
153
- * });
154
- *
155
- * // Draw callback - called every frame
156
- * textmodifier.draw(() => {
157
- * textmodifier.background(128);
158
- * textmodifier.rect(0, 0, cellWidth, cellHeight);
159
- * });
160
- * ```
161
- */
162
- setup(callback: () => void): void;
163
- /**
164
- * Set a draw callback function that will be executed before each render.
165
- *
166
- * This callback function is where all drawing commands should be placed for textmode rendering.
167
- *
168
- * @param callback The function to call before each render
169
- *
170
- * @example
171
- * ```javascript
172
- * // Create a standalone textmodifier instance
173
- * const t = textmode.create({
174
- * width: 800,
175
- * height: 600,
176
- * });
177
- *
178
- * // Set up draw callback
179
- * t.draw(() => {
180
- * // Set background color
181
- * t.background(128);
182
- *
183
- * // Draw a textmode rectangle with default settings
184
- * t.rect(0, 0, 16, 16);
185
- * });
186
- * ```
187
- */
188
- draw(callback: () => void): void;
189
- /**
190
- * Set a callback function that will be called when the window is resized.
191
- * @param callback The function to call when the window is resized.
192
- *
193
- * @example
194
- * ```javascript
195
- * // Create a standalone textmodifier instance
196
- * const t = textmode.create({
197
- * width: window.innerWidth,
198
- * height: window.innerHeight,
199
- * });
200
- *
201
- * // Draw callback to update content
202
- * t.draw(() => {
203
- * // Set background color
204
- * t.background(128);
205
- *
206
- * t.rect(0, 0, t.grid.cols, t.grid.rows);
207
- * });
208
- *
209
- * // Set up window resize callback
210
- * t.windowResized(() => {
211
- * // Resize the canvas to match window size
212
- * t.resizeCanvas(window.innerWidth, window.innerHeight);
213
- * });
214
- *
215
- */
216
- windowResized(callback: () => void): void;
217
- /**
218
- * Resize the canvas and adjust all related components accordingly.
219
- *
220
- * @param width The new width of the canvas.
221
- * @param height The new height of the canvas.
222
- */
223
74
  resizeCanvas(width: number, height: number): void;
224
- /**
225
- * Completely destroy this Textmodifier instance and free all associated resources.
226
- *
227
- * After calling this method, the instance should not be used and will be eligible for garbage collection.
228
- *
229
- * @example
230
- * ```javascript
231
- * // Create a textmodifier instance
232
- * const textmodifier = textmode.create();
233
- *
234
- * // ...
235
- *
236
- * // When done, completely clean up
237
- * textmodifier.destroy();
238
- *
239
- * // Instance is now safely disposed and ready for garbage collection
240
- * ```
241
- */
242
75
  destroy(): void;
243
- /** Get the current grid object used for rendering. */
76
+ private _performDestroy;
77
+ /** Callbacks */
78
+ setup(callback: () => void | Promise<void>): void;
79
+ draw(callback: () => void): void;
80
+ windowResized(callback: () => void): void;
244
81
  get grid(): TextmodeGrid;
245
- /** Get the current font object used for rendering. */
246
82
  get font(): TextmodeFont;
247
- /** Get the width of the canvas. */
248
83
  get width(): number;
249
- /** Get the height of the canvas. */
250
84
  get height(): number;
251
- /** Get the textmodifier canvas containing the rendered output. */
252
85
  get canvas(): HTMLCanvasElement;
253
- /** Get the WebGL framebuffer used for drawing operations. */
254
86
  get drawFramebuffer(): GLFramebuffer;
255
- /** Check if the instance has been disposed/destroyed. */
256
87
  get isDisposed(): boolean;
257
- /**
258
- * If in overlay mode, returns the {@link TextmodeImage} instance capturing the target canvas/video content,
259
- * allowing further configuration of the conversion parameters.
260
- */
261
88
  get overlay(): TextmodeImage | undefined;
89
+ get loading(): LoadingScreenManager;
262
90
  }
263
- export interface Textmodifier extends RenderingCapabilities, FontCapabilities, AnimationCapabilities, MouseCapabilities, TouchCapabilities, KeyboardCapabilities {
91
+ export interface Textmodifier extends IRenderingMixin, IFontMixin, IAnimationMixin, IMouseMixin, ITouchMixin, IKeyboardMixin {
264
92
  }
265
93
  export {};
@@ -0,0 +1,272 @@
1
+ import type { TextmodeGrid } from '../Grid';
2
+ import type { TextmodeFont } from '../loadables/font';
3
+ import type { TextmodeImage } from '../loadables/TextmodeImage';
4
+ import type { TextmodeCanvas } from '../Canvas';
5
+ import type { AnimationController } from '../AnimationController';
6
+ import type { GLFramebuffer, Shader } from '../../rendering';
7
+ import type { GLRenderer } from '../../rendering/webgl/core/Renderer';
8
+ import type { MouseManager } from '../managers/MouseManager';
9
+ import type { KeyboardManager } from '../managers/KeyboardManager';
10
+ import type { TouchManager } from '../managers/TouchManager';
11
+ import type { IRenderingMixin } from '../mixins/interfaces/IRenderingMixin';
12
+ import type { IFontMixin } from '../mixins/interfaces/IFontMixin';
13
+ import type { IKeyboardMixin } from '../mixins/interfaces/IKeyboardMixin';
14
+ import type { ITouchMixin } from '../mixins/interfaces/ITouchMixin';
15
+ import type { IMouseMixin } from '../mixins/interfaces/IMouseMixin';
16
+ import type { IAnimationMixin } from '../mixins/interfaces/IAnimationMixin';
17
+ import type { LoadingScreenManager } from '../loading/LoadingScreenManager';
18
+ /**
19
+ * Manages textmode rendering on a [`HTMLCanvasElement`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement) and provides methods for drawing,
20
+ * exporting, font management, event handling, and animation control.
21
+ *
22
+ * If the `Textmodifier` instance is created without a canvas parameter,
23
+ * it creates a new `HTMLCanvasElement` to draw on using the `textmode.js` drawing API.
24
+ * If a canvas is provided, it will use that canvas instead.
25
+ */
26
+ export interface ITextmodifier extends IRenderingMixin, IFontMixin, IAnimationMixin, IMouseMixin, ITouchMixin, IKeyboardMixin {
27
+ /** Core WebGL renderer @ignore */
28
+ readonly _renderer: GLRenderer;
29
+ /** Font management @ignore */
30
+ readonly _font: TextmodeFont;
31
+ /** Canvas management @ignore */
32
+ readonly _canvas: TextmodeCanvas;
33
+ /** Grid management @ignore */
34
+ readonly _grid: TextmodeGrid;
35
+ /** Animation controller for managing rendering loop @ignore */
36
+ readonly _animationController: AnimationController;
37
+ /** Mouse interaction manager @ignore */
38
+ readonly _mouseManager: MouseManager;
39
+ /** Touch interaction manager @ignore */
40
+ readonly _touchManager: TouchManager;
41
+ /** Keyboard interaction manager @ignore */
42
+ readonly _keyboardManager: KeyboardManager;
43
+ /** Framebuffer used for offscreen rendering @ignore */
44
+ readonly _textmodeDrawFramebuffer: GLFramebuffer;
45
+ /** Shader used for converting pixels to textmode grid format @ignore */
46
+ readonly _textmodeConversionShader: Shader;
47
+ /** Framebuffer used for textmode conversion @ignore */
48
+ readonly _textmodeFramebuffer: GLFramebuffer;
49
+ /** Shader used for final presentation to the screen @ignore */
50
+ readonly _presentShader: Shader;
51
+ /** Loading screen manager for boot-time UX @ignore */
52
+ readonly _loading: LoadingScreenManager;
53
+ /** Main render method @ignore */
54
+ $render(): void;
55
+ /**
56
+ * Set a setup callback function that will be executed once when initialization is complete.
57
+ *
58
+ * This callback is called after font loading and grid initialization, allowing access to
59
+ * properties like `textmodifier.grid.cols` for calculating layout or setup variables.
60
+ *
61
+ * @param callback The function to call when setup is complete
62
+ *
63
+ * @example
64
+ * ```javascript
65
+ * const textmodifier = textmode.create({
66
+ * width: 800,
67
+ * height: 600,
68
+ * fontSize: 16
69
+ * });
70
+ *
71
+ * // Setup callback - called once when ready
72
+ * textmodifier.setup(() => {
73
+ * // Now you can access grid properties
74
+ * const cols = textmodifier.grid.cols;
75
+ * const rows = textmodifier.grid.rows;
76
+ *
77
+ * // Initialize any variables that depend on grid size
78
+ * cellWidth = Math.floor(cols / 3);
79
+ * cellHeight = Math.floor(rows / 2);
80
+ * });
81
+ *
82
+ * // Draw callback - called every frame
83
+ * textmodifier.draw(() => {
84
+ * textmodifier.background(128);
85
+ * textmodifier.rect(0, 0, cellWidth, cellHeight);
86
+ * });
87
+ * ```
88
+ */
89
+ setup(callback: () => void): void;
90
+ /**
91
+ * Set a draw callback function that will be executed before each render.
92
+ *
93
+ * This callback function is where all drawing commands should be placed for textmode rendering.
94
+ *
95
+ * @param callback The function to call before each render
96
+ *
97
+ * @example
98
+ * ```javascript
99
+ * // Create a textmodifier instance
100
+ * const t = textmode.create({
101
+ * width: 800,
102
+ * height: 600,
103
+ * });
104
+ *
105
+ * // Set up draw callback
106
+ * t.draw(() => {
107
+ * // Set background color
108
+ * t.background(128);
109
+ *
110
+ * // Draw a textmode rectangle
111
+ * t.char('A');
112
+ * t.rotateZ(t.frameCount * 2);
113
+ * t.rect(16, 16);
114
+ * });
115
+ * ```
116
+ */
117
+ draw(callback: () => void): void;
118
+ /**
119
+ * Set a callback function that will be called when the window is resized.
120
+ * @param callback The function to call when the window is resized.
121
+ *
122
+ * @example
123
+ * ```javascript
124
+ * // Create a standalone textmodifier instance
125
+ * const t = textmode.create({
126
+ * width: window.innerWidth,
127
+ * height: window.innerHeight,
128
+ * });
129
+ *
130
+ * // Draw callback to update content
131
+ * t.draw(() => {
132
+ * // Set background color
133
+ * t.background(128);
134
+ *
135
+ * t.rect(0, 0, t.grid.cols, t.grid.rows);
136
+ * });
137
+ *
138
+ * // Set up window resize callback
139
+ * t.windowResized(() => {
140
+ * // Resize the canvas to match window size
141
+ * t.resizeCanvas(window.innerWidth, window.innerHeight);
142
+ * });
143
+ *
144
+ */
145
+ windowResized(callback: () => void): void;
146
+ /**
147
+ * Resize the canvas and adjust all related components accordingly.
148
+ *
149
+ * @param width The new width of the canvas.
150
+ * @param height The new height of the canvas.
151
+ *
152
+ * @example
153
+ * ```javascript
154
+ * // Create a standalone textmodifier instance
155
+ * const t = textmode.create({
156
+ * width: window.innerWidth,
157
+ * height: window.innerHeight,
158
+ * });
159
+ *
160
+ * // Draw callback to update content
161
+ * t.draw(() => {
162
+ * // Set background color
163
+ * t.background(128);
164
+ * t.char('A');
165
+ * t.rotateZ(t.frameCount * 2);
166
+ * t.rect(16, 16);
167
+ * });
168
+ *
169
+ * // Set up window resize callback
170
+ * t.windowResized(() => {
171
+ * // Resize the canvas to match window size
172
+ * t.resizeCanvas(window.innerWidth, window.innerHeight);
173
+ * });
174
+ * ```
175
+ */
176
+ resizeCanvas(width: number, height: number): void;
177
+ /**
178
+ * Completely destroy this Textmodifier instance and free all associated resources.
179
+ *
180
+ * After calling this method, the instance should not be used and will be eligible for garbage collection.
181
+ *
182
+ * @example
183
+ * ```javascript
184
+ * // Create a textmodifier instance
185
+ * const textmodifier = textmode.create();
186
+ *
187
+ * // ...
188
+ *
189
+ * // When done, completely clean up
190
+ * textmodifier.destroy();
191
+ *
192
+ * // Instance is now safely disposed and ready for garbage collection
193
+ * ```
194
+ */
195
+ destroy(): void;
196
+ /** Get the current grid object used for rendering. */
197
+ readonly grid: TextmodeGrid;
198
+ /** Get the current font object used for rendering. */
199
+ readonly font: TextmodeFont;
200
+ /** Get the width of the canvas in pixels. */
201
+ readonly width: number;
202
+ /** Get the height of the canvas in pixels. */
203
+ readonly height: number;
204
+ /** Get the textmodifier canvas containing the rendered output. */
205
+ readonly canvas: HTMLCanvasElement;
206
+ /** Get the WebGL framebuffer used for drawing operations in {@link Textmodifier.draw}. */
207
+ readonly drawFramebuffer: GLFramebuffer;
208
+ /** Check if the instance has been disposed/destroyed. */
209
+ readonly isDisposed: boolean;
210
+ /**
211
+ * If in overlay mode, returns the {@link TextmodeImage} instance capturing the target canvas/video content,
212
+ * allowing further configuration of the conversion parameters.
213
+ *
214
+ * @example
215
+ * ```javascript
216
+ * // Create the textmode instance using the p5 canvas as input overlay
217
+ * const t = textmode.create({ fontSize: 16, canvas: p.canvas, overlay: true });
218
+ *
219
+ * // Configure overlay conversion once fonts and grid are ready
220
+ * t.setup(() => {
221
+ * t.overlay
222
+ * .characters(' .:-=+*#%@') // Character set for brightness mapping
223
+ * .cellColorMode('fixed') // Use fixed background cell color
224
+ * .cellColor(0, 0, 0) // Black background for each cell
225
+ * .charColorMode('sampled') // Sample the character color from the image
226
+ * .background(0, 0, 0, 255); // Black fallback for transparent pixels
227
+ * });
228
+ *
229
+ * // In the draw loop, pass the overlay into the text grid
230
+ * t.draw(() => {
231
+ * t.clear();
232
+ * t.image(t.overlay, t.grid.cols, t.grid.rows);
233
+ * });
234
+ *```
235
+ */
236
+ readonly overlay: TextmodeImage | undefined;
237
+ /**
238
+ * Provides access to the loading screen manager to control boot-time loading UX.
239
+ *
240
+ * @example
241
+ * ```javascript
242
+ * const t = textmode.create({ width: 800, height: 600, loadingScreen: { message: 'loading...' } });
243
+ *
244
+ * t.setup(async () => {
245
+ * // Initialize two loading phases
246
+ * const phase1 = t.loading.addPhase('Loading assets');
247
+ * const phase2 = t.loading.addPhase('Initializing game');
248
+ *
249
+ * // Start the first phase and simulate asset loading
250
+ * await phase1.track(async () => {
251
+ * for (let i = 0; i <= 5; i++) {
252
+ * phase1.report(i / 5);
253
+ * // Small delay — increases visibility of the loading animation
254
+ * await new Promise((r) => setTimeout(r, 200));
255
+ * }
256
+ * });
257
+ *
258
+ * // Start the second phase and simulate initialization
259
+ * await phase2.track(async () => {
260
+ * for (let i = 0; i <= 5; i++) {
261
+ * phase2.report(i / 5);
262
+ * await new Promise((r) => setTimeout(r, 150));
263
+ * }
264
+ * });
265
+ *
266
+ * // Optionally set a final message before the screen transitions away
267
+ * t.loading.message('Ready - enjoy!');
268
+ * });
269
+ * ```
270
+ */
271
+ readonly loading: LoadingScreenManager;
272
+ }
@@ -0,0 +1 @@
1
+ export type { ITextmodifier } from './ITextmodifier';