piximps 0.1.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/.github/workflows/ci.yml +20 -0
- package/.github/workflows/demo.yml +22 -0
- package/.github/workflows/release.yml +22 -0
- package/README.md +110 -0
- package/docs/browser.global.js +1539 -0
- package/docs/index.html +442 -0
- package/package.json +42 -0
- package/src/piximps/browser.ts +114 -0
- package/src/piximps/common/templates/accessories.ts +174 -0
- package/src/piximps/common/templates/body.ts +390 -0
- package/src/piximps/common/templates/eyes.ts +95 -0
- package/src/piximps/common/templates/horns.ts +152 -0
- package/src/piximps/common/templates/mouth.ts +96 -0
- package/src/piximps/common/templates/types.ts +4 -0
- package/src/piximps/domain/color-palette.ts +22 -0
- package/src/piximps/domain/imp-traits.ts +35 -0
- package/src/piximps/domain/template.ts +35 -0
- package/src/piximps/domain/types.ts +34 -0
- package/src/piximps/entrypoints/renderers/to-png-binary.ts +13 -0
- package/src/piximps/entrypoints/renderers/to-rgba-buffer.ts +26 -0
- package/src/piximps/entrypoints/renderers/to-svg-string.ts +28 -0
- package/src/piximps/index.ts +117 -0
- package/src/piximps/services/edge-detector.ts +60 -0
- package/src/piximps/services/hash-to-byte-sequence.ts +75 -0
- package/src/piximps/services/layer-compositor.ts +157 -0
- package/src/piximps/services/palette-deriver.ts +75 -0
- package/src/piximps/services/trait-extractor.ts +88 -0
- package/tests/functional/test-domain-models.test.ts +136 -0
- package/tests/functional/test-edge-detector.test.ts +64 -0
- package/tests/functional/test-hash-to-byte-sequence.test.ts +39 -0
- package/tests/functional/test-layer-compositor.test.ts +107 -0
- package/tests/functional/test-palette-deriver.test.ts +43 -0
- package/tests/functional/test-renderers.test.ts +105 -0
- package/tests/functional/test-trait-extractor.test.ts +50 -0
- package/tests/integration/test-determinism.test.ts +40 -0
- package/tests/integration/test-generator-builder.test.ts +56 -0
- package/tests/integration/test-output-formats.test.ts +47 -0
- package/tsconfig.json +24 -0
- package/tsup.config.ts +11 -0
- package/vitest.config.ts +18 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
- uses: actions/setup-node@v4
|
|
15
|
+
with:
|
|
16
|
+
node-version: 20
|
|
17
|
+
cache: npm
|
|
18
|
+
- run: npm ci
|
|
19
|
+
- run: npm run build
|
|
20
|
+
- run: npm test
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
name: Demo Deploy
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
paths: ['src/**']
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
build-demo:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
- uses: actions/setup-node@v4
|
|
14
|
+
with:
|
|
15
|
+
node-version: 20
|
|
16
|
+
cache: npm
|
|
17
|
+
- run: npm ci
|
|
18
|
+
- run: npm run build:demo
|
|
19
|
+
- uses: stefanzweifel/git-auto-commit-action@v5
|
|
20
|
+
with:
|
|
21
|
+
commit_message: 'chore: update demo bundle'
|
|
22
|
+
file_pattern: docs/browser.global.js
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags: ['v*']
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
publish:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v4
|
|
12
|
+
- uses: actions/setup-node@v4
|
|
13
|
+
with:
|
|
14
|
+
node-version: 20
|
|
15
|
+
registry-url: https://registry.npmjs.org
|
|
16
|
+
cache: npm
|
|
17
|
+
- run: npm ci
|
|
18
|
+
- run: npm test
|
|
19
|
+
- run: npm run build
|
|
20
|
+
- run: npm publish
|
|
21
|
+
env:
|
|
22
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/README.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
```
|
|
2
|
+
___ _ _
|
|
3
|
+
/ _ \(_)_ __(_)_ __ ___ _ __ ___
|
|
4
|
+
/ /_)/ \ \/ /| | '_ ` _ \| '_ \/ __|
|
|
5
|
+
/ ___/| |> < | | | | | | | |_) \__ \
|
|
6
|
+
\/ |_/_/\_\|_|_| |_| |_| .__/|___/
|
|
7
|
+
|_|
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
Deterministic demonic pixel-art avatars. Feed it a string, get a unique imp.
|
|
11
|
+
|
|
12
|
+
**[Live Demo](https://kamilrybacki.github.io/Piximps/)**
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install piximps
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { ImpGenerator } from 'piximps'
|
|
26
|
+
|
|
27
|
+
const gen = new ImpGenerator()
|
|
28
|
+
|
|
29
|
+
// Deterministic — same input, same imp, every time
|
|
30
|
+
const svg = await gen.format('svg').generate('your-username')
|
|
31
|
+
|
|
32
|
+
// Random imp
|
|
33
|
+
const random = await gen.format('svg').generate()
|
|
34
|
+
|
|
35
|
+
// PNG output (Node.js only — requires pngjs)
|
|
36
|
+
const png = await gen.format('png').generate('hello')
|
|
37
|
+
|
|
38
|
+
// Raw RGBA buffer
|
|
39
|
+
const buf = await gen.format('buffer').size(256).generate('world')
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## How It Works
|
|
43
|
+
|
|
44
|
+
1. **Hash** — your input string is hashed into a byte sequence
|
|
45
|
+
2. **Traits** — bytes are mapped to body shape, horns, eyes, mouth, and accessories (tail, wings, weapon, hat)
|
|
46
|
+
3. **Palette** — a unique 4-color palette (skin, accent, glow, secondary) is derived from the hash
|
|
47
|
+
4. **Compose** — layers are composited onto the pixel grid with symmetry and probabilistic fill
|
|
48
|
+
5. **Edge detect** — outlines are added for that crisp pixel-art look
|
|
49
|
+
6. **Render** — output as SVG string, PNG binary, or raw RGBA buffer
|
|
50
|
+
|
|
51
|
+
## API
|
|
52
|
+
|
|
53
|
+
### `new ImpGenerator(options?)`
|
|
54
|
+
|
|
55
|
+
| Option | Type | Default | Description |
|
|
56
|
+
|----------|--------------------|---------|--------------------------|
|
|
57
|
+
| `size` | `number` | `128` | Output size in pixels |
|
|
58
|
+
| `grid` | `8 \| 16 \| 32` | `16` | Pixel grid resolution |
|
|
59
|
+
| `format` | `'svg' \| 'png' \| 'buffer'` | `'png'` | Output format |
|
|
60
|
+
|
|
61
|
+
The constructor returns an immutable generator. Use the fluent API to derive new instances:
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
const gen = new ImpGenerator()
|
|
65
|
+
const big = gen.size(512) // new generator, 512px output
|
|
66
|
+
const svg = big.format('svg') // new generator, SVG format
|
|
67
|
+
const hd = svg.grid(32) // new generator, 32x32 grid
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### `.generate(input?: string): Promise<Uint8Array | string>`
|
|
71
|
+
|
|
72
|
+
- With a string: deterministic output (same string = same imp)
|
|
73
|
+
- Without arguments: random imp every time
|
|
74
|
+
- Returns `string` for SVG, `Uint8Array` for PNG and buffer
|
|
75
|
+
|
|
76
|
+
### `.getOptions(): Readonly<ImpGeneratorOptions>`
|
|
77
|
+
|
|
78
|
+
Returns the current configuration.
|
|
79
|
+
|
|
80
|
+
## Output Formats
|
|
81
|
+
|
|
82
|
+
| Format | Return type | Environment |
|
|
83
|
+
|----------|---------------|-----------------|
|
|
84
|
+
| `'svg'` | `string` | Node.js + Browser |
|
|
85
|
+
| `'png'` | `Uint8Array` | Node.js only |
|
|
86
|
+
| `'buffer'`| `Uint8Array` | Node.js + Browser |
|
|
87
|
+
|
|
88
|
+
> **Browser usage:** only `svg` and `buffer` formats work client-side. The `png` format depends on `pngjs` which requires Node.js `Buffer`.
|
|
89
|
+
|
|
90
|
+
## Grid Sizes
|
|
91
|
+
|
|
92
|
+
- **8x8** — chunky, iconic
|
|
93
|
+
- **16x16** — balanced detail (default)
|
|
94
|
+
- **32x32** — high detail imps
|
|
95
|
+
|
|
96
|
+
## Traits
|
|
97
|
+
|
|
98
|
+
Each imp is assembled from interchangeable parts:
|
|
99
|
+
|
|
100
|
+
- **Body** — the base silhouette
|
|
101
|
+
- **Horns** — various horn styles
|
|
102
|
+
- **Eyes** — expression and character
|
|
103
|
+
- **Mouth** — grins, fangs, smirks
|
|
104
|
+
- **Accessories** — tail, wings, weapon, hat (each independently present or absent)
|
|
105
|
+
|
|
106
|
+
All traits are deterministically selected from the input hash. Two imps with the same seed are guaranteed identical.
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
ISC
|