asciify-engine 1.0.64 → 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.js CHANGED
@@ -1168,8 +1168,15 @@ function sizeCanvasToContainer(canvas, container, aspect) {
1168
1168
  h = height;
1169
1169
  w = h * aspect;
1170
1170
  }
1171
- canvas.width = Math.round(w);
1172
- canvas.height = Math.round(h);
1171
+ const dpr = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
1172
+ const cssW = Math.round(w);
1173
+ const cssH = Math.round(h);
1174
+ canvas.width = Math.round(cssW * dpr);
1175
+ canvas.height = Math.round(cssH * dpr);
1176
+ canvas.style.width = cssW + "px";
1177
+ canvas.style.height = cssH + "px";
1178
+ canvas.__cssW = cssW;
1179
+ canvas.__cssH = cssH;
1173
1180
  }
1174
1181
  async function asciify(source, canvas, { fontSize = 10, artStyle = "classic", options = {} } = {}) {
1175
1182
  let el;
@@ -1247,15 +1254,21 @@ async function asciifyVideo(source, canvas, { fontSize = 10, artStyle = "classic
1247
1254
  video2 = source;
1248
1255
  }
1249
1256
  if (container) sizeCanvasToContainer(canvas, container, video2.videoWidth / video2.videoHeight);
1257
+ const srcW = video2.videoWidth;
1258
+ const srcH = video2.videoHeight;
1250
1259
  const maxDur = trimEnd !== void 0 ? trimEnd - trimStart : 10;
1251
- const { frames, fps } = await videoToAsciiFrames(video2, merged, canvas.width, canvas.height, void 0, maxDur, void 0, trimStart);
1260
+ const { frames, fps } = await videoToAsciiFrames(video2, merged, srcW, srcH, void 0, maxDur, void 0, trimStart);
1252
1261
  let cancelled2 = false, animId2, i = 0, last = performance.now();
1253
1262
  let firstFrame2 = true;
1254
1263
  const interval = 1e3 / fps;
1255
1264
  const tick2 = (now) => {
1256
1265
  if (cancelled2) return;
1266
+ const cssW = canvas.__cssW || canvas.width;
1267
+ const cssH = canvas.__cssH || canvas.height;
1257
1268
  if (now - last >= interval) {
1258
- renderFrameToCanvas(ctx, frames[i], merged, canvas.width, canvas.height);
1269
+ const dpr = window.devicePixelRatio || 1;
1270
+ ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
1271
+ renderFrameToCanvas(ctx, frames[i], merged, cssW, cssH);
1259
1272
  i = (i + 1) % frames.length;
1260
1273
  last = now;
1261
1274
  if (firstFrame2) {
@@ -1341,9 +1354,15 @@ async function asciifyVideo(source, canvas, { fontSize = 10, artStyle = "classic
1341
1354
  if (video.readyState < 2 || canvas.width === 0 || canvas.height === 0) return;
1342
1355
  if (trimStart > 0 && video.currentTime < trimStart) return;
1343
1356
  if (trimEnd !== void 0 && video.currentTime >= trimEnd) return;
1344
- const { frame } = imageToAsciiFrame(video, merged, canvas.width, canvas.height);
1357
+ const srcW = video.videoWidth;
1358
+ const srcH = video.videoHeight;
1359
+ const { frame } = imageToAsciiFrame(video, merged, srcW, srcH);
1345
1360
  if (frame.length > 0) {
1346
- renderFrameToCanvas(ctx, frame, merged, canvas.width, canvas.height, 0, null);
1361
+ const cssW = canvas.__cssW || canvas.width;
1362
+ const cssH = canvas.__cssH || canvas.height;
1363
+ const dpr = window.devicePixelRatio || 1;
1364
+ ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
1365
+ renderFrameToCanvas(ctx, frame, merged, cssW, cssH, 0, null);
1347
1366
  if (firstFrame) {
1348
1367
  firstFrame = false;
1349
1368
  onReady?.(video);