asciify-engine 1.0.1 → 1.0.3
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/dist/index.cjs +565 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +50 -3
- package/dist/index.d.ts +50 -3
- package/dist/index.js +564 -36
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
type ColorMode = 'grayscale' | 'fullcolor' | 'matrix' | 'accent';
|
|
2
2
|
type RenderMode = 'ascii' | 'dots';
|
|
3
3
|
type AnimationStyle = 'none' | 'wave' | 'pulse' | 'rain' | 'breathe' | 'sparkle' | 'glitch' | 'spiral' | 'typewriter' | 'scatter';
|
|
4
|
-
type ArtStyle = 'classic' | 'particles' | 'letters' | 'claudeCode' | 'art' | 'terminal';
|
|
4
|
+
type ArtStyle = 'classic' | 'particles' | 'letters' | 'claudeCode' | 'art' | 'terminal' | 'box' | 'lines';
|
|
5
5
|
type HoverEffect = 'spotlight' | 'magnify' | 'repel' | 'glow' | 'colorShift';
|
|
6
6
|
type HoverPreset = 'none' | 'subtle' | 'flashlight' | 'magnifier' | 'forceField' | 'neon' | 'fire' | 'ice';
|
|
7
7
|
type SourceType = 'image' | 'video' | null;
|
|
@@ -24,6 +24,7 @@ interface AsciiOptions {
|
|
|
24
24
|
hoverEffect: HoverEffect;
|
|
25
25
|
hoverColor: string;
|
|
26
26
|
artStyle: ArtStyle;
|
|
27
|
+
customText: string;
|
|
27
28
|
}
|
|
28
29
|
interface AsciiCell {
|
|
29
30
|
char: string;
|
|
@@ -48,6 +49,8 @@ declare const CHARSETS: {
|
|
|
48
49
|
readonly dots: " ⠁⠃⠇⡇⣇⣧⣷⣿";
|
|
49
50
|
readonly letters: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
50
51
|
readonly claudeCode: " ╔╗╚╝║═╠╣╦╩╬░▒▓█│─┌┐└┘├┤┬┴┼";
|
|
52
|
+
readonly box: " ▪◾◼■█";
|
|
53
|
+
readonly lines: " ˗‐–—―━";
|
|
51
54
|
};
|
|
52
55
|
type CharsetKey = keyof typeof CHARSETS;
|
|
53
56
|
/**
|
|
@@ -95,7 +98,14 @@ declare function gifToAsciiFrames(buffer: ArrayBuffer, options: AsciiOptions, ta
|
|
|
95
98
|
/**
|
|
96
99
|
* Render an ASCII frame to a canvas context.
|
|
97
100
|
* Supports both ASCII text mode and Dots mode.
|
|
98
|
-
*
|
|
101
|
+
* Always renders every cell at full quality.
|
|
102
|
+
*
|
|
103
|
+
* Performance strategy:
|
|
104
|
+
* - fillRect fast path for sub-6px text (30x faster than fillText)
|
|
105
|
+
* - Auto-scaling hover radius: at high cell counts, the hover area
|
|
106
|
+
* is proportionally smaller so fewer cells compute hover effects
|
|
107
|
+
* - Hover bounding box early-exit skips cells outside the hover zone
|
|
108
|
+
*
|
|
99
109
|
* @param time - elapsed time in seconds for animation effects
|
|
100
110
|
* @param hoverPos - optional smoothed mouse position {x, y, intensity} for hover effect
|
|
101
111
|
*/
|
|
@@ -104,6 +114,26 @@ declare function renderFrameToCanvas(ctx: CanvasRenderingContext2D, frame: Ascii
|
|
|
104
114
|
y: number;
|
|
105
115
|
intensity?: number;
|
|
106
116
|
} | null): void;
|
|
117
|
+
interface AsciifySimpleOptions {
|
|
118
|
+
/** Character size in pixels. Default: 10 */
|
|
119
|
+
fontSize?: number;
|
|
120
|
+
/** Art style preset. Default: 'classic' */
|
|
121
|
+
style?: ArtStyle;
|
|
122
|
+
/** Extra options to merge on top of the preset */
|
|
123
|
+
options?: Partial<AsciiOptions>;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Convert an image/video/canvas element to ASCII art and render it onto a canvas.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* const img = document.querySelector('img');
|
|
130
|
+
* const canvas = document.querySelector('canvas');
|
|
131
|
+
* await asciify(img, canvas);
|
|
132
|
+
*
|
|
133
|
+
* @example with options
|
|
134
|
+
* await asciify(img, canvas, { fontSize: 8, style: 'letters' });
|
|
135
|
+
*/
|
|
136
|
+
declare function asciify(source: HTMLImageElement | HTMLVideoElement | HTMLCanvasElement | string, canvas: HTMLCanvasElement, { fontSize, style, options }?: AsciifySimpleOptions): Promise<void>;
|
|
107
137
|
/**
|
|
108
138
|
* Generate a self-contained HTML embed snippet for an ASCII image.
|
|
109
139
|
* Features: canvas rendering, animation loop, hover effects.
|
|
@@ -115,4 +145,21 @@ declare function generateEmbedCode(frame: AsciiFrame, options: AsciiOptions, wid
|
|
|
115
145
|
*/
|
|
116
146
|
declare function generateAnimatedEmbedCode(frames: AsciiFrame[], options: AsciiOptions, fps: number, width: number, height: number): string;
|
|
117
147
|
|
|
118
|
-
|
|
148
|
+
interface WebGLRenderer {
|
|
149
|
+
render(frame: AsciiFrame, options: AsciiOptions, displayW: number, displayH: number, time: number, hoverPos?: {
|
|
150
|
+
x: number;
|
|
151
|
+
y: number;
|
|
152
|
+
intensity?: number;
|
|
153
|
+
} | null): void;
|
|
154
|
+
/** Call when options or the source frame has changed to invalidate cell data cache. */
|
|
155
|
+
notifyDirty(): void;
|
|
156
|
+
destroy(): void;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Try to create a WebGL2 renderer for the given canvas.
|
|
160
|
+
* Returns null if WebGL2 is unavailable (caller can then use Canvas2D).
|
|
161
|
+
* On setup failure after context is claimed, returns a stub that clears to dark.
|
|
162
|
+
*/
|
|
163
|
+
declare function tryCreateWebGLRenderer(canvas: HTMLCanvasElement): WebGLRenderer | null;
|
|
164
|
+
|
|
165
|
+
export { ART_STYLE_PRESETS, type AnimationStyle, type ArtStyle, type AsciiCell, type AsciiFrame, type AsciiOptions, type AsciiResult, type AsciifySimpleOptions, CHARSETS, type CharsetKey, type ColorMode, DEFAULT_OPTIONS, HOVER_PRESETS, type HoverEffect, type HoverPreset, type RenderMode, type SourceType, type WebGLRenderer, asciify, generateAnimatedEmbedCode, generateEmbedCode, gifToAsciiFrames, imageToAsciiFrame, renderFrameToCanvas, tryCreateWebGLRenderer, videoToAsciiFrames };
|