asciify-engine 1.0.45 → 1.0.47
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/README.md +38 -2
- package/dist/index.cjs +30 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +30 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -129,6 +129,35 @@ interface AsciiOptions {
|
|
|
129
129
|
* a custom charset. Leave empty to use the selected `charset`. Default: `''`
|
|
130
130
|
*/
|
|
131
131
|
customText: string;
|
|
132
|
+
/**
|
|
133
|
+
* Chroma-key colour to remove from the source (green screen / blue screen).
|
|
134
|
+
* Pixels whose RGB distance from this colour is within `chromaKeyTolerance`
|
|
135
|
+
* are keyed out: their character becomes a space and alpha is set to 0,
|
|
136
|
+
* letting the canvas background show through.
|
|
137
|
+
*
|
|
138
|
+
* - `true` — smart default: automatically uses standard broadcast green
|
|
139
|
+
* (`#00b140`). No colour to declare, just turn it on.
|
|
140
|
+
* - `{ r, g, b }` or CSS colour string — custom key colour
|
|
141
|
+
* - `null` / `false` — disabled (default)
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* // Standard green screen — zero config:
|
|
145
|
+
* options: { chromaKey: true }
|
|
146
|
+
*
|
|
147
|
+
* // Blue screen:
|
|
148
|
+
* options: { chromaKey: 'blue', chromaKeyTolerance: 70 }
|
|
149
|
+
*/
|
|
150
|
+
chromaKey: {
|
|
151
|
+
r: number;
|
|
152
|
+
g: number;
|
|
153
|
+
b: number;
|
|
154
|
+
} | string | boolean | null;
|
|
155
|
+
/**
|
|
156
|
+
* Euclidean RGB tolerance radius for chroma-key detection.
|
|
157
|
+
* `0` = exact match only, `441` ≈ key out everything.
|
|
158
|
+
* Higher values remove more pixels. Default: `60`
|
|
159
|
+
*/
|
|
160
|
+
chromaKeyTolerance: number;
|
|
132
161
|
}
|
|
133
162
|
interface AsciiCell {
|
|
134
163
|
char: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -129,6 +129,35 @@ interface AsciiOptions {
|
|
|
129
129
|
* a custom charset. Leave empty to use the selected `charset`. Default: `''`
|
|
130
130
|
*/
|
|
131
131
|
customText: string;
|
|
132
|
+
/**
|
|
133
|
+
* Chroma-key colour to remove from the source (green screen / blue screen).
|
|
134
|
+
* Pixels whose RGB distance from this colour is within `chromaKeyTolerance`
|
|
135
|
+
* are keyed out: their character becomes a space and alpha is set to 0,
|
|
136
|
+
* letting the canvas background show through.
|
|
137
|
+
*
|
|
138
|
+
* - `true` — smart default: automatically uses standard broadcast green
|
|
139
|
+
* (`#00b140`). No colour to declare, just turn it on.
|
|
140
|
+
* - `{ r, g, b }` or CSS colour string — custom key colour
|
|
141
|
+
* - `null` / `false` — disabled (default)
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* // Standard green screen — zero config:
|
|
145
|
+
* options: { chromaKey: true }
|
|
146
|
+
*
|
|
147
|
+
* // Blue screen:
|
|
148
|
+
* options: { chromaKey: 'blue', chromaKeyTolerance: 70 }
|
|
149
|
+
*/
|
|
150
|
+
chromaKey: {
|
|
151
|
+
r: number;
|
|
152
|
+
g: number;
|
|
153
|
+
b: number;
|
|
154
|
+
} | string | boolean | null;
|
|
155
|
+
/**
|
|
156
|
+
* Euclidean RGB tolerance radius for chroma-key detection.
|
|
157
|
+
* `0` = exact match only, `441` ≈ key out everything.
|
|
158
|
+
* Higher values remove more pixels. Default: `60`
|
|
159
|
+
*/
|
|
160
|
+
chromaKeyTolerance: number;
|
|
132
161
|
}
|
|
133
162
|
interface AsciiCell {
|
|
134
163
|
char: string;
|
package/dist/index.js
CHANGED
|
@@ -117,7 +117,9 @@ var DEFAULT_OPTIONS = {
|
|
|
117
117
|
hoverEffect: "spotlight",
|
|
118
118
|
hoverColor: "#ffffff",
|
|
119
119
|
artStyle: "classic",
|
|
120
|
-
customText: ""
|
|
120
|
+
customText: "",
|
|
121
|
+
chromaKey: null,
|
|
122
|
+
chromaKeyTolerance: 60
|
|
121
123
|
};
|
|
122
124
|
var HOVER_PRESETS = {
|
|
123
125
|
none: {
|
|
@@ -256,6 +258,17 @@ function getCellColorRGB(cell, colorMode, acR, acG, acB) {
|
|
|
256
258
|
}
|
|
257
259
|
return _colorRGB;
|
|
258
260
|
}
|
|
261
|
+
function parseChromaKeyColor(color) {
|
|
262
|
+
if (typeof color !== "string") return color;
|
|
263
|
+
const canvas = document.createElement("canvas");
|
|
264
|
+
canvas.width = 1;
|
|
265
|
+
canvas.height = 1;
|
|
266
|
+
const ctx = canvas.getContext("2d");
|
|
267
|
+
ctx.fillStyle = color;
|
|
268
|
+
ctx.fillRect(0, 0, 1, 1);
|
|
269
|
+
const d = ctx.getImageData(0, 0, 1, 1).data;
|
|
270
|
+
return { r: d[0], g: d[1], b: d[2] };
|
|
271
|
+
}
|
|
259
272
|
|
|
260
273
|
// src/core/animation.ts
|
|
261
274
|
function smoothstep(t) {
|
|
@@ -633,6 +646,13 @@ function imageToAsciiFrame(source, options, targetWidth, targetHeight) {
|
|
|
633
646
|
normRange = hi > lo ? hi - lo : 255;
|
|
634
647
|
}
|
|
635
648
|
const frame = [];
|
|
649
|
+
let ckRGB = null;
|
|
650
|
+
let ckTolSq = 0;
|
|
651
|
+
const ck = options.chromaKey;
|
|
652
|
+
if (ck != null && ck !== false) {
|
|
653
|
+
ckRGB = ck === true ? { r: 0, g: 177, b: 64 } : parseChromaKeyColor(ck);
|
|
654
|
+
ckTolSq = (options.chromaKeyTolerance ?? 60) ** 2;
|
|
655
|
+
}
|
|
636
656
|
for (let y = 0; y < rows; y++) {
|
|
637
657
|
const row = [];
|
|
638
658
|
for (let x = 0; x < cols; x++) {
|
|
@@ -641,6 +661,15 @@ function imageToAsciiFrame(source, options, targetWidth, targetHeight) {
|
|
|
641
661
|
const g = pixels[i + 1];
|
|
642
662
|
const b = pixels[i + 2];
|
|
643
663
|
const a = pixels[i + 3];
|
|
664
|
+
if (ckRGB !== null) {
|
|
665
|
+
const dr = r - ckRGB.r;
|
|
666
|
+
const dg = g - ckRGB.g;
|
|
667
|
+
const db = b - ckRGB.b;
|
|
668
|
+
if (dr * dr + dg * dg + db * db <= ckTolSq) {
|
|
669
|
+
row.push({ char: " ", r: 0, g: 0, b: 0, a: 0 });
|
|
670
|
+
continue;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
644
673
|
const rawLum = 0.299 * r + 0.587 * g + 0.114 * b;
|
|
645
674
|
const lum = options.normalize ? (rawLum - normMin) / normRange * 255 : rawLum;
|
|
646
675
|
const adjustedLum = adjustLuminance(lum, options.brightness, options.contrast);
|