asciify-engine 1.0.50 → 1.0.52
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 +19 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +19 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -214,7 +214,7 @@ for (let _i = 0; _i < 256; _i++) {
|
|
|
214
214
|
GRAY_LUT[_i] = `rgb(${_i},${_i},${_i})`;
|
|
215
215
|
GREEN_LUT[_i] = `rgb(0,${_i},0)`;
|
|
216
216
|
}
|
|
217
|
-
function getCellColorStr(cell, colorMode, acR, acG, acB) {
|
|
217
|
+
function getCellColorStr(cell, colorMode, acR, acG, acB, isInverted = false) {
|
|
218
218
|
switch (colorMode) {
|
|
219
219
|
case "fullcolor":
|
|
220
220
|
return `rgb(${cell.r},${cell.g},${cell.b})`;
|
|
@@ -224,12 +224,14 @@ function getCellColorStr(cell, colorMode, acR, acG, acB) {
|
|
|
224
224
|
const ab = (0.299 * cell.r + 0.587 * cell.g + 0.114 * cell.b) / 255;
|
|
225
225
|
return `rgb(${acR * ab | 0},${acG * ab | 0},${acB * ab | 0})`;
|
|
226
226
|
}
|
|
227
|
-
default:
|
|
228
|
-
|
|
227
|
+
default: {
|
|
228
|
+
const gray = 0.299 * cell.r + 0.587 * cell.g + 0.114 * cell.b | 0;
|
|
229
|
+
return GRAY_LUT[isInverted ? 255 - gray : gray];
|
|
230
|
+
}
|
|
229
231
|
}
|
|
230
232
|
}
|
|
231
233
|
var _colorRGB = [0, 0, 0];
|
|
232
|
-
function getCellColorRGB(cell, colorMode, acR, acG, acB) {
|
|
234
|
+
function getCellColorRGB(cell, colorMode, acR, acG, acB, isInverted = false) {
|
|
233
235
|
switch (colorMode) {
|
|
234
236
|
case "fullcolor":
|
|
235
237
|
_colorRGB[0] = cell.r;
|
|
@@ -251,7 +253,8 @@ function getCellColorRGB(cell, colorMode, acR, acG, acB) {
|
|
|
251
253
|
break;
|
|
252
254
|
}
|
|
253
255
|
default: {
|
|
254
|
-
|
|
256
|
+
let gray = 0.299 * cell.r + 0.587 * cell.g + 0.114 * cell.b | 0;
|
|
257
|
+
if (isInverted) gray = 255 - gray;
|
|
255
258
|
_colorRGB[0] = gray;
|
|
256
259
|
_colorRGB[1] = gray;
|
|
257
260
|
_colorRGB[2] = gray;
|
|
@@ -615,6 +618,10 @@ function renderWaveBackground(ctx, width, height, time, mousePos = { x: 0.5, y:
|
|
|
615
618
|
}
|
|
616
619
|
|
|
617
620
|
// src/core/renderer.ts
|
|
621
|
+
function resolveInvert(invert) {
|
|
622
|
+
if (invert !== "auto") return invert;
|
|
623
|
+
return typeof window !== "undefined" && !window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
624
|
+
}
|
|
618
625
|
function imageToAsciiFrame(source, options, targetWidth, targetHeight) {
|
|
619
626
|
const srcWidth = source instanceof HTMLVideoElement ? source.videoWidth : source.width;
|
|
620
627
|
const srcHeight = source instanceof HTMLVideoElement ? source.videoHeight : source.height;
|
|
@@ -648,6 +655,7 @@ function imageToAsciiFrame(source, options, targetWidth, targetHeight) {
|
|
|
648
655
|
normRange = hi > lo ? hi - lo : 255;
|
|
649
656
|
}
|
|
650
657
|
const frame = [];
|
|
658
|
+
const invertVal = resolveInvert(options.invert);
|
|
651
659
|
const ck = options.chromaKey;
|
|
652
660
|
const ckEnabled = ck != null && ck !== false;
|
|
653
661
|
const ckHeuristicGreen = ck === true;
|
|
@@ -687,7 +695,7 @@ function imageToAsciiFrame(source, options, targetWidth, targetHeight) {
|
|
|
687
695
|
const lum = options.normalize ? (rawLum - normMin) / normRange * 255 : rawLum;
|
|
688
696
|
const adjustedLum = adjustLuminance(lum, options.brightness, options.contrast);
|
|
689
697
|
const ditheredLum = applyDither(adjustedLum, x, y, options.ditherStrength);
|
|
690
|
-
const char = options.customText ? customTextToChar(ditheredLum, options.customText, x, y, cols,
|
|
698
|
+
const char = options.customText ? customTextToChar(ditheredLum, options.customText, x, y, cols, invertVal) : luminanceToChar(ditheredLum, options.charset, invertVal);
|
|
691
699
|
row.push({ char, r, g, b, a });
|
|
692
700
|
}
|
|
693
701
|
frame.push(row);
|
|
@@ -846,7 +854,7 @@ function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, tim
|
|
|
846
854
|
const hoverStrength = options.hoverStrength;
|
|
847
855
|
const hoverEffect = options.hoverEffect;
|
|
848
856
|
const hoverRadiusFactor = effectiveHoverRadius;
|
|
849
|
-
const isInverted = options.invert;
|
|
857
|
+
const isInverted = resolveInvert(options.invert);
|
|
850
858
|
const colorMode = options.colorMode;
|
|
851
859
|
const TWO_PI = Math.PI * 2;
|
|
852
860
|
const invCols = 1 / cols;
|
|
@@ -894,13 +902,13 @@ function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, tim
|
|
|
894
902
|
const py = y * cellH + cellH * 0.5 + hoverOffY;
|
|
895
903
|
let color;
|
|
896
904
|
if (hoverBlend > 0) {
|
|
897
|
-
const rgb = getCellColorRGB(cell, colorMode, acR, acG, acB);
|
|
905
|
+
const rgb = getCellColorRGB(cell, colorMode, acR, acG, acB, isInverted);
|
|
898
906
|
const cr = Math.min(255, rgb[0] + (hcR - rgb[0]) * hoverBlend | 0);
|
|
899
907
|
const cg = Math.min(255, rgb[1] + (hcG - rgb[1]) * hoverBlend | 0);
|
|
900
908
|
const cb = Math.min(255, rgb[2] + (hcB - rgb[2]) * hoverBlend | 0);
|
|
901
909
|
color = `rgb(${cr},${cg},${cb})`;
|
|
902
910
|
} else {
|
|
903
|
-
color = getCellColorStr(cell, colorMode, acR, acG, acB);
|
|
911
|
+
color = getCellColorStr(cell, colorMode, acR, acG, acB, isInverted);
|
|
904
912
|
}
|
|
905
913
|
const alpha = Math.min(1, cell.a * 0.00392156863 * animMul * (1 + hoverGlow));
|
|
906
914
|
if (alpha !== lastAlpha) {
|
|
@@ -976,13 +984,13 @@ function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, tim
|
|
|
976
984
|
const py = y * cellH + cellH * 0.5 + hoverOffY;
|
|
977
985
|
let color;
|
|
978
986
|
if (hoverBlend > 0) {
|
|
979
|
-
const rgb = getCellColorRGB(cell, colorMode, acR, acG, acB);
|
|
987
|
+
const rgb = getCellColorRGB(cell, colorMode, acR, acG, acB, isInverted);
|
|
980
988
|
const cr = Math.min(255, rgb[0] + (hcR - rgb[0]) * hoverBlend | 0);
|
|
981
989
|
const cg = Math.min(255, rgb[1] + (hcG - rgb[1]) * hoverBlend | 0);
|
|
982
990
|
const cb = Math.min(255, rgb[2] + (hcB - rgb[2]) * hoverBlend | 0);
|
|
983
991
|
color = `rgb(${cr},${cg},${cb})`;
|
|
984
992
|
} else {
|
|
985
|
-
color = getCellColorStr(cell, colorMode, acR, acG, acB);
|
|
993
|
+
color = getCellColorStr(cell, colorMode, acR, acG, acB, isInverted);
|
|
986
994
|
}
|
|
987
995
|
if (useFastRect) {
|
|
988
996
|
const weight = charWeights[cell.char] ?? 0.5;
|