asciify-engine 1.0.42 → 1.0.43
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 +9 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -2
- package/dist/index.d.ts +12 -2
- package/dist/index.js +9 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -232,6 +232,16 @@ interface AsciifySimpleOptions {
|
|
|
232
232
|
/** Extra options to merge on top of the preset */
|
|
233
233
|
options?: Partial<AsciiOptions>;
|
|
234
234
|
}
|
|
235
|
+
interface AsciifyLiveVideoOptions extends AsciifySimpleOptions {
|
|
236
|
+
/**
|
|
237
|
+
* Called once when the video metadata is ready and playback has started.
|
|
238
|
+
* Receive the backing video element — useful for sizing the canvas or
|
|
239
|
+
* triggering a ready state in your UI.
|
|
240
|
+
*/
|
|
241
|
+
onReady?: (video: HTMLVideoElement) => void;
|
|
242
|
+
/** Called after every rendered frame. Useful for frame counters or timers. */
|
|
243
|
+
onFrame?: () => void;
|
|
244
|
+
}
|
|
235
245
|
/**
|
|
236
246
|
* Convert an image/video/canvas element to ASCII art and render it onto a canvas.
|
|
237
247
|
*
|
|
@@ -278,7 +288,7 @@ declare function asciifyVideo(source: HTMLVideoElement | string, canvas: HTMLCan
|
|
|
278
288
|
* const stop = await asciifyLiveVideo('/clip.mp4', canvas);
|
|
279
289
|
* // later: stop();
|
|
280
290
|
*/
|
|
281
|
-
declare function asciifyLiveVideo(source: HTMLVideoElement | string, canvas: HTMLCanvasElement, { fontSize, artStyle, options }?:
|
|
291
|
+
declare function asciifyLiveVideo(source: HTMLVideoElement | string, canvas: HTMLCanvasElement, { fontSize, artStyle, options, onReady, onFrame }?: AsciifyLiveVideoOptions): Promise<() => void>;
|
|
282
292
|
|
|
283
293
|
interface WaveBackgroundOptions {
|
|
284
294
|
/** Font size in CSS pixels (default: 13) */
|
|
@@ -939,4 +949,4 @@ interface WebcamOptions {
|
|
|
939
949
|
*/
|
|
940
950
|
declare function asciifyWebcam(canvas: HTMLCanvasElement, { fontSize, style, options, liveOptions, mirror, constraints, dpr: dprOverride, }?: WebcamOptions): Promise<() => void>;
|
|
941
951
|
|
|
942
|
-
export { ART_STYLE_PRESETS, type AnimationStyle, type ArtStyle, type AsciiBackgroundOptions, type AsciiCell, type AsciiFrame, type AsciiOptions, type AsciiResult, type AsciifySimpleOptions, type AuroraBackgroundOptions, BACKGROUND_TYPES, type BackgroundType, CHARSETS, type CharsetKey, type CircuitBackgroundOptions, type ColorMode, DEFAULT_OPTIONS, type DnaBackgroundOptions, type FireBackgroundOptions, type GridBackgroundOptions, HOVER_PRESETS, type HoverEffect, type HoverPreset, type MorphBackgroundOptions, type MountWaveOptions, type NoiseBackgroundOptions, PALETTE_THEMES, type PaletteTheme, type PulseBackgroundOptions, type RainBackgroundOptions, type RenderMode, type SilkBackgroundOptions, type SnapshotOptions, type SourceType, type StarsBackgroundOptions, type TerrainBackgroundOptions, type TextBackgroundOptions, type VoidBackgroundOptions, type WaveBackgroundOptions, type WebcamOptions, asciiBackground, asciiText, asciiTextAnsi, asciify, asciifyGif, asciifyLiveVideo, asciifyVideo, asciifyWebcam, buildTextFrame, captureSnapshot, gifToAsciiFrames, imageToAsciiFrame, mountWaveBackground, renderAuroraBackground, renderCircuitBackground, renderDnaBackground, renderFireBackground, renderFrameToCanvas, renderGridBackground, renderMorphBackground, renderNoiseBackground, renderPulseBackground, renderRainBackground, renderSilkBackground, renderStarsBackground, renderTerrainBackground, renderTextBackground, renderVoidBackground, renderWaveBackground, snapshotAndDownload, videoToAsciiFrames };
|
|
952
|
+
export { ART_STYLE_PRESETS, type AnimationStyle, type ArtStyle, type AsciiBackgroundOptions, type AsciiCell, type AsciiFrame, type AsciiOptions, type AsciiResult, type AsciifyLiveVideoOptions, type AsciifySimpleOptions, type AuroraBackgroundOptions, BACKGROUND_TYPES, type BackgroundType, CHARSETS, type CharsetKey, type CircuitBackgroundOptions, type ColorMode, DEFAULT_OPTIONS, type DnaBackgroundOptions, type FireBackgroundOptions, type GridBackgroundOptions, HOVER_PRESETS, type HoverEffect, type HoverPreset, type MorphBackgroundOptions, type MountWaveOptions, type NoiseBackgroundOptions, PALETTE_THEMES, type PaletteTheme, type PulseBackgroundOptions, type RainBackgroundOptions, type RenderMode, type SilkBackgroundOptions, type SnapshotOptions, type SourceType, type StarsBackgroundOptions, type TerrainBackgroundOptions, type TextBackgroundOptions, type VoidBackgroundOptions, type WaveBackgroundOptions, type WebcamOptions, asciiBackground, asciiText, asciiTextAnsi, asciify, asciifyGif, asciifyLiveVideo, asciifyVideo, asciifyWebcam, buildTextFrame, captureSnapshot, gifToAsciiFrames, imageToAsciiFrame, mountWaveBackground, renderAuroraBackground, renderCircuitBackground, renderDnaBackground, renderFireBackground, renderFrameToCanvas, renderGridBackground, renderMorphBackground, renderNoiseBackground, renderPulseBackground, renderRainBackground, renderSilkBackground, renderStarsBackground, renderTerrainBackground, renderTextBackground, renderVoidBackground, renderWaveBackground, snapshotAndDownload, videoToAsciiFrames };
|
package/dist/index.d.ts
CHANGED
|
@@ -232,6 +232,16 @@ interface AsciifySimpleOptions {
|
|
|
232
232
|
/** Extra options to merge on top of the preset */
|
|
233
233
|
options?: Partial<AsciiOptions>;
|
|
234
234
|
}
|
|
235
|
+
interface AsciifyLiveVideoOptions extends AsciifySimpleOptions {
|
|
236
|
+
/**
|
|
237
|
+
* Called once when the video metadata is ready and playback has started.
|
|
238
|
+
* Receive the backing video element — useful for sizing the canvas or
|
|
239
|
+
* triggering a ready state in your UI.
|
|
240
|
+
*/
|
|
241
|
+
onReady?: (video: HTMLVideoElement) => void;
|
|
242
|
+
/** Called after every rendered frame. Useful for frame counters or timers. */
|
|
243
|
+
onFrame?: () => void;
|
|
244
|
+
}
|
|
235
245
|
/**
|
|
236
246
|
* Convert an image/video/canvas element to ASCII art and render it onto a canvas.
|
|
237
247
|
*
|
|
@@ -278,7 +288,7 @@ declare function asciifyVideo(source: HTMLVideoElement | string, canvas: HTMLCan
|
|
|
278
288
|
* const stop = await asciifyLiveVideo('/clip.mp4', canvas);
|
|
279
289
|
* // later: stop();
|
|
280
290
|
*/
|
|
281
|
-
declare function asciifyLiveVideo(source: HTMLVideoElement | string, canvas: HTMLCanvasElement, { fontSize, artStyle, options }?:
|
|
291
|
+
declare function asciifyLiveVideo(source: HTMLVideoElement | string, canvas: HTMLCanvasElement, { fontSize, artStyle, options, onReady, onFrame }?: AsciifyLiveVideoOptions): Promise<() => void>;
|
|
282
292
|
|
|
283
293
|
interface WaveBackgroundOptions {
|
|
284
294
|
/** Font size in CSS pixels (default: 13) */
|
|
@@ -939,4 +949,4 @@ interface WebcamOptions {
|
|
|
939
949
|
*/
|
|
940
950
|
declare function asciifyWebcam(canvas: HTMLCanvasElement, { fontSize, style, options, liveOptions, mirror, constraints, dpr: dprOverride, }?: WebcamOptions): Promise<() => void>;
|
|
941
951
|
|
|
942
|
-
export { ART_STYLE_PRESETS, type AnimationStyle, type ArtStyle, type AsciiBackgroundOptions, type AsciiCell, type AsciiFrame, type AsciiOptions, type AsciiResult, type AsciifySimpleOptions, type AuroraBackgroundOptions, BACKGROUND_TYPES, type BackgroundType, CHARSETS, type CharsetKey, type CircuitBackgroundOptions, type ColorMode, DEFAULT_OPTIONS, type DnaBackgroundOptions, type FireBackgroundOptions, type GridBackgroundOptions, HOVER_PRESETS, type HoverEffect, type HoverPreset, type MorphBackgroundOptions, type MountWaveOptions, type NoiseBackgroundOptions, PALETTE_THEMES, type PaletteTheme, type PulseBackgroundOptions, type RainBackgroundOptions, type RenderMode, type SilkBackgroundOptions, type SnapshotOptions, type SourceType, type StarsBackgroundOptions, type TerrainBackgroundOptions, type TextBackgroundOptions, type VoidBackgroundOptions, type WaveBackgroundOptions, type WebcamOptions, asciiBackground, asciiText, asciiTextAnsi, asciify, asciifyGif, asciifyLiveVideo, asciifyVideo, asciifyWebcam, buildTextFrame, captureSnapshot, gifToAsciiFrames, imageToAsciiFrame, mountWaveBackground, renderAuroraBackground, renderCircuitBackground, renderDnaBackground, renderFireBackground, renderFrameToCanvas, renderGridBackground, renderMorphBackground, renderNoiseBackground, renderPulseBackground, renderRainBackground, renderSilkBackground, renderStarsBackground, renderTerrainBackground, renderTextBackground, renderVoidBackground, renderWaveBackground, snapshotAndDownload, videoToAsciiFrames };
|
|
952
|
+
export { ART_STYLE_PRESETS, type AnimationStyle, type ArtStyle, type AsciiBackgroundOptions, type AsciiCell, type AsciiFrame, type AsciiOptions, type AsciiResult, type AsciifyLiveVideoOptions, type AsciifySimpleOptions, type AuroraBackgroundOptions, BACKGROUND_TYPES, type BackgroundType, CHARSETS, type CharsetKey, type CircuitBackgroundOptions, type ColorMode, DEFAULT_OPTIONS, type DnaBackgroundOptions, type FireBackgroundOptions, type GridBackgroundOptions, HOVER_PRESETS, type HoverEffect, type HoverPreset, type MorphBackgroundOptions, type MountWaveOptions, type NoiseBackgroundOptions, PALETTE_THEMES, type PaletteTheme, type PulseBackgroundOptions, type RainBackgroundOptions, type RenderMode, type SilkBackgroundOptions, type SnapshotOptions, type SourceType, type StarsBackgroundOptions, type TerrainBackgroundOptions, type TextBackgroundOptions, type VoidBackgroundOptions, type WaveBackgroundOptions, type WebcamOptions, asciiBackground, asciiText, asciiTextAnsi, asciify, asciifyGif, asciifyLiveVideo, asciifyVideo, asciifyWebcam, buildTextFrame, captureSnapshot, gifToAsciiFrames, imageToAsciiFrame, mountWaveBackground, renderAuroraBackground, renderCircuitBackground, renderDnaBackground, renderFireBackground, renderFrameToCanvas, renderGridBackground, renderMorphBackground, renderNoiseBackground, renderPulseBackground, renderRainBackground, renderSilkBackground, renderStarsBackground, renderTerrainBackground, renderTextBackground, renderVoidBackground, renderWaveBackground, snapshotAndDownload, videoToAsciiFrames };
|
package/dist/index.js
CHANGED
|
@@ -1075,7 +1075,7 @@ async function asciifyVideo(source, canvas, { fontSize = 10, artStyle = "classic
|
|
|
1075
1075
|
cancelAnimationFrame(animId);
|
|
1076
1076
|
};
|
|
1077
1077
|
}
|
|
1078
|
-
async function asciifyLiveVideo(source, canvas, { fontSize = 10, artStyle = "classic", options = {} } = {}) {
|
|
1078
|
+
async function asciifyLiveVideo(source, canvas, { fontSize = 10, artStyle = "classic", options = {}, onReady, onFrame } = {}) {
|
|
1079
1079
|
let video;
|
|
1080
1080
|
let ownedVideo = false;
|
|
1081
1081
|
if (typeof source === "string") {
|
|
@@ -1101,12 +1101,14 @@ async function asciifyLiveVideo(source, canvas, { fontSize = 10, artStyle = "cla
|
|
|
1101
1101
|
video.onloadedmetadata = () => resolve();
|
|
1102
1102
|
video.onerror = () => reject(new Error(`asciifyLiveVideo: failed to load "${source}"`));
|
|
1103
1103
|
});
|
|
1104
|
-
video.play().catch(() => {
|
|
1104
|
+
await video.play().catch(() => {
|
|
1105
1105
|
});
|
|
1106
|
+
onReady?.(video);
|
|
1106
1107
|
} else {
|
|
1107
1108
|
video = source;
|
|
1108
|
-
if (video.paused) video.play().catch(() => {
|
|
1109
|
+
if (video.paused) await video.play().catch(() => {
|
|
1109
1110
|
});
|
|
1111
|
+
onReady?.(video);
|
|
1110
1112
|
}
|
|
1111
1113
|
const merged = { ...DEFAULT_OPTIONS, ...ART_STYLE_PRESETS[artStyle], ...options, fontSize };
|
|
1112
1114
|
const ctx = canvas.getContext("2d");
|
|
@@ -1118,7 +1120,10 @@ async function asciifyLiveVideo(source, canvas, { fontSize = 10, artStyle = "cla
|
|
|
1118
1120
|
animId = requestAnimationFrame(tick);
|
|
1119
1121
|
if (video.readyState < 2 || canvas.width === 0 || canvas.height === 0) return;
|
|
1120
1122
|
const { frame } = imageToAsciiFrame(video, merged, canvas.width, canvas.height);
|
|
1121
|
-
if (frame.length > 0)
|
|
1123
|
+
if (frame.length > 0) {
|
|
1124
|
+
renderFrameToCanvas(ctx, frame, merged, canvas.width, canvas.height, 0, null);
|
|
1125
|
+
onFrame?.();
|
|
1126
|
+
}
|
|
1122
1127
|
};
|
|
1123
1128
|
animId = requestAnimationFrame(tick);
|
|
1124
1129
|
return () => {
|