asciify-engine 1.0.13 → 1.0.14
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 +152 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +68 -5
- package/dist/index.d.ts +68 -5
- package/dist/index.js +151 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -832,7 +832,7 @@ async function asciifyVideo(source, canvas, { fontSize = 10, style = "classic",
|
|
|
832
832
|
cancelAnimationFrame(animId);
|
|
833
833
|
};
|
|
834
834
|
}
|
|
835
|
-
var EMBED_CDN_VERSION = "1.0.
|
|
835
|
+
var EMBED_CDN_VERSION = "1.0.14";
|
|
836
836
|
function buildEmbedOpts(options, rows, cols, width, height, fps, animated) {
|
|
837
837
|
const o = {
|
|
838
838
|
r: rows,
|
|
@@ -999,6 +999,127 @@ function renderWaveBackground(ctx, width, height, time, mousePos = { x: 0.5, y:
|
|
|
999
999
|
}
|
|
1000
1000
|
}
|
|
1001
1001
|
}
|
|
1002
|
+
function renderRainBackground(ctx, width, height, time, options = {}) {
|
|
1003
|
+
const {
|
|
1004
|
+
fontSize = 13,
|
|
1005
|
+
chars = "0123456789ABCDEF@#$&*+=/<>",
|
|
1006
|
+
accentColor = "#d4ff00",
|
|
1007
|
+
color,
|
|
1008
|
+
speed = 1,
|
|
1009
|
+
density = 0.55,
|
|
1010
|
+
tailLength = 14,
|
|
1011
|
+
lightMode = false
|
|
1012
|
+
} = options;
|
|
1013
|
+
const charW = fontSize * 0.62;
|
|
1014
|
+
const lineH = fontSize * 1.4;
|
|
1015
|
+
const cols = Math.ceil(width / charW);
|
|
1016
|
+
const rows = Math.ceil(height / lineH);
|
|
1017
|
+
ctx.clearRect(0, 0, width, height);
|
|
1018
|
+
ctx.font = `${fontSize}px monospace`;
|
|
1019
|
+
ctx.textBaseline = "top";
|
|
1020
|
+
let br = 255, bg = 255, bb = 255;
|
|
1021
|
+
if (lightMode) {
|
|
1022
|
+
br = 0;
|
|
1023
|
+
bg = 0;
|
|
1024
|
+
bb = 0;
|
|
1025
|
+
}
|
|
1026
|
+
if (color) {
|
|
1027
|
+
const p = _parseColor(color);
|
|
1028
|
+
if (p) {
|
|
1029
|
+
br = p.r;
|
|
1030
|
+
bg = p.g;
|
|
1031
|
+
bb = p.b;
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
let acR = 212, acG = 255, acB = 0;
|
|
1035
|
+
const ap = _parseColor(accentColor);
|
|
1036
|
+
if (ap) {
|
|
1037
|
+
acR = ap.r;
|
|
1038
|
+
acG = ap.g;
|
|
1039
|
+
acB = ap.b;
|
|
1040
|
+
}
|
|
1041
|
+
const period = rows + tailLength;
|
|
1042
|
+
for (let c = 0; c < cols; c++) {
|
|
1043
|
+
if (_hash2(c * 17, 3) > density) continue;
|
|
1044
|
+
const colSpeed = (0.5 + _hash2(c * 31, 7) * 1.5) * speed;
|
|
1045
|
+
const phase = _hash2(c * 13, 11) * period;
|
|
1046
|
+
const headRow = Math.floor((time * colSpeed * 7 + phase) % period);
|
|
1047
|
+
const x = c * charW;
|
|
1048
|
+
for (let k = 0; k <= tailLength; k++) {
|
|
1049
|
+
const row = headRow - (tailLength - k);
|
|
1050
|
+
if (row < 0 || row >= rows) continue;
|
|
1051
|
+
const y = row * lineH;
|
|
1052
|
+
const charSeed = _hash2(c * 53 + Math.floor(time * 5 + k), row * 7);
|
|
1053
|
+
const ch = chars[Math.floor(charSeed * chars.length)];
|
|
1054
|
+
const t = k / tailLength;
|
|
1055
|
+
if (k === tailLength) {
|
|
1056
|
+
ctx.fillStyle = `rgba(${acR},${acG},${acB},${lightMode ? 0.7 : 0.85})`;
|
|
1057
|
+
} else {
|
|
1058
|
+
const alpha = lightMode ? t * 0.22 : t * 0.15;
|
|
1059
|
+
ctx.fillStyle = `rgba(${br},${bg},${bb},${alpha})`;
|
|
1060
|
+
}
|
|
1061
|
+
ctx.fillText(ch, x, y);
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
function renderStarsBackground(ctx, width, height, time, mousePos = { x: 0.5, y: 0.5 }, options = {}) {
|
|
1066
|
+
const {
|
|
1067
|
+
fontSize = 14,
|
|
1068
|
+
chars = " . \xB7 * + \xB0 \u2605",
|
|
1069
|
+
accentColor = "#d4ff00",
|
|
1070
|
+
color,
|
|
1071
|
+
speed = 1,
|
|
1072
|
+
count = 180,
|
|
1073
|
+
lightMode = false
|
|
1074
|
+
} = options;
|
|
1075
|
+
ctx.clearRect(0, 0, width, height);
|
|
1076
|
+
ctx.textBaseline = "middle";
|
|
1077
|
+
ctx.textAlign = "center";
|
|
1078
|
+
const cx = width * (0.2 + mousePos.x * 0.6);
|
|
1079
|
+
const cy = height * (0.2 + mousePos.y * 0.6);
|
|
1080
|
+
const maxR = Math.sqrt(width * width + height * height) * 0.65;
|
|
1081
|
+
let br = 255, bg = 255, bb = 255;
|
|
1082
|
+
if (lightMode) {
|
|
1083
|
+
br = 0;
|
|
1084
|
+
bg = 0;
|
|
1085
|
+
bb = 0;
|
|
1086
|
+
}
|
|
1087
|
+
if (color) {
|
|
1088
|
+
const p = _parseColor(color);
|
|
1089
|
+
if (p) {
|
|
1090
|
+
br = p.r;
|
|
1091
|
+
bg = p.g;
|
|
1092
|
+
bb = p.b;
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
let acR = 212, acG = 255, acB = 0;
|
|
1096
|
+
const ap = _parseColor(accentColor);
|
|
1097
|
+
if (ap) {
|
|
1098
|
+
acR = ap.r;
|
|
1099
|
+
acG = ap.g;
|
|
1100
|
+
acB = ap.b;
|
|
1101
|
+
}
|
|
1102
|
+
const charArr = chars.replace(/ /g, "").split("");
|
|
1103
|
+
if (charArr.length === 0) return;
|
|
1104
|
+
for (let i = 0; i < count; i++) {
|
|
1105
|
+
const angle = _hash2(i * 17, 3) * Math.PI * 2;
|
|
1106
|
+
const baseSpd = 0.15 + _hash2(i * 31, 7) * 0.85;
|
|
1107
|
+
const phase = _hash2(i * 13, 11);
|
|
1108
|
+
const r = (time * baseSpd * speed * 0.22 + phase) % 1;
|
|
1109
|
+
const x = cx + Math.cos(angle) * r * maxR;
|
|
1110
|
+
const y = cy + Math.sin(angle) * r * maxR;
|
|
1111
|
+
if (x < -20 || x > width + 20 || y < -20 || y > height + 20) continue;
|
|
1112
|
+
const sz = Math.max(6, fontSize * (0.4 + r * 0.9));
|
|
1113
|
+
ctx.font = `${sz}px monospace`;
|
|
1114
|
+
const charIdx = Math.min(charArr.length - 1, Math.floor(r * charArr.length));
|
|
1115
|
+
const ch = charArr[charIdx];
|
|
1116
|
+
const isAccent = r > 0.72;
|
|
1117
|
+
const alpha = lightMode ? r * 0.28 : r * 0.2;
|
|
1118
|
+
ctx.fillStyle = isAccent ? `rgba(${acR},${acG},${acB},${Math.min(lightMode ? 0.45 : 0.32, alpha * 2.2)})` : `rgba(${br},${bg},${bb},${alpha})`;
|
|
1119
|
+
ctx.fillText(ch, x, y);
|
|
1120
|
+
}
|
|
1121
|
+
ctx.textAlign = "left";
|
|
1122
|
+
}
|
|
1002
1123
|
function _parseColor(c) {
|
|
1003
1124
|
const hex = c.match(/^#([0-9a-f]{3,8})$/i)?.[1];
|
|
1004
1125
|
if (hex) {
|
|
@@ -1011,6 +1132,7 @@ function _parseColor(c) {
|
|
|
1011
1132
|
}
|
|
1012
1133
|
function asciiBackground(target, options = {}) {
|
|
1013
1134
|
const {
|
|
1135
|
+
type = "wave",
|
|
1014
1136
|
opacity = 0.2,
|
|
1015
1137
|
className,
|
|
1016
1138
|
zIndex = 0,
|
|
@@ -1050,16 +1172,31 @@ function asciiBackground(target, options = {}) {
|
|
|
1050
1172
|
if (colorScheme === "dark") return false;
|
|
1051
1173
|
return mq.matches;
|
|
1052
1174
|
};
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
const buildOpts = () => ({
|
|
1175
|
+
const parsedColor = color ? _parseColor(color) : null;
|
|
1176
|
+
const buildWaveOpts = () => ({
|
|
1056
1177
|
...renderOpts,
|
|
1057
1178
|
lightMode: renderOpts.lightMode !== void 0 ? renderOpts.lightMode : isLight(),
|
|
1058
1179
|
baseColor: parsedColor ? `rgba(${parsedColor.r},${parsedColor.g},${parsedColor.b},{a})` : renderOpts.baseColor
|
|
1059
1180
|
});
|
|
1060
|
-
const
|
|
1181
|
+
const buildRainOpts = () => ({
|
|
1182
|
+
...renderOpts,
|
|
1183
|
+
lightMode: renderOpts.lightMode !== void 0 ? renderOpts.lightMode : isLight(),
|
|
1184
|
+
color: color ?? renderOpts.color
|
|
1185
|
+
});
|
|
1186
|
+
const buildStarsOpts = () => ({
|
|
1187
|
+
...renderOpts,
|
|
1188
|
+
lightMode: renderOpts.lightMode !== void 0 ? renderOpts.lightMode : isLight(),
|
|
1189
|
+
color: color ?? renderOpts.color
|
|
1190
|
+
});
|
|
1191
|
+
const optsRef = { current: buildWaveOpts() };
|
|
1192
|
+
const rebuildOpts = () => {
|
|
1193
|
+
if (type === "rain") optsRef.current = buildRainOpts();
|
|
1194
|
+
else if (type === "stars") optsRef.current = buildStarsOpts();
|
|
1195
|
+
else optsRef.current = buildWaveOpts();
|
|
1196
|
+
};
|
|
1197
|
+
rebuildOpts();
|
|
1061
1198
|
const onSchemeChange = () => {
|
|
1062
|
-
|
|
1199
|
+
rebuildOpts();
|
|
1063
1200
|
};
|
|
1064
1201
|
if (colorScheme === "auto") mq.addEventListener("change", onSchemeChange);
|
|
1065
1202
|
const resize = () => {
|
|
@@ -1083,7 +1220,13 @@ function asciiBackground(target, options = {}) {
|
|
|
1083
1220
|
smoothMouse.x += (mouse.x - smoothMouse.x) * 0.07;
|
|
1084
1221
|
smoothMouse.y += (mouse.y - smoothMouse.y) * 0.07;
|
|
1085
1222
|
const r = container.getBoundingClientRect();
|
|
1086
|
-
|
|
1223
|
+
if (type === "rain") {
|
|
1224
|
+
renderRainBackground(ctx, r.width, r.height, time, optsRef.current);
|
|
1225
|
+
} else if (type === "stars") {
|
|
1226
|
+
renderStarsBackground(ctx, r.width, r.height, time, smoothMouse, optsRef.current);
|
|
1227
|
+
} else {
|
|
1228
|
+
renderWaveBackground(ctx, r.width, r.height, time, smoothMouse, optsRef.current);
|
|
1229
|
+
}
|
|
1087
1230
|
time += 0.016;
|
|
1088
1231
|
raf = requestAnimationFrame(tick);
|
|
1089
1232
|
};
|
|
@@ -1563,6 +1706,8 @@ exports.gifToAsciiFrames = gifToAsciiFrames;
|
|
|
1563
1706
|
exports.imageToAsciiFrame = imageToAsciiFrame;
|
|
1564
1707
|
exports.mountWaveBackground = mountWaveBackground;
|
|
1565
1708
|
exports.renderFrameToCanvas = renderFrameToCanvas;
|
|
1709
|
+
exports.renderRainBackground = renderRainBackground;
|
|
1710
|
+
exports.renderStarsBackground = renderStarsBackground;
|
|
1566
1711
|
exports.renderWaveBackground = renderWaveBackground;
|
|
1567
1712
|
exports.tryCreateWebGLRenderer = tryCreateWebGLRenderer;
|
|
1568
1713
|
exports.videoToAsciiFrames = videoToAsciiFrames;
|