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.cjs CHANGED
@@ -1170,8 +1170,15 @@ function sizeCanvasToContainer(canvas, container, aspect) {
1170
1170
  h = height;
1171
1171
  w = h * aspect;
1172
1172
  }
1173
- canvas.width = Math.round(w);
1174
- canvas.height = Math.round(h);
1173
+ const dpr = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
1174
+ const cssW = Math.round(w);
1175
+ const cssH = Math.round(h);
1176
+ canvas.width = Math.round(cssW * dpr);
1177
+ canvas.height = Math.round(cssH * dpr);
1178
+ canvas.style.width = cssW + "px";
1179
+ canvas.style.height = cssH + "px";
1180
+ canvas.__cssW = cssW;
1181
+ canvas.__cssH = cssH;
1175
1182
  }
1176
1183
  async function asciify(source, canvas, { fontSize = 10, artStyle = "classic", options = {} } = {}) {
1177
1184
  let el;
@@ -1249,15 +1256,21 @@ async function asciifyVideo(source, canvas, { fontSize = 10, artStyle = "classic
1249
1256
  video2 = source;
1250
1257
  }
1251
1258
  if (container) sizeCanvasToContainer(canvas, container, video2.videoWidth / video2.videoHeight);
1259
+ const srcW = video2.videoWidth;
1260
+ const srcH = video2.videoHeight;
1252
1261
  const maxDur = trimEnd !== void 0 ? trimEnd - trimStart : 10;
1253
- 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);
1254
1263
  let cancelled2 = false, animId2, i = 0, last = performance.now();
1255
1264
  let firstFrame2 = true;
1256
1265
  const interval = 1e3 / fps;
1257
1266
  const tick2 = (now) => {
1258
1267
  if (cancelled2) return;
1268
+ const cssW = canvas.__cssW || canvas.width;
1269
+ const cssH = canvas.__cssH || canvas.height;
1259
1270
  if (now - last >= interval) {
1260
- 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);
1261
1274
  i = (i + 1) % frames.length;
1262
1275
  last = now;
1263
1276
  if (firstFrame2) {
@@ -1343,9 +1356,15 @@ async function asciifyVideo(source, canvas, { fontSize = 10, artStyle = "classic
1343
1356
  if (video.readyState < 2 || canvas.width === 0 || canvas.height === 0) return;
1344
1357
  if (trimStart > 0 && video.currentTime < trimStart) return;
1345
1358
  if (trimEnd !== void 0 && video.currentTime >= trimEnd) return;
1346
- 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);
1347
1362
  if (frame.length > 0) {
1348
- 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);
1349
1368
  if (firstFrame) {
1350
1369
  firstFrame = false;
1351
1370
  onReady?.(video);