asciify-engine 1.0.23 → 1.0.24
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 +618 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +210 -8
- package/dist/index.d.ts +210 -8
- package/dist/index.js +610 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
type ColorMode = 'grayscale' | 'fullcolor' | 'matrix' | 'accent';
|
|
2
2
|
type RenderMode = 'ascii' | 'dots';
|
|
3
|
-
type AnimationStyle = 'none' | 'wave' | 'pulse' | 'rain' | 'breathe' | 'sparkle' | 'glitch' | 'spiral' | 'typewriter' | 'scatter' | 'waveField';
|
|
4
|
-
type ArtStyle = 'classic' | 'particles' | 'letters' | 'claudeCode' | 'art' | 'terminal' | 'box' | 'lines';
|
|
5
|
-
type HoverEffect = 'spotlight' | 'magnify' | 'repel' | 'glow' | 'colorShift';
|
|
6
|
-
type HoverPreset = 'none' | 'subtle' | 'flashlight' | 'magnifier' | 'forceField' | 'neon' | 'fire' | 'ice';
|
|
3
|
+
type AnimationStyle = 'none' | 'wave' | 'pulse' | 'rain' | 'breathe' | 'sparkle' | 'glitch' | 'spiral' | 'typewriter' | 'scatter' | 'waveField' | 'ripple' | 'melt' | 'orbit' | 'cellular';
|
|
4
|
+
type ArtStyle = 'classic' | 'particles' | 'letters' | 'claudeCode' | 'art' | 'terminal' | 'box' | 'lines' | 'braille' | 'katakana' | 'musical' | 'emoji';
|
|
5
|
+
type HoverEffect = 'spotlight' | 'magnify' | 'repel' | 'glow' | 'colorShift' | 'attract' | 'shatter' | 'trail';
|
|
6
|
+
type HoverPreset = 'none' | 'subtle' | 'flashlight' | 'magnifier' | 'forceField' | 'neon' | 'fire' | 'ice' | 'gravity' | 'shatter' | 'ghost';
|
|
7
|
+
/**
|
|
8
|
+
* Named colour palette presets — pass as `colorMode` for themed rendering.
|
|
9
|
+
* Applied as a post-process colour remap over the standard grayscale output.
|
|
10
|
+
*/
|
|
11
|
+
type PaletteTheme = 'dracula' | 'monokai' | 'nord' | 'catppuccin' | 'solarized' | 'gruvbox';
|
|
12
|
+
declare const PALETTE_THEMES: Record<PaletteTheme, {
|
|
13
|
+
name: string;
|
|
14
|
+
accent: string;
|
|
15
|
+
bg: string;
|
|
16
|
+
fg: string;
|
|
17
|
+
}>;
|
|
7
18
|
type SourceType = 'image' | 'video' | 'gif' | null;
|
|
8
19
|
interface AsciiOptions {
|
|
9
20
|
fontSize: number;
|
|
@@ -44,13 +55,17 @@ declare const CHARSETS: {
|
|
|
44
55
|
readonly standard: " .:-=+*#%@";
|
|
45
56
|
readonly blocks: " ░▒▓█";
|
|
46
57
|
readonly minimal: " .:+";
|
|
47
|
-
readonly dense: " .'`^\",:;Il!i><~+_-?][}{1)(
|
|
58
|
+
readonly dense: " .'`^\",:;Il!i><~+_-?][}{1)(|/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$";
|
|
48
59
|
readonly binary: "01";
|
|
49
60
|
readonly dots: " ⠁⠃⠇⡇⣇⣧⣷⣿";
|
|
50
61
|
readonly letters: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
51
62
|
readonly claudeCode: " ╔╗╚╝║═╠╣╦╩╬░▒▓█│─┌┐└┘├┤┬┴┼";
|
|
52
63
|
readonly box: " ▪◾◼■█";
|
|
53
64
|
readonly lines: " ˗‐–—―━";
|
|
65
|
+
readonly braille: " ⠁⠂⠃⠄⠅⠆⠇⠈⠉⠊⠋⠌⠍⠎⠏⠐⠑⠒⠓⠔⠕⠖⠗⠘⠙⠚⠛⠜⠝⠞⠟⠠⠡⠢⠣⠤⠥⠦⠧⠨⠩⠪⠫⠬⠭⠮⠯⠰⠱⠲⠳⠴⠵⠶⠷⠸⠹⠺⠻⠼⠽⠾⠿⡀⡁⡂⡃⡄⡅⡆⡇⣀⣁⣂⣃⣄⣅⣆⣇⣈⣉⣊⣋⣌⣍⣎⣏⣐⣑⣒⣓⣔⣕⣖⣗⣘⣙⣚⣛⣜⣝⣞⣟⣠⣡⣢⣣⣤⣥⣦⣧⣨⣩⣪⣫⣬⣭⣮⣯⣰⣱⣲⣳⣴⣵⣶⣷⣸⣹⣺⣻⣼⣽⣾⣿";
|
|
66
|
+
readonly katakana: " ヲァィゥェォャュョッアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン";
|
|
67
|
+
readonly musical: " ♩♪♫♬♭♮♯";
|
|
68
|
+
readonly emoji: " ⬛🟫🟥🟧🟨🟩🟦🟪⬜";
|
|
54
69
|
};
|
|
55
70
|
type CharsetKey = keyof typeof CHARSETS;
|
|
56
71
|
/**
|
|
@@ -392,6 +407,90 @@ interface MorphBackgroundOptions {
|
|
|
392
407
|
}
|
|
393
408
|
declare function renderMorphBackground(ctx: CanvasRenderingContext2D, width: number, height: number, time: number, options?: MorphBackgroundOptions): void;
|
|
394
409
|
|
|
410
|
+
interface FireBackgroundOptions {
|
|
411
|
+
/** Font size in CSS pixels (default: 13) */
|
|
412
|
+
fontSize?: number;
|
|
413
|
+
/** Characters mapped from cool→hot (default: ' .,:;i+xX#&@') */
|
|
414
|
+
chars?: string;
|
|
415
|
+
/** Base flame colour (default: '#ff4500') */
|
|
416
|
+
color?: string;
|
|
417
|
+
/** Secondary hot-tip colour (default: '#ffe066') */
|
|
418
|
+
hotColor?: string;
|
|
419
|
+
/** Flame intensity 0–1 (default: 0.85) */
|
|
420
|
+
intensity?: number;
|
|
421
|
+
/** Horizontal wind force -1..1 (default: 0) */
|
|
422
|
+
wind?: number;
|
|
423
|
+
/** Global speed multiplier (default: 1) */
|
|
424
|
+
speed?: number;
|
|
425
|
+
/** Light mode: invert text colours (default: false) */
|
|
426
|
+
lightMode?: boolean;
|
|
427
|
+
}
|
|
428
|
+
declare function renderFireBackground(ctx: CanvasRenderingContext2D, width: number, height: number, time: number, options?: FireBackgroundOptions): void;
|
|
429
|
+
|
|
430
|
+
interface DnaBackgroundOptions {
|
|
431
|
+
/** Font size in CSS pixels (default: 13) */
|
|
432
|
+
fontSize?: number;
|
|
433
|
+
/** Characters for strand nodes (default: 'ATCG') */
|
|
434
|
+
baseChars?: string;
|
|
435
|
+
/** Characters for the connectors between strands (default: '-=≡') */
|
|
436
|
+
bridgeChars?: string;
|
|
437
|
+
/** Primary strand colour (default: '#00e5ff') */
|
|
438
|
+
color?: string;
|
|
439
|
+
/** Secondary strand colour (default: '#ff4081') */
|
|
440
|
+
color2?: string;
|
|
441
|
+
/** Bridge / connector colour (default: '#88ffcc') */
|
|
442
|
+
bridgeColor?: string;
|
|
443
|
+
/** Speed multiplier (default: 1) */
|
|
444
|
+
speed?: number;
|
|
445
|
+
/** Number of helix columns (default: auto, ~1 per 80px) */
|
|
446
|
+
helixCount?: number;
|
|
447
|
+
/** Light mode (default: false) */
|
|
448
|
+
lightMode?: boolean;
|
|
449
|
+
}
|
|
450
|
+
declare function renderDnaBackground(ctx: CanvasRenderingContext2D, width: number, height: number, time: number, options?: DnaBackgroundOptions): void;
|
|
451
|
+
|
|
452
|
+
interface TerrainBackgroundOptions {
|
|
453
|
+
/** Font size in CSS pixels (default: 13) */
|
|
454
|
+
fontSize?: number;
|
|
455
|
+
/** Characters for terrain density (default: ' .,:;+*#@') */
|
|
456
|
+
chars?: string;
|
|
457
|
+
/** Foreground ground colour (default: '#4caf50') */
|
|
458
|
+
color?: string;
|
|
459
|
+
/** Sky / star colour (default: '#1a237e') */
|
|
460
|
+
skyColor?: string;
|
|
461
|
+
/** Peak / snow-cap colour (default: '#e0e0e0') */
|
|
462
|
+
peakColor?: string;
|
|
463
|
+
/** Horizontal scroll speed (default: 1) */
|
|
464
|
+
speed?: number;
|
|
465
|
+
/** Terrain roughness 0.1–1 (default: 0.55) */
|
|
466
|
+
roughness?: number;
|
|
467
|
+
/** Mountain height fraction 0–1 (default: 0.55) */
|
|
468
|
+
heightScale?: number;
|
|
469
|
+
/** Show faint background stars (default: true) */
|
|
470
|
+
stars?: boolean;
|
|
471
|
+
/** Light mode (default: false) */
|
|
472
|
+
lightMode?: boolean;
|
|
473
|
+
}
|
|
474
|
+
declare function renderTerrainBackground(ctx: CanvasRenderingContext2D, width: number, height: number, time: number, options?: TerrainBackgroundOptions): void;
|
|
475
|
+
|
|
476
|
+
interface CircuitBackgroundOptions {
|
|
477
|
+
/** Font size in CSS pixels (default: 13) */
|
|
478
|
+
fontSize?: number;
|
|
479
|
+
/** Trace characters (default: '─│┌┐└┘├┤┬┴┼') */
|
|
480
|
+
chars?: string;
|
|
481
|
+
/** Trace colour (default: '#00ff88') */
|
|
482
|
+
color?: string;
|
|
483
|
+
/** Signal pulse colour (default: '#ffffff') */
|
|
484
|
+
pulseColor?: string;
|
|
485
|
+
/** Fraction of cells that have a trace (default: 0.38) */
|
|
486
|
+
density?: number;
|
|
487
|
+
/** Signal pulse speed (default: 1) */
|
|
488
|
+
speed?: number;
|
|
489
|
+
/** Light mode (default: false) */
|
|
490
|
+
lightMode?: boolean;
|
|
491
|
+
}
|
|
492
|
+
declare function renderCircuitBackground(ctx: CanvasRenderingContext2D, width: number, height: number, time: number, options?: CircuitBackgroundOptions): void;
|
|
493
|
+
|
|
395
494
|
/**
|
|
396
495
|
* ASCII Background — public entry point for the backgrounds sub-system.
|
|
397
496
|
*
|
|
@@ -407,7 +506,7 @@ declare function renderMorphBackground(ctx: CanvasRenderingContext2D, width: num
|
|
|
407
506
|
* Combined options for `asciiBackground()`. Extends all 10 background option
|
|
408
507
|
* interfaces so every background's options can be passed through one object.
|
|
409
508
|
*/
|
|
410
|
-
interface AsciiBackgroundOptions extends WaveBackgroundOptions, RainBackgroundOptions, StarsBackgroundOptions, PulseBackgroundOptions, NoiseBackgroundOptions, GridBackgroundOptions, AuroraBackgroundOptions, SilkBackgroundOptions, VoidBackgroundOptions, MorphBackgroundOptions {
|
|
509
|
+
interface AsciiBackgroundOptions extends WaveBackgroundOptions, RainBackgroundOptions, StarsBackgroundOptions, PulseBackgroundOptions, NoiseBackgroundOptions, GridBackgroundOptions, AuroraBackgroundOptions, SilkBackgroundOptions, VoidBackgroundOptions, MorphBackgroundOptions, FireBackgroundOptions, DnaBackgroundOptions, TerrainBackgroundOptions, CircuitBackgroundOptions {
|
|
411
510
|
/**
|
|
412
511
|
* Which background to render (default: 'wave').
|
|
413
512
|
* - 'wave' — interactive ASCII field with vortex, sparkles, breathe
|
|
@@ -420,8 +519,12 @@ interface AsciiBackgroundOptions extends WaveBackgroundOptions, RainBackgroundOp
|
|
|
420
519
|
* - 'silk' — smooth directional flow-field ribbons
|
|
421
520
|
* - 'void' — gravitational singularity follows the cursor
|
|
422
521
|
* - 'morph' — per-cell multi-frequency shimmer
|
|
522
|
+
* - 'fire' — upward cellular-automata flame simulation
|
|
523
|
+
* - 'dna' — double-helix strand scrolling with base-pair chars
|
|
524
|
+
* - 'terrain' — scrolling ASCII side-scroll heightmap landscape
|
|
525
|
+
* - 'circuit' — procedural PCB traces with traveling signal pulses
|
|
423
526
|
*/
|
|
424
|
-
type?: 'wave' | 'rain' | 'stars' | 'pulse' | 'noise' | 'grid' | 'aurora' | 'silk' | 'void' | 'morph';
|
|
527
|
+
type?: 'wave' | 'rain' | 'stars' | 'pulse' | 'noise' | 'grid' | 'aurora' | 'silk' | 'void' | 'morph' | 'fire' | 'dna' | 'terrain' | 'circuit';
|
|
425
528
|
/** CSS opacity applied to the canvas element (default: 0.2) */
|
|
426
529
|
opacity?: number;
|
|
427
530
|
/** Extra CSS class names added to the injected canvas */
|
|
@@ -466,6 +569,105 @@ declare const mountWaveBackground: typeof asciiBackground;
|
|
|
466
569
|
/** @deprecated Use `AsciiBackgroundOptions` instead. */
|
|
467
570
|
type MountWaveOptions = AsciiBackgroundOptions;
|
|
468
571
|
|
|
572
|
+
/**
|
|
573
|
+
* asciiText — pure string output (no canvas required).
|
|
574
|
+
* Converts an image/video/canvas element to a plain-text ASCII string
|
|
575
|
+
* suitable for server-side rendering, clipboard export, or terminal output.
|
|
576
|
+
*/
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Convert any image/video/canvas source to a plain multi-line string of ASCII.
|
|
580
|
+
*
|
|
581
|
+
* @example
|
|
582
|
+
* ```ts
|
|
583
|
+
* const text = asciiText(imgEl, { fontSize: 8, colorMode: 'grayscale' });
|
|
584
|
+
* console.log(text);
|
|
585
|
+
* ```
|
|
586
|
+
*
|
|
587
|
+
* @example SSR (Node/JSDOM)
|
|
588
|
+
* ```ts
|
|
589
|
+
* const { createCanvas, loadImage } = require('@napi-rs/canvas');
|
|
590
|
+
* const img = await loadImage('./photo.jpg');
|
|
591
|
+
* const canvas = createCanvas(img.width, img.height);
|
|
592
|
+
* const ctx = canvas.getContext('2d');
|
|
593
|
+
* ctx.drawImage(img, 0, 0);
|
|
594
|
+
* const text = asciiText(canvas as unknown as HTMLCanvasElement, { fontSize: 10 });
|
|
595
|
+
* ```
|
|
596
|
+
*/
|
|
597
|
+
declare function asciiText(source: HTMLImageElement | HTMLVideoElement | HTMLCanvasElement, options?: Partial<AsciiOptions>, targetWidth?: number, targetHeight?: number): string;
|
|
598
|
+
/**
|
|
599
|
+
* Convert any source to an ASCII string with ANSI 256-colour escape codes.
|
|
600
|
+
* Works in any terminal that supports ANSI colours.
|
|
601
|
+
*
|
|
602
|
+
* @example
|
|
603
|
+
* ```ts
|
|
604
|
+
* process.stdout.write(asciiTextAnsi(imgEl, { fontSize: 8 }));
|
|
605
|
+
* ```
|
|
606
|
+
*/
|
|
607
|
+
declare function asciiTextAnsi(source: HTMLImageElement | HTMLVideoElement | HTMLCanvasElement, options?: Partial<AsciiOptions>, targetWidth?: number, targetHeight?: number): string;
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* record() — capture a rolling frame buffer from a running ASCII canvas
|
|
611
|
+
* and export it as a downloadable animated GIF or WebP data URL.
|
|
612
|
+
*
|
|
613
|
+
* Usage:
|
|
614
|
+
* ```ts
|
|
615
|
+
* const recorder = createRecorder(canvasEl, { fps: 15, maxFrames: 120 });
|
|
616
|
+
* recorder.start();
|
|
617
|
+
* // ... after a few seconds ...
|
|
618
|
+
* const dataUrl = await recorder.stop(); // 'data:image/gif;base64,...'
|
|
619
|
+
* ```
|
|
620
|
+
*/
|
|
621
|
+
interface RecorderOptions {
|
|
622
|
+
/** Target capture frame rate (default: 15) */
|
|
623
|
+
fps?: number;
|
|
624
|
+
/** Maximum number of frames to buffer (default: 120 → 8 s at 15 fps) */
|
|
625
|
+
maxFrames?: number;
|
|
626
|
+
/**
|
|
627
|
+
* Output format.
|
|
628
|
+
* - 'gif' — animated GIF via gif.js worker (requires gif.worker.js in public/)
|
|
629
|
+
* - 'webp' — animated WebP via MediaRecorder API (Chrome/Edge only)
|
|
630
|
+
* - 'png-sequence' — returns a JSON array of PNG data URLs (universal)
|
|
631
|
+
* Default: 'gif'
|
|
632
|
+
*/
|
|
633
|
+
format?: 'gif' | 'webp' | 'png-sequence';
|
|
634
|
+
/** GIF quality 1 (best) – 30 (smallest) — only used for format:'gif' (default: 10) */
|
|
635
|
+
quality?: number;
|
|
636
|
+
/**
|
|
637
|
+
* Scale factor applied to the canvas before capture (default: 1).
|
|
638
|
+
* Use 0.5 to halve dimensions and reduce file size.
|
|
639
|
+
*/
|
|
640
|
+
scale?: number;
|
|
641
|
+
}
|
|
642
|
+
interface Recorder {
|
|
643
|
+
/** Start capturing frames from the canvas. */
|
|
644
|
+
start(): void;
|
|
645
|
+
/**
|
|
646
|
+
* Stop capturing and encode.
|
|
647
|
+
* Resolves with a data URL (gif/webp) or JSON string (png-sequence).
|
|
648
|
+
*/
|
|
649
|
+
stop(): Promise<string>;
|
|
650
|
+
/** True while recording. */
|
|
651
|
+
readonly isRecording: boolean;
|
|
652
|
+
/** Number of frames captured so far. */
|
|
653
|
+
readonly frameCount: number;
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* Create a Recorder bound to a canvas element.
|
|
657
|
+
*/
|
|
658
|
+
declare function createRecorder(canvas: HTMLCanvasElement, options?: RecorderOptions): Recorder;
|
|
659
|
+
/**
|
|
660
|
+
* Convenience: record for a fixed duration and auto-download.
|
|
661
|
+
*
|
|
662
|
+
* @example
|
|
663
|
+
* ```ts
|
|
664
|
+
* await recordAndDownload(canvasEl, 3000, { fps: 15, format: 'gif' });
|
|
665
|
+
* ```
|
|
666
|
+
*/
|
|
667
|
+
declare function recordAndDownload(canvas: HTMLCanvasElement, durationMs: number, options?: RecorderOptions & {
|
|
668
|
+
filename?: string;
|
|
669
|
+
}): Promise<void>;
|
|
670
|
+
|
|
469
671
|
interface WebGLRenderer {
|
|
470
672
|
render(frame: AsciiFrame, options: AsciiOptions, displayW: number, displayH: number, time: number, hoverPos?: {
|
|
471
673
|
x: number;
|
|
@@ -483,4 +685,4 @@ interface WebGLRenderer {
|
|
|
483
685
|
*/
|
|
484
686
|
declare function tryCreateWebGLRenderer(canvas: HTMLCanvasElement): WebGLRenderer | null;
|
|
485
687
|
|
|
486
|
-
export { ART_STYLE_PRESETS, type AnimationStyle, type ArtStyle, type AsciiBackgroundOptions, type AsciiCell, type AsciiFrame, type AsciiOptions, type AsciiResult, type AsciifySimpleOptions, type AuroraBackgroundOptions, CHARSETS, type CharsetKey, type ColorMode, DEFAULT_OPTIONS, type GridBackgroundOptions, HOVER_PRESETS, type HoverEffect, type HoverPreset, type MorphBackgroundOptions, type MountWaveOptions, type NoiseBackgroundOptions, type PulseBackgroundOptions, type RainBackgroundOptions, type RenderMode, type SilkBackgroundOptions, type SourceType, type StarsBackgroundOptions, type VoidBackgroundOptions, type WaveBackgroundOptions, type WebGLRenderer, asciiBackground, asciify, asciifyGif, asciifyVideo, generateAnimatedEmbedCode, generateEmbedCode, gifToAsciiFrames, imageToAsciiFrame, mountWaveBackground, renderAuroraBackground, renderFrameToCanvas, renderGridBackground, renderMorphBackground, renderNoiseBackground, renderPulseBackground, renderRainBackground, renderSilkBackground, renderStarsBackground, renderVoidBackground, renderWaveBackground, tryCreateWebGLRenderer, videoToAsciiFrames };
|
|
688
|
+
export { ART_STYLE_PRESETS, type AnimationStyle, type ArtStyle, type AsciiBackgroundOptions, type AsciiCell, type AsciiFrame, type AsciiOptions, type AsciiResult, type AsciifySimpleOptions, type AuroraBackgroundOptions, 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 Recorder, type RecorderOptions, type RenderMode, type SilkBackgroundOptions, type SourceType, type StarsBackgroundOptions, type TerrainBackgroundOptions, type VoidBackgroundOptions, type WaveBackgroundOptions, type WebGLRenderer, asciiBackground, asciiText, asciiTextAnsi, asciify, asciifyGif, asciifyVideo, createRecorder, generateAnimatedEmbedCode, generateEmbedCode, gifToAsciiFrames, imageToAsciiFrame, mountWaveBackground, recordAndDownload, renderAuroraBackground, renderCircuitBackground, renderDnaBackground, renderFireBackground, renderFrameToCanvas, renderGridBackground, renderMorphBackground, renderNoiseBackground, renderPulseBackground, renderRainBackground, renderSilkBackground, renderStarsBackground, renderTerrainBackground, renderVoidBackground, renderWaveBackground, tryCreateWebGLRenderer, videoToAsciiFrames };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
type ColorMode = 'grayscale' | 'fullcolor' | 'matrix' | 'accent';
|
|
2
2
|
type RenderMode = 'ascii' | 'dots';
|
|
3
|
-
type AnimationStyle = 'none' | 'wave' | 'pulse' | 'rain' | 'breathe' | 'sparkle' | 'glitch' | 'spiral' | 'typewriter' | 'scatter' | 'waveField';
|
|
4
|
-
type ArtStyle = 'classic' | 'particles' | 'letters' | 'claudeCode' | 'art' | 'terminal' | 'box' | 'lines';
|
|
5
|
-
type HoverEffect = 'spotlight' | 'magnify' | 'repel' | 'glow' | 'colorShift';
|
|
6
|
-
type HoverPreset = 'none' | 'subtle' | 'flashlight' | 'magnifier' | 'forceField' | 'neon' | 'fire' | 'ice';
|
|
3
|
+
type AnimationStyle = 'none' | 'wave' | 'pulse' | 'rain' | 'breathe' | 'sparkle' | 'glitch' | 'spiral' | 'typewriter' | 'scatter' | 'waveField' | 'ripple' | 'melt' | 'orbit' | 'cellular';
|
|
4
|
+
type ArtStyle = 'classic' | 'particles' | 'letters' | 'claudeCode' | 'art' | 'terminal' | 'box' | 'lines' | 'braille' | 'katakana' | 'musical' | 'emoji';
|
|
5
|
+
type HoverEffect = 'spotlight' | 'magnify' | 'repel' | 'glow' | 'colorShift' | 'attract' | 'shatter' | 'trail';
|
|
6
|
+
type HoverPreset = 'none' | 'subtle' | 'flashlight' | 'magnifier' | 'forceField' | 'neon' | 'fire' | 'ice' | 'gravity' | 'shatter' | 'ghost';
|
|
7
|
+
/**
|
|
8
|
+
* Named colour palette presets — pass as `colorMode` for themed rendering.
|
|
9
|
+
* Applied as a post-process colour remap over the standard grayscale output.
|
|
10
|
+
*/
|
|
11
|
+
type PaletteTheme = 'dracula' | 'monokai' | 'nord' | 'catppuccin' | 'solarized' | 'gruvbox';
|
|
12
|
+
declare const PALETTE_THEMES: Record<PaletteTheme, {
|
|
13
|
+
name: string;
|
|
14
|
+
accent: string;
|
|
15
|
+
bg: string;
|
|
16
|
+
fg: string;
|
|
17
|
+
}>;
|
|
7
18
|
type SourceType = 'image' | 'video' | 'gif' | null;
|
|
8
19
|
interface AsciiOptions {
|
|
9
20
|
fontSize: number;
|
|
@@ -44,13 +55,17 @@ declare const CHARSETS: {
|
|
|
44
55
|
readonly standard: " .:-=+*#%@";
|
|
45
56
|
readonly blocks: " ░▒▓█";
|
|
46
57
|
readonly minimal: " .:+";
|
|
47
|
-
readonly dense: " .'`^\",:;Il!i><~+_-?][}{1)(
|
|
58
|
+
readonly dense: " .'`^\",:;Il!i><~+_-?][}{1)(|/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$";
|
|
48
59
|
readonly binary: "01";
|
|
49
60
|
readonly dots: " ⠁⠃⠇⡇⣇⣧⣷⣿";
|
|
50
61
|
readonly letters: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
51
62
|
readonly claudeCode: " ╔╗╚╝║═╠╣╦╩╬░▒▓█│─┌┐└┘├┤┬┴┼";
|
|
52
63
|
readonly box: " ▪◾◼■█";
|
|
53
64
|
readonly lines: " ˗‐–—―━";
|
|
65
|
+
readonly braille: " ⠁⠂⠃⠄⠅⠆⠇⠈⠉⠊⠋⠌⠍⠎⠏⠐⠑⠒⠓⠔⠕⠖⠗⠘⠙⠚⠛⠜⠝⠞⠟⠠⠡⠢⠣⠤⠥⠦⠧⠨⠩⠪⠫⠬⠭⠮⠯⠰⠱⠲⠳⠴⠵⠶⠷⠸⠹⠺⠻⠼⠽⠾⠿⡀⡁⡂⡃⡄⡅⡆⡇⣀⣁⣂⣃⣄⣅⣆⣇⣈⣉⣊⣋⣌⣍⣎⣏⣐⣑⣒⣓⣔⣕⣖⣗⣘⣙⣚⣛⣜⣝⣞⣟⣠⣡⣢⣣⣤⣥⣦⣧⣨⣩⣪⣫⣬⣭⣮⣯⣰⣱⣲⣳⣴⣵⣶⣷⣸⣹⣺⣻⣼⣽⣾⣿";
|
|
66
|
+
readonly katakana: " ヲァィゥェォャュョッアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン";
|
|
67
|
+
readonly musical: " ♩♪♫♬♭♮♯";
|
|
68
|
+
readonly emoji: " ⬛🟫🟥🟧🟨🟩🟦🟪⬜";
|
|
54
69
|
};
|
|
55
70
|
type CharsetKey = keyof typeof CHARSETS;
|
|
56
71
|
/**
|
|
@@ -392,6 +407,90 @@ interface MorphBackgroundOptions {
|
|
|
392
407
|
}
|
|
393
408
|
declare function renderMorphBackground(ctx: CanvasRenderingContext2D, width: number, height: number, time: number, options?: MorphBackgroundOptions): void;
|
|
394
409
|
|
|
410
|
+
interface FireBackgroundOptions {
|
|
411
|
+
/** Font size in CSS pixels (default: 13) */
|
|
412
|
+
fontSize?: number;
|
|
413
|
+
/** Characters mapped from cool→hot (default: ' .,:;i+xX#&@') */
|
|
414
|
+
chars?: string;
|
|
415
|
+
/** Base flame colour (default: '#ff4500') */
|
|
416
|
+
color?: string;
|
|
417
|
+
/** Secondary hot-tip colour (default: '#ffe066') */
|
|
418
|
+
hotColor?: string;
|
|
419
|
+
/** Flame intensity 0–1 (default: 0.85) */
|
|
420
|
+
intensity?: number;
|
|
421
|
+
/** Horizontal wind force -1..1 (default: 0) */
|
|
422
|
+
wind?: number;
|
|
423
|
+
/** Global speed multiplier (default: 1) */
|
|
424
|
+
speed?: number;
|
|
425
|
+
/** Light mode: invert text colours (default: false) */
|
|
426
|
+
lightMode?: boolean;
|
|
427
|
+
}
|
|
428
|
+
declare function renderFireBackground(ctx: CanvasRenderingContext2D, width: number, height: number, time: number, options?: FireBackgroundOptions): void;
|
|
429
|
+
|
|
430
|
+
interface DnaBackgroundOptions {
|
|
431
|
+
/** Font size in CSS pixels (default: 13) */
|
|
432
|
+
fontSize?: number;
|
|
433
|
+
/** Characters for strand nodes (default: 'ATCG') */
|
|
434
|
+
baseChars?: string;
|
|
435
|
+
/** Characters for the connectors between strands (default: '-=≡') */
|
|
436
|
+
bridgeChars?: string;
|
|
437
|
+
/** Primary strand colour (default: '#00e5ff') */
|
|
438
|
+
color?: string;
|
|
439
|
+
/** Secondary strand colour (default: '#ff4081') */
|
|
440
|
+
color2?: string;
|
|
441
|
+
/** Bridge / connector colour (default: '#88ffcc') */
|
|
442
|
+
bridgeColor?: string;
|
|
443
|
+
/** Speed multiplier (default: 1) */
|
|
444
|
+
speed?: number;
|
|
445
|
+
/** Number of helix columns (default: auto, ~1 per 80px) */
|
|
446
|
+
helixCount?: number;
|
|
447
|
+
/** Light mode (default: false) */
|
|
448
|
+
lightMode?: boolean;
|
|
449
|
+
}
|
|
450
|
+
declare function renderDnaBackground(ctx: CanvasRenderingContext2D, width: number, height: number, time: number, options?: DnaBackgroundOptions): void;
|
|
451
|
+
|
|
452
|
+
interface TerrainBackgroundOptions {
|
|
453
|
+
/** Font size in CSS pixels (default: 13) */
|
|
454
|
+
fontSize?: number;
|
|
455
|
+
/** Characters for terrain density (default: ' .,:;+*#@') */
|
|
456
|
+
chars?: string;
|
|
457
|
+
/** Foreground ground colour (default: '#4caf50') */
|
|
458
|
+
color?: string;
|
|
459
|
+
/** Sky / star colour (default: '#1a237e') */
|
|
460
|
+
skyColor?: string;
|
|
461
|
+
/** Peak / snow-cap colour (default: '#e0e0e0') */
|
|
462
|
+
peakColor?: string;
|
|
463
|
+
/** Horizontal scroll speed (default: 1) */
|
|
464
|
+
speed?: number;
|
|
465
|
+
/** Terrain roughness 0.1–1 (default: 0.55) */
|
|
466
|
+
roughness?: number;
|
|
467
|
+
/** Mountain height fraction 0–1 (default: 0.55) */
|
|
468
|
+
heightScale?: number;
|
|
469
|
+
/** Show faint background stars (default: true) */
|
|
470
|
+
stars?: boolean;
|
|
471
|
+
/** Light mode (default: false) */
|
|
472
|
+
lightMode?: boolean;
|
|
473
|
+
}
|
|
474
|
+
declare function renderTerrainBackground(ctx: CanvasRenderingContext2D, width: number, height: number, time: number, options?: TerrainBackgroundOptions): void;
|
|
475
|
+
|
|
476
|
+
interface CircuitBackgroundOptions {
|
|
477
|
+
/** Font size in CSS pixels (default: 13) */
|
|
478
|
+
fontSize?: number;
|
|
479
|
+
/** Trace characters (default: '─│┌┐└┘├┤┬┴┼') */
|
|
480
|
+
chars?: string;
|
|
481
|
+
/** Trace colour (default: '#00ff88') */
|
|
482
|
+
color?: string;
|
|
483
|
+
/** Signal pulse colour (default: '#ffffff') */
|
|
484
|
+
pulseColor?: string;
|
|
485
|
+
/** Fraction of cells that have a trace (default: 0.38) */
|
|
486
|
+
density?: number;
|
|
487
|
+
/** Signal pulse speed (default: 1) */
|
|
488
|
+
speed?: number;
|
|
489
|
+
/** Light mode (default: false) */
|
|
490
|
+
lightMode?: boolean;
|
|
491
|
+
}
|
|
492
|
+
declare function renderCircuitBackground(ctx: CanvasRenderingContext2D, width: number, height: number, time: number, options?: CircuitBackgroundOptions): void;
|
|
493
|
+
|
|
395
494
|
/**
|
|
396
495
|
* ASCII Background — public entry point for the backgrounds sub-system.
|
|
397
496
|
*
|
|
@@ -407,7 +506,7 @@ declare function renderMorphBackground(ctx: CanvasRenderingContext2D, width: num
|
|
|
407
506
|
* Combined options for `asciiBackground()`. Extends all 10 background option
|
|
408
507
|
* interfaces so every background's options can be passed through one object.
|
|
409
508
|
*/
|
|
410
|
-
interface AsciiBackgroundOptions extends WaveBackgroundOptions, RainBackgroundOptions, StarsBackgroundOptions, PulseBackgroundOptions, NoiseBackgroundOptions, GridBackgroundOptions, AuroraBackgroundOptions, SilkBackgroundOptions, VoidBackgroundOptions, MorphBackgroundOptions {
|
|
509
|
+
interface AsciiBackgroundOptions extends WaveBackgroundOptions, RainBackgroundOptions, StarsBackgroundOptions, PulseBackgroundOptions, NoiseBackgroundOptions, GridBackgroundOptions, AuroraBackgroundOptions, SilkBackgroundOptions, VoidBackgroundOptions, MorphBackgroundOptions, FireBackgroundOptions, DnaBackgroundOptions, TerrainBackgroundOptions, CircuitBackgroundOptions {
|
|
411
510
|
/**
|
|
412
511
|
* Which background to render (default: 'wave').
|
|
413
512
|
* - 'wave' — interactive ASCII field with vortex, sparkles, breathe
|
|
@@ -420,8 +519,12 @@ interface AsciiBackgroundOptions extends WaveBackgroundOptions, RainBackgroundOp
|
|
|
420
519
|
* - 'silk' — smooth directional flow-field ribbons
|
|
421
520
|
* - 'void' — gravitational singularity follows the cursor
|
|
422
521
|
* - 'morph' — per-cell multi-frequency shimmer
|
|
522
|
+
* - 'fire' — upward cellular-automata flame simulation
|
|
523
|
+
* - 'dna' — double-helix strand scrolling with base-pair chars
|
|
524
|
+
* - 'terrain' — scrolling ASCII side-scroll heightmap landscape
|
|
525
|
+
* - 'circuit' — procedural PCB traces with traveling signal pulses
|
|
423
526
|
*/
|
|
424
|
-
type?: 'wave' | 'rain' | 'stars' | 'pulse' | 'noise' | 'grid' | 'aurora' | 'silk' | 'void' | 'morph';
|
|
527
|
+
type?: 'wave' | 'rain' | 'stars' | 'pulse' | 'noise' | 'grid' | 'aurora' | 'silk' | 'void' | 'morph' | 'fire' | 'dna' | 'terrain' | 'circuit';
|
|
425
528
|
/** CSS opacity applied to the canvas element (default: 0.2) */
|
|
426
529
|
opacity?: number;
|
|
427
530
|
/** Extra CSS class names added to the injected canvas */
|
|
@@ -466,6 +569,105 @@ declare const mountWaveBackground: typeof asciiBackground;
|
|
|
466
569
|
/** @deprecated Use `AsciiBackgroundOptions` instead. */
|
|
467
570
|
type MountWaveOptions = AsciiBackgroundOptions;
|
|
468
571
|
|
|
572
|
+
/**
|
|
573
|
+
* asciiText — pure string output (no canvas required).
|
|
574
|
+
* Converts an image/video/canvas element to a plain-text ASCII string
|
|
575
|
+
* suitable for server-side rendering, clipboard export, or terminal output.
|
|
576
|
+
*/
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Convert any image/video/canvas source to a plain multi-line string of ASCII.
|
|
580
|
+
*
|
|
581
|
+
* @example
|
|
582
|
+
* ```ts
|
|
583
|
+
* const text = asciiText(imgEl, { fontSize: 8, colorMode: 'grayscale' });
|
|
584
|
+
* console.log(text);
|
|
585
|
+
* ```
|
|
586
|
+
*
|
|
587
|
+
* @example SSR (Node/JSDOM)
|
|
588
|
+
* ```ts
|
|
589
|
+
* const { createCanvas, loadImage } = require('@napi-rs/canvas');
|
|
590
|
+
* const img = await loadImage('./photo.jpg');
|
|
591
|
+
* const canvas = createCanvas(img.width, img.height);
|
|
592
|
+
* const ctx = canvas.getContext('2d');
|
|
593
|
+
* ctx.drawImage(img, 0, 0);
|
|
594
|
+
* const text = asciiText(canvas as unknown as HTMLCanvasElement, { fontSize: 10 });
|
|
595
|
+
* ```
|
|
596
|
+
*/
|
|
597
|
+
declare function asciiText(source: HTMLImageElement | HTMLVideoElement | HTMLCanvasElement, options?: Partial<AsciiOptions>, targetWidth?: number, targetHeight?: number): string;
|
|
598
|
+
/**
|
|
599
|
+
* Convert any source to an ASCII string with ANSI 256-colour escape codes.
|
|
600
|
+
* Works in any terminal that supports ANSI colours.
|
|
601
|
+
*
|
|
602
|
+
* @example
|
|
603
|
+
* ```ts
|
|
604
|
+
* process.stdout.write(asciiTextAnsi(imgEl, { fontSize: 8 }));
|
|
605
|
+
* ```
|
|
606
|
+
*/
|
|
607
|
+
declare function asciiTextAnsi(source: HTMLImageElement | HTMLVideoElement | HTMLCanvasElement, options?: Partial<AsciiOptions>, targetWidth?: number, targetHeight?: number): string;
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* record() — capture a rolling frame buffer from a running ASCII canvas
|
|
611
|
+
* and export it as a downloadable animated GIF or WebP data URL.
|
|
612
|
+
*
|
|
613
|
+
* Usage:
|
|
614
|
+
* ```ts
|
|
615
|
+
* const recorder = createRecorder(canvasEl, { fps: 15, maxFrames: 120 });
|
|
616
|
+
* recorder.start();
|
|
617
|
+
* // ... after a few seconds ...
|
|
618
|
+
* const dataUrl = await recorder.stop(); // 'data:image/gif;base64,...'
|
|
619
|
+
* ```
|
|
620
|
+
*/
|
|
621
|
+
interface RecorderOptions {
|
|
622
|
+
/** Target capture frame rate (default: 15) */
|
|
623
|
+
fps?: number;
|
|
624
|
+
/** Maximum number of frames to buffer (default: 120 → 8 s at 15 fps) */
|
|
625
|
+
maxFrames?: number;
|
|
626
|
+
/**
|
|
627
|
+
* Output format.
|
|
628
|
+
* - 'gif' — animated GIF via gif.js worker (requires gif.worker.js in public/)
|
|
629
|
+
* - 'webp' — animated WebP via MediaRecorder API (Chrome/Edge only)
|
|
630
|
+
* - 'png-sequence' — returns a JSON array of PNG data URLs (universal)
|
|
631
|
+
* Default: 'gif'
|
|
632
|
+
*/
|
|
633
|
+
format?: 'gif' | 'webp' | 'png-sequence';
|
|
634
|
+
/** GIF quality 1 (best) – 30 (smallest) — only used for format:'gif' (default: 10) */
|
|
635
|
+
quality?: number;
|
|
636
|
+
/**
|
|
637
|
+
* Scale factor applied to the canvas before capture (default: 1).
|
|
638
|
+
* Use 0.5 to halve dimensions and reduce file size.
|
|
639
|
+
*/
|
|
640
|
+
scale?: number;
|
|
641
|
+
}
|
|
642
|
+
interface Recorder {
|
|
643
|
+
/** Start capturing frames from the canvas. */
|
|
644
|
+
start(): void;
|
|
645
|
+
/**
|
|
646
|
+
* Stop capturing and encode.
|
|
647
|
+
* Resolves with a data URL (gif/webp) or JSON string (png-sequence).
|
|
648
|
+
*/
|
|
649
|
+
stop(): Promise<string>;
|
|
650
|
+
/** True while recording. */
|
|
651
|
+
readonly isRecording: boolean;
|
|
652
|
+
/** Number of frames captured so far. */
|
|
653
|
+
readonly frameCount: number;
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* Create a Recorder bound to a canvas element.
|
|
657
|
+
*/
|
|
658
|
+
declare function createRecorder(canvas: HTMLCanvasElement, options?: RecorderOptions): Recorder;
|
|
659
|
+
/**
|
|
660
|
+
* Convenience: record for a fixed duration and auto-download.
|
|
661
|
+
*
|
|
662
|
+
* @example
|
|
663
|
+
* ```ts
|
|
664
|
+
* await recordAndDownload(canvasEl, 3000, { fps: 15, format: 'gif' });
|
|
665
|
+
* ```
|
|
666
|
+
*/
|
|
667
|
+
declare function recordAndDownload(canvas: HTMLCanvasElement, durationMs: number, options?: RecorderOptions & {
|
|
668
|
+
filename?: string;
|
|
669
|
+
}): Promise<void>;
|
|
670
|
+
|
|
469
671
|
interface WebGLRenderer {
|
|
470
672
|
render(frame: AsciiFrame, options: AsciiOptions, displayW: number, displayH: number, time: number, hoverPos?: {
|
|
471
673
|
x: number;
|
|
@@ -483,4 +685,4 @@ interface WebGLRenderer {
|
|
|
483
685
|
*/
|
|
484
686
|
declare function tryCreateWebGLRenderer(canvas: HTMLCanvasElement): WebGLRenderer | null;
|
|
485
687
|
|
|
486
|
-
export { ART_STYLE_PRESETS, type AnimationStyle, type ArtStyle, type AsciiBackgroundOptions, type AsciiCell, type AsciiFrame, type AsciiOptions, type AsciiResult, type AsciifySimpleOptions, type AuroraBackgroundOptions, CHARSETS, type CharsetKey, type ColorMode, DEFAULT_OPTIONS, type GridBackgroundOptions, HOVER_PRESETS, type HoverEffect, type HoverPreset, type MorphBackgroundOptions, type MountWaveOptions, type NoiseBackgroundOptions, type PulseBackgroundOptions, type RainBackgroundOptions, type RenderMode, type SilkBackgroundOptions, type SourceType, type StarsBackgroundOptions, type VoidBackgroundOptions, type WaveBackgroundOptions, type WebGLRenderer, asciiBackground, asciify, asciifyGif, asciifyVideo, generateAnimatedEmbedCode, generateEmbedCode, gifToAsciiFrames, imageToAsciiFrame, mountWaveBackground, renderAuroraBackground, renderFrameToCanvas, renderGridBackground, renderMorphBackground, renderNoiseBackground, renderPulseBackground, renderRainBackground, renderSilkBackground, renderStarsBackground, renderVoidBackground, renderWaveBackground, tryCreateWebGLRenderer, videoToAsciiFrames };
|
|
688
|
+
export { ART_STYLE_PRESETS, type AnimationStyle, type ArtStyle, type AsciiBackgroundOptions, type AsciiCell, type AsciiFrame, type AsciiOptions, type AsciiResult, type AsciifySimpleOptions, type AuroraBackgroundOptions, 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 Recorder, type RecorderOptions, type RenderMode, type SilkBackgroundOptions, type SourceType, type StarsBackgroundOptions, type TerrainBackgroundOptions, type VoidBackgroundOptions, type WaveBackgroundOptions, type WebGLRenderer, asciiBackground, asciiText, asciiTextAnsi, asciify, asciifyGif, asciifyVideo, createRecorder, generateAnimatedEmbedCode, generateEmbedCode, gifToAsciiFrames, imageToAsciiFrame, mountWaveBackground, recordAndDownload, renderAuroraBackground, renderCircuitBackground, renderDnaBackground, renderFireBackground, renderFrameToCanvas, renderGridBackground, renderMorphBackground, renderNoiseBackground, renderPulseBackground, renderRainBackground, renderSilkBackground, renderStarsBackground, renderTerrainBackground, renderVoidBackground, renderWaveBackground, tryCreateWebGLRenderer, videoToAsciiFrames };
|