asciify-engine 1.0.65 → 1.0.66

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 CHANGED
@@ -1177,6 +1177,8 @@ function sizeCanvasToContainer(canvas, container, aspect) {
1177
1177
  canvas.height = Math.round(cssH * dpr);
1178
1178
  canvas.style.width = cssW + "px";
1179
1179
  canvas.style.height = cssH + "px";
1180
+ canvas.__cssW = cssW;
1181
+ canvas.__cssH = cssH;
1180
1182
  }
1181
1183
  async function asciify(source, canvas, { fontSize = 10, artStyle = "classic", options = {} } = {}) {
1182
1184
  let el;
@@ -1254,15 +1256,21 @@ async function asciifyVideo(source, canvas, { fontSize = 10, artStyle = "classic
1254
1256
  video2 = source;
1255
1257
  }
1256
1258
  if (container) sizeCanvasToContainer(canvas, container, video2.videoWidth / video2.videoHeight);
1259
+ const srcW = video2.videoWidth;
1260
+ const srcH = video2.videoHeight;
1257
1261
  const maxDur = trimEnd !== void 0 ? trimEnd - trimStart : 10;
1258
- const { frames, fps } = await videoToAsciiFrames(video2, merged, canvas.width, canvas.height, void 0, maxDur, void 0, trimStart);
1262
+ const { frames, fps } = await videoToAsciiFrames(video2, merged, srcW, srcH, void 0, maxDur, void 0, trimStart);
1259
1263
  let cancelled2 = false, animId2, i = 0, last = performance.now();
1260
1264
  let firstFrame2 = true;
1261
1265
  const interval = 1e3 / fps;
1262
1266
  const tick2 = (now) => {
1263
1267
  if (cancelled2) return;
1268
+ const cssW = canvas.__cssW || canvas.width;
1269
+ const cssH = canvas.__cssH || canvas.height;
1264
1270
  if (now - last >= interval) {
1265
- renderFrameToCanvas(ctx, frames[i], merged, canvas.width, canvas.height);
1271
+ const dpr = window.devicePixelRatio || 1;
1272
+ ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
1273
+ renderFrameToCanvas(ctx, frames[i], merged, cssW, cssH);
1266
1274
  i = (i + 1) % frames.length;
1267
1275
  last = now;
1268
1276
  if (firstFrame2) {
@@ -1348,9 +1356,15 @@ async function asciifyVideo(source, canvas, { fontSize = 10, artStyle = "classic
1348
1356
  if (video.readyState < 2 || canvas.width === 0 || canvas.height === 0) return;
1349
1357
  if (trimStart > 0 && video.currentTime < trimStart) return;
1350
1358
  if (trimEnd !== void 0 && video.currentTime >= trimEnd) return;
1351
- const { frame } = imageToAsciiFrame(video, merged, canvas.width, canvas.height);
1359
+ const srcW = video.videoWidth;
1360
+ const srcH = video.videoHeight;
1361
+ const { frame } = imageToAsciiFrame(video, merged, srcW, srcH);
1352
1362
  if (frame.length > 0) {
1353
- renderFrameToCanvas(ctx, frame, merged, canvas.width, canvas.height, 0, null);
1363
+ const cssW = canvas.__cssW || canvas.width;
1364
+ const cssH = canvas.__cssH || canvas.height;
1365
+ const dpr = window.devicePixelRatio || 1;
1366
+ ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
1367
+ renderFrameToCanvas(ctx, frame, merged, cssW, cssH, 0, null);
1354
1368
  if (firstFrame) {
1355
1369
  firstFrame = false;
1356
1370
  onReady?.(video);