asciify-engine 1.0.55 → 1.0.57
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 +38 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +44 -1
- package/dist/index.d.ts +44 -1
- package/dist/index.js +38 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -35,6 +35,24 @@ var CHARSETS = {
|
|
|
35
35
|
shards: " \u2571\u2572\u2573\u25E4\u25E5\u25E3\u25E2\u25B3\u25B2\u25C6\u25FC\u2588",
|
|
36
36
|
smoke: " \xB7\u02D9\u205A\u2056\u2236\u2237\u22EE\u22F0\u22F1\u2234\u2235"
|
|
37
37
|
};
|
|
38
|
+
var CHARSET_SEQUENCES = {
|
|
39
|
+
/** Stars → softcircles → orbs — dreamy space feel */
|
|
40
|
+
cosmic: [CHARSETS.starfield, CHARSETS.circles, CHARSETS.shadows],
|
|
41
|
+
/** Katakana → braille dots → binary — hacker rain */
|
|
42
|
+
rain: [CHARSETS.katakana, CHARSETS.braille, CHARSETS.binary],
|
|
43
|
+
/** Box pipes → Claude glyphs → classic — terminal morph */
|
|
44
|
+
terminal: [CHARSETS.pipes, CHARSETS.claudeCode, CHARSETS.standard],
|
|
45
|
+
/** Shards → blocks → squares — shattering crystal */
|
|
46
|
+
crystal: [CHARSETS.shards, CHARSETS.geometric, CHARSETS.blocks],
|
|
47
|
+
/** Wave glyphs → smoke dots → circles — fluid / organic */
|
|
48
|
+
fluid: [CHARSETS.waves, CHARSETS.smoke, CHARSETS.circles],
|
|
49
|
+
/** Dense classic → art → blocks — maximum detail pulse */
|
|
50
|
+
pulse: [CHARSETS.dense, CHARSETS.standard, CHARSETS.blocks],
|
|
51
|
+
/** Braille → shadows → smoke — ethereal / dream-like */
|
|
52
|
+
dream: [CHARSETS.braille, CHARSETS.shadows, CHARSETS.smoke],
|
|
53
|
+
/** Geometric shapes → shards → starfield — sci-fi angular */
|
|
54
|
+
angular: [CHARSETS.geometric, CHARSETS.shards, CHARSETS.starfield]
|
|
55
|
+
};
|
|
38
56
|
var ART_STYLE_PRESETS = {
|
|
39
57
|
classic: {
|
|
40
58
|
renderMode: "ascii",
|
|
@@ -769,7 +787,7 @@ function imageToAsciiFrame(source, options, targetWidth, targetHeight) {
|
|
|
769
787
|
const adjustedLum = adjustLuminance(lum, options.brightness, options.contrast);
|
|
770
788
|
const ditheredLum = applyDither(adjustedLum, x, y, options.ditherStrength);
|
|
771
789
|
const char = options.customText ? customTextToChar(ditheredLum, options.customText, x, y, cols, invertVal) : luminanceToChar(ditheredLum, options.charset, invertVal);
|
|
772
|
-
row.push({ char, r, g, b, a });
|
|
790
|
+
row.push({ char, r, g, b, a, lum: ditheredLum });
|
|
773
791
|
}
|
|
774
792
|
frame.push(row);
|
|
775
793
|
}
|
|
@@ -1013,9 +1031,12 @@ function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, tim
|
|
|
1013
1031
|
ctx.textBaseline = "middle";
|
|
1014
1032
|
}
|
|
1015
1033
|
let charWeights = null;
|
|
1034
|
+
const dynFrms = options.charsetFrames;
|
|
1035
|
+
const hasDyn = !!dynFrms?.length;
|
|
1036
|
+
const dynCharset = hasDyn ? dynFrms[Math.floor(Math.max(0, time) * (options.charsetFps ?? 2)) % dynFrms.length] : options.charset;
|
|
1016
1037
|
if (useFastRect) {
|
|
1017
1038
|
charWeights = {};
|
|
1018
|
-
const csChars = [...
|
|
1039
|
+
const csChars = [...dynCharset];
|
|
1019
1040
|
const csLen = csChars.length;
|
|
1020
1041
|
for (let i = 0; i < csLen; i++) {
|
|
1021
1042
|
charWeights[csChars[i]] = Math.max(0.1, (i + 0.3) / csLen);
|
|
@@ -1026,7 +1047,9 @@ function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, tim
|
|
|
1026
1047
|
const rowData = frame[y];
|
|
1027
1048
|
for (let x = 0; x < cols; x++) {
|
|
1028
1049
|
const cell = rowData[x];
|
|
1029
|
-
if (cell.
|
|
1050
|
+
if (cell.a < 10) continue;
|
|
1051
|
+
const drawChar = hasDyn && cell.lum != null ? luminanceToChar(cell.lum, dynCharset, isInverted) : cell.char;
|
|
1052
|
+
if (drawChar === " ") continue;
|
|
1030
1053
|
const animMul = noAnimation ? 1 : getAnimationMultiplier(x, y, cols, rows, time, animStyle, animSpeed);
|
|
1031
1054
|
if (animMul < 0.05) continue;
|
|
1032
1055
|
let hoverScale = 1;
|
|
@@ -1066,7 +1089,7 @@ function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, tim
|
|
|
1066
1089
|
color = getCellColorStr(cell, colorMode, acR, acG, acB, isInverted);
|
|
1067
1090
|
}
|
|
1068
1091
|
if (useFastRect) {
|
|
1069
|
-
const weight = charWeights[
|
|
1092
|
+
const weight = charWeights[drawChar] ?? 0.5;
|
|
1070
1093
|
const effAlpha = Math.min(1, cell.a * 0.00392156863 * animMul * (1 + hoverGlow)) * weight;
|
|
1071
1094
|
if (effAlpha < 0.02) continue;
|
|
1072
1095
|
if (effAlpha !== lastAlpha) {
|
|
@@ -1093,10 +1116,10 @@ function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, tim
|
|
|
1093
1116
|
if (hoverScale !== 1) {
|
|
1094
1117
|
ctx.translate(px, py);
|
|
1095
1118
|
ctx.scale(hoverScale, hoverScale);
|
|
1096
|
-
ctx.fillText(
|
|
1119
|
+
ctx.fillText(drawChar, 0, 0);
|
|
1097
1120
|
ctx.setTransform(baseTransform);
|
|
1098
1121
|
} else {
|
|
1099
|
-
ctx.fillText(
|
|
1122
|
+
ctx.fillText(drawChar, px, py);
|
|
1100
1123
|
}
|
|
1101
1124
|
}
|
|
1102
1125
|
}
|
|
@@ -1261,9 +1284,13 @@ async function asciifyVideo(source, canvas, { fontSize = 10, artStyle = "classic
|
|
|
1261
1284
|
});
|
|
1262
1285
|
}
|
|
1263
1286
|
let timeupdateHandler = null;
|
|
1264
|
-
if (trimEnd !== void 0) {
|
|
1287
|
+
if (trimStart > 0 || trimEnd !== void 0) {
|
|
1265
1288
|
timeupdateHandler = () => {
|
|
1266
|
-
if (video.currentTime >= trimEnd)
|
|
1289
|
+
if (trimEnd !== void 0 && video.currentTime >= trimEnd) {
|
|
1290
|
+
video.currentTime = trimStart;
|
|
1291
|
+
} else if (trimStart > 0 && video.currentTime < trimStart) {
|
|
1292
|
+
video.currentTime = trimStart;
|
|
1293
|
+
}
|
|
1267
1294
|
};
|
|
1268
1295
|
video.addEventListener("timeupdate", timeupdateHandler);
|
|
1269
1296
|
}
|
|
@@ -1281,6 +1308,8 @@ async function asciifyVideo(source, canvas, { fontSize = 10, artStyle = "classic
|
|
|
1281
1308
|
if (cancelled) return;
|
|
1282
1309
|
animId = requestAnimationFrame(tick);
|
|
1283
1310
|
if (video.readyState < 2 || canvas.width === 0 || canvas.height === 0) return;
|
|
1311
|
+
if (trimStart > 0 && video.currentTime < trimStart) return;
|
|
1312
|
+
if (trimEnd !== void 0 && video.currentTime >= trimEnd) return;
|
|
1284
1313
|
const { frame } = imageToAsciiFrame(video, merged, canvas.width, canvas.height);
|
|
1285
1314
|
if (frame.length > 0) {
|
|
1286
1315
|
renderFrameToCanvas(ctx, frame, merged, canvas.width, canvas.height, 0, null);
|
|
@@ -2690,6 +2719,7 @@ async function asciifyWebcam(canvas, {
|
|
|
2690
2719
|
exports.ART_STYLE_PRESETS = ART_STYLE_PRESETS;
|
|
2691
2720
|
exports.BACKGROUND_TYPES = BACKGROUND_TYPES;
|
|
2692
2721
|
exports.CHARSETS = CHARSETS;
|
|
2722
|
+
exports.CHARSET_SEQUENCES = CHARSET_SEQUENCES;
|
|
2693
2723
|
exports.DEFAULT_OPTIONS = DEFAULT_OPTIONS;
|
|
2694
2724
|
exports.HOVER_PRESETS = HOVER_PRESETS;
|
|
2695
2725
|
exports.PALETTE_THEMES = PALETTE_THEMES;
|