asciify-engine 1.0.67 → 1.0.68
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 +25 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +25 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1162,19 +1162,29 @@ function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, tim
|
|
|
1162
1162
|
}
|
|
1163
1163
|
|
|
1164
1164
|
// src/core/simple-api.ts
|
|
1165
|
-
function sizeCanvasToContainer(canvas, container, aspect) {
|
|
1165
|
+
function sizeCanvasToContainer(canvas, container, aspect, srcW, srcH) {
|
|
1166
1166
|
const { width, height } = container.getBoundingClientRect();
|
|
1167
1167
|
if (!width || !height) return;
|
|
1168
|
-
let
|
|
1169
|
-
if (
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
}
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
const
|
|
1176
|
-
|
|
1177
|
-
|
|
1168
|
+
let cssW = width, cssH = cssW / aspect;
|
|
1169
|
+
if (cssH > height) {
|
|
1170
|
+
cssH = height;
|
|
1171
|
+
cssW = cssH * aspect;
|
|
1172
|
+
}
|
|
1173
|
+
cssW = Math.round(cssW);
|
|
1174
|
+
cssH = Math.round(cssH);
|
|
1175
|
+
const MAX_BUF = 2048;
|
|
1176
|
+
let bufW, bufH;
|
|
1177
|
+
if (srcW && srcH && (srcW > cssW || srcH > cssH)) {
|
|
1178
|
+
const scale = Math.min(1, MAX_BUF / Math.max(srcW, srcH));
|
|
1179
|
+
bufW = Math.round(srcW * scale);
|
|
1180
|
+
bufH = Math.round(srcH * scale);
|
|
1181
|
+
} else {
|
|
1182
|
+
const dpr = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
|
|
1183
|
+
bufW = Math.round(cssW * dpr);
|
|
1184
|
+
bufH = Math.round(cssH * dpr);
|
|
1185
|
+
}
|
|
1186
|
+
canvas.width = bufW;
|
|
1187
|
+
canvas.height = bufH;
|
|
1178
1188
|
canvas.style.width = cssW + "px";
|
|
1179
1189
|
canvas.style.height = cssH + "px";
|
|
1180
1190
|
}
|
|
@@ -1253,7 +1263,7 @@ async function asciifyVideo(source, canvas, { fontSize = 10, artStyle = "classic
|
|
|
1253
1263
|
} else {
|
|
1254
1264
|
video2 = source;
|
|
1255
1265
|
}
|
|
1256
|
-
if (container) sizeCanvasToContainer(canvas, container, video2.videoWidth / video2.videoHeight);
|
|
1266
|
+
if (container) sizeCanvasToContainer(canvas, container, video2.videoWidth / video2.videoHeight, video2.videoWidth, video2.videoHeight);
|
|
1257
1267
|
const maxDur = trimEnd !== void 0 ? trimEnd - trimStart : 10;
|
|
1258
1268
|
const { frames, fps } = await videoToAsciiFrames(video2, merged, canvas.width, canvas.height, void 0, maxDur, void 0, trimStart);
|
|
1259
1269
|
let cancelled2 = false, animId2, i = 0, last = performance.now();
|
|
@@ -1335,8 +1345,9 @@ async function asciifyVideo(source, canvas, { fontSize = 10, artStyle = "classic
|
|
|
1335
1345
|
let ro = null;
|
|
1336
1346
|
if (container) {
|
|
1337
1347
|
const aspect = video.videoWidth / video.videoHeight;
|
|
1338
|
-
|
|
1339
|
-
|
|
1348
|
+
const vw = video.videoWidth, vh = video.videoHeight;
|
|
1349
|
+
sizeCanvasToContainer(canvas, container, aspect, vw, vh);
|
|
1350
|
+
ro = new ResizeObserver(() => sizeCanvasToContainer(canvas, container, aspect, vw, vh));
|
|
1340
1351
|
ro.observe(container);
|
|
1341
1352
|
}
|
|
1342
1353
|
let cancelled = false;
|