asciify-engine 1.0.2 → 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 +28 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -1
- package/dist/index.d.ts +21 -1
- package/dist/index.js +28 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -114,6 +114,26 @@ declare function renderFrameToCanvas(ctx: CanvasRenderingContext2D, frame: Ascii
|
|
|
114
114
|
y: number;
|
|
115
115
|
intensity?: number;
|
|
116
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>;
|
|
117
137
|
/**
|
|
118
138
|
* Generate a self-contained HTML embed snippet for an ASCII image.
|
|
119
139
|
* Features: canvas rendering, animation loop, hover effects.
|
|
@@ -142,4 +162,4 @@ interface WebGLRenderer {
|
|
|
142
162
|
*/
|
|
143
163
|
declare function tryCreateWebGLRenderer(canvas: HTMLCanvasElement): WebGLRenderer | null;
|
|
144
164
|
|
|
145
|
-
export { ART_STYLE_PRESETS, type AnimationStyle, type ArtStyle, type AsciiCell, type AsciiFrame, type AsciiOptions, type AsciiResult, CHARSETS, type CharsetKey, type ColorMode, DEFAULT_OPTIONS, HOVER_PRESETS, type HoverEffect, type HoverPreset, type RenderMode, type SourceType, type WebGLRenderer, generateAnimatedEmbedCode, generateEmbedCode, gifToAsciiFrames, imageToAsciiFrame, renderFrameToCanvas, tryCreateWebGLRenderer, videoToAsciiFrames };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -114,6 +114,26 @@ declare function renderFrameToCanvas(ctx: CanvasRenderingContext2D, frame: Ascii
|
|
|
114
114
|
y: number;
|
|
115
115
|
intensity?: number;
|
|
116
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>;
|
|
117
137
|
/**
|
|
118
138
|
* Generate a self-contained HTML embed snippet for an ASCII image.
|
|
119
139
|
* Features: canvas rendering, animation loop, hover effects.
|
|
@@ -142,4 +162,4 @@ interface WebGLRenderer {
|
|
|
142
162
|
*/
|
|
143
163
|
declare function tryCreateWebGLRenderer(canvas: HTMLCanvasElement): WebGLRenderer | null;
|
|
144
164
|
|
|
145
|
-
export { ART_STYLE_PRESETS, type AnimationStyle, type ArtStyle, type AsciiCell, type AsciiFrame, type AsciiOptions, type AsciiResult, CHARSETS, type CharsetKey, type ColorMode, DEFAULT_OPTIONS, HOVER_PRESETS, type HoverEffect, type HoverPreset, type RenderMode, type SourceType, type WebGLRenderer, generateAnimatedEmbedCode, generateEmbedCode, gifToAsciiFrames, imageToAsciiFrame, renderFrameToCanvas, tryCreateWebGLRenderer, videoToAsciiFrames };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -729,6 +729,33 @@ function buildColorFnJS(options) {
|
|
|
729
729
|
return `function(c){var g=Math.floor(.299*c.r+.587*c.g+.114*c.b);return 'rgb('+g+','+g+','+g+')'}`;
|
|
730
730
|
}
|
|
731
731
|
}
|
|
732
|
+
async function asciify(source, canvas, { fontSize = 10, style = "classic", options = {} } = {}) {
|
|
733
|
+
let el;
|
|
734
|
+
if (typeof source === "string") {
|
|
735
|
+
const img = new Image();
|
|
736
|
+
img.crossOrigin = "anonymous";
|
|
737
|
+
await new Promise((resolve, reject) => {
|
|
738
|
+
img.onload = () => resolve();
|
|
739
|
+
img.onerror = () => reject(new Error(`Failed to load image: ${source}`));
|
|
740
|
+
img.src = source;
|
|
741
|
+
});
|
|
742
|
+
el = img;
|
|
743
|
+
} else if (source instanceof HTMLImageElement && !source.complete) {
|
|
744
|
+
await new Promise((resolve, reject) => {
|
|
745
|
+
source.onload = () => resolve();
|
|
746
|
+
source.onerror = () => reject(new Error("Image failed to load"));
|
|
747
|
+
});
|
|
748
|
+
el = source;
|
|
749
|
+
} else {
|
|
750
|
+
el = source;
|
|
751
|
+
}
|
|
752
|
+
const preset = ART_STYLE_PRESETS[style];
|
|
753
|
+
const merged = { ...DEFAULT_OPTIONS, ...preset, ...options, fontSize };
|
|
754
|
+
const ctx = canvas.getContext("2d");
|
|
755
|
+
if (!ctx) throw new Error("Could not get 2d context from canvas");
|
|
756
|
+
const { frame } = imageToAsciiFrame(el, merged, canvas.width, canvas.height);
|
|
757
|
+
renderFrameToCanvas(ctx, frame, merged, canvas.width, canvas.height);
|
|
758
|
+
}
|
|
732
759
|
function generateEmbedCode(frame, options, width, height) {
|
|
733
760
|
const rows = frame.length;
|
|
734
761
|
if (rows === 0) return "";
|
|
@@ -1361,6 +1388,6 @@ function tryCreateWebGLRenderer(canvas) {
|
|
|
1361
1388
|
}
|
|
1362
1389
|
}
|
|
1363
1390
|
|
|
1364
|
-
export { ART_STYLE_PRESETS, CHARSETS, DEFAULT_OPTIONS, HOVER_PRESETS, generateAnimatedEmbedCode, generateEmbedCode, gifToAsciiFrames, imageToAsciiFrame, renderFrameToCanvas, tryCreateWebGLRenderer, videoToAsciiFrames };
|
|
1391
|
+
export { ART_STYLE_PRESETS, CHARSETS, DEFAULT_OPTIONS, HOVER_PRESETS, asciify, generateAnimatedEmbedCode, generateEmbedCode, gifToAsciiFrames, imageToAsciiFrame, renderFrameToCanvas, tryCreateWebGLRenderer, videoToAsciiFrames };
|
|
1365
1392
|
//# sourceMappingURL=index.js.map
|
|
1366
1393
|
//# sourceMappingURL=index.js.map
|