asciify-engine 1.0.50 → 1.0.51

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
@@ -615,6 +615,10 @@ function renderWaveBackground(ctx, width, height, time, mousePos = { x: 0.5, y:
615
615
  }
616
616
 
617
617
  // src/core/renderer.ts
618
+ function resolveInvert(invert) {
619
+ if (invert !== "auto") return invert;
620
+ return typeof window !== "undefined" && !window.matchMedia("(prefers-color-scheme: dark)").matches;
621
+ }
618
622
  function imageToAsciiFrame(source, options, targetWidth, targetHeight) {
619
623
  const srcWidth = source instanceof HTMLVideoElement ? source.videoWidth : source.width;
620
624
  const srcHeight = source instanceof HTMLVideoElement ? source.videoHeight : source.height;
@@ -648,6 +652,7 @@ function imageToAsciiFrame(source, options, targetWidth, targetHeight) {
648
652
  normRange = hi > lo ? hi - lo : 255;
649
653
  }
650
654
  const frame = [];
655
+ const invertVal = resolveInvert(options.invert);
651
656
  const ck = options.chromaKey;
652
657
  const ckEnabled = ck != null && ck !== false;
653
658
  const ckHeuristicGreen = ck === true;
@@ -687,7 +692,7 @@ function imageToAsciiFrame(source, options, targetWidth, targetHeight) {
687
692
  const lum = options.normalize ? (rawLum - normMin) / normRange * 255 : rawLum;
688
693
  const adjustedLum = adjustLuminance(lum, options.brightness, options.contrast);
689
694
  const ditheredLum = applyDither(adjustedLum, x, y, options.ditherStrength);
690
- const char = options.customText ? customTextToChar(ditheredLum, options.customText, x, y, cols, options.invert) : luminanceToChar(ditheredLum, options.charset, options.invert);
695
+ const char = options.customText ? customTextToChar(ditheredLum, options.customText, x, y, cols, invertVal) : luminanceToChar(ditheredLum, options.charset, invertVal);
691
696
  row.push({ char, r, g, b, a });
692
697
  }
693
698
  frame.push(row);
@@ -846,7 +851,7 @@ function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, tim
846
851
  const hoverStrength = options.hoverStrength;
847
852
  const hoverEffect = options.hoverEffect;
848
853
  const hoverRadiusFactor = effectiveHoverRadius;
849
- const isInverted = options.invert;
854
+ const isInverted = resolveInvert(options.invert);
850
855
  const colorMode = options.colorMode;
851
856
  const TWO_PI = Math.PI * 2;
852
857
  const invCols = 1 / cols;