textmode.js 0.6.0-beta.4 → 0.6.0

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 (26) hide show
  1. package/dist/textmode.esm.js +1947 -2019
  2. package/dist/textmode.umd.js +11 -11
  3. package/dist/types/index.d.ts +1 -1
  4. package/dist/types/rendering/index.d.ts +1 -1
  5. package/dist/types/rendering/webgl/core/Renderer.d.ts +1 -4
  6. package/dist/types/rendering/webgl/core/Shader.d.ts +1 -2
  7. package/dist/types/rendering/webgl/materials/MaterialManager.d.ts +0 -1
  8. package/dist/types/textmode/TextmodeColor.d.ts +2 -13
  9. package/dist/types/textmode/Textmodifier.d.ts +4 -5
  10. package/dist/types/textmode/conversion/ConversionRegistry.d.ts +30 -2
  11. package/dist/types/textmode/interfaces/ITextmodifier.d.ts +5 -5
  12. package/dist/types/textmode/loadables/TextmodeImage.d.ts +1 -1
  13. package/dist/types/textmode/loadables/TextmodeSource.d.ts +21 -7
  14. package/dist/types/textmode/loadables/font/CharacterColorMapper.d.ts +11 -14
  15. package/dist/types/textmode/loadables/font/MetricsCalculator.d.ts +0 -4
  16. package/dist/types/textmode/loadables/font/TextmodeFont.d.ts +7 -19
  17. package/dist/types/textmode/loadables/font/TextureAtlas.d.ts +1 -9
  18. package/dist/types/textmode/loadables/font/index.d.ts +1 -1
  19. package/dist/types/textmode/loadables/font/types.d.ts +26 -2
  20. package/dist/types/textmode/loadables/font/utils/FontTableReader.d.ts +1 -12
  21. package/dist/types/textmode/loadables/index.d.ts +2 -4
  22. package/dist/types/textmode/loadables/{TextmodeVideo.d.ts → video/TextmodeVideo.d.ts} +8 -76
  23. package/dist/types/textmode/loadables/video/TextmodeVideoPreloader.d.ts +29 -0
  24. package/dist/types/textmode/loadables/video/types.d.ts +43 -0
  25. package/dist/types/textmode/mixins/interfaces/IRenderingMixin.d.ts +5 -13
  26. package/package.json +2 -1
@@ -1,45 +1,9 @@
1
- import type { GLRenderer } from '../../rendering/webgl/core/Renderer';
2
- import type { Material } from '../../rendering/webgl/materials/Material';
3
- import type { TextmodeFont } from './font/TextmodeFont';
4
- import { TextmodeSource } from './TextmodeSource';
5
- type TextmodeVideoPreloadStrategy = 'captureStream' | 'seeking';
6
- export interface TextmodeVideoPreloadProgress {
7
- percent: number;
8
- loadedFrames: number;
9
- totalFrames: number;
10
- strategy: TextmodeVideoPreloadStrategy;
11
- }
12
- export interface TextmodeVideoPreloadComplete {
13
- totalFrames: number;
14
- strategy: TextmodeVideoPreloadStrategy;
15
- }
16
- /**
17
- * Options for preloading video frames in {@link TextmodeVideo}.
18
- *
19
- * When providing this options object as a second argument to {@link Textmodifier.loadVideo},
20
- * you can choose to preload all video frames at a specified frame rate before using the video.
21
- *
22
- * When preloading, the video will not play live asynchronously. Instead, all frames will be captured
23
- * upfront, allowing for frame-accurate seeking and rendering.
24
- *
25
- * This is especially useful for scenarios where precise frame control is needed,
26
- * like capturing GIFs/videos from textmode.js canvas using the `textmode.export.js` add-on library without
27
- * missing frames due to asynchronous video playback.
28
- *
29
- * Preloading takes time proportional to the video length and frame rate, which introduces significant delays
30
- * before the sketch can start rendering. Therefore, it is recommended to use this feature only when intending
31
- * to capture or export frames, rather than for real-time playback.
32
- */
33
- export interface TextmodeVideoOptions {
34
- /** Frame rate to use when preloading video frames. If not specified, video will not be preloaded. */
35
- frameRate?: number;
36
- /** Callback invoked periodically during preloading to report progress. */
37
- onProgress?: (progress: TextmodeVideoPreloadProgress) => void;
38
- /** Callback invoked once preloading is complete. */
39
- onComplete?: (summary: TextmodeVideoPreloadComplete) => void;
40
- /** Callback invoked if an error occurs during preloading. */
41
- onError?: (error: Error) => void;
42
- }
1
+ import type { GLRenderer } from '../../../rendering/webgl/core/Renderer';
2
+ import type { Material } from '../../../rendering/webgl/materials/Material';
3
+ import type { TextmodeFont } from '../font/TextmodeFont';
4
+ import { TextmodeSource } from '../TextmodeSource';
5
+ import type { TextmodeVideoOptions } from './types';
6
+ export type { TextmodeVideoOptions, TextmodeVideoPreloadStrategy, TextmodeVideoPreloadProgress, TextmodeVideoPreloadComplete, } from './types';
43
7
  /**
44
8
  * Represents a video element for textmode rendering via {@link Textmodifier.loadVideo}.
45
9
  *
@@ -79,12 +43,8 @@ export interface TextmodeVideoOptions {
79
43
  */
80
44
  export declare class TextmodeVideo extends TextmodeSource {
81
45
  private _videoElement;
82
- private _isPreloaded;
83
- private _preloadedFrames;
84
- private _frameRate;
85
- private _totalFrames;
86
46
  private _currentFrameIndex;
87
- private _lastProgressBucket;
47
+ private _preloader;
88
48
  /**
89
49
  * Create a new TextmodeVideo instance.
90
50
  * @param gl WebGL2 rendering context
@@ -125,20 +85,6 @@ export declare class TextmodeVideo extends TextmodeSource {
125
85
  */
126
86
  $getMaterial(): Material;
127
87
  protected $beforeMaterialUpdate(): void;
128
- /**
129
- * Preload all frames of the video at the specified frame rate.
130
- * Chooses the most optimal strategy based on browser capabilities.
131
- * @param frameRate Frame rate to use for capturing frames
132
- * @ignore
133
- */
134
- private _preloadFrames;
135
- private _initializePreloadState;
136
- private _finalizePreloadSuccess;
137
- private _captureSourceToTexture;
138
- private _reportPreloadProgress;
139
- private _tryPreloadWithTrackProcessor;
140
- private _preloadWithLegacySeeking;
141
- private _waitForSeek;
142
88
  /**
143
89
  * For preloaded videos, set or get the current frame index.
144
90
  * When called without arguments, returns this video instance for use with t.image().
@@ -171,12 +117,11 @@ export declare class TextmodeVideo extends TextmodeSource {
171
117
  * @param source Video URL string or HTMLVideoElement
172
118
  * @param gridCols Number of columns in the grid
173
119
  * @param gridRows Number of rows in the grid
174
- * @param glyphResolver Function to resolve character strings to glyph colors
175
120
  * @param options Optional preload configuration (frameRate, onProgress, onComplete, onError).
176
121
  * @returns Promise resolving to TextmodeVideo instance
177
122
  * @ignore
178
123
  */
179
- static $fromSource(renderer: GLRenderer, font: TextmodeFont, source: string | HTMLVideoElement, gridCols: number, gridRows: number, glyphResolver: (s: string) => ([number, number, number])[], options?: TextmodeVideoOptions): Promise<TextmodeVideo>;
124
+ static $fromSource(renderer: GLRenderer, font: TextmodeFont, source: string, gridCols: number, gridRows: number, options?: TextmodeVideoOptions): Promise<TextmodeVideo>;
180
125
  /**
181
126
  * Play the video.
182
127
  * @returns Promise that resolves when playback starts
@@ -246,21 +191,8 @@ export declare class TextmodeVideo extends TextmodeSource {
246
191
  * Whether the video is currently playing.
247
192
  */
248
193
  get isPlaying(): boolean;
249
- /**
250
- * Whether this video has been preloaded with frames.
251
- */
252
- get isPreloaded(): boolean;
253
194
  /**
254
195
  * Total number of preloaded frames. Returns 0 for non-preloaded videos.
255
196
  */
256
197
  get totalFrames(): number;
257
- /**
258
- * The frame rate used for preloading. Returns null for non-preloaded videos.
259
- */
260
- get preloadFrameRate(): number | null;
261
- /**
262
- * Current frame index for preloaded videos. Returns 0 for non-preloaded videos.
263
- */
264
- get currentFrameIndex(): number;
265
198
  }
266
- export {};
@@ -0,0 +1,29 @@
1
+ import type { TextmodeVideoPreloadCallbacks, TextmodeVideoPreloadStrategy } from './types';
2
+ /**
3
+ * Handles extracting still frames from an {@link HTMLVideoElement} into WebGL textures
4
+ * so that {@link TextmodeVideo} can render deterministic, frame-accurate playback.
5
+ */
6
+ export declare class TextmodeVideoPreloader {
7
+ private readonly _gl;
8
+ private readonly _videoElement;
9
+ private _frameRate;
10
+ private _totalFrames;
11
+ private _isPreloaded;
12
+ private _preloadedFrames;
13
+ private _lastProgressBucket;
14
+ constructor(gl: WebGL2RenderingContext, videoElement: HTMLVideoElement);
15
+ get isPreloaded(): boolean;
16
+ get totalFrames(): number;
17
+ get frameRate(): number | null;
18
+ get textures(): readonly WebGLTexture[];
19
+ dispose(): void;
20
+ preload(frameRate: number, callbacks?: TextmodeVideoPreloadCallbacks): Promise<TextmodeVideoPreloadStrategy>;
21
+ private _initializePreloadState;
22
+ private _finalizePreloadSuccess;
23
+ private _captureSourceToTexture;
24
+ private _reportPreloadProgress;
25
+ private _tryPreloadWithTrackProcessor;
26
+ private _preloadWithLegacySeeking;
27
+ private _waitForSeek;
28
+ private _deletePreloadedTextures;
29
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Options for preloading video frames in {@link TextmodeVideo}.
3
+ *
4
+ * When providing this options object as a second argument to {@link Textmodifier.loadVideo},
5
+ * you can choose to preload all video frames at a specified frame rate before using the video.
6
+ *
7
+ * When preloading, the video will not play live asynchronously. Instead, all frames will be captured
8
+ * upfront, allowing for frame-accurate seeking and rendering.
9
+ *
10
+ * This is especially useful for scenarios where precise frame control is needed,
11
+ * like capturing GIFs/videos from textmode.js canvas using the `textmode.export.js` add-on library without
12
+ * missing frames due to asynchronous video playback.
13
+ *
14
+ * Preloading takes time proportional to the video length and frame rate, which introduces significant delays
15
+ * before the sketch can start rendering. Therefore, it is recommended to use this feature only when intending
16
+ * to capture or export frames, rather than for real-time playback.
17
+ */
18
+ export interface TextmodeVideoOptions {
19
+ /** Frame rate to use when preloading video frames. If not specified, video will not be preloaded. */
20
+ frameRate?: number;
21
+ /** Callback invoked periodically during preloading to report progress. */
22
+ onProgress?: (progress: TextmodeVideoPreloadProgress) => void;
23
+ /** Callback invoked once preloading is complete. */
24
+ onComplete?: (summary: TextmodeVideoPreloadComplete) => void;
25
+ /** Callback invoked if an error occurs during preloading. */
26
+ onError?: (error: Error) => void;
27
+ }
28
+ export type TextmodeVideoPreloadStrategy = 'captureStream' | 'seeking';
29
+ export interface TextmodeVideoPreloadProgress {
30
+ percent: number;
31
+ loadedFrames: number;
32
+ totalFrames: number;
33
+ strategy: TextmodeVideoPreloadStrategy;
34
+ }
35
+ export interface TextmodeVideoPreloadComplete {
36
+ totalFrames: number;
37
+ strategy: TextmodeVideoPreloadStrategy;
38
+ }
39
+ export type TextmodeVideoPreloadCallbacks = {
40
+ onProgress?: (progress: TextmodeVideoPreloadProgress) => void;
41
+ onComplete?: (summary: TextmodeVideoPreloadComplete) => void;
42
+ onError?: (error: Error) => void;
43
+ };
@@ -1,7 +1,7 @@
1
1
  import type { GLFramebuffer, GLShader, TextmodeFramebufferOptions, UniformValue } from "../../../rendering/webgl";
2
2
  import type { TextmodeSource } from '../../loadables/TextmodeSource';
3
3
  import type { TextmodeImage } from '../../loadables/TextmodeImage';
4
- import type { TextmodeVideo, TextmodeVideoOptions } from "../../loadables/TextmodeVideo";
4
+ import type { TextmodeVideo, TextmodeVideoOptions } from "../../loadables/video/TextmodeVideo";
5
5
  import type { TextmodeColor } from "../../TextmodeColor";
6
6
  /**
7
7
  * Interface for rendering capabilities that will be mixed into Textmodifier
@@ -81,9 +81,9 @@ export interface IRenderingMixin {
81
81
  */
82
82
  createFramebuffer(options: TextmodeFramebufferOptions): GLFramebuffer;
83
83
  /**
84
- * Draw a TextmodeFramebuffer or TextmodeImage to the current render target.
84
+ * Draw a TextmodeFramebuffer or TextmodeSource (TextmodeImage/TextmodeVideo) to the current render target.
85
85
  *
86
- * @param source The TextmodeFramebuffer or TextmodeImage to render
86
+ * @param source The TextmodeFramebuffer or TextmodeSource to render
87
87
  * @param x X position on the grid where to place the content *(top-left corner)*
88
88
  * @param y Y position on the grid where to place the content *(top-left corner)*
89
89
  * @param width Width to potentially scale the content
@@ -546,8 +546,7 @@ export interface IRenderingMixin {
546
546
  /**
547
547
  * Create a reusable color object compatible with textmode drawing APIs.
548
548
  *
549
- * Accepts grayscale, RGB, RGBA, hex string values as arguments, and
550
- * single characters that resolve to their encoded glyph color. Returned
549
+ * Accepts grayscale, RGB, RGBA, and hex string values as arguments. Returned
551
550
  * {@link TextmodeColor} instances can be passed to {@link background},
552
551
  * {@link char}, {@link charColor}, {@link cellColor}, and more.
553
552
  *
@@ -574,13 +573,6 @@ export interface IRenderingMixin {
574
573
  * // Hex string
575
574
  * const dusk = t.color('#203040');
576
575
  *
577
- * // Single character: resolves to a TextmodeColor that may encode a glyph
578
- * let glyphColor;
579
- *
580
- * t.setup(() => {
581
- * glyphColor = t.color('B'); // Color based on 'B' character glyph
582
- * });
583
- *
584
576
  * t.draw(() => {
585
577
  * // Using colors with other drawing APIs
586
578
  * t.background(gray);
@@ -595,7 +587,7 @@ export interface IRenderingMixin {
595
587
  *
596
588
  * t.translate(5, 0);
597
589
  * t.charColor("#FF00FF");
598
- * t.char(glyphColor);
590
+ * t.char("B");
599
591
  * t.rect(5, 5);
600
592
  * });
601
593
  * ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "textmode.js",
3
- "version": "0.6.0-beta.4",
3
+ "version": "0.6.0",
4
4
  "description": "textmode.js is a lightweight creative coding library for creating real-time ASCII art on the web.",
5
5
  "type": "module",
6
6
  "types": "./dist/types/index.d.ts",
@@ -41,6 +41,7 @@
41
41
  "tslib": "^2.8.1",
42
42
  "typedoc": "^0.28.13",
43
43
  "typedoc-plugin-markdown": "^4.7.0",
44
+ "typedoc-vitepress-theme": "^1.1.2",
44
45
  "typescript": "^5.9.2",
45
46
  "vite": "^6.3.4",
46
47
  "vite-plugin-glsl": "^1.5.1",