asciify-engine 1.0.43 → 1.0.44
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/README.md +21 -2
- package/dist/index.cjs +6 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -3
- package/dist/index.d.ts +10 -3
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -87,14 +87,33 @@ setInterval(() => {
|
|
|
87
87
|
import { asciifyLiveVideo } from 'asciify-engine';
|
|
88
88
|
|
|
89
89
|
const canvas = document.getElementById('ascii') as HTMLCanvasElement;
|
|
90
|
-
const stop = await asciifyLiveVideo('/clip.mp4', canvas);
|
|
91
90
|
|
|
92
|
-
//
|
|
91
|
+
// Sizes canvas to the video's native dimensions automatically:
|
|
92
|
+
const stop = await asciifyLiveVideo('/clip.mp4', canvas, { autoSize: true });
|
|
93
|
+
|
|
94
|
+
// With art style:
|
|
93
95
|
const stop = await asciifyLiveVideo('/clip.mp4', canvas, {
|
|
96
|
+
autoSize: true,
|
|
94
97
|
fontSize: 6,
|
|
95
98
|
artStyle: 'matrix',
|
|
96
99
|
});
|
|
97
100
|
|
|
101
|
+
// With lifecycle hooks — useful for sizing the canvas, loading indicators, timers:
|
|
102
|
+
const stop = await asciifyLiveVideo('/clip.mp4', canvas, {
|
|
103
|
+
fontSize: 6,
|
|
104
|
+
onReady: (video) => {
|
|
105
|
+
// Called once when metadata is loaded and playback has started.
|
|
106
|
+
// Resize the canvas to match the video here, update your UI, etc.
|
|
107
|
+
canvas.width = video.videoWidth;
|
|
108
|
+
canvas.height = video.videoHeight;
|
|
109
|
+
setReady(true);
|
|
110
|
+
},
|
|
111
|
+
onFrame: () => {
|
|
112
|
+
// Called after every rendered frame.
|
|
113
|
+
setElapsed(Math.floor(performance.now() / 1000));
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
|
|
98
117
|
// Clean up:
|
|
99
118
|
stop();
|
|
100
119
|
```
|
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 = {}, onReady, onFrame } = {}) {
|
|
1080
|
+
async function asciifyLiveVideo(source, canvas, { fontSize = 10, artStyle = "classic", options = {}, autoSize = false, onReady, onFrame } = {}) {
|
|
1081
1081
|
let video;
|
|
1082
1082
|
let ownedVideo = false;
|
|
1083
1083
|
if (typeof source === "string") {
|
|
@@ -1105,13 +1105,16 @@ async function asciifyLiveVideo(source, canvas, { fontSize = 10, artStyle = "cla
|
|
|
1105
1105
|
});
|
|
1106
1106
|
await video.play().catch(() => {
|
|
1107
1107
|
});
|
|
1108
|
-
onReady?.(video);
|
|
1109
1108
|
} else {
|
|
1110
1109
|
video = source;
|
|
1111
1110
|
if (video.paused) await video.play().catch(() => {
|
|
1112
1111
|
});
|
|
1113
|
-
onReady?.(video);
|
|
1114
1112
|
}
|
|
1113
|
+
if (autoSize) {
|
|
1114
|
+
canvas.width = video.videoWidth;
|
|
1115
|
+
canvas.height = video.videoHeight;
|
|
1116
|
+
}
|
|
1117
|
+
onReady?.(video);
|
|
1115
1118
|
const merged = { ...DEFAULT_OPTIONS, ...ART_STYLE_PRESETS[artStyle], ...options, fontSize };
|
|
1116
1119
|
const ctx = canvas.getContext("2d");
|
|
1117
1120
|
if (!ctx) throw new Error("asciifyLiveVideo: could not get 2d context from canvas.");
|