textmode.js 0.1.6-beta.5 → 0.1.6-beta.7

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 (48) hide show
  1. package/dist/textmode.esm.js +1871 -0
  2. package/dist/textmode.esm.min.js +1870 -0
  3. package/dist/textmode.umd.js +64 -0
  4. package/dist/textmode.umd.min.js +63 -0
  5. package/dist/types/ColorPalette.d.ts +1 -5
  6. package/dist/types/Textmode.d.ts +0 -10
  7. package/dist/types/errors/Error.d.ts +3 -5
  8. package/dist/types/errors/ErrorHandler.d.ts +3 -3
  9. package/dist/types/export/base/DataExtractor.d.ts +3 -3
  10. package/dist/types/export/base/FileHandler.d.ts +6 -6
  11. package/dist/types/export/image/ImageContentGenerator.d.ts +3 -3
  12. package/dist/types/export/image/ImageDataExtractor.d.ts +2 -2
  13. package/dist/types/export/image/ImageExporter.d.ts +9 -9
  14. package/dist/types/export/image/ImageFileHandler.d.ts +3 -21
  15. package/dist/types/export/svg/SVGContentGenerator.d.ts +12 -12
  16. package/dist/types/export/svg/SVGDataExtractor.d.ts +4 -4
  17. package/dist/types/export/svg/SVGExporter.d.ts +6 -6
  18. package/dist/types/export/svg/SVGFileHandler.d.ts +3 -3
  19. package/dist/types/export/svg/SVGPathGenerator.d.ts +5 -11
  20. package/dist/types/export/txt/TXTContentGenerator.d.ts +1 -1
  21. package/dist/types/export/txt/TXTDataExtractor.d.ts +2 -2
  22. package/dist/types/export/txt/TXTExporter.d.ts +6 -6
  23. package/dist/types/export/txt/TXTFileHandler.d.ts +2 -2
  24. package/dist/types/index.d.ts +0 -1
  25. package/dist/types/rendering/webgl/Framebuffer.d.ts +8 -8
  26. package/dist/types/rendering/webgl/Renderer.d.ts +35 -35
  27. package/dist/types/rendering/webgl/Shader.d.ts +14 -14
  28. package/dist/types/rendering/webgl/geometries/BaseGeometry.d.ts +10 -10
  29. package/dist/types/rendering/webgl/geometries/Line.d.ts +1 -1
  30. package/dist/types/rendering/webgl/geometries/Rectangle.d.ts +2 -2
  31. package/dist/types/textmode/Canvas.d.ts +9 -18
  32. package/dist/types/textmode/ConversionPipeline.d.ts +31 -20
  33. package/dist/types/textmode/Grid.d.ts +7 -12
  34. package/dist/types/textmode/Textmodifier.d.ts +18 -40
  35. package/dist/types/textmode/converters/BrightnessConverter.d.ts +8 -8
  36. package/dist/types/textmode/converters/Converter.d.ts +5 -5
  37. package/dist/types/textmode/converters/FeatureConverter.d.ts +27 -3
  38. package/dist/types/textmode/font/TextmodeFont.d.ts +8 -8
  39. package/dist/types/textmode/mixins/ConversionMixin.d.ts +63 -0
  40. package/dist/types/textmode/mixins/ExportMixin.d.ts +112 -1
  41. package/dist/types/textmode/mixins/FontMixin.d.ts +1 -1
  42. package/dist/types/textmode/mixins/RenderingMixin.d.ts +304 -1
  43. package/dist/types/textmode/mixins/{MixinBase.d.ts → TextmodifierMixin.d.ts} +4 -4
  44. package/dist/types/textmode/mixins/index.d.ts +2 -1
  45. package/package.json +16 -2
  46. package/dist/textmode.js +0 -26
  47. package/dist/textmode.min.js +0 -25
  48. package/dist/types/types/index.d.ts +0 -4
@@ -6,9 +6,9 @@ import type { TextmodeGrid } from "../Grid";
6
6
  * Base class for all textmode converters.
7
7
  */
8
8
  export declare class TextmodeConverter {
9
- protected renderer: GLRenderer;
10
- protected fontManager: TextmodeFont;
11
- protected grid: TextmodeGrid;
9
+ protected _renderer: GLRenderer;
10
+ protected _fontManager: TextmodeFont;
11
+ protected _grid: TextmodeGrid;
12
12
  protected _characterFramebuffer: Framebuffer;
13
13
  protected _primaryColorFramebuffer: Framebuffer;
14
14
  protected _secondaryColorFramebuffer: Framebuffer;
@@ -28,7 +28,7 @@ export declare class TextmodeConverter {
28
28
  * Resizes all internal framebuffers to match the grid dimensions.
29
29
  * @ignore
30
30
  */
31
- resize(): void;
31
+ $resize(): void;
32
32
  /**
33
33
  * Enables or disables the converter.
34
34
  * @param enabled Whether to enable or disable the converter.
@@ -46,7 +46,7 @@ export declare class TextmodeConverter {
46
46
  * Dispose of all framebuffers used by this converter.
47
47
  * This method is idempotent and safe to call multiple times.
48
48
  */
49
- dispose(): void;
49
+ $dispose(): void;
50
50
  /** Returns the framebuffer containing character data. */
51
51
  get characterFramebuffer(): Framebuffer;
52
52
  /** Returns the framebuffer containing primary color data. */
@@ -8,14 +8,14 @@ import type { Framebuffer } from "../../rendering/webgl/Framebuffer";
8
8
  * Abstract base class for all feature-based textmode converters like `'brightness'`.
9
9
  */
10
10
  export declare abstract class TextmodeFeatureConverter extends TextmodeConverter {
11
- protected palette: ColorPalette;
11
+ protected _palette: ColorPalette;
12
12
  protected constructor(renderer: GLRenderer, fontManager: TextmodeFont, grid: TextmodeGrid, options?: any);
13
13
  /**
14
14
  * Converts the source framebuffer to the target format.
15
15
  * @param sourceFramebuffer The source framebuffer to convert.
16
16
  * @ignore
17
17
  */
18
- abstract convert(sourceFramebuffer: Framebuffer): void;
18
+ abstract $convert(sourceFramebuffer: Framebuffer): void;
19
19
  /**
20
20
  * Sets the characters used for mapping.
21
21
  * @param characters The characters to use for mapping, usually ordered from darkest to brightest.
@@ -73,10 +73,34 @@ export declare abstract class TextmodeFeatureConverter extends TextmodeConverter
73
73
  * @param flip If `true`, characters are flipped vertically. If `false`, no flip is applied.
74
74
  */
75
75
  flipVertically(flip: boolean | number): void;
76
+ /**
77
+ * Helper method to parse color values from either hex string or RGB(A) parameters.
78
+ * @param r Red component (0-255) or hex string.
79
+ * @param methodName The name of the calling method for error reporting.
80
+ * @param g Green component (0-255).
81
+ * @param b Blue component (0-255).
82
+ * @param a Alpha component (0-255).
83
+ * @returns Normalized RGBA array [r, g, b, a] (0-1 range) or null if invalid.
84
+ */
85
+ private _parseColor;
86
+ /**
87
+ * Helper method to set color mode with validation.
88
+ * @param mode The color mode to set.
89
+ * @param optionKey The option key to set in _options.
90
+ * @param errorMessage The error message to show if validation fails.
91
+ */
92
+ private _setColorMode;
93
+ /**
94
+ * Helper method to set boolean options with validation.
95
+ * @param value The boolean or number value to set.
96
+ * @param optionKey The option key to set in _options.
97
+ * @param displayName The display name for error messages.
98
+ */
99
+ private _setBooleanOption;
76
100
  /**
77
101
  * Parses a hex color string and returns RGBA values.
78
102
  * @param hex Hex color string (e.g., '#FF0000', '#F00', 'FF0000', 'F00').
79
103
  * @returns RGBA array [r, g, b, a] or null if invalid.
80
104
  */
81
- private parseHexColor;
105
+ private _parseHexColor;
82
106
  }
@@ -34,20 +34,20 @@ export declare class TextmodeFont {
34
34
  * @returns Promise that resolves when initialization is complete
35
35
  * @ignore
36
36
  */
37
- initialize(fontSource?: string | URL): Promise<void>;
37
+ $initialize(fontSource?: string | URL): Promise<void>;
38
38
  /**
39
39
  * Sets the font size for rendering.
40
40
  * @param size The font size to set. If undefined, returns the current font size.
41
41
  * @ignore
42
42
  */
43
- setFontSize(size: number | undefined): void | number;
43
+ $setFontSize(size: number | undefined): void | number;
44
44
  /**
45
45
  * Loads a new font from a file path.
46
46
  * @param fontPath Path to the .otf or .ttf font file
47
47
  * @returns Promise that resolves when font loading is complete
48
48
  * @ignore
49
49
  */
50
- loadFont(fontPath: string): Promise<void>;
50
+ $loadFont(fontPath: string): Promise<void>;
51
51
  /**
52
52
  * Loads a FontFace from a font buffer.
53
53
  * @param fontBuffer ArrayBuffer containing font data
@@ -76,6 +76,11 @@ export declare class TextmodeFont {
76
76
  * @returns `true` if all characters exist in the font, `false` otherwise.
77
77
  */
78
78
  hasAllCharacters(str: string): boolean;
79
+ /**
80
+ * Dispose of all resources used by this font manager.
81
+ * This method is idempotent and safe to call multiple times.
82
+ */
83
+ $dispose(): void;
79
84
  /**
80
85
  * Returns the WebGL framebuffer containing the font texture atlas.
81
86
  * @ignore
@@ -92,11 +97,6 @@ export declare class TextmodeFont {
92
97
  width: number;
93
98
  height: number;
94
99
  };
95
- /**
96
- * Dispose of all resources used by this font manager.
97
- * This method is idempotent and safe to call multiple times.
98
- */
99
- dispose(): void;
100
100
  /** Returns the font size used for rendering. */
101
101
  get fontSize(): number;
102
102
  /** Returns the Typr.js font object. @ignore */
@@ -0,0 +1,63 @@
1
+ import type { Mixin } from './TextmodifierMixin';
2
+ import type { TextmodeConverter } from '../converters';
3
+ /**
4
+ * Interface for conversion pipeline capabilities that will be mixed into Textmodifier
5
+ */
6
+ export interface ConversionCapabilities {
7
+ /**
8
+ * Adds a new converter to the pipeline.
9
+ * @param name A unique name for the converter.
10
+ * @param type The type of converter to add. Can be either "brightness" or "custom".
11
+ * @returns The newly created {@link TextmodeConverter} instance or `void` if the addition failed.
12
+ *
13
+ * @example
14
+ * ```javascript
15
+ * // Fetch a canvas element to apply textmode rendering to
16
+ * const canvas = document.querySelector('canvas#myCanvas');
17
+ *
18
+ * // Create a Textmodifier instance
19
+ * const textmodifier = await textmode.create(canvas);
20
+ *
21
+ * // Add a new brightness converter
22
+ * const myConverter = textmodifier.addConverter('my-brightness', 'brightness');
23
+ *
24
+ * // Configure the new converter
25
+ * myConverter.characters("▓▒░ ");
26
+ * myConverter.enabled(true);
27
+ *
28
+ * // Add a custom converter
29
+ * const customConverter = textmodifier.addConverter('my-custom', 'custom');
30
+ * ```
31
+ */
32
+ addConverter(name: string, type: 'brightness' | 'custom'): TextmodeConverter | void;
33
+ /**
34
+ * Removes a converter from the pipeline by name or instance.
35
+ * @param nameOrInstance The unique name of the converter or the converter instance to remove.
36
+ *
37
+ * @example
38
+ * ```javascript
39
+ * // Fetch a canvas element to apply textmode rendering to
40
+ * const canvas = document.querySelector('canvas#myCanvas');
41
+ *
42
+ * // Create a Textmodifier instance
43
+ * const textmodifier = await textmode.create(canvas);
44
+ *
45
+ * // Add a converter
46
+ * const myConverter = textmodifier.addConverter('temp-converter', 'brightness');
47
+ *
48
+ * // Remove by name
49
+ * textmodifier.removeConverter('temp-converter');
50
+ *
51
+ * // Or remove by instance
52
+ * const anotherConverter = textmodifier.addConverter('another', 'custom');
53
+ * textmodifier.removeConverter(anotherConverter);
54
+ * ```
55
+ */
56
+ removeConverter(nameOrInstance: string | TextmodeConverter): void;
57
+ }
58
+ /**
59
+ * Mixin that adds conversion pipeline capabilities to a class by delegating to TextmodeConversionPipeline
60
+ * @param Base The base class to extend
61
+ * @returns Extended class with conversion capabilities
62
+ */
63
+ export declare const ConversionMixin: Mixin<ConversionCapabilities>;
@@ -1,4 +1,4 @@
1
- import type { Mixin } from './MixinBase';
1
+ import type { Mixin } from './TextmodifierMixin';
2
2
  import { type SVGExportOptions } from '../../export/svg';
3
3
  import { type TXTExportOptions } from '../../export/txt';
4
4
  import { type ImageExportOptions, type ImageFormat } from '../../export/image';
@@ -10,22 +10,111 @@ export interface ExportCapabilities {
10
10
  * Generate the current textmode rendering as a text string.
11
11
  * @param options Options for text generation *(excluding filename)*
12
12
  * @returns Textmode grid content as a string.
13
+ *
14
+ * @example
15
+ * ```javascript
16
+ * // Fetch a canvas element to apply textmode rendering to
17
+ * const canvas = document.querySelector('canvas#myCanvas');
18
+ *
19
+ * // Create a Textmodifier instance
20
+ * const textmodifier = await textmode.create(canvas, {renderMode: 'manual'});
21
+ *
22
+ * // Render a single frame
23
+ * textmodifier.render();
24
+ *
25
+ * // Get the current rendering as a text string
26
+ * const textString = textmodifier.toString({
27
+ * preserveTrailingSpaces: false,
28
+ * lineEnding: 'lf'
29
+ * });
30
+ *
31
+ * // Print to console or use otherwise
32
+ * console.log(textString);
33
+ *
34
+ * ////////
35
+ *
36
+ * // Example with video element
37
+ * const video = document.querySelector('video#myVideo');
38
+ * const videoTextmodifier = await textmode.create(video);
39
+ *
40
+ * // The textmode overlay will automatically update as the video plays
41
+ * video.play();
42
+ *
43
+ * // Get current frame as ASCII
44
+ * const videoFrame = videoTextmodifier.toString();
45
+ * ```
13
46
  */
14
47
  toString(options?: Omit<TXTExportOptions, 'filename'>): string;
15
48
  /**
16
49
  * Export the current textmode rendering to a TXT file.
17
50
  * @param options Options for TXT export
51
+ *
52
+ * @example
53
+ * ```javascript
54
+ * // Fetch a canvas element to apply textmode rendering to
55
+ * const canvas = document.querySelector('canvas#myCanvas');
56
+ *
57
+ * // Create a Textmodifier instance
58
+ * const textmodifier = await textmode.create(canvas, {renderMode: 'manual'});
59
+ *
60
+ * // Render a single frame
61
+ * textmodifier.render();
62
+ *
63
+ * // Export the current rendering to a TXT file
64
+ * textmodifier.saveStrings({
65
+ * filename: 'my_textmode_rendering',
66
+ * preserveTrailingSpaces: false
67
+ * });
68
+ * ```
18
69
  */
19
70
  saveStrings(options?: TXTExportOptions): void;
20
71
  /**
21
72
  * Generate the current textmode rendering as an SVG string.
22
73
  * @param options Options for SVG generation *(excluding filename)*
23
74
  * @returns SVG content as a string.
75
+ *
76
+ * @example
77
+ * ```javascript
78
+ * // Fetch a canvas element to apply textmode rendering to
79
+ * const canvas = document.querySelector('canvas#myCanvas');
80
+ *
81
+ * // Create a Textmodifier instance
82
+ * const textmodifier = await textmode.create(canvas, {renderMode: 'manual'});
83
+ *
84
+ * // Render a single frame
85
+ * textmodifier.render();
86
+ *
87
+ * // Get the current rendering as an SVG string
88
+ * const svgString = textmodifier.toSVG({
89
+ * includeBackgroundRectangles: true,
90
+ * drawMode: 'fill'
91
+ * });
92
+ *
93
+ * // Print to console or use otherwise
94
+ * console.log(svgString);
95
+ * ```
24
96
  */
25
97
  toSVG(options?: Omit<SVGExportOptions, 'filename'>): string;
26
98
  /**
27
99
  * Export the current textmode rendering to an SVG file.
28
100
  * @param options Options for SVG export
101
+ *
102
+ * @example
103
+ * ```javascript
104
+ * // Fetch a canvas element to apply textmode rendering to
105
+ * const canvas = document.querySelector('canvas#myCanvas');
106
+ *
107
+ * // Create a Textmodifier instance
108
+ * const textmodifier = await textmode.create(canvas, {renderMode: 'manual'});
109
+ *
110
+ * // Render a single frame
111
+ * textmodifier.render();
112
+ *
113
+ * // Export the current rendering to an SVG file
114
+ * textmodifier.saveSVG({
115
+ * filename: 'my_textmode_rendering',
116
+ * });
117
+ * ```
29
118
  */
30
119
  saveSVG(options?: SVGExportOptions): void;
31
120
  /**
@@ -33,6 +122,28 @@ export interface ExportCapabilities {
33
122
  * @param filename The filename (without extension) to save the image as
34
123
  * @param format The image format ('png', 'jpg', or 'webp')
35
124
  * @param options Additional options for image export
125
+ *
126
+ * @example
127
+ * ```javascript
128
+ * // Fetch a canvas element to apply textmode rendering to
129
+ * const canvas = document.querySelector('canvas#myCanvas');
130
+ *
131
+ * // Create a Textmodifier instance
132
+ * const textmodifier = await textmode.create(canvas, {renderMode: 'manual'});
133
+ *
134
+ * // Render a single frame
135
+ * textmodifier.render();
136
+ *
137
+ * // Export the current rendering to a PNG file
138
+ * textmodifier.saveCanvas('my_textmode_rendering', 'png');
139
+ *
140
+ * // Export with custom options
141
+ * textmodifier.saveCanvas('my_textmode_rendering', 'jpg', {
142
+ * quality: 0.8,
143
+ * scale: 2.0,
144
+ * backgroundColor: 'white'
145
+ * });
146
+ * ```
36
147
  */
37
148
  saveCanvas(filename: string, format?: ImageFormat, options?: Omit<ImageExportOptions, 'filename' | 'format'>): Promise<void>;
38
149
  }
@@ -1,4 +1,4 @@
1
- import type { Mixin } from './MixinBase';
1
+ import type { Mixin } from './TextmodifierMixin';
2
2
  /**
3
3
  * Interface for font capabilities that will be mixed into Textmodifier
4
4
  */