@ignaciocabeza/bitface 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) 2026 Ignacio
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,305 @@
1
+ # bitface
2
+
3
+ **Tiny pixel art avatars that pack a punch.**
4
+
5
+ Generate unique 16x16 pixel art faces as clean SVGs — no dependencies, no canvas, no nonsense. Works everywhere: browsers, servers, React, Vue, Svelte, or just plain JavaScript.
6
+
7
+ ```
8
+ +--+--+--+--+--+--+
9
+ | |##|##|##|##| |
10
+ +--+--+--+--+--+--+
11
+ |##| |##|##| |##| <-- that's a face
12
+ +--+--+--+--+--+--+
13
+ | | | > < | | |
14
+ +--+--+--+--+--+--+
15
+ | | | \_/ | | |
16
+ +--+--+--+--+--+--+
17
+ ```
18
+
19
+ ## Why bitface?
20
+
21
+ - **Zero dependencies** — just your code and some math
22
+ - **Tiny output** — SVGs are a handful of `<rect>` elements, optimized by merging adjacent pixels
23
+ - **Deterministic** — same config = same face, every time
24
+ - **Framework agnostic** — first-class React, Vue, and Svelte support, but works without any of them
25
+ - **Animations** — idle, blink, talk, and emote presets built in
26
+ - **9 customizable features** — face shape, eyes, eyebrows, mouth, nose, ears, hair, beard, and accessories
27
+ - **Color presets** — 6 skin tones, 13 hair colors, 4 eye colors, or use any hex color
28
+
29
+ ## Install
30
+
31
+ ```bash
32
+ npm install @ignaciocabeza/bitface
33
+ ```
34
+
35
+ ## Quick start
36
+
37
+ ```js
38
+ import { generateFace, generateRandomConfig } from '@ignaciocabeza/bitface'
39
+
40
+ // Generate a random avatar
41
+ const svg = generateFace()
42
+
43
+ // Generate with a specific config
44
+ const config = generateRandomConfig()
45
+ config.hair = 'mohawk'
46
+ config.accessories = 'sunglasses'
47
+ const coolAvatar = generateFace(config)
48
+ ```
49
+
50
+ That's it. `coolAvatar` is an SVG string you can drop into any `innerHTML`, save to a file, or send over an API.
51
+
52
+ ## Framework usage
53
+
54
+ ### React
55
+
56
+ ```jsx
57
+ import { Avatar } from '@ignaciocabeza/bitface/react'
58
+
59
+ function Profile() {
60
+ return (
61
+ <Avatar
62
+ config={{
63
+ faceShape: 'round',
64
+ eyes: 'big',
65
+ eyebrows: 'arched',
66
+ mouth: 'smile',
67
+ nose: 'button',
68
+ ears: 'small',
69
+ hair: 'curly',
70
+ hairColor: 'auburn',
71
+ skinColor: 'medium',
72
+ accessories: 'glasses',
73
+ }}
74
+ size={128}
75
+ animation="idle"
76
+ />
77
+ )
78
+ }
79
+ ```
80
+
81
+ **Hooks:**
82
+
83
+ ```jsx
84
+ import { useAvatar, useAnimatedAvatar } from '@ignaciocabeza/bitface/react'
85
+
86
+ // Static avatar
87
+ const svg = useAvatar(config)
88
+
89
+ // Animated avatar
90
+ const svg = useAnimatedAvatar(config, 'blink')
91
+ ```
92
+
93
+ ### Vue
94
+
95
+ ```vue
96
+ <script setup>
97
+ import { Avatar } from '@ignaciocabeza/bitface/vue'
98
+
99
+ const config = {
100
+ faceShape: 'oval',
101
+ eyes: 'round',
102
+ eyebrows: 'thick',
103
+ mouth: 'grin',
104
+ nose: 'pointy',
105
+ ears: 'pointed',
106
+ hair: 'spiky',
107
+ hairColor: 'blue',
108
+ beard: 'goatee',
109
+ }
110
+ </script>
111
+
112
+ <template>
113
+ <Avatar :config="config" :size="128" animation="talk" />
114
+ </template>
115
+ ```
116
+
117
+ **Composables:**
118
+
119
+ ```js
120
+ import { useAvatar, useAnimatedAvatar } from '@ignaciocabeza/bitface/vue'
121
+
122
+ const svg = useAvatar(() => config)
123
+ const animatedSvg = useAnimatedAvatar(() => config, () => 'emote')
124
+ ```
125
+
126
+ ### Svelte
127
+
128
+ ```svelte
129
+ <script>
130
+ import Avatar from '@ignaciocabeza/bitface/svelte'
131
+
132
+ const config = {
133
+ faceShape: 'heart',
134
+ eyes: 'wink',
135
+ eyebrows: 'thin',
136
+ mouth: 'smirk',
137
+ nose: 'small',
138
+ ears: 'elf',
139
+ hair: 'ponytail',
140
+ hairColor: 'pink',
141
+ accessories: 'earrings',
142
+ }
143
+ </script>
144
+
145
+ <Avatar {config} size={128} animation="idle" />
146
+ ```
147
+
148
+ ### Node.js / server-side
149
+
150
+ ```js
151
+ import { generateFace } from '@ignaciocabeza/bitface'
152
+ import { writeFileSync } from 'fs'
153
+
154
+ const svg = generateFace({
155
+ faceShape: 'square',
156
+ eyes: 'angry',
157
+ eyebrows: 'angry',
158
+ mouth: 'frown',
159
+ nose: 'wide',
160
+ ears: 'big',
161
+ hair: 'mohawk',
162
+ hairColor: 'red',
163
+ beard: 'full',
164
+ backgroundColor: 'transparent',
165
+ })
166
+
167
+ writeFileSync('avatar.svg', svg)
168
+ ```
169
+
170
+ ## API
171
+
172
+ ### `generateFace(config?)`
173
+
174
+ Returns an SVG string. Pass a `FaceConfig` for a specific face, or call with no arguments for a random one.
175
+
176
+ ### `generateRandomConfig()`
177
+
178
+ Returns a random `FaceConfig` object with all fields populated.
179
+
180
+ ### `getAvailableParts()`
181
+
182
+ Returns all part variants grouped by category:
183
+
184
+ ```js
185
+ {
186
+ faceShape: ['round', 'oval', 'square', 'heart', 'long', 'diamond', 'wide'],
187
+ eyes: ['big', 'small', 'narrow', 'round', 'wink', 'happy', 'angry', 'dots', 'sleepy', 'cross', 'heart'],
188
+ eyebrows: ['thick', 'thin', 'arched', 'angry', 'worried', 'unibrow', 'none'],
189
+ mouth: ['smile', 'frown', 'open', 'flat', 'teeth', 'smirk', 'grin', 'tongue', 'oh'],
190
+ nose: ['small', 'pointy', 'wide', 'button', 'long', 'snub'],
191
+ ears: ['small', 'big', 'pointed', 'elf', 'none'],
192
+ hair: ['short', 'long', 'curly', 'mohawk', 'bald', 'ponytail', 'spiky', 'bob', 'afro', 'bangs'],
193
+ beard: ['stubble', 'goatee', 'full', 'mustache', 'handlebar', 'none'],
194
+ accessories: ['glasses', 'sunglasses', 'hat', 'headband', 'earrings', 'none'],
195
+ }
196
+ ```
197
+
198
+ ### `getPartThumbnail(category, name, skinColor?, hairColor?, eyeColor?)`
199
+
200
+ Returns an SVG string for a single part preview. Useful for building part pickers.
201
+
202
+ ### `getAnimationNames()`
203
+
204
+ Returns `['idle', 'talk', 'blink', 'emote']`.
205
+
206
+ ## FaceConfig
207
+
208
+ | Property | Required | Values | Default |
209
+ |---|---|---|---|
210
+ | `faceShape` | Yes | `round` `oval` `square` `heart` `long` `diamond` `wide` | — |
211
+ | `eyes` | Yes | `big` `small` `narrow` `round` `wink` `happy` `angry` `dots` `sleepy` `cross` `heart` | — |
212
+ | `eyebrows` | Yes | `thick` `thin` `arched` `angry` `worried` `unibrow` `none` | — |
213
+ | `mouth` | Yes | `smile` `frown` `open` `flat` `teeth` `smirk` `grin` `tongue` `oh` | — |
214
+ | `nose` | Yes | `small` `pointy` `wide` `button` `long` `snub` | — |
215
+ | `ears` | Yes | `small` `big` `pointed` `elf` `none` | — |
216
+ | `hair` | Yes | `short` `long` `curly` `mohawk` `bald` `ponytail` `spiky` `bob` `afro` `bangs` | — |
217
+ | `beard` | No | `stubble` `goatee` `full` `mustache` `handlebar` `none` | `none` |
218
+ | `accessories` | No | `glasses` `sunglasses` `hat` `headband` `earrings` `none` | `none` |
219
+ | `skinColor` | No | Preset name or hex color | `medium` |
220
+ | `hairColor` | No | Preset name or hex color | `black` |
221
+ | `eyeColor` | No | Preset name or hex color | `brown` |
222
+ | `backgroundColor` | No | Hex color or `transparent` | `#87CEEB` |
223
+
224
+ ## Color presets
225
+
226
+ ### Skin
227
+
228
+ | Preset | Color |
229
+ |---|---|
230
+ | `light` | `#FDDCB5` |
231
+ | `medium` | `#E8B88A` |
232
+ | `tan` | `#C8956C` |
233
+ | `brown` | `#8D5E3C` |
234
+ | `dark` | `#5C3A1E` |
235
+ | `pale` | `#FFF0E0` |
236
+
237
+ ### Hair
238
+
239
+ `black` `brown` `blonde` `red` `gray` `white` `auburn` `strawberry` `platinum` `pink` `blue` `purple` `teal`
240
+
241
+ ### Eyes
242
+
243
+ `brown` `blue` `green` `gray`
244
+
245
+ You can also pass any valid hex color (e.g. `#FF6600`) for any color property.
246
+
247
+ ## Animations
248
+
249
+ Built-in animation presets that cycle through face variations:
250
+
251
+ | Name | Duration | What it does |
252
+ |---|---|---|
253
+ | `idle` | 3.3s | Rests, then does a quick happy-eyes blink |
254
+ | `blink` | 3s | Natural eye blink cycle |
255
+ | `talk` | 1s | Mouth shape variations |
256
+ | `emote` | 1.6s | Eyebrow raise + mouth reaction |
257
+
258
+ Pass them as strings to any framework component:
259
+
260
+ ```jsx
261
+ <Avatar config={config} animation="blink" />
262
+ ```
263
+
264
+ Or use the hooks/composables for more control:
265
+
266
+ ```js
267
+ const svg = useAnimatedAvatar(config, 'talk')
268
+ ```
269
+
270
+ You can also define custom animation sequences:
271
+
272
+ ```js
273
+ const myAnimation = {
274
+ name: 'custom',
275
+ frames: [
276
+ { duration: 500, overrides: {} },
277
+ { duration: 200, overrides: { eyes: 'wink', mouth: 'smirk' } },
278
+ { duration: 300, overrides: { eyes: 'big', mouth: 'grin' } },
279
+ ],
280
+ }
281
+ ```
282
+
283
+ ## How it works
284
+
285
+ Each avatar is a 16x16 pixel grid. Parts (face, eyes, hair, etc.) are stamped onto the grid in layers, bottom to top:
286
+
287
+ ```
288
+ Layer 0: Face shape (base)
289
+ Layer 1: Ears
290
+ Layer 2: Nose
291
+ Layer 3: Mouth
292
+ Layer 4: Eyes
293
+ Layer 5: Eyebrows
294
+ Layer 6: Hair
295
+ Layer 7: Beard
296
+ Layer 8: Accessories
297
+ ```
298
+
299
+ Each part is defined as a small pixel array where numbers map to color roles (`1` = skin, `2` = shadow, etc.). The renderer resolves colors, stamps parts onto the grid, then converts the grid to an optimized SVG by merging horizontally adjacent same-color pixels into wider `<rect>` elements.
300
+
301
+ The result is a clean, scalable SVG with crisp pixel-art rendering — no blurry edges, no canvas required.
302
+
303
+ ## License
304
+
305
+ [MIT](LICENSE) — do whatever you want with it.
@@ -0,0 +1,53 @@
1
+ interface FaceConfig {
2
+ faceShape: string;
3
+ eyes: string;
4
+ eyebrows: string;
5
+ mouth: string;
6
+ nose: string;
7
+ ears: string;
8
+ hair: string;
9
+ beard?: string;
10
+ accessories?: string;
11
+ skinColor?: string;
12
+ hairColor?: string;
13
+ eyeColor?: string;
14
+ backgroundColor?: string;
15
+ }
16
+ /** 16×16 grid. Each cell is a hex color string or null (transparent). */
17
+ type PixelGrid = (string | null)[][];
18
+ /**
19
+ * A part pattern definition.
20
+ * - `pixels`: 2D array of integers. 0 = transparent, 1+ = color slot reference.
21
+ * - `slotMap`: maps integer keys to color role names (e.g. "skin", "hair", "eyes").
22
+ * - `offsetX`, `offsetY`: where this part is placed on the 16×16 canvas.
23
+ */
24
+ interface PartPattern {
25
+ pixels: number[][];
26
+ slotMap: Record<number, string>;
27
+ offsetX: number;
28
+ offsetY: number;
29
+ }
30
+ /** A named collection of part variants for one category. */
31
+ type PartCategory = Record<string, PartPattern>;
32
+
33
+ /** Generate a random FaceConfig by picking random parts and colors. */
34
+ declare function generateRandomConfig(): FaceConfig;
35
+ /** Generate a complete face SVG string. If no config is provided, a random face is generated. */
36
+ declare function generateFace(config?: FaceConfig): string;
37
+ /** Get all available part variant names, keyed by category. */
38
+ declare function getAvailableParts(): Record<string, string[]>;
39
+ /** Generate a thumbnail SVG string showing a single part variant. */
40
+ declare function getPartThumbnail(category: string, name: string, skinColor?: string, hairColor?: string, eyeColor?: string): string;
41
+
42
+ interface AnimationFrame {
43
+ duration: number;
44
+ overrides: Partial<FaceConfig>;
45
+ }
46
+ interface AnimationSequence {
47
+ name: string;
48
+ frames: AnimationFrame[];
49
+ }
50
+ declare const ANIMATIONS: Record<string, AnimationSequence>;
51
+ declare function getAnimationNames(): string[];
52
+
53
+ export { ANIMATIONS as A, type FaceConfig as F, type PartCategory as P, type AnimationFrame as a, type AnimationSequence as b, type PartPattern as c, type PixelGrid as d, generateRandomConfig as e, getAnimationNames as f, generateFace as g, getAvailableParts as h, getPartThumbnail as i };
@@ -0,0 +1,53 @@
1
+ interface FaceConfig {
2
+ faceShape: string;
3
+ eyes: string;
4
+ eyebrows: string;
5
+ mouth: string;
6
+ nose: string;
7
+ ears: string;
8
+ hair: string;
9
+ beard?: string;
10
+ accessories?: string;
11
+ skinColor?: string;
12
+ hairColor?: string;
13
+ eyeColor?: string;
14
+ backgroundColor?: string;
15
+ }
16
+ /** 16×16 grid. Each cell is a hex color string or null (transparent). */
17
+ type PixelGrid = (string | null)[][];
18
+ /**
19
+ * A part pattern definition.
20
+ * - `pixels`: 2D array of integers. 0 = transparent, 1+ = color slot reference.
21
+ * - `slotMap`: maps integer keys to color role names (e.g. "skin", "hair", "eyes").
22
+ * - `offsetX`, `offsetY`: where this part is placed on the 16×16 canvas.
23
+ */
24
+ interface PartPattern {
25
+ pixels: number[][];
26
+ slotMap: Record<number, string>;
27
+ offsetX: number;
28
+ offsetY: number;
29
+ }
30
+ /** A named collection of part variants for one category. */
31
+ type PartCategory = Record<string, PartPattern>;
32
+
33
+ /** Generate a random FaceConfig by picking random parts and colors. */
34
+ declare function generateRandomConfig(): FaceConfig;
35
+ /** Generate a complete face SVG string. If no config is provided, a random face is generated. */
36
+ declare function generateFace(config?: FaceConfig): string;
37
+ /** Get all available part variant names, keyed by category. */
38
+ declare function getAvailableParts(): Record<string, string[]>;
39
+ /** Generate a thumbnail SVG string showing a single part variant. */
40
+ declare function getPartThumbnail(category: string, name: string, skinColor?: string, hairColor?: string, eyeColor?: string): string;
41
+
42
+ interface AnimationFrame {
43
+ duration: number;
44
+ overrides: Partial<FaceConfig>;
45
+ }
46
+ interface AnimationSequence {
47
+ name: string;
48
+ frames: AnimationFrame[];
49
+ }
50
+ declare const ANIMATIONS: Record<string, AnimationSequence>;
51
+ declare function getAnimationNames(): string[];
52
+
53
+ export { ANIMATIONS as A, type FaceConfig as F, type PartCategory as P, type AnimationFrame as a, type AnimationSequence as b, type PartPattern as c, type PixelGrid as d, generateRandomConfig as e, getAnimationNames as f, generateFace as g, getAvailableParts as h, getPartThumbnail as i };