asciify-engine 1.0.51 → 1.0.53
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 +22 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +22 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -51,6 +51,11 @@ interface AsciiOptions {
|
|
|
51
51
|
* The accent colour used when `colorMode` is `'accent'` or `'matrix'`.
|
|
52
52
|
* Any CSS colour string. Default: `'#d4ff00'`
|
|
53
53
|
*/
|
|
54
|
+
/**
|
|
55
|
+
* Hex color string used when `colorMode` is `'accent'`.
|
|
56
|
+
* Set to `'auto'` to let the engine pick contrasting ink automatically:
|
|
57
|
+
* dark ink (`#0d0d0d`) in light mode, light ink (`#faf9f7`) in dark mode.
|
|
58
|
+
*/
|
|
54
59
|
accentColor: string;
|
|
55
60
|
/**
|
|
56
61
|
* Invert luminance mapping (light pixels → dense chars). Default: `false`
|
package/dist/index.d.ts
CHANGED
|
@@ -51,6 +51,11 @@ interface AsciiOptions {
|
|
|
51
51
|
* The accent colour used when `colorMode` is `'accent'` or `'matrix'`.
|
|
52
52
|
* Any CSS colour string. Default: `'#d4ff00'`
|
|
53
53
|
*/
|
|
54
|
+
/**
|
|
55
|
+
* Hex color string used when `colorMode` is `'accent'`.
|
|
56
|
+
* Set to `'auto'` to let the engine pick contrasting ink automatically:
|
|
57
|
+
* dark ink (`#0d0d0d`) in light mode, light ink (`#faf9f7`) in dark mode.
|
|
58
|
+
*/
|
|
54
59
|
accentColor: string;
|
|
55
60
|
/**
|
|
56
61
|
* Invert luminance mapping (light pixels → dense chars). Default: `false`
|
package/dist/index.js
CHANGED
|
@@ -212,7 +212,7 @@ for (let _i = 0; _i < 256; _i++) {
|
|
|
212
212
|
GRAY_LUT[_i] = `rgb(${_i},${_i},${_i})`;
|
|
213
213
|
GREEN_LUT[_i] = `rgb(0,${_i},0)`;
|
|
214
214
|
}
|
|
215
|
-
function getCellColorStr(cell, colorMode, acR, acG, acB) {
|
|
215
|
+
function getCellColorStr(cell, colorMode, acR, acG, acB, isInverted = false) {
|
|
216
216
|
switch (colorMode) {
|
|
217
217
|
case "fullcolor":
|
|
218
218
|
return `rgb(${cell.r},${cell.g},${cell.b})`;
|
|
@@ -222,12 +222,14 @@ function getCellColorStr(cell, colorMode, acR, acG, acB) {
|
|
|
222
222
|
const ab = (0.299 * cell.r + 0.587 * cell.g + 0.114 * cell.b) / 255;
|
|
223
223
|
return `rgb(${acR * ab | 0},${acG * ab | 0},${acB * ab | 0})`;
|
|
224
224
|
}
|
|
225
|
-
default:
|
|
226
|
-
|
|
225
|
+
default: {
|
|
226
|
+
const gray = 0.299 * cell.r + 0.587 * cell.g + 0.114 * cell.b | 0;
|
|
227
|
+
return GRAY_LUT[isInverted ? 255 - gray : gray];
|
|
228
|
+
}
|
|
227
229
|
}
|
|
228
230
|
}
|
|
229
231
|
var _colorRGB = [0, 0, 0];
|
|
230
|
-
function getCellColorRGB(cell, colorMode, acR, acG, acB) {
|
|
232
|
+
function getCellColorRGB(cell, colorMode, acR, acG, acB, isInverted = false) {
|
|
231
233
|
switch (colorMode) {
|
|
232
234
|
case "fullcolor":
|
|
233
235
|
_colorRGB[0] = cell.r;
|
|
@@ -249,7 +251,8 @@ function getCellColorRGB(cell, colorMode, acR, acG, acB) {
|
|
|
249
251
|
break;
|
|
250
252
|
}
|
|
251
253
|
default: {
|
|
252
|
-
|
|
254
|
+
let gray = 0.299 * cell.r + 0.587 * cell.g + 0.114 * cell.b | 0;
|
|
255
|
+
if (isInverted) gray = 255 - gray;
|
|
253
256
|
_colorRGB[0] = gray;
|
|
254
257
|
_colorRGB[1] = gray;
|
|
255
258
|
_colorRGB[2] = gray;
|
|
@@ -617,6 +620,14 @@ function resolveInvert(invert) {
|
|
|
617
620
|
if (invert !== "auto") return invert;
|
|
618
621
|
return typeof window !== "undefined" && !window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
619
622
|
}
|
|
623
|
+
function resolveAccentHex(accentColor) {
|
|
624
|
+
const v = accentColor || "auto";
|
|
625
|
+
if (v === "auto") {
|
|
626
|
+
const isDark = typeof window !== "undefined" && window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
627
|
+
return isDark ? "faf9f7" : "0d0d0d";
|
|
628
|
+
}
|
|
629
|
+
return v.replace("#", "");
|
|
630
|
+
}
|
|
620
631
|
function imageToAsciiFrame(source, options, targetWidth, targetHeight) {
|
|
621
632
|
const srcWidth = source instanceof HTMLVideoElement ? source.videoWidth : source.width;
|
|
622
633
|
const srcHeight = source instanceof HTMLVideoElement ? source.videoHeight : source.height;
|
|
@@ -781,7 +792,7 @@ async function gifToAsciiFrames(buffer, options, targetWidth, targetHeight, onPr
|
|
|
781
792
|
function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, time = 0, hoverPos) {
|
|
782
793
|
if (options.animationStyle === "waveField") {
|
|
783
794
|
const mouseNorm = hoverPos ? { x: hoverPos.x, y: hoverPos.y } : { x: 0.5, y: 0.5 };
|
|
784
|
-
const acHexWF = (options.accentColor
|
|
795
|
+
const acHexWF = options.accentColor ? resolveAccentHex(options.accentColor) : "d4ff00";
|
|
785
796
|
renderWaveBackground(ctx, canvasWidth, canvasHeight, time, mouseNorm, {
|
|
786
797
|
accentColor: `#${acHexWF}`,
|
|
787
798
|
accentThreshold: 0.52,
|
|
@@ -826,7 +837,7 @@ function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, tim
|
|
|
826
837
|
const hcR = parseInt(hc.slice(1, 3), 16) || 255;
|
|
827
838
|
const hcG = parseInt(hc.slice(3, 5), 16) || 255;
|
|
828
839
|
const hcB = parseInt(hc.slice(5, 7), 16) || 255;
|
|
829
|
-
const acHex = (options.accentColor
|
|
840
|
+
const acHex = resolveAccentHex(options.accentColor);
|
|
830
841
|
const acR = parseInt(acHex.substring(0, 2), 16) || 255;
|
|
831
842
|
const acG = parseInt(acHex.substring(2, 4), 16) || 255;
|
|
832
843
|
const acB = parseInt(acHex.substring(4, 6), 16) || 255;
|
|
@@ -897,13 +908,13 @@ function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, tim
|
|
|
897
908
|
const py = y * cellH + cellH * 0.5 + hoverOffY;
|
|
898
909
|
let color;
|
|
899
910
|
if (hoverBlend > 0) {
|
|
900
|
-
const rgb = getCellColorRGB(cell, colorMode, acR, acG, acB);
|
|
911
|
+
const rgb = getCellColorRGB(cell, colorMode, acR, acG, acB, isInverted);
|
|
901
912
|
const cr = Math.min(255, rgb[0] + (hcR - rgb[0]) * hoverBlend | 0);
|
|
902
913
|
const cg = Math.min(255, rgb[1] + (hcG - rgb[1]) * hoverBlend | 0);
|
|
903
914
|
const cb = Math.min(255, rgb[2] + (hcB - rgb[2]) * hoverBlend | 0);
|
|
904
915
|
color = `rgb(${cr},${cg},${cb})`;
|
|
905
916
|
} else {
|
|
906
|
-
color = getCellColorStr(cell, colorMode, acR, acG, acB);
|
|
917
|
+
color = getCellColorStr(cell, colorMode, acR, acG, acB, isInverted);
|
|
907
918
|
}
|
|
908
919
|
const alpha = Math.min(1, cell.a * 0.00392156863 * animMul * (1 + hoverGlow));
|
|
909
920
|
if (alpha !== lastAlpha) {
|
|
@@ -979,13 +990,13 @@ function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, tim
|
|
|
979
990
|
const py = y * cellH + cellH * 0.5 + hoverOffY;
|
|
980
991
|
let color;
|
|
981
992
|
if (hoverBlend > 0) {
|
|
982
|
-
const rgb = getCellColorRGB(cell, colorMode, acR, acG, acB);
|
|
993
|
+
const rgb = getCellColorRGB(cell, colorMode, acR, acG, acB, isInverted);
|
|
983
994
|
const cr = Math.min(255, rgb[0] + (hcR - rgb[0]) * hoverBlend | 0);
|
|
984
995
|
const cg = Math.min(255, rgb[1] + (hcG - rgb[1]) * hoverBlend | 0);
|
|
985
996
|
const cb = Math.min(255, rgb[2] + (hcB - rgb[2]) * hoverBlend | 0);
|
|
986
997
|
color = `rgb(${cr},${cg},${cb})`;
|
|
987
998
|
} else {
|
|
988
|
-
color = getCellColorStr(cell, colorMode, acR, acG, acB);
|
|
999
|
+
color = getCellColorStr(cell, colorMode, acR, acG, acB, isInverted);
|
|
989
1000
|
}
|
|
990
1001
|
if (useFastRect) {
|
|
991
1002
|
const weight = charWeights[cell.char] ?? 0.5;
|