asciify-engine 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 ayangabryl
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,204 @@
1
+ # asciify-engine
2
+
3
+ Framework-agnostic ASCII art engine. Convert images, videos, and GIFs into ASCII art rendered on HTML canvas.
4
+
5
+ ## Features
6
+
7
+ - **Image → ASCII** — single-frame conversion
8
+ - **Video → ASCII** — extract frames from `<video>` elements
9
+ - **GIF → ASCII** — parse and convert animated GIFs
10
+ - **Canvas rendering** — render ASCII frames to any `<canvas>`
11
+ - **6 art styles** — Classic, Particles, Letters, Box Drawing, Dense Art, Terminal
12
+ - **Color modes** — Grayscale, Full Color, Matrix, Accent
13
+ - **Hover effects** — Spotlight, Magnify, Repel, Glow, Color Shift
14
+ - **Embed code generation** — self-contained HTML output
15
+ - **Zero framework dependencies** — works with React, Angular, Vue, Svelte, vanilla JS
16
+
17
+ ## Install
18
+
19
+ ```bash
20
+ npm install asciify-engine
21
+ ```
22
+
23
+ ## Quick Start
24
+
25
+ ### Vanilla JS
26
+
27
+ ```html
28
+ <canvas id="ascii" width="800" height="600"></canvas>
29
+ <script type="module">
30
+ import {
31
+ imageToAsciiFrame,
32
+ renderFrameToCanvas,
33
+ DEFAULT_OPTIONS,
34
+ ART_STYLE_PRESETS,
35
+ } from 'asciify-engine';
36
+
37
+ const img = new Image();
38
+ img.crossOrigin = 'anonymous';
39
+ img.src = 'https://picsum.photos/600/400';
40
+ img.onload = () => {
41
+ const canvas = document.getElementById('ascii');
42
+ const options = { ...DEFAULT_OPTIONS, ...ART_STYLE_PRESETS.classic, fontSize: 10 };
43
+ const cols = Math.floor(canvas.width / options.fontSize);
44
+ const rows = Math.floor(canvas.height / (options.fontSize * 1.8));
45
+ const frame = imageToAsciiFrame(img, options, cols, rows);
46
+ renderFrameToCanvas(canvas.getContext('2d'), frame, options, canvas.width, canvas.height);
47
+ };
48
+ </script>
49
+ ```
50
+
51
+ ### React
52
+
53
+ ```tsx
54
+ import { useEffect, useRef } from 'react';
55
+ import {
56
+ imageToAsciiFrame,
57
+ renderFrameToCanvas,
58
+ DEFAULT_OPTIONS,
59
+ ART_STYLE_PRESETS,
60
+ type ArtStyle,
61
+ } from 'asciify-engine';
62
+
63
+ export function AsciiImage({ src, style = 'classic' }: { src: string; style?: ArtStyle }) {
64
+ const ref = useRef<HTMLCanvasElement>(null);
65
+
66
+ useEffect(() => {
67
+ const img = new Image();
68
+ img.crossOrigin = 'anonymous';
69
+ img.src = src;
70
+ img.onload = () => {
71
+ const canvas = ref.current!;
72
+ const opts = { ...DEFAULT_OPTIONS, ...ART_STYLE_PRESETS[style], fontSize: 10 };
73
+ const cols = Math.floor(canvas.width / opts.fontSize);
74
+ const rows = Math.floor(canvas.height / (opts.fontSize * 1.8));
75
+ const frame = imageToAsciiFrame(img, opts, cols, rows);
76
+ renderFrameToCanvas(canvas.getContext('2d')!, frame, opts, canvas.width, canvas.height);
77
+ };
78
+ }, [src, style]);
79
+
80
+ return <canvas ref={ref} width={800} height={600} />;
81
+ }
82
+ ```
83
+
84
+ ### Angular
85
+
86
+ ```typescript
87
+ import { Component, ElementRef, Input, ViewChild, AfterViewInit } from '@angular/core';
88
+ import {
89
+ imageToAsciiFrame,
90
+ renderFrameToCanvas,
91
+ DEFAULT_OPTIONS,
92
+ ART_STYLE_PRESETS,
93
+ } from 'asciify-engine';
94
+
95
+ @Component({
96
+ selector: 'app-ascii',
97
+ template: `<canvas #canvas [width]="800" [height]="600"></canvas>`,
98
+ })
99
+ export class AsciiComponent implements AfterViewInit {
100
+ @ViewChild('canvas') canvasRef!: ElementRef<HTMLCanvasElement>;
101
+ @Input() src!: string;
102
+ @Input() artStyle = 'classic';
103
+
104
+ ngAfterViewInit() {
105
+ const img = new Image();
106
+ img.crossOrigin = 'anonymous';
107
+ img.src = this.src;
108
+ img.onload = () => {
109
+ const canvas = this.canvasRef.nativeElement;
110
+ const opts = { ...DEFAULT_OPTIONS, ...ART_STYLE_PRESETS[this.artStyle], fontSize: 10 };
111
+ const cols = Math.floor(canvas.width / opts.fontSize);
112
+ const rows = Math.floor(canvas.height / (opts.fontSize * 1.8));
113
+ const frame = imageToAsciiFrame(img, opts, cols, rows);
114
+ renderFrameToCanvas(canvas.getContext('2d')!, frame, opts, canvas.width, canvas.height);
115
+ };
116
+ }
117
+ }
118
+ ```
119
+
120
+ ### GIF Animation
121
+
122
+ ```ts
123
+ import { gifToAsciiFrames, renderFrameToCanvas, DEFAULT_OPTIONS } from 'asciify-engine';
124
+
125
+ const response = await fetch('https://media.giphy.com/media/ENagATV1Gr9eg/giphy.gif');
126
+ const buffer = await response.arrayBuffer();
127
+
128
+ const canvas = document.getElementById('ascii') as HTMLCanvasElement;
129
+ const ctx = canvas.getContext('2d')!;
130
+ const options = { ...DEFAULT_OPTIONS, fontSize: 8 };
131
+ const cols = Math.floor(canvas.width / options.fontSize);
132
+ const rows = Math.floor(canvas.height / (options.fontSize * 1.8));
133
+
134
+ const { frames, fps } = await gifToAsciiFrames(buffer, options, cols, rows);
135
+
136
+ let i = 0;
137
+ setInterval(() => {
138
+ renderFrameToCanvas(ctx, frames[i], options, canvas.width, canvas.height);
139
+ i = (i + 1) % frames.length;
140
+ }, 1000 / fps);
141
+ ```
142
+
143
+ ### Video
144
+
145
+ ```ts
146
+ import { videoToAsciiFrames, renderFrameToCanvas, DEFAULT_OPTIONS } from 'asciify-engine';
147
+
148
+ const video = document.createElement('video');
149
+ video.crossOrigin = 'anonymous';
150
+ video.src = '/my-video.mp4';
151
+ await new Promise((r) => (video.onloadeddata = r));
152
+
153
+ const options = { ...DEFAULT_OPTIONS, fontSize: 8 };
154
+ const cols = 120;
155
+ const rows = 50;
156
+ const { frames, fps } = await videoToAsciiFrames(video, options, cols, rows, 10, 6);
157
+
158
+ let i = 0;
159
+ setInterval(() => {
160
+ const ctx = document.getElementById('ascii').getContext('2d');
161
+ renderFrameToCanvas(ctx, frames[i], options, 800, 600);
162
+ i = (i + 1) % frames.length;
163
+ }, 1000 / fps);
164
+ ```
165
+
166
+ ## API
167
+
168
+ ### Functions
169
+
170
+ | Function | Description |
171
+ |---|---|
172
+ | `imageToAsciiFrame(img, options, cols, rows)` | Convert an image element to a single ASCII frame |
173
+ | `renderFrameToCanvas(ctx, frame, options, width, height)` | Render an ASCII frame onto a canvas context |
174
+ | `gifToAsciiFrames(buffer, options, cols, rows, onProgress?)` | Convert a GIF `ArrayBuffer` to animated frames |
175
+ | `videoToAsciiFrames(video, options, cols, rows, fps, maxDuration, onProgress?)` | Convert a `<video>` to animated frames |
176
+ | `generateEmbedCode(frame, options)` | Generate self-contained HTML embed string |
177
+ | `generateAnimatedEmbedCode(frames, options, fps)` | Generate animated HTML embed string |
178
+
179
+ ### Art Styles
180
+
181
+ | Style | Charset | Color Mode |
182
+ |---|---|---|
183
+ | `classic` | ` .:-=+*#%@` | Grayscale |
184
+ | `particles` | Dots mode | Full Color |
185
+ | `letters` | A-Z a-z | Full Color |
186
+ | `claudeCode` | Box drawing `╔╗╚╝║═...` | Accent |
187
+ | `art` | Dense 70-char set | Full Color |
188
+ | `terminal` | ` .:-=+*#%@` | Matrix green |
189
+
190
+ ### Options
191
+
192
+ See `AsciiOptions` type for full configuration. Key options:
193
+
194
+ - `fontSize` — character size in pixels (default: 10)
195
+ - `colorMode` — `'grayscale' | 'fullcolor' | 'matrix' | 'accent'`
196
+ - `renderMode` — `'ascii' | 'dots'`
197
+ - `charset` — character ramp string
198
+ - `brightness` / `contrast` — image adjustments
199
+ - `invert` — invert luminance mapping
200
+ - `hoverEffect` / `hoverStrength` / `hoverRadius` — interactive hover
201
+
202
+ ## License
203
+
204
+ MIT