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 +7 -2
- 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 +7 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -52,8 +52,14 @@ interface AsciiOptions {
|
|
|
52
52
|
* Any CSS colour string. Default: `'#d4ff00'`
|
|
53
53
|
*/
|
|
54
54
|
accentColor: string;
|
|
55
|
-
/**
|
|
56
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Invert luminance mapping (light pixels → dense chars). Default: `false`
|
|
57
|
+
*
|
|
58
|
+
* Set to `'auto'` to let the engine detect the OS color scheme:
|
|
59
|
+
* - Light mode → inverts (bright pixel = dark char = visible on white background)
|
|
60
|
+
* - Dark mode → normal (bright pixel = bright char = visible on dark background)
|
|
61
|
+
*/
|
|
62
|
+
invert: boolean | 'auto';
|
|
57
63
|
/**
|
|
58
64
|
* Render mode.
|
|
59
65
|
* - `'ascii'` — characters drawn as text
|
package/dist/index.d.ts
CHANGED
|
@@ -52,8 +52,14 @@ interface AsciiOptions {
|
|
|
52
52
|
* Any CSS colour string. Default: `'#d4ff00'`
|
|
53
53
|
*/
|
|
54
54
|
accentColor: string;
|
|
55
|
-
/**
|
|
56
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Invert luminance mapping (light pixels → dense chars). Default: `false`
|
|
57
|
+
*
|
|
58
|
+
* Set to `'auto'` to let the engine detect the OS color scheme:
|
|
59
|
+
* - Light mode → inverts (bright pixel = dark char = visible on white background)
|
|
60
|
+
* - Dark mode → normal (bright pixel = bright char = visible on dark background)
|
|
61
|
+
*/
|
|
62
|
+
invert: boolean | 'auto';
|
|
57
63
|
/**
|
|
58
64
|
* Render mode.
|
|
59
65
|
* - `'ascii'` — characters drawn as text
|
package/dist/index.js
CHANGED
|
@@ -613,6 +613,10 @@ function renderWaveBackground(ctx, width, height, time, mousePos = { x: 0.5, y:
|
|
|
613
613
|
}
|
|
614
614
|
|
|
615
615
|
// src/core/renderer.ts
|
|
616
|
+
function resolveInvert(invert) {
|
|
617
|
+
if (invert !== "auto") return invert;
|
|
618
|
+
return typeof window !== "undefined" && !window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
619
|
+
}
|
|
616
620
|
function imageToAsciiFrame(source, options, targetWidth, targetHeight) {
|
|
617
621
|
const srcWidth = source instanceof HTMLVideoElement ? source.videoWidth : source.width;
|
|
618
622
|
const srcHeight = source instanceof HTMLVideoElement ? source.videoHeight : source.height;
|
|
@@ -646,6 +650,7 @@ function imageToAsciiFrame(source, options, targetWidth, targetHeight) {
|
|
|
646
650
|
normRange = hi > lo ? hi - lo : 255;
|
|
647
651
|
}
|
|
648
652
|
const frame = [];
|
|
653
|
+
const invertVal = resolveInvert(options.invert);
|
|
649
654
|
const ck = options.chromaKey;
|
|
650
655
|
const ckEnabled = ck != null && ck !== false;
|
|
651
656
|
const ckHeuristicGreen = ck === true;
|
|
@@ -685,7 +690,7 @@ function imageToAsciiFrame(source, options, targetWidth, targetHeight) {
|
|
|
685
690
|
const lum = options.normalize ? (rawLum - normMin) / normRange * 255 : rawLum;
|
|
686
691
|
const adjustedLum = adjustLuminance(lum, options.brightness, options.contrast);
|
|
687
692
|
const ditheredLum = applyDither(adjustedLum, x, y, options.ditherStrength);
|
|
688
|
-
const char = options.customText ? customTextToChar(ditheredLum, options.customText, x, y, cols,
|
|
693
|
+
const char = options.customText ? customTextToChar(ditheredLum, options.customText, x, y, cols, invertVal) : luminanceToChar(ditheredLum, options.charset, invertVal);
|
|
689
694
|
row.push({ char, r, g, b, a });
|
|
690
695
|
}
|
|
691
696
|
frame.push(row);
|
|
@@ -844,7 +849,7 @@ function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, tim
|
|
|
844
849
|
const hoverStrength = options.hoverStrength;
|
|
845
850
|
const hoverEffect = options.hoverEffect;
|
|
846
851
|
const hoverRadiusFactor = effectiveHoverRadius;
|
|
847
|
-
const isInverted = options.invert;
|
|
852
|
+
const isInverted = resolveInvert(options.invert);
|
|
848
853
|
const colorMode = options.colorMode;
|
|
849
854
|
const TWO_PI = Math.PI * 2;
|
|
850
855
|
const invCols = 1 / cols;
|