asciify-engine 1.0.55 → 1.0.56

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.d.cts CHANGED
@@ -174,6 +174,20 @@ interface AsciiOptions {
174
174
  * Higher values remove more pixels. Default: `60`
175
175
  */
176
176
  chromaKeyTolerance: number;
177
+ /**
178
+ * Array of charset strings to cycle through over time.
179
+ * The engine picks `charsetFrames[Math.floor(time * charsetFps) % length]` on each
180
+ * render tick, re-mapping characters from stored cell luminance.
181
+ * Pairs beautifully with `animationStyle` and `asciiBackground`.
182
+ *
183
+ * Use `CHARSET_SEQUENCES` for curated combinations or build your own:
184
+ * @example
185
+ * options: { charsetFrames: CHARSET_SEQUENCES.cosmic }
186
+ * options: { charsetFrames: [CHARSETS.standard, CHARSETS.blocks, CHARSETS.circles] }
187
+ */
188
+ charsetFrames?: string[];
189
+ /** Cycle rate for `charsetFrames` in frames-per-second. Default: `2` */
190
+ charsetFps?: number;
177
191
  }
178
192
  interface AsciiCell {
179
193
  char: string;
@@ -181,6 +195,8 @@ interface AsciiCell {
181
195
  g: number;
182
196
  b: number;
183
197
  a: number;
198
+ /** Stored dithered luminance (0–255). Present when the frame was generated by the engine. Used for dynamic charset re-selection at render time via `charsetFrames`. */
199
+ lum?: number;
184
200
  }
185
201
  type AsciiFrame = AsciiCell[][];
186
202
  interface AsciiResult {
@@ -213,6 +229,33 @@ declare const CHARSETS: {
213
229
  readonly shards: " ╱╲╳◤◥◣◢△▲◆◼█";
214
230
  readonly smoke: " ·˙⁚⁖∶∷⋮⋰⋱∴∵";
215
231
  };
232
+ /**
233
+ * Curated charset sequences for use with `charsetFrames`.
234
+ * Each sequence morphs between 2–3 complementary charsets over time,
235
+ * creating a living texture effect.
236
+ *
237
+ * @example
238
+ * asciiBackground('#hero', { charsetFrames: CHARSET_SEQUENCES.cosmic })
239
+ */
240
+ declare const CHARSET_SEQUENCES: {
241
+ /** Stars → softcircles → orbs — dreamy space feel */
242
+ readonly cosmic: string[];
243
+ /** Katakana → braille dots → binary — hacker rain */
244
+ readonly rain: string[];
245
+ /** Box pipes → Claude glyphs → classic — terminal morph */
246
+ readonly terminal: string[];
247
+ /** Shards → blocks → squares — shattering crystal */
248
+ readonly crystal: string[];
249
+ /** Wave glyphs → smoke dots → circles — fluid / organic */
250
+ readonly fluid: string[];
251
+ /** Dense classic → art → blocks — maximum detail pulse */
252
+ readonly pulse: string[];
253
+ /** Braille → shadows → smoke — ethereal / dream-like */
254
+ readonly dream: string[];
255
+ /** Geometric shapes → shards → starfield — sci-fi angular */
256
+ readonly angular: string[];
257
+ };
258
+ type CharsetSequenceKey = keyof typeof CHARSET_SEQUENCES;
216
259
  type CharsetKey = keyof typeof CHARSETS;
217
260
  /**
218
261
  * Art Style presets — each one sets render mode, charset, color mode, etc.
@@ -1039,4 +1082,4 @@ interface WebcamOptions {
1039
1082
  */
1040
1083
  declare function asciifyWebcam(canvas: HTMLCanvasElement, { fontSize, style, options, liveOptions, mirror, constraints, dpr: dprOverride, }?: WebcamOptions): Promise<() => void>;
1041
1084
 
1042
- export { ART_STYLE_PRESETS, type AnimationStyle, type ArtStyle, type AsciiBackgroundOptions, type AsciiCell, type AsciiFrame, type AsciiOptions, type AsciiResult, type AsciifyLiveVideoOptions, type AsciifySimpleOptions, type AsciifyVideoOptions, type AuroraBackgroundOptions, BACKGROUND_TYPES, type BackgroundType, CHARSETS, type CharsetKey, type CircuitBackgroundOptions, type ColorMode, DEFAULT_OPTIONS, type DnaBackgroundOptions, type FireBackgroundOptions, type GridBackgroundOptions, HOVER_PRESETS, type HoverEffect, type HoverPreset, type MorphBackgroundOptions, type MountWaveOptions, type NoiseBackgroundOptions, PALETTE_THEMES, type PaletteTheme, type PulseBackgroundOptions, type RainBackgroundOptions, type RenderMode, type SilkBackgroundOptions, type SnapshotOptions, type SourceType, type StarsBackgroundOptions, type TerrainBackgroundOptions, type TextBackgroundOptions, type VoidBackgroundOptions, type WaveBackgroundOptions, type WebcamOptions, asciiBackground, asciiText, asciiTextAnsi, asciify, asciifyGif, asciifyLiveVideo, asciifyVideo, asciifyWebcam, buildTextFrame, captureSnapshot, gifToAsciiFrames, imageToAsciiFrame, mountWaveBackground, renderAuroraBackground, renderCircuitBackground, renderDnaBackground, renderFireBackground, renderFrameToCanvas, renderGridBackground, renderMorphBackground, renderNoiseBackground, renderPulseBackground, renderRainBackground, renderSilkBackground, renderStarsBackground, renderTerrainBackground, renderTextBackground, renderVoidBackground, renderWaveBackground, snapshotAndDownload, videoToAsciiFrames };
1085
+ export { ART_STYLE_PRESETS, type AnimationStyle, type ArtStyle, type AsciiBackgroundOptions, type AsciiCell, type AsciiFrame, type AsciiOptions, type AsciiResult, type AsciifyLiveVideoOptions, type AsciifySimpleOptions, type AsciifyVideoOptions, type AuroraBackgroundOptions, BACKGROUND_TYPES, type BackgroundType, CHARSETS, CHARSET_SEQUENCES, type CharsetKey, type CharsetSequenceKey, type CircuitBackgroundOptions, type ColorMode, DEFAULT_OPTIONS, type DnaBackgroundOptions, type FireBackgroundOptions, type GridBackgroundOptions, HOVER_PRESETS, type HoverEffect, type HoverPreset, type MorphBackgroundOptions, type MountWaveOptions, type NoiseBackgroundOptions, PALETTE_THEMES, type PaletteTheme, type PulseBackgroundOptions, type RainBackgroundOptions, type RenderMode, type SilkBackgroundOptions, type SnapshotOptions, type SourceType, type StarsBackgroundOptions, type TerrainBackgroundOptions, type TextBackgroundOptions, type VoidBackgroundOptions, type WaveBackgroundOptions, type WebcamOptions, asciiBackground, asciiText, asciiTextAnsi, asciify, asciifyGif, asciifyLiveVideo, asciifyVideo, asciifyWebcam, buildTextFrame, captureSnapshot, gifToAsciiFrames, imageToAsciiFrame, mountWaveBackground, renderAuroraBackground, renderCircuitBackground, renderDnaBackground, renderFireBackground, renderFrameToCanvas, renderGridBackground, renderMorphBackground, renderNoiseBackground, renderPulseBackground, renderRainBackground, renderSilkBackground, renderStarsBackground, renderTerrainBackground, renderTextBackground, renderVoidBackground, renderWaveBackground, snapshotAndDownload, videoToAsciiFrames };
package/dist/index.d.ts CHANGED
@@ -174,6 +174,20 @@ interface AsciiOptions {
174
174
  * Higher values remove more pixels. Default: `60`
175
175
  */
176
176
  chromaKeyTolerance: number;
177
+ /**
178
+ * Array of charset strings to cycle through over time.
179
+ * The engine picks `charsetFrames[Math.floor(time * charsetFps) % length]` on each
180
+ * render tick, re-mapping characters from stored cell luminance.
181
+ * Pairs beautifully with `animationStyle` and `asciiBackground`.
182
+ *
183
+ * Use `CHARSET_SEQUENCES` for curated combinations or build your own:
184
+ * @example
185
+ * options: { charsetFrames: CHARSET_SEQUENCES.cosmic }
186
+ * options: { charsetFrames: [CHARSETS.standard, CHARSETS.blocks, CHARSETS.circles] }
187
+ */
188
+ charsetFrames?: string[];
189
+ /** Cycle rate for `charsetFrames` in frames-per-second. Default: `2` */
190
+ charsetFps?: number;
177
191
  }
178
192
  interface AsciiCell {
179
193
  char: string;
@@ -181,6 +195,8 @@ interface AsciiCell {
181
195
  g: number;
182
196
  b: number;
183
197
  a: number;
198
+ /** Stored dithered luminance (0–255). Present when the frame was generated by the engine. Used for dynamic charset re-selection at render time via `charsetFrames`. */
199
+ lum?: number;
184
200
  }
185
201
  type AsciiFrame = AsciiCell[][];
186
202
  interface AsciiResult {
@@ -213,6 +229,33 @@ declare const CHARSETS: {
213
229
  readonly shards: " ╱╲╳◤◥◣◢△▲◆◼█";
214
230
  readonly smoke: " ·˙⁚⁖∶∷⋮⋰⋱∴∵";
215
231
  };
232
+ /**
233
+ * Curated charset sequences for use with `charsetFrames`.
234
+ * Each sequence morphs between 2–3 complementary charsets over time,
235
+ * creating a living texture effect.
236
+ *
237
+ * @example
238
+ * asciiBackground('#hero', { charsetFrames: CHARSET_SEQUENCES.cosmic })
239
+ */
240
+ declare const CHARSET_SEQUENCES: {
241
+ /** Stars → softcircles → orbs — dreamy space feel */
242
+ readonly cosmic: string[];
243
+ /** Katakana → braille dots → binary — hacker rain */
244
+ readonly rain: string[];
245
+ /** Box pipes → Claude glyphs → classic — terminal morph */
246
+ readonly terminal: string[];
247
+ /** Shards → blocks → squares — shattering crystal */
248
+ readonly crystal: string[];
249
+ /** Wave glyphs → smoke dots → circles — fluid / organic */
250
+ readonly fluid: string[];
251
+ /** Dense classic → art → blocks — maximum detail pulse */
252
+ readonly pulse: string[];
253
+ /** Braille → shadows → smoke — ethereal / dream-like */
254
+ readonly dream: string[];
255
+ /** Geometric shapes → shards → starfield — sci-fi angular */
256
+ readonly angular: string[];
257
+ };
258
+ type CharsetSequenceKey = keyof typeof CHARSET_SEQUENCES;
216
259
  type CharsetKey = keyof typeof CHARSETS;
217
260
  /**
218
261
  * Art Style presets — each one sets render mode, charset, color mode, etc.
@@ -1039,4 +1082,4 @@ interface WebcamOptions {
1039
1082
  */
1040
1083
  declare function asciifyWebcam(canvas: HTMLCanvasElement, { fontSize, style, options, liveOptions, mirror, constraints, dpr: dprOverride, }?: WebcamOptions): Promise<() => void>;
1041
1084
 
1042
- export { ART_STYLE_PRESETS, type AnimationStyle, type ArtStyle, type AsciiBackgroundOptions, type AsciiCell, type AsciiFrame, type AsciiOptions, type AsciiResult, type AsciifyLiveVideoOptions, type AsciifySimpleOptions, type AsciifyVideoOptions, type AuroraBackgroundOptions, BACKGROUND_TYPES, type BackgroundType, CHARSETS, type CharsetKey, type CircuitBackgroundOptions, type ColorMode, DEFAULT_OPTIONS, type DnaBackgroundOptions, type FireBackgroundOptions, type GridBackgroundOptions, HOVER_PRESETS, type HoverEffect, type HoverPreset, type MorphBackgroundOptions, type MountWaveOptions, type NoiseBackgroundOptions, PALETTE_THEMES, type PaletteTheme, type PulseBackgroundOptions, type RainBackgroundOptions, type RenderMode, type SilkBackgroundOptions, type SnapshotOptions, type SourceType, type StarsBackgroundOptions, type TerrainBackgroundOptions, type TextBackgroundOptions, type VoidBackgroundOptions, type WaveBackgroundOptions, type WebcamOptions, asciiBackground, asciiText, asciiTextAnsi, asciify, asciifyGif, asciifyLiveVideo, asciifyVideo, asciifyWebcam, buildTextFrame, captureSnapshot, gifToAsciiFrames, imageToAsciiFrame, mountWaveBackground, renderAuroraBackground, renderCircuitBackground, renderDnaBackground, renderFireBackground, renderFrameToCanvas, renderGridBackground, renderMorphBackground, renderNoiseBackground, renderPulseBackground, renderRainBackground, renderSilkBackground, renderStarsBackground, renderTerrainBackground, renderTextBackground, renderVoidBackground, renderWaveBackground, snapshotAndDownload, videoToAsciiFrames };
1085
+ export { ART_STYLE_PRESETS, type AnimationStyle, type ArtStyle, type AsciiBackgroundOptions, type AsciiCell, type AsciiFrame, type AsciiOptions, type AsciiResult, type AsciifyLiveVideoOptions, type AsciifySimpleOptions, type AsciifyVideoOptions, type AuroraBackgroundOptions, BACKGROUND_TYPES, type BackgroundType, CHARSETS, CHARSET_SEQUENCES, type CharsetKey, type CharsetSequenceKey, type CircuitBackgroundOptions, type ColorMode, DEFAULT_OPTIONS, type DnaBackgroundOptions, type FireBackgroundOptions, type GridBackgroundOptions, HOVER_PRESETS, type HoverEffect, type HoverPreset, type MorphBackgroundOptions, type MountWaveOptions, type NoiseBackgroundOptions, PALETTE_THEMES, type PaletteTheme, type PulseBackgroundOptions, type RainBackgroundOptions, type RenderMode, type SilkBackgroundOptions, type SnapshotOptions, type SourceType, type StarsBackgroundOptions, type TerrainBackgroundOptions, type TextBackgroundOptions, type VoidBackgroundOptions, type WaveBackgroundOptions, type WebcamOptions, asciiBackground, asciiText, asciiTextAnsi, asciify, asciifyGif, asciifyLiveVideo, asciifyVideo, asciifyWebcam, buildTextFrame, captureSnapshot, gifToAsciiFrames, imageToAsciiFrame, mountWaveBackground, renderAuroraBackground, renderCircuitBackground, renderDnaBackground, renderFireBackground, renderFrameToCanvas, renderGridBackground, renderMorphBackground, renderNoiseBackground, renderPulseBackground, renderRainBackground, renderSilkBackground, renderStarsBackground, renderTerrainBackground, renderTextBackground, renderVoidBackground, renderWaveBackground, snapshotAndDownload, videoToAsciiFrames };
package/dist/index.js CHANGED
@@ -33,6 +33,24 @@ var CHARSETS = {
33
33
  shards: " \u2571\u2572\u2573\u25E4\u25E5\u25E3\u25E2\u25B3\u25B2\u25C6\u25FC\u2588",
34
34
  smoke: " \xB7\u02D9\u205A\u2056\u2236\u2237\u22EE\u22F0\u22F1\u2234\u2235"
35
35
  };
36
+ var CHARSET_SEQUENCES = {
37
+ /** Stars → softcircles → orbs — dreamy space feel */
38
+ cosmic: [CHARSETS.starfield, CHARSETS.circles, CHARSETS.shadows],
39
+ /** Katakana → braille dots → binary — hacker rain */
40
+ rain: [CHARSETS.katakana, CHARSETS.braille, CHARSETS.binary],
41
+ /** Box pipes → Claude glyphs → classic — terminal morph */
42
+ terminal: [CHARSETS.pipes, CHARSETS.claudeCode, CHARSETS.standard],
43
+ /** Shards → blocks → squares — shattering crystal */
44
+ crystal: [CHARSETS.shards, CHARSETS.geometric, CHARSETS.blocks],
45
+ /** Wave glyphs → smoke dots → circles — fluid / organic */
46
+ fluid: [CHARSETS.waves, CHARSETS.smoke, CHARSETS.circles],
47
+ /** Dense classic → art → blocks — maximum detail pulse */
48
+ pulse: [CHARSETS.dense, CHARSETS.standard, CHARSETS.blocks],
49
+ /** Braille → shadows → smoke — ethereal / dream-like */
50
+ dream: [CHARSETS.braille, CHARSETS.shadows, CHARSETS.smoke],
51
+ /** Geometric shapes → shards → starfield — sci-fi angular */
52
+ angular: [CHARSETS.geometric, CHARSETS.shards, CHARSETS.starfield]
53
+ };
36
54
  var ART_STYLE_PRESETS = {
37
55
  classic: {
38
56
  renderMode: "ascii",
@@ -767,7 +785,7 @@ function imageToAsciiFrame(source, options, targetWidth, targetHeight) {
767
785
  const adjustedLum = adjustLuminance(lum, options.brightness, options.contrast);
768
786
  const ditheredLum = applyDither(adjustedLum, x, y, options.ditherStrength);
769
787
  const char = options.customText ? customTextToChar(ditheredLum, options.customText, x, y, cols, invertVal) : luminanceToChar(ditheredLum, options.charset, invertVal);
770
- row.push({ char, r, g, b, a });
788
+ row.push({ char, r, g, b, a, lum: ditheredLum });
771
789
  }
772
790
  frame.push(row);
773
791
  }
@@ -1011,9 +1029,12 @@ function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, tim
1011
1029
  ctx.textBaseline = "middle";
1012
1030
  }
1013
1031
  let charWeights = null;
1032
+ const dynFrms = options.charsetFrames;
1033
+ const hasDyn = !!dynFrms?.length;
1034
+ const dynCharset = hasDyn ? dynFrms[Math.floor(Math.max(0, time) * (options.charsetFps ?? 2)) % dynFrms.length] : options.charset;
1014
1035
  if (useFastRect) {
1015
1036
  charWeights = {};
1016
- const csChars = [...options.charset];
1037
+ const csChars = [...dynCharset];
1017
1038
  const csLen = csChars.length;
1018
1039
  for (let i = 0; i < csLen; i++) {
1019
1040
  charWeights[csChars[i]] = Math.max(0.1, (i + 0.3) / csLen);
@@ -1024,7 +1045,9 @@ function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, tim
1024
1045
  const rowData = frame[y];
1025
1046
  for (let x = 0; x < cols; x++) {
1026
1047
  const cell = rowData[x];
1027
- if (cell.char === " " || cell.a < 10) continue;
1048
+ if (cell.a < 10) continue;
1049
+ const drawChar = hasDyn && cell.lum != null ? luminanceToChar(cell.lum, dynCharset, isInverted) : cell.char;
1050
+ if (drawChar === " ") continue;
1028
1051
  const animMul = noAnimation ? 1 : getAnimationMultiplier(x, y, cols, rows, time, animStyle, animSpeed);
1029
1052
  if (animMul < 0.05) continue;
1030
1053
  let hoverScale = 1;
@@ -1064,7 +1087,7 @@ function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, tim
1064
1087
  color = getCellColorStr(cell, colorMode, acR, acG, acB, isInverted);
1065
1088
  }
1066
1089
  if (useFastRect) {
1067
- const weight = charWeights[cell.char] ?? 0.5;
1090
+ const weight = charWeights[drawChar] ?? 0.5;
1068
1091
  const effAlpha = Math.min(1, cell.a * 0.00392156863 * animMul * (1 + hoverGlow)) * weight;
1069
1092
  if (effAlpha < 0.02) continue;
1070
1093
  if (effAlpha !== lastAlpha) {
@@ -1091,10 +1114,10 @@ function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, tim
1091
1114
  if (hoverScale !== 1) {
1092
1115
  ctx.translate(px, py);
1093
1116
  ctx.scale(hoverScale, hoverScale);
1094
- ctx.fillText(cell.char, 0, 0);
1117
+ ctx.fillText(drawChar, 0, 0);
1095
1118
  ctx.setTransform(baseTransform);
1096
1119
  } else {
1097
- ctx.fillText(cell.char, px, py);
1120
+ ctx.fillText(drawChar, px, py);
1098
1121
  }
1099
1122
  }
1100
1123
  }
@@ -2685,6 +2708,6 @@ async function asciifyWebcam(canvas, {
2685
2708
  };
2686
2709
  }
2687
2710
 
2688
- export { ART_STYLE_PRESETS, BACKGROUND_TYPES, CHARSETS, DEFAULT_OPTIONS, HOVER_PRESETS, PALETTE_THEMES, asciiBackground, asciiText, asciiTextAnsi, asciify, asciifyGif, asciifyLiveVideo, asciifyVideo, asciifyWebcam, buildTextFrame, captureSnapshot, gifToAsciiFrames, imageToAsciiFrame, mountWaveBackground, renderAuroraBackground, renderCircuitBackground, renderDnaBackground, renderFireBackground, renderFrameToCanvas, renderGridBackground, renderMorphBackground, renderNoiseBackground, renderPulseBackground, renderRainBackground, renderSilkBackground, renderStarsBackground, renderTerrainBackground, renderTextBackground, renderVoidBackground, renderWaveBackground, snapshotAndDownload, videoToAsciiFrames };
2711
+ export { ART_STYLE_PRESETS, BACKGROUND_TYPES, CHARSETS, CHARSET_SEQUENCES, DEFAULT_OPTIONS, HOVER_PRESETS, PALETTE_THEMES, asciiBackground, asciiText, asciiTextAnsi, asciify, asciifyGif, asciifyLiveVideo, asciifyVideo, asciifyWebcam, buildTextFrame, captureSnapshot, gifToAsciiFrames, imageToAsciiFrame, mountWaveBackground, renderAuroraBackground, renderCircuitBackground, renderDnaBackground, renderFireBackground, renderFrameToCanvas, renderGridBackground, renderMorphBackground, renderNoiseBackground, renderPulseBackground, renderRainBackground, renderSilkBackground, renderStarsBackground, renderTerrainBackground, renderTextBackground, renderVoidBackground, renderWaveBackground, snapshotAndDownload, videoToAsciiFrames };
2689
2712
  //# sourceMappingURL=index.js.map
2690
2713
  //# sourceMappingURL=index.js.map