asciify-engine 1.0.24 → 1.0.26
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 +28 -108
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -15
- package/dist/index.d.ts +1 -15
- package/dist/index.js +29 -107
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/embed.js +0 -1
package/dist/index.cjs
CHANGED
|
@@ -583,7 +583,7 @@ function renderWaveBackground(ctx, width, height, time, mousePos = { x: 0.5, y:
|
|
|
583
583
|
} else if (baseColor) {
|
|
584
584
|
ctx.fillStyle = baseColor.replace("{a}", String(alpha));
|
|
585
585
|
} else if (lightMode) {
|
|
586
|
-
ctx.fillStyle = `rgba(
|
|
586
|
+
ctx.fillStyle = `rgba(55,55,55,${alpha * 7})`;
|
|
587
587
|
} else {
|
|
588
588
|
ctx.fillStyle = `rgba(255,255,255,${alpha})`;
|
|
589
589
|
}
|
|
@@ -962,84 +962,6 @@ function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, tim
|
|
|
962
962
|
ctx.globalAlpha = 1;
|
|
963
963
|
}
|
|
964
964
|
|
|
965
|
-
// src/core/embed-gen.ts
|
|
966
|
-
var EMBED_CDN_VERSION = "1.0.17";
|
|
967
|
-
function serializeFrame(frame, fullColor) {
|
|
968
|
-
const rows = frame.length;
|
|
969
|
-
const cols = rows > 0 ? frame[0].length : 0;
|
|
970
|
-
const stride = fullColor ? 3 : 1;
|
|
971
|
-
const buf = new Uint8Array(1 + rows * cols * stride);
|
|
972
|
-
buf[0] = stride;
|
|
973
|
-
let i = 1;
|
|
974
|
-
for (let y = 0; y < rows; y++) {
|
|
975
|
-
for (let x = 0; x < cols; x++) {
|
|
976
|
-
const cell = frame[y][x];
|
|
977
|
-
if (fullColor) {
|
|
978
|
-
buf[i++] = cell.r;
|
|
979
|
-
buf[i++] = cell.g;
|
|
980
|
-
buf[i++] = cell.b;
|
|
981
|
-
} else {
|
|
982
|
-
buf[i++] = Math.round(0.299 * cell.r + 0.587 * cell.g + 0.114 * cell.b);
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
let binary = "";
|
|
987
|
-
for (let j = 0; j < buf.length; j++) binary += String.fromCharCode(buf[j]);
|
|
988
|
-
return btoa(binary);
|
|
989
|
-
}
|
|
990
|
-
function buildEmbedOpts(options, rows, cols, width, height, fps, animated) {
|
|
991
|
-
const o = {
|
|
992
|
-
r: rows,
|
|
993
|
-
c: cols,
|
|
994
|
-
w: width,
|
|
995
|
-
h: height,
|
|
996
|
-
cs: options.charset,
|
|
997
|
-
cm: options.colorMode,
|
|
998
|
-
as: options.animationStyle,
|
|
999
|
-
sp: options.animationSpeed,
|
|
1000
|
-
inv: options.invert,
|
|
1001
|
-
hs: options.hoverStrength,
|
|
1002
|
-
hr: options.hoverRadius,
|
|
1003
|
-
he: options.hoverEffect,
|
|
1004
|
-
hc: options.hoverColor,
|
|
1005
|
-
dr: options.dotSizeRatio,
|
|
1006
|
-
dots: options.renderMode === "dots"
|
|
1007
|
-
};
|
|
1008
|
-
if (options.colorMode === "accent") o.ac = options.accentColor;
|
|
1009
|
-
if (fps !== void 0) o.fps = fps;
|
|
1010
|
-
if (animated) o.anim = true;
|
|
1011
|
-
return JSON.stringify(o);
|
|
1012
|
-
}
|
|
1013
|
-
var CDN_SCRIPT = `<script src="https://cdn.jsdelivr.net/npm/asciify-engine@${EMBED_CDN_VERSION}/dist/embed.js" async></script>`;
|
|
1014
|
-
function generateEmbedCode(frame, options, width, height) {
|
|
1015
|
-
const rows = frame.length;
|
|
1016
|
-
if (rows === 0) return "";
|
|
1017
|
-
const cols = frame[0].length;
|
|
1018
|
-
const isFullColor = options.colorMode === "fullcolor";
|
|
1019
|
-
const data = serializeFrame(frame, isFullColor);
|
|
1020
|
-
const id = `ar-${Math.random().toString(36).slice(2, 9)}`;
|
|
1021
|
-
const opts = buildEmbedOpts(options, rows, cols, width, height);
|
|
1022
|
-
return `<!-- Asciify Embed -->
|
|
1023
|
-
<canvas id="${id}" data-asciify-opts='${opts}' width="${width}" height="${height}"></canvas>
|
|
1024
|
-
<script type="application/json" id="${id}-d">"${data}"</script>
|
|
1025
|
-
${CDN_SCRIPT}
|
|
1026
|
-
<!-- /Asciify Embed -->`;
|
|
1027
|
-
}
|
|
1028
|
-
function generateAnimatedEmbedCode(frames, options, fps, width, height) {
|
|
1029
|
-
if (frames.length === 0) return "";
|
|
1030
|
-
const rows = frames[0].length;
|
|
1031
|
-
const cols = frames[0][0].length;
|
|
1032
|
-
const isFullColor = options.colorMode === "fullcolor";
|
|
1033
|
-
const allData = frames.map((f) => serializeFrame(f, isFullColor));
|
|
1034
|
-
const id = `ar-${Math.random().toString(36).slice(2, 9)}`;
|
|
1035
|
-
const opts = buildEmbedOpts(options, rows, cols, width, height, fps, true);
|
|
1036
|
-
return `<!-- Asciify Animated Embed -->
|
|
1037
|
-
<canvas id="${id}" data-asciify-opts='${opts}' width="${width}" height="${height}"></canvas>
|
|
1038
|
-
<script type="application/json" id="${id}-d">${JSON.stringify(allData)}</script>
|
|
1039
|
-
${CDN_SCRIPT}
|
|
1040
|
-
<!-- /Asciify Animated Embed -->`;
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
965
|
// src/core/simple-api.ts
|
|
1044
966
|
async function asciify(source, canvas, { fontSize = 10, style = "classic", options = {} } = {}) {
|
|
1045
967
|
let el;
|
|
@@ -1154,9 +1076,9 @@ function renderRainBackground(ctx, width, height, time, options = {}) {
|
|
|
1154
1076
|
ctx.textBaseline = "top";
|
|
1155
1077
|
let br = 255, bg = 255, bb = 255;
|
|
1156
1078
|
if (lightMode) {
|
|
1157
|
-
br =
|
|
1158
|
-
bg =
|
|
1159
|
-
bb =
|
|
1079
|
+
br = 55;
|
|
1080
|
+
bg = 55;
|
|
1081
|
+
bb = 55;
|
|
1160
1082
|
}
|
|
1161
1083
|
if (color) {
|
|
1162
1084
|
const p = parseColor(color);
|
|
@@ -1218,9 +1140,9 @@ function renderStarsBackground(ctx, width, height, time, mousePos = { x: 0.5, y:
|
|
|
1218
1140
|
const maxR = Math.sqrt(width * width + height * height) * 0.65;
|
|
1219
1141
|
let br = 255, bg = 255, bb = 255;
|
|
1220
1142
|
if (lightMode) {
|
|
1221
|
-
br =
|
|
1222
|
-
bg =
|
|
1223
|
-
bb =
|
|
1143
|
+
br = 55;
|
|
1144
|
+
bg = 55;
|
|
1145
|
+
bb = 55;
|
|
1224
1146
|
}
|
|
1225
1147
|
if (color) {
|
|
1226
1148
|
const p = parseColor(color);
|
|
@@ -1280,9 +1202,9 @@ function renderPulseBackground(ctx, width, height, time, mousePos = { x: 0.5, y:
|
|
|
1280
1202
|
const maxDist = Math.sqrt(cx * cx + cy * cy) * 1.6 + Math.sqrt(width * width + height * height) * 0.2;
|
|
1281
1203
|
let br = 255, bg = 255, bb = 255;
|
|
1282
1204
|
if (lightMode) {
|
|
1283
|
-
br =
|
|
1284
|
-
bg =
|
|
1285
|
-
bb =
|
|
1205
|
+
br = 55;
|
|
1206
|
+
bg = 55;
|
|
1207
|
+
bb = 55;
|
|
1286
1208
|
}
|
|
1287
1209
|
if (color) {
|
|
1288
1210
|
const p = parseColor(color);
|
|
@@ -1357,9 +1279,9 @@ function renderNoiseBackground(ctx, width, height, time, mousePos = { x: 0.5, y:
|
|
|
1357
1279
|
ctx.textBaseline = "top";
|
|
1358
1280
|
let br = 255, bgc = 255, bb = 255;
|
|
1359
1281
|
if (lightMode) {
|
|
1360
|
-
br =
|
|
1361
|
-
bgc =
|
|
1362
|
-
bb =
|
|
1282
|
+
br = 55;
|
|
1283
|
+
bgc = 55;
|
|
1284
|
+
bb = 55;
|
|
1363
1285
|
}
|
|
1364
1286
|
if (color) {
|
|
1365
1287
|
const p = parseColor(color);
|
|
@@ -1436,9 +1358,9 @@ function renderGridBackground(ctx, width, height, time, mousePos = { x: 0.5, y:
|
|
|
1436
1358
|
ctx.textBaseline = "top";
|
|
1437
1359
|
let br = 255, bgv = 255, bb = 255;
|
|
1438
1360
|
if (lightMode) {
|
|
1439
|
-
br =
|
|
1440
|
-
bgv =
|
|
1441
|
-
bb =
|
|
1361
|
+
br = 55;
|
|
1362
|
+
bgv = 55;
|
|
1363
|
+
bb = 55;
|
|
1442
1364
|
}
|
|
1443
1365
|
if (color) {
|
|
1444
1366
|
const p = parseColor(color);
|
|
@@ -1508,9 +1430,9 @@ function renderAuroraBackground(ctx, width, height, time, mousePos = { x: 0.5, y
|
|
|
1508
1430
|
ctx.textBaseline = "top";
|
|
1509
1431
|
let cr = 255, cg = 255, cb = 255;
|
|
1510
1432
|
if (lightMode) {
|
|
1511
|
-
cr =
|
|
1512
|
-
cg =
|
|
1513
|
-
cb =
|
|
1433
|
+
cr = 55;
|
|
1434
|
+
cg = 55;
|
|
1435
|
+
cb = 55;
|
|
1514
1436
|
}
|
|
1515
1437
|
if (color) {
|
|
1516
1438
|
const p = parseColor(color);
|
|
@@ -1593,9 +1515,9 @@ function renderSilkBackground(ctx, width, height, time, options = {}) {
|
|
|
1593
1515
|
ctx.textBaseline = "top";
|
|
1594
1516
|
let cr = 255, cg = 255, cb = 255;
|
|
1595
1517
|
if (lightMode) {
|
|
1596
|
-
cr =
|
|
1597
|
-
cg =
|
|
1598
|
-
cb =
|
|
1518
|
+
cr = 55;
|
|
1519
|
+
cg = 55;
|
|
1520
|
+
cb = 55;
|
|
1599
1521
|
}
|
|
1600
1522
|
if (color) {
|
|
1601
1523
|
const p = parseColor(color);
|
|
@@ -1670,9 +1592,9 @@ function renderVoidBackground(ctx, width, height, time, mousePos = { x: 0.5, y:
|
|
|
1670
1592
|
ctx.textBaseline = "top";
|
|
1671
1593
|
let cr = 255, cg = 255, cb = 255;
|
|
1672
1594
|
if (lightMode) {
|
|
1673
|
-
cr =
|
|
1674
|
-
cg =
|
|
1675
|
-
cb =
|
|
1595
|
+
cr = 55;
|
|
1596
|
+
cg = 55;
|
|
1597
|
+
cb = 55;
|
|
1676
1598
|
}
|
|
1677
1599
|
if (color) {
|
|
1678
1600
|
const p = parseColor(color);
|
|
@@ -1742,9 +1664,9 @@ function renderMorphBackground(ctx, width, height, time, options = {}) {
|
|
|
1742
1664
|
ctx.textBaseline = "top";
|
|
1743
1665
|
let cr = 255, cg = 255, cb = 255;
|
|
1744
1666
|
if (lightMode) {
|
|
1745
|
-
cr =
|
|
1746
|
-
cg =
|
|
1747
|
-
cb =
|
|
1667
|
+
cr = 55;
|
|
1668
|
+
cg = 55;
|
|
1669
|
+
cb = 55;
|
|
1748
1670
|
}
|
|
1749
1671
|
if (color) {
|
|
1750
1672
|
const p = parseColor(color);
|
|
@@ -2915,8 +2837,6 @@ exports.asciify = asciify;
|
|
|
2915
2837
|
exports.asciifyGif = asciifyGif;
|
|
2916
2838
|
exports.asciifyVideo = asciifyVideo;
|
|
2917
2839
|
exports.createRecorder = createRecorder;
|
|
2918
|
-
exports.generateAnimatedEmbedCode = generateAnimatedEmbedCode;
|
|
2919
|
-
exports.generateEmbedCode = generateEmbedCode;
|
|
2920
2840
|
exports.gifToAsciiFrames = gifToAsciiFrames;
|
|
2921
2841
|
exports.imageToAsciiFrame = imageToAsciiFrame;
|
|
2922
2842
|
exports.mountWaveBackground = mountWaveBackground;
|