asciify-engine 1.0.25 → 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 +0 -80
- 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 +1 -79
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/embed.js +0 -1
package/dist/index.cjs
CHANGED
|
@@ -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;
|
|
@@ -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;
|