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 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
- return GRAY_LUT[0.299 * cell.r + 0.587 * cell.g + 0.114 * cell.b | 0];
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
- const gray = 0.299 * cell.r + 0.587 * cell.g + 0.114 * cell.b | 0;
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;
@@ -619,6 +622,14 @@ function resolveInvert(invert) {
619
622
  if (invert !== "auto") return invert;
620
623
  return typeof window !== "undefined" && !window.matchMedia("(prefers-color-scheme: dark)").matches;
621
624
  }
625
+ function resolveAccentHex(accentColor) {
626
+ const v = accentColor || "auto";
627
+ if (v === "auto") {
628
+ const isDark = typeof window !== "undefined" && window.matchMedia("(prefers-color-scheme: dark)").matches;
629
+ return isDark ? "faf9f7" : "0d0d0d";
630
+ }
631
+ return v.replace("#", "");
632
+ }
622
633
  function imageToAsciiFrame(source, options, targetWidth, targetHeight) {
623
634
  const srcWidth = source instanceof HTMLVideoElement ? source.videoWidth : source.width;
624
635
  const srcHeight = source instanceof HTMLVideoElement ? source.videoHeight : source.height;
@@ -783,7 +794,7 @@ async function gifToAsciiFrames(buffer, options, targetWidth, targetHeight, onPr
783
794
  function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, time = 0, hoverPos) {
784
795
  if (options.animationStyle === "waveField") {
785
796
  const mouseNorm = hoverPos ? { x: hoverPos.x, y: hoverPos.y } : { x: 0.5, y: 0.5 };
786
- const acHexWF = (options.accentColor || "#d4ff00").replace("#", "");
797
+ const acHexWF = options.accentColor ? resolveAccentHex(options.accentColor) : "d4ff00";
787
798
  renderWaveBackground(ctx, canvasWidth, canvasHeight, time, mouseNorm, {
788
799
  accentColor: `#${acHexWF}`,
789
800
  accentThreshold: 0.52,
@@ -828,7 +839,7 @@ function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, tim
828
839
  const hcR = parseInt(hc.slice(1, 3), 16) || 255;
829
840
  const hcG = parseInt(hc.slice(3, 5), 16) || 255;
830
841
  const hcB = parseInt(hc.slice(5, 7), 16) || 255;
831
- const acHex = (options.accentColor || "#ffffff").replace("#", "");
842
+ const acHex = resolveAccentHex(options.accentColor);
832
843
  const acR = parseInt(acHex.substring(0, 2), 16) || 255;
833
844
  const acG = parseInt(acHex.substring(2, 4), 16) || 255;
834
845
  const acB = parseInt(acHex.substring(4, 6), 16) || 255;
@@ -899,13 +910,13 @@ function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, tim
899
910
  const py = y * cellH + cellH * 0.5 + hoverOffY;
900
911
  let color;
901
912
  if (hoverBlend > 0) {
902
- const rgb = getCellColorRGB(cell, colorMode, acR, acG, acB);
913
+ const rgb = getCellColorRGB(cell, colorMode, acR, acG, acB, isInverted);
903
914
  const cr = Math.min(255, rgb[0] + (hcR - rgb[0]) * hoverBlend | 0);
904
915
  const cg = Math.min(255, rgb[1] + (hcG - rgb[1]) * hoverBlend | 0);
905
916
  const cb = Math.min(255, rgb[2] + (hcB - rgb[2]) * hoverBlend | 0);
906
917
  color = `rgb(${cr},${cg},${cb})`;
907
918
  } else {
908
- color = getCellColorStr(cell, colorMode, acR, acG, acB);
919
+ color = getCellColorStr(cell, colorMode, acR, acG, acB, isInverted);
909
920
  }
910
921
  const alpha = Math.min(1, cell.a * 0.00392156863 * animMul * (1 + hoverGlow));
911
922
  if (alpha !== lastAlpha) {
@@ -981,13 +992,13 @@ function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, tim
981
992
  const py = y * cellH + cellH * 0.5 + hoverOffY;
982
993
  let color;
983
994
  if (hoverBlend > 0) {
984
- const rgb = getCellColorRGB(cell, colorMode, acR, acG, acB);
995
+ const rgb = getCellColorRGB(cell, colorMode, acR, acG, acB, isInverted);
985
996
  const cr = Math.min(255, rgb[0] + (hcR - rgb[0]) * hoverBlend | 0);
986
997
  const cg = Math.min(255, rgb[1] + (hcG - rgb[1]) * hoverBlend | 0);
987
998
  const cb = Math.min(255, rgb[2] + (hcB - rgb[2]) * hoverBlend | 0);
988
999
  color = `rgb(${cr},${cg},${cb})`;
989
1000
  } else {
990
- color = getCellColorStr(cell, colorMode, acR, acG, acB);
1001
+ color = getCellColorStr(cell, colorMode, acR, acG, acB, isInverted);
991
1002
  }
992
1003
  if (useFastRect) {
993
1004
  const weight = charWeights[cell.char] ?? 0.5;