asciify-engine 1.0.25 → 1.0.27
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 +43 -80
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +119 -15
- package/dist/index.d.ts +119 -15
- package/dist/index.js +42 -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;
|
|
@@ -2314,6 +2236,47 @@ function asciiTextAnsi(source, options = {}, targetWidth, targetHeight) {
|
|
|
2314
2236
|
return lines.join("\n");
|
|
2315
2237
|
}
|
|
2316
2238
|
|
|
2239
|
+
// src/core/text-frame.ts
|
|
2240
|
+
function buildTextFrame(text, cols, rows, color = "#505050", opacity = 100) {
|
|
2241
|
+
if (!text || cols <= 0 || rows <= 0) return [];
|
|
2242
|
+
const parsed = parseColor(color) ?? { r: 80, g: 80, b: 80 };
|
|
2243
|
+
const pattern = text;
|
|
2244
|
+
const len = pattern.length;
|
|
2245
|
+
return Array.from(
|
|
2246
|
+
{ length: rows },
|
|
2247
|
+
(_, row) => Array.from({ length: cols }, (_2, col) => ({
|
|
2248
|
+
char: pattern[(row * cols + col) % len],
|
|
2249
|
+
r: parsed.r,
|
|
2250
|
+
g: parsed.g,
|
|
2251
|
+
b: parsed.b,
|
|
2252
|
+
a: opacity
|
|
2253
|
+
}))
|
|
2254
|
+
);
|
|
2255
|
+
}
|
|
2256
|
+
function renderTextBackground(ctx, width, height, text, options = {}, hoverPos) {
|
|
2257
|
+
const {
|
|
2258
|
+
fontSize = 10,
|
|
2259
|
+
lineHeight = 1.6,
|
|
2260
|
+
color = "#505050",
|
|
2261
|
+
opacity = 100,
|
|
2262
|
+
hoverEffect = "spotlight",
|
|
2263
|
+
hoverStrength = 0.85,
|
|
2264
|
+
hoverRadius = 0.18,
|
|
2265
|
+
hoverColor = "#d4ff00"
|
|
2266
|
+
} = options;
|
|
2267
|
+
const cols = Math.max(1, Math.floor(width / fontSize));
|
|
2268
|
+
const rows = Math.max(1, Math.floor(height / (fontSize * lineHeight)));
|
|
2269
|
+
const frame = buildTextFrame(text, cols, rows, color, opacity);
|
|
2270
|
+
const renderOpts = {
|
|
2271
|
+
...DEFAULT_OPTIONS,
|
|
2272
|
+
hoverEffect,
|
|
2273
|
+
hoverStrength,
|
|
2274
|
+
hoverRadius,
|
|
2275
|
+
hoverColor
|
|
2276
|
+
};
|
|
2277
|
+
renderFrameToCanvas(ctx, frame, renderOpts, width, height, 0, hoverPos ?? null);
|
|
2278
|
+
}
|
|
2279
|
+
|
|
2317
2280
|
// src/core/record.ts
|
|
2318
2281
|
function createRecorder(canvas, options = {}) {
|
|
2319
2282
|
const {
|
|
@@ -2914,9 +2877,8 @@ exports.asciiTextAnsi = asciiTextAnsi;
|
|
|
2914
2877
|
exports.asciify = asciify;
|
|
2915
2878
|
exports.asciifyGif = asciifyGif;
|
|
2916
2879
|
exports.asciifyVideo = asciifyVideo;
|
|
2880
|
+
exports.buildTextFrame = buildTextFrame;
|
|
2917
2881
|
exports.createRecorder = createRecorder;
|
|
2918
|
-
exports.generateAnimatedEmbedCode = generateAnimatedEmbedCode;
|
|
2919
|
-
exports.generateEmbedCode = generateEmbedCode;
|
|
2920
2882
|
exports.gifToAsciiFrames = gifToAsciiFrames;
|
|
2921
2883
|
exports.imageToAsciiFrame = imageToAsciiFrame;
|
|
2922
2884
|
exports.mountWaveBackground = mountWaveBackground;
|
|
@@ -2934,6 +2896,7 @@ exports.renderRainBackground = renderRainBackground;
|
|
|
2934
2896
|
exports.renderSilkBackground = renderSilkBackground;
|
|
2935
2897
|
exports.renderStarsBackground = renderStarsBackground;
|
|
2936
2898
|
exports.renderTerrainBackground = renderTerrainBackground;
|
|
2899
|
+
exports.renderTextBackground = renderTextBackground;
|
|
2937
2900
|
exports.renderVoidBackground = renderVoidBackground;
|
|
2938
2901
|
exports.renderWaveBackground = renderWaveBackground;
|
|
2939
2902
|
exports.tryCreateWebGLRenderer = tryCreateWebGLRenderer;
|