asciify-engine 1.0.3 → 1.0.5
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 +65 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +27 -2
- package/dist/index.d.ts +27 -2
- package/dist/index.js +64 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -4,7 +4,7 @@ type AnimationStyle = 'none' | 'wave' | 'pulse' | 'rain' | 'breathe' | 'sparkle'
|
|
|
4
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
|
-
type SourceType = 'image' | 'video' | null;
|
|
7
|
+
type SourceType = 'image' | 'video' | 'gif' | null;
|
|
8
8
|
interface AsciiOptions {
|
|
9
9
|
fontSize: number;
|
|
10
10
|
charSpacing: number;
|
|
@@ -134,6 +134,31 @@ interface AsciifySimpleOptions {
|
|
|
134
134
|
* await asciify(img, canvas, { fontSize: 8, style: 'letters' });
|
|
135
135
|
*/
|
|
136
136
|
declare function asciify(source: HTMLImageElement | HTMLVideoElement | HTMLCanvasElement | string, canvas: HTMLCanvasElement, { fontSize, style, options }?: AsciifySimpleOptions): Promise<void>;
|
|
137
|
+
/**
|
|
138
|
+
* Fetch a GIF, convert it to ASCII, and start an animation loop on a canvas.
|
|
139
|
+
* Returns a `stop()` function that cancels the loop.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* const stop = await asciifyGif('animation.gif', canvas);
|
|
143
|
+
* // later: stop();
|
|
144
|
+
*
|
|
145
|
+
* @example with style
|
|
146
|
+
* const stop = await asciifyGif('animation.gif', canvas, { style: 'letters' });
|
|
147
|
+
*/
|
|
148
|
+
declare function asciifyGif(source: string | ArrayBuffer, canvas: HTMLCanvasElement, { fontSize, style, options }?: AsciifySimpleOptions): Promise<() => void>;
|
|
149
|
+
/**
|
|
150
|
+
* Convert a video element to ASCII art and start an animation loop on a canvas.
|
|
151
|
+
* Returns a `stop()` function that cancels the loop.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* const video = document.querySelector('video');
|
|
155
|
+
* const stop = await asciifyVideo(video, canvas);
|
|
156
|
+
* // later: stop();
|
|
157
|
+
*
|
|
158
|
+
* @example with style
|
|
159
|
+
* const stop = await asciifyVideo(video, canvas, { fontSize: 8, style: 'art' });
|
|
160
|
+
*/
|
|
161
|
+
declare function asciifyVideo(source: HTMLVideoElement | string, canvas: HTMLCanvasElement, { fontSize, style, options }?: AsciifySimpleOptions): Promise<() => void>;
|
|
137
162
|
/**
|
|
138
163
|
* Generate a self-contained HTML embed snippet for an ASCII image.
|
|
139
164
|
* Features: canvas rendering, animation loop, hover effects.
|
|
@@ -162,4 +187,4 @@ interface WebGLRenderer {
|
|
|
162
187
|
*/
|
|
163
188
|
declare function tryCreateWebGLRenderer(canvas: HTMLCanvasElement): WebGLRenderer | null;
|
|
164
189
|
|
|
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 };
|
|
190
|
+
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, asciifyGif, asciifyVideo, generateAnimatedEmbedCode, generateEmbedCode, gifToAsciiFrames, imageToAsciiFrame, renderFrameToCanvas, tryCreateWebGLRenderer, videoToAsciiFrames };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ type AnimationStyle = 'none' | 'wave' | 'pulse' | 'rain' | 'breathe' | 'sparkle'
|
|
|
4
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
|
-
type SourceType = 'image' | 'video' | null;
|
|
7
|
+
type SourceType = 'image' | 'video' | 'gif' | null;
|
|
8
8
|
interface AsciiOptions {
|
|
9
9
|
fontSize: number;
|
|
10
10
|
charSpacing: number;
|
|
@@ -134,6 +134,31 @@ interface AsciifySimpleOptions {
|
|
|
134
134
|
* await asciify(img, canvas, { fontSize: 8, style: 'letters' });
|
|
135
135
|
*/
|
|
136
136
|
declare function asciify(source: HTMLImageElement | HTMLVideoElement | HTMLCanvasElement | string, canvas: HTMLCanvasElement, { fontSize, style, options }?: AsciifySimpleOptions): Promise<void>;
|
|
137
|
+
/**
|
|
138
|
+
* Fetch a GIF, convert it to ASCII, and start an animation loop on a canvas.
|
|
139
|
+
* Returns a `stop()` function that cancels the loop.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* const stop = await asciifyGif('animation.gif', canvas);
|
|
143
|
+
* // later: stop();
|
|
144
|
+
*
|
|
145
|
+
* @example with style
|
|
146
|
+
* const stop = await asciifyGif('animation.gif', canvas, { style: 'letters' });
|
|
147
|
+
*/
|
|
148
|
+
declare function asciifyGif(source: string | ArrayBuffer, canvas: HTMLCanvasElement, { fontSize, style, options }?: AsciifySimpleOptions): Promise<() => void>;
|
|
149
|
+
/**
|
|
150
|
+
* Convert a video element to ASCII art and start an animation loop on a canvas.
|
|
151
|
+
* Returns a `stop()` function that cancels the loop.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* const video = document.querySelector('video');
|
|
155
|
+
* const stop = await asciifyVideo(video, canvas);
|
|
156
|
+
* // later: stop();
|
|
157
|
+
*
|
|
158
|
+
* @example with style
|
|
159
|
+
* const stop = await asciifyVideo(video, canvas, { fontSize: 8, style: 'art' });
|
|
160
|
+
*/
|
|
161
|
+
declare function asciifyVideo(source: HTMLVideoElement | string, canvas: HTMLCanvasElement, { fontSize, style, options }?: AsciifySimpleOptions): Promise<() => void>;
|
|
137
162
|
/**
|
|
138
163
|
* Generate a self-contained HTML embed snippet for an ASCII image.
|
|
139
164
|
* Features: canvas rendering, animation loop, hover effects.
|
|
@@ -162,4 +187,4 @@ interface WebGLRenderer {
|
|
|
162
187
|
*/
|
|
163
188
|
declare function tryCreateWebGLRenderer(canvas: HTMLCanvasElement): WebGLRenderer | null;
|
|
164
189
|
|
|
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 };
|
|
190
|
+
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, asciifyGif, asciifyVideo, generateAnimatedEmbedCode, generateEmbedCode, gifToAsciiFrames, imageToAsciiFrame, renderFrameToCanvas, tryCreateWebGLRenderer, videoToAsciiFrames };
|
package/dist/index.js
CHANGED
|
@@ -756,6 +756,69 @@ async function asciify(source, canvas, { fontSize = 10, style = "classic", optio
|
|
|
756
756
|
const { frame } = imageToAsciiFrame(el, merged, canvas.width, canvas.height);
|
|
757
757
|
renderFrameToCanvas(ctx, frame, merged, canvas.width, canvas.height);
|
|
758
758
|
}
|
|
759
|
+
async function asciifyGif(source, canvas, { fontSize = 10, style = "classic", options = {} } = {}) {
|
|
760
|
+
const buffer = typeof source === "string" ? await fetch(source).then((r) => r.arrayBuffer()) : source;
|
|
761
|
+
const merged = { ...DEFAULT_OPTIONS, ...ART_STYLE_PRESETS[style], ...options, fontSize };
|
|
762
|
+
const ctx = canvas.getContext("2d");
|
|
763
|
+
if (!ctx) throw new Error("Could not get 2d context from canvas");
|
|
764
|
+
const { frames, fps } = await gifToAsciiFrames(buffer, merged, canvas.width, canvas.height);
|
|
765
|
+
let cancelled = false;
|
|
766
|
+
let animId;
|
|
767
|
+
let i = 0;
|
|
768
|
+
let last = performance.now();
|
|
769
|
+
const interval = 1e3 / fps;
|
|
770
|
+
const tick = (now) => {
|
|
771
|
+
if (cancelled) return;
|
|
772
|
+
if (now - last >= interval) {
|
|
773
|
+
renderFrameToCanvas(ctx, frames[i], merged, canvas.width, canvas.height);
|
|
774
|
+
i = (i + 1) % frames.length;
|
|
775
|
+
last = now;
|
|
776
|
+
}
|
|
777
|
+
animId = requestAnimationFrame(tick);
|
|
778
|
+
};
|
|
779
|
+
animId = requestAnimationFrame(tick);
|
|
780
|
+
return () => {
|
|
781
|
+
cancelled = true;
|
|
782
|
+
cancelAnimationFrame(animId);
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
async function asciifyVideo(source, canvas, { fontSize = 10, style = "classic", options = {} } = {}) {
|
|
786
|
+
let video;
|
|
787
|
+
if (typeof source === "string") {
|
|
788
|
+
video = document.createElement("video");
|
|
789
|
+
video.crossOrigin = "anonymous";
|
|
790
|
+
video.src = source;
|
|
791
|
+
await new Promise((resolve, reject) => {
|
|
792
|
+
video.onloadeddata = () => resolve();
|
|
793
|
+
video.onerror = () => reject(new Error(`Failed to load video: ${source}`));
|
|
794
|
+
});
|
|
795
|
+
} else {
|
|
796
|
+
video = source;
|
|
797
|
+
}
|
|
798
|
+
const merged = { ...DEFAULT_OPTIONS, ...ART_STYLE_PRESETS[style], ...options, fontSize };
|
|
799
|
+
const ctx = canvas.getContext("2d");
|
|
800
|
+
if (!ctx) throw new Error("Could not get 2d context from canvas");
|
|
801
|
+
const { frames, fps } = await videoToAsciiFrames(video, merged, canvas.width, canvas.height);
|
|
802
|
+
let cancelled = false;
|
|
803
|
+
let animId;
|
|
804
|
+
let i = 0;
|
|
805
|
+
let last = performance.now();
|
|
806
|
+
const interval = 1e3 / fps;
|
|
807
|
+
const tick = (now) => {
|
|
808
|
+
if (cancelled) return;
|
|
809
|
+
if (now - last >= interval) {
|
|
810
|
+
renderFrameToCanvas(ctx, frames[i], merged, canvas.width, canvas.height);
|
|
811
|
+
i = (i + 1) % frames.length;
|
|
812
|
+
last = now;
|
|
813
|
+
}
|
|
814
|
+
animId = requestAnimationFrame(tick);
|
|
815
|
+
};
|
|
816
|
+
animId = requestAnimationFrame(tick);
|
|
817
|
+
return () => {
|
|
818
|
+
cancelled = true;
|
|
819
|
+
cancelAnimationFrame(animId);
|
|
820
|
+
};
|
|
821
|
+
}
|
|
759
822
|
function generateEmbedCode(frame, options, width, height) {
|
|
760
823
|
const rows = frame.length;
|
|
761
824
|
if (rows === 0) return "";
|
|
@@ -1388,6 +1451,6 @@ function tryCreateWebGLRenderer(canvas) {
|
|
|
1388
1451
|
}
|
|
1389
1452
|
}
|
|
1390
1453
|
|
|
1391
|
-
export { ART_STYLE_PRESETS, CHARSETS, DEFAULT_OPTIONS, HOVER_PRESETS, asciify, generateAnimatedEmbedCode, generateEmbedCode, gifToAsciiFrames, imageToAsciiFrame, renderFrameToCanvas, tryCreateWebGLRenderer, videoToAsciiFrames };
|
|
1454
|
+
export { ART_STYLE_PRESETS, CHARSETS, DEFAULT_OPTIONS, HOVER_PRESETS, asciify, asciifyGif, asciifyVideo, generateAnimatedEmbedCode, generateEmbedCode, gifToAsciiFrames, imageToAsciiFrame, renderFrameToCanvas, tryCreateWebGLRenderer, videoToAsciiFrames };
|
|
1392
1455
|
//# sourceMappingURL=index.js.map
|
|
1393
1456
|
//# sourceMappingURL=index.js.map
|