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.cjs
CHANGED
|
@@ -1077,7 +1077,7 @@ async function asciifyVideo(source, canvas, { fontSize = 10, artStyle = "classic
|
|
|
1077
1077
|
cancelAnimationFrame(animId);
|
|
1078
1078
|
};
|
|
1079
1079
|
}
|
|
1080
|
-
async function asciifyLiveVideo(source, canvas, { fontSize = 10, artStyle = "classic", options = {} } = {}) {
|
|
1080
|
+
async function asciifyLiveVideo(source, canvas, { fontSize = 10, artStyle = "classic", options = {}, onReady, onFrame } = {}) {
|
|
1081
1081
|
let video;
|
|
1082
1082
|
let ownedVideo = false;
|
|
1083
1083
|
if (typeof source === "string") {
|
|
@@ -1103,12 +1103,14 @@ async function asciifyLiveVideo(source, canvas, { fontSize = 10, artStyle = "cla
|
|
|
1103
1103
|
video.onloadedmetadata = () => resolve();
|
|
1104
1104
|
video.onerror = () => reject(new Error(`asciifyLiveVideo: failed to load "${source}"`));
|
|
1105
1105
|
});
|
|
1106
|
-
video.play().catch(() => {
|
|
1106
|
+
await video.play().catch(() => {
|
|
1107
1107
|
});
|
|
1108
|
+
onReady?.(video);
|
|
1108
1109
|
} else {
|
|
1109
1110
|
video = source;
|
|
1110
|
-
if (video.paused) video.play().catch(() => {
|
|
1111
|
+
if (video.paused) await video.play().catch(() => {
|
|
1111
1112
|
});
|
|
1113
|
+
onReady?.(video);
|
|
1112
1114
|
}
|
|
1113
1115
|
const merged = { ...DEFAULT_OPTIONS, ...ART_STYLE_PRESETS[artStyle], ...options, fontSize };
|
|
1114
1116
|
const ctx = canvas.getContext("2d");
|
|
@@ -1120,7 +1122,10 @@ async function asciifyLiveVideo(source, canvas, { fontSize = 10, artStyle = "cla
|
|
|
1120
1122
|
animId = requestAnimationFrame(tick);
|
|
1121
1123
|
if (video.readyState < 2 || canvas.width === 0 || canvas.height === 0) return;
|
|
1122
1124
|
const { frame } = imageToAsciiFrame(video, merged, canvas.width, canvas.height);
|
|
1123
|
-
if (frame.length > 0)
|
|
1125
|
+
if (frame.length > 0) {
|
|
1126
|
+
renderFrameToCanvas(ctx, frame, merged, canvas.width, canvas.height, 0, null);
|
|
1127
|
+
onFrame?.();
|
|
1128
|
+
}
|
|
1124
1129
|
};
|
|
1125
1130
|
animId = requestAnimationFrame(tick);
|
|
1126
1131
|
return () => {
|