textmode.js 0.0.1 → 0.0.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.
- package/README.md +3 -0
- package/dist/textmode.esm.js +988 -921
- package/dist/textmode.umd.js +6 -5
- package/dist/types/ColorPalette.d.ts +2 -2
- package/dist/types/errors/Error.d.ts +6 -2
- package/dist/types/errors/ErrorHandler.d.ts +10 -14
- package/dist/types/index.d.ts +5 -3
- package/dist/types/textmode/Canvas.d.ts +5 -0
- package/dist/types/{FontManager.d.ts → textmode/Font.d.ts} +47 -13
- package/dist/types/textmode/Grid.d.ts +1 -1
- package/dist/types/textmode/Textmodifier.d.ts +31 -15
- package/dist/types/textmode/converters/BrightnessConverter.d.ts +6 -18
- package/dist/types/textmode/converters/FeatureConverter.d.ts +33 -0
- package/package.json +8 -2
- package/dist/types/textmode/converters/Converter.d.ts +0 -21
- /package/dist/types/{renderer → rendering}/Framebuffer.d.ts +0 -0
- /package/dist/types/{renderer → rendering}/Renderer.d.ts +0 -0
- /package/dist/types/{renderer → rendering}/Shader.d.ts +0 -0
- /package/dist/types/{renderer → rendering}/geometries/Rectangle.d.ts +0 -0
|
@@ -1,11 +1,22 @@
|
|
|
1
|
-
import type { Renderer } from '
|
|
2
|
-
import type { Framebuffer } from '
|
|
3
|
-
|
|
1
|
+
import type { Renderer } from '../rendering/Renderer.ts';
|
|
2
|
+
import type { Framebuffer } from '../rendering/Framebuffer.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a single character in the textmode font.
|
|
5
|
+
*/
|
|
6
|
+
export type TextmodeCharacter = {
|
|
7
|
+
/** The character itself. */
|
|
4
8
|
character: string;
|
|
9
|
+
/** The Unicode code point of the character. */
|
|
5
10
|
unicode: number;
|
|
11
|
+
/** The RGB color associated with the character for identification. */
|
|
6
12
|
color: [number, number, number];
|
|
7
|
-
}
|
|
8
|
-
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Manages the textmode font used for rendering characters.
|
|
16
|
+
*
|
|
17
|
+
* This class handles loading the font, creating a texture atlas, and providing character color information.
|
|
18
|
+
*/
|
|
19
|
+
export declare class TextmodeFont {
|
|
9
20
|
private _font;
|
|
10
21
|
private _characters;
|
|
11
22
|
private _fontFramebuffer;
|
|
@@ -22,11 +33,13 @@ export declare class FontManager {
|
|
|
22
33
|
* Creates a new FontManager instance
|
|
23
34
|
* @param renderer Renderer instance for texture creation
|
|
24
35
|
* @param fontSize Font size to use for the texture atlas
|
|
36
|
+
* @ignore
|
|
25
37
|
*/
|
|
26
38
|
constructor(renderer: Renderer, fontSize?: number);
|
|
27
39
|
/**
|
|
28
40
|
* Initializes the font manager by loading the font and creating the texture atlas
|
|
29
41
|
* @returns Promise that resolves when initialization is complete
|
|
42
|
+
* @ignore
|
|
30
43
|
*/
|
|
31
44
|
initialize(): Promise<void>;
|
|
32
45
|
/**
|
|
@@ -41,30 +54,51 @@ export declare class FontManager {
|
|
|
41
54
|
* Creates the texture atlas containing all characters
|
|
42
55
|
*/
|
|
43
56
|
private _createTextureAtlas;
|
|
57
|
+
/**
|
|
58
|
+
* Get the color associated with a character.
|
|
59
|
+
* @param character The character to get the color for.
|
|
60
|
+
* @returns The RGB color as an array `[r, g, b]`.
|
|
61
|
+
*/
|
|
44
62
|
getCharacterColor(character: string): [number, number, number];
|
|
63
|
+
/**
|
|
64
|
+
* Get the colors associated with a string of characters.
|
|
65
|
+
* @param characters The string of characters to get colors for.
|
|
66
|
+
* @returns An array of RGB colors for each character in the string.
|
|
67
|
+
* Each color is represented as an array `[r, g, b]`.
|
|
68
|
+
*/
|
|
45
69
|
getCharacterColors(characters: string): [number, number, number][];
|
|
70
|
+
/**
|
|
71
|
+
* Checks if all characters in the given string exist in the font.
|
|
72
|
+
* @param str The string to check.
|
|
73
|
+
* @returns `true` if all characters exist in the font, `false` otherwise.
|
|
74
|
+
*/
|
|
75
|
+
hasAllCharacters(str: string): boolean;
|
|
46
76
|
/**
|
|
47
77
|
* Updates the font by loading a new font file and regenerating all related properties
|
|
48
78
|
* @param fontPath Path to the .otf or .ttf font file
|
|
49
79
|
* @param fontSize Optional new font size (defaults to current fontSize)
|
|
50
80
|
* @returns Promise that resolves when font update is complete
|
|
81
|
+
* @ignore
|
|
51
82
|
*/
|
|
52
83
|
loadFont(fontPath: string): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Returns the WebGL framebuffer containing the font texture atlas.
|
|
86
|
+
* @ignore
|
|
87
|
+
*/
|
|
53
88
|
get fontFramebuffer(): Framebuffer;
|
|
54
|
-
|
|
55
|
-
get
|
|
56
|
-
|
|
57
|
-
get characters(): FontCharacter[];
|
|
89
|
+
/** Returns the array of {@link TextmodeCharacter} objects in the font. */
|
|
90
|
+
get characters(): TextmodeCharacter[];
|
|
91
|
+
/** Returns a string representation of all characters in the font.*/
|
|
58
92
|
get charactersString(): string;
|
|
93
|
+
/** Returns the number of columns in the texture atlas.*/
|
|
59
94
|
get textureColumns(): number;
|
|
95
|
+
/** Returns the number of rows in the texture atlas. */
|
|
60
96
|
get textureRows(): number;
|
|
97
|
+
/** Returns the maximum dimensions of a glyph in the font. */
|
|
61
98
|
get maxGlyphDimensions(): {
|
|
62
99
|
width: number;
|
|
63
100
|
height: number;
|
|
64
101
|
};
|
|
102
|
+
/** Returns the font size used for rendering. */
|
|
65
103
|
get fontSize(): number;
|
|
66
|
-
get textureDimensions(): {
|
|
67
|
-
width: number;
|
|
68
|
-
height: number;
|
|
69
|
-
};
|
|
70
104
|
}
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import { TextmodeFont } from './Font';
|
|
2
|
+
import { TextmodeGrid } from './Grid';
|
|
3
|
+
import { TextmodeErrorLevel } from '../errors';
|
|
4
|
+
/**
|
|
5
|
+
* Options for initializing a {@link Textmodifier} instance.
|
|
6
|
+
*/
|
|
7
|
+
export type TextmodeOptions = {
|
|
8
|
+
/** The font size to use for text rendering. Defaults to 16. */
|
|
2
9
|
fontSize?: number;
|
|
3
|
-
}
|
|
4
|
-
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Main class for handling textmode rendering in a WebGL context.
|
|
13
|
+
*/
|
|
5
14
|
export declare class Textmodifier {
|
|
6
15
|
/** The canvas element to capture content from */
|
|
7
16
|
private captureCanvas;
|
|
@@ -12,26 +21,33 @@ export declare class Textmodifier {
|
|
|
12
21
|
private asciiShader;
|
|
13
22
|
private canvasFramebuffer;
|
|
14
23
|
private brightnessConverter;
|
|
15
|
-
private
|
|
16
|
-
private
|
|
24
|
+
private _fontManager;
|
|
25
|
+
private _grid;
|
|
17
26
|
private resizeObserver;
|
|
18
27
|
private resultFramebuffer;
|
|
19
|
-
private
|
|
20
|
-
constructor(canvas: HTMLCanvasElement, opts?: TextModeOptions);
|
|
28
|
+
private constructor();
|
|
21
29
|
/**
|
|
22
|
-
*
|
|
30
|
+
* Static factory method for creating and initializing a Textmodifier instance.
|
|
31
|
+
* @param canvas The HTML canvas element to capture content from.
|
|
32
|
+
* @param opts Optional configuration options for the `Textmodifier` instance.
|
|
23
33
|
*/
|
|
24
|
-
|
|
34
|
+
static create(canvas: HTMLCanvasElement, opts?: TextmodeOptions): Promise<Textmodifier>;
|
|
35
|
+
private setupEventListeners;
|
|
25
36
|
/**
|
|
26
|
-
*
|
|
37
|
+
* Update the font used for rendering.
|
|
38
|
+
* @param fontUrl The URL of the font to load.
|
|
27
39
|
*/
|
|
28
|
-
|
|
40
|
+
loadFont(fontUrl: string): Promise<void>;
|
|
29
41
|
/**
|
|
30
|
-
*
|
|
42
|
+
* Apply textmode rendering to the canvas.
|
|
31
43
|
*/
|
|
32
|
-
static create(canvas: HTMLCanvasElement, opts?: TextModeOptions): Promise<Textmodifier>;
|
|
33
|
-
private setupEventListeners;
|
|
34
|
-
loadFont(fontUrl: string): Promise<void>;
|
|
35
44
|
render(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Set the global error handling level for the library. This applies to all `Textmodifier` instances.
|
|
47
|
+
* @param level The error handling level to set.
|
|
48
|
+
*/
|
|
49
|
+
setErrorLevel(level: TextmodeErrorLevel): void;
|
|
36
50
|
private resize;
|
|
51
|
+
get grid(): TextmodeGrid;
|
|
52
|
+
get fontManager(): TextmodeFont;
|
|
37
53
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { Renderer } from "../../
|
|
2
|
-
import { Framebuffer } from "../../
|
|
3
|
-
import {
|
|
4
|
-
import { FontManager } from "../../FontManager";
|
|
1
|
+
import { Renderer } from "../../rendering/Renderer";
|
|
2
|
+
import { Framebuffer } from "../../rendering/Framebuffer";
|
|
3
|
+
import { TextmodeFont } from "../Font";
|
|
5
4
|
import { TextmodeGrid } from "../Grid";
|
|
6
|
-
import {
|
|
5
|
+
import { TextmodeFeatureConverter } from "./FeatureConverter";
|
|
7
6
|
export declare const BRIGHTNESS_DEFAULT_OPTIONS: {
|
|
8
7
|
/** Enable/disable the renderer */
|
|
9
8
|
enabled: boolean;
|
|
@@ -28,23 +27,12 @@ export declare const BRIGHTNESS_DEFAULT_OPTIONS: {
|
|
|
28
27
|
/** Range of brightness values to map to ASCII characters */
|
|
29
28
|
brightnessRange: [number, number];
|
|
30
29
|
};
|
|
31
|
-
export declare class
|
|
30
|
+
export declare class TextmodeBrightnessConverter extends TextmodeFeatureConverter {
|
|
32
31
|
private sampleShader;
|
|
33
32
|
private charMappingShader;
|
|
34
33
|
sampleFramebuffer: Framebuffer;
|
|
35
|
-
|
|
36
|
-
private options;
|
|
37
|
-
constructor(renderer: Renderer, fontManager: FontManager, grid: TextmodeGrid);
|
|
34
|
+
constructor(renderer: Renderer, fontManager: TextmodeFont, grid: TextmodeGrid);
|
|
38
35
|
convert(framebuffer: Framebuffer): void;
|
|
39
36
|
resize(): void;
|
|
40
|
-
characters(characters: string): void;
|
|
41
|
-
characterColor(r: number, g?: number, b?: number, a?: number): void;
|
|
42
|
-
characterColorMode(mode: "sampled" | "fixed"): void;
|
|
43
|
-
backgroundColor(r: number, g?: number, b?: number, a?: number): void;
|
|
44
|
-
backgroundColorMode(mode: "sampled" | "fixed"): void;
|
|
45
|
-
invert(invert: boolean): void;
|
|
46
|
-
rotation(angle: number): void;
|
|
47
|
-
flipHorizontally(flip: boolean): void;
|
|
48
|
-
flipVertically(flip: boolean): void;
|
|
49
37
|
brightnessRange(range: [number, number]): void;
|
|
50
38
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ColorPalette } from "../../ColorPalette";
|
|
2
|
+
import type { TextmodeFont } from "../Font";
|
|
3
|
+
import type { Framebuffer } from "../../rendering/Framebuffer";
|
|
4
|
+
import type { Renderer } from "../../rendering/Renderer";
|
|
5
|
+
import type { TextmodeGrid } from "../Grid";
|
|
6
|
+
export declare class TextmodeFeatureConverter {
|
|
7
|
+
protected renderer: Renderer;
|
|
8
|
+
protected fontManager: TextmodeFont;
|
|
9
|
+
protected grid: TextmodeGrid;
|
|
10
|
+
protected _characterFramebuffer: Framebuffer;
|
|
11
|
+
protected _primaryColorFramebuffer: Framebuffer;
|
|
12
|
+
protected _secondaryColorFramebuffer: Framebuffer;
|
|
13
|
+
protected _rotationFramebuffer: Framebuffer;
|
|
14
|
+
protected _transformFramebuffer: Framebuffer;
|
|
15
|
+
protected palette: ColorPalette;
|
|
16
|
+
protected options: any;
|
|
17
|
+
constructor(renderer: Renderer, fontManager: TextmodeFont, grid: TextmodeGrid, options?: any);
|
|
18
|
+
resize(): void;
|
|
19
|
+
characters(characters: string): void;
|
|
20
|
+
characterColor(r: number, g?: number, b?: number, a?: number): void;
|
|
21
|
+
characterColorMode(mode: "sampled" | "fixed"): void;
|
|
22
|
+
backgroundColor(r: number, g?: number, b?: number, a?: number): void;
|
|
23
|
+
backgroundColorMode(mode: "sampled" | "fixed"): void;
|
|
24
|
+
invert(invert: boolean | number): void;
|
|
25
|
+
rotation(angle: number): void;
|
|
26
|
+
flipHorizontally(flip: boolean | number): void;
|
|
27
|
+
flipVertically(flip: boolean | number): void;
|
|
28
|
+
get characterFramebuffer(): Framebuffer;
|
|
29
|
+
get primaryColorFramebuffer(): Framebuffer;
|
|
30
|
+
get secondaryColorFramebuffer(): Framebuffer;
|
|
31
|
+
get rotationFramebuffer(): Framebuffer;
|
|
32
|
+
get transformFramebuffer(): Framebuffer;
|
|
33
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "textmode.js",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Apply real-time ASCII conversion to any HTML canvas.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/types/index.d.ts",
|
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
"scripts": {
|
|
17
17
|
"dev": "vite",
|
|
18
18
|
"build": "vite build && tsc",
|
|
19
|
+
"build-docs": "typedoc",
|
|
20
|
+
"dev-docs": "typedoc --watch",
|
|
19
21
|
"preview": "vite preview"
|
|
20
22
|
},
|
|
21
23
|
"devDependencies": {
|
|
@@ -47,5 +49,9 @@
|
|
|
47
49
|
"homepage": "https://github.com/humanbydefinition/textmode.js",
|
|
48
50
|
"files": [
|
|
49
51
|
"dist"
|
|
50
|
-
]
|
|
52
|
+
],
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"typedoc": "^0.28.7",
|
|
55
|
+
"typedoc-plugin-markdown": "^4.7.0"
|
|
56
|
+
}
|
|
51
57
|
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { FontManager } from "../../FontManager";
|
|
2
|
-
import type { Framebuffer } from "../../renderer/Framebuffer";
|
|
3
|
-
import type { Renderer } from "../../renderer/Renderer";
|
|
4
|
-
import type { TextmodeGrid } from "../Grid";
|
|
5
|
-
export declare class Converter {
|
|
6
|
-
protected renderer: Renderer;
|
|
7
|
-
protected fontManager: FontManager;
|
|
8
|
-
protected grid: TextmodeGrid;
|
|
9
|
-
protected _characterFramebuffer: Framebuffer;
|
|
10
|
-
protected _primaryColorFramebuffer: Framebuffer;
|
|
11
|
-
protected _secondaryColorFramebuffer: Framebuffer;
|
|
12
|
-
protected _rotationFramebuffer: Framebuffer;
|
|
13
|
-
protected _transformFramebuffer: Framebuffer;
|
|
14
|
-
constructor(renderer: Renderer, fontManager: FontManager, grid: TextmodeGrid);
|
|
15
|
-
resize(): void;
|
|
16
|
-
get characterFramebuffer(): Framebuffer;
|
|
17
|
-
get primaryColorFramebuffer(): Framebuffer;
|
|
18
|
-
get secondaryColorFramebuffer(): Framebuffer;
|
|
19
|
-
get rotationFramebuffer(): Framebuffer;
|
|
20
|
-
get transformFramebuffer(): Framebuffer;
|
|
21
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|