git-hash-art 0.1.0 → 0.2.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.
@@ -0,0 +1,16 @@
1
+ # Product: git-hash-art
2
+
3
+ A cross-platform library that generates deterministic abstract art from git commit hashes. Given a hex hash string, it produces a unique image using layered geometric shapes, sacred geometry patterns, and harmonious color schemes. Works in both Node.js and browser environments.
4
+
5
+ Key capabilities:
6
+ - Deterministic output: same hash always produces the same image
7
+ - Configurable canvas size, grid density, layers, shape sizes, and opacity
8
+ - Built-in presets for social media (Instagram, Twitter, LinkedIn), device wallpapers, and print sizes
9
+ - CLI for generating art from the current commit or a specific hash
10
+ - Cross-platform: Node.js (via `@napi-rs/canvas`) and browsers (native Canvas 2D API)
11
+
12
+ ## Public API
13
+
14
+ - Node entry (`git-hash-art`): `generateImageFromHash` (returns PNG Buffer), `saveImageToFile`, `renderHashArt`
15
+ - Browser entry (`git-hash-art/browser`): `renderToCanvas`, `generateImageBlob`, `generateDataURL`, `renderHashArt`
16
+ - Both re-export `PRESETS`, `DEFAULT_CONFIG`, and the `GenerationConfig` type
@@ -0,0 +1,40 @@
1
+ # Project Structure
2
+
3
+ ```
4
+ src/
5
+ index.ts # Node.js entry: generateImageFromHash, saveImageToFile, re-exports renderHashArt
6
+ browser.ts # Browser entry: renderToCanvas, generateImageBlob, generateDataURL, re-exports renderHashArt
7
+ types.ts # Shared GenerationConfig interface and DEFAULT_CONFIG
8
+ __tests__/ # Vitest test files (*.test.ts)
9
+ lib/
10
+ render.ts # Pure rendering logic (environment-agnostic) — renderHashArt()
11
+ utils.ts # Hash-to-seed conversion, deterministic RNG, PatternCombiner
12
+ constants.ts # PRESETS, default shape config, proportions, pattern presets
13
+ canvas/
14
+ colors.ts # Color scheme generation (generateColorScheme, SacredColorScheme class)
15
+ draw.ts # Shape drawing and enhancement (drawShape, enhanceShapeGeneration)
16
+ shapes/
17
+ index.ts # Aggregates and re-exports all shape draw functions
18
+ basic.ts # Circle, square, triangle, hexagon, star
19
+ complex.ts # Platonic solids, fibonacci, golden ratio shapes
20
+ sacred.ts # Flower of life, tree of life, Metatron's cube, Sri Yantra
21
+ utils.ts # Geometry helpers (transforms, degree conversion)
22
+ bin/
23
+ generateExamples.js # Script to generate example images from PRESETS
24
+ examples/ # Generated example PNGs (gitignored)
25
+ ```
26
+
27
+ ## Architecture
28
+
29
+ - `src/lib/render.ts` contains the pure rendering core (`renderHashArt`) that only uses the standard `CanvasRenderingContext2D` API — no Node or browser dependencies
30
+ - `src/index.ts` is the Node entry point — wraps `renderHashArt` with `@napi-rs/canvas` for PNG buffer output and `fs` for file saving
31
+ - `src/browser.ts` is the browser entry point — wraps `renderHashArt` with `HTMLCanvasElement`/`OffscreenCanvas` helpers
32
+ - `@napi-rs/canvas` is an optional peer dependency, only required for Node.js usage
33
+
34
+ ## Conventions
35
+
36
+ - Shape draw functions follow the `DrawFunction` signature: `(ctx: CanvasRenderingContext2D, size: number, config?: any) => void`
37
+ - Shapes are grouped by category (basic, complex, sacred) and merged via the barrel `shapes/index.ts`
38
+ - All randomness is derived deterministically from the git hash via `getRandomFromHash` — never use `Math.random()`
39
+ - Tests live in `src/__tests__/` and use Vitest (`describe`/`it`/`expect`)
40
+ - The `examples/` directory is gitignored; regenerate with `yarn build:examples`
@@ -0,0 +1,24 @@
1
+ # Tech Stack
2
+
3
+ - Language: TypeScript (strict mode, ES2020 target)
4
+ - Runtime: Node.js and browsers
5
+ - Canvas (Node): `@napi-rs/canvas` (optional peer dependency)
6
+ - Canvas (Browser): native Canvas 2D API / OffscreenCanvas
7
+ - Color generation: `color-scheme` (declared in `global.d.ts` since it lacks types)
8
+ - Bundler: Parcel (outputs CJS `dist/main.js`, ESM `dist/module.js`, browser `dist/browser.js`, types `dist/types.d.ts`)
9
+ - Test framework: Vitest
10
+ - Formatter: Prettier
11
+ - Release: release-it
12
+ - Package manager: Yarn
13
+
14
+ ## Common Commands
15
+
16
+ | Command | Purpose |
17
+ |---|---|
18
+ | `yarn build` | Production build (clears `.parcel-cache` first via `prebuild`) |
19
+ | `yarn watch` | Dev build with file watching |
20
+ | `npx vitest --run` | Run tests once |
21
+ | `yarn format` | Format source files with Prettier |
22
+ | `yarn format:check` | Check formatting without writing |
23
+ | `yarn build:examples` | Generate example images via `bin/generateExamples.js` |
24
+ | `yarn test:publish` | Dry-run npm publish |
package/CHANGELOG.md CHANGED
@@ -4,9 +4,20 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
+ #### [0.2.0](https://github.com/gfargo/git-hash-art/compare/0.1.0...0.2.0)
8
+
9
+ - feat: add cross-platform browser support [`#8`](https://github.com/gfargo/git-hash-art/pull/8)
10
+ - feat: add visual effects for richer art generation [`#6`](https://github.com/gfargo/git-hash-art/pull/6)
11
+ - fix: improve art generation quality [`#5`](https://github.com/gfargo/git-hash-art/pull/5)
12
+ - docs: update README to reflect current algorithm and features [`15879c6`](https://github.com/gfargo/git-hash-art/commit/15879c62480a2d418c4ef8dcb479d912a7160345)
13
+ - fix(shapes): handle missing shape type default [`860bfd3`](https://github.com/gfargo/git-hash-art/commit/860bfd36caab97d6ed44dd441ea1a995863b6068)
14
+
7
15
  #### [0.1.0](https://github.com/gfargo/git-hash-art/compare/0.0.4...0.1.0)
8
16
 
17
+ > 18 March 2026
18
+
9
19
  - update shape drawing for platonic solids [`c26decd`](https://github.com/gfargo/git-hash-art/commit/c26decd8df9d7d47615efce37da8fdf554cdfcc4)
20
+ - chore: release v0.1.0 [`f83dce5`](https://github.com/gfargo/git-hash-art/commit/f83dce5de7a03da5432b1bb538643b7fcb9cd29f)
10
21
 
11
22
  #### [0.0.4](https://github.com/gfargo/git-hash-art/compare/0.0.3...0.0.4)
12
23
 
package/README.md CHANGED
@@ -2,15 +2,22 @@
2
2
 
3
3
  Generate beautiful, deterministic abstract art from git commit hashes. Perfect for creating unique visual representations of your project's commits, generating placeholder images, or creating artistic wallpapers.
4
4
 
5
+ Works in both Node.js and browser environments.
6
+
5
7
  ## Features
6
8
 
7
- - Generate consistent, deterministic abstract art from any git hash
8
- - Configurable canvas sizes and output formats
9
- - Built-in presets for common social media and device sizes
10
- - Harmonious color schemes based on hash values
11
- - Grid-based composition system for balanced layouts
12
- - Multiple shape types and layering effects
13
- - Customizable output settings
9
+ - Deterministic output same hash always produces the same image
10
+ - Hash-derived harmonious color schemes (analogic, complementary, and triadic palettes)
11
+ - 20+ shape types across three categories: basic, complex, and sacred geometry
12
+ - Layered composition with depth early layers use simple shapes, later layers use intricate ones
13
+ - Watercolor-style transparency with semi-transparent fills and color blending
14
+ - Glow effects on sacred geometry shapes for an ethereal quality
15
+ - Radial gradient fills and organic color jitter for a hand-painted feel
16
+ - Organic bezier curves connecting nearby shapes
17
+ - Configurable canvas size, layers, shape sizes, and opacity
18
+ - Built-in presets for social media, device wallpapers, and print sizes
19
+ - CLI for generating art from the current commit or a specific hash
20
+ - Cross-platform: runs in Node.js (via `@napi-rs/canvas`) and browsers (native Canvas API)
14
21
 
15
22
  ## Installation
16
23
 
@@ -18,87 +25,170 @@ Generate beautiful, deterministic abstract art from git commit hashes. Perfect f
18
25
  npm install git-hash-art
19
26
  ```
20
27
 
21
- ## Basic Usage
28
+ For Node.js usage you also need the canvas backend:
29
+
30
+ ```bash
31
+ npm install @napi-rs/canvas
32
+ ```
33
+
34
+ Browser usage requires no additional dependencies — the library uses the native Canvas 2D API.
35
+
36
+ ## Node.js Usage
22
37
 
23
38
  ```javascript
24
- import { generateImageFromHash } from 'git-hash-art';
39
+ import { generateImageFromHash, saveImageToFile } from 'git-hash-art';
25
40
 
26
- // Generate art from a git hash with default settings
41
+ // Generate a PNG buffer from a git hash
27
42
  const gitHash = '46192e59d42f741c761cbea79462a8b3815dd905';
28
- generateImageFromHash(gitHash);
43
+ const imageBuffer = generateImageFromHash(gitHash);
44
+
45
+ // Save to disk
46
+ saveImageToFile(imageBuffer, './output', gitHash, 'my-art', 2048, 2048);
29
47
  ```
30
48
 
31
- ## Advanced Usage
49
+ ### Advanced Node.js Usage
32
50
 
33
51
  ```javascript
34
- // Custom configuration
52
+ import { generateImageFromHash } from 'git-hash-art';
53
+
35
54
  const config = {
36
55
  width: 1920,
37
56
  height: 1080,
38
57
  gridSize: 6,
39
- layers: 7,
40
- shapesPerLayer: 30,
58
+ layers: 5,
59
+ shapesPerLayer: 40,
41
60
  minShapeSize: 20,
42
- maxShapeSize: 180,
43
- baseOpacity: 0.6,
44
- opacityReduction: 0.1
61
+ maxShapeSize: 300,
62
+ baseOpacity: 0.7,
63
+ opacityReduction: 0.12
45
64
  };
46
65
 
47
- generateImageFromHash(gitHash, config);
66
+ const imageBuffer = generateImageFromHash(gitHash, config);
48
67
  ```
49
68
 
50
- ## Configuration Options
69
+ ## Browser Usage
51
70
 
52
- | Option | Type | Default | Description |
53
- |--------|------|---------|-------------|
54
- | `width` | number | 1024 | Canvas width in pixels |
55
- | `height` | number | 1024 | Canvas height in pixels |
56
- | `gridSize` | number | 4 | Number of grid cells (gridSize x gridSize) |
57
- | `layers` | number | 5 | Number of layers to generate |
58
- | `shapesPerLayer` | number | - | Base number of shapes per layer (defaults to grid cells * 1.5) |
59
- | `minShapeSize` | number | 20 | Minimum shape size |
60
- | `maxShapeSize` | number | 180 | Maximum shape size |
61
- | `baseOpacity` | number | 0.6 | Starting opacity for first layer |
62
- | `opacityReduction` | number | 0.1 | How much to reduce opacity per layer |
71
+ ```javascript
72
+ import { renderToCanvas, generateDataURL, generateImageBlob } from 'git-hash-art/browser';
73
+ ```
63
74
 
64
- ## Preset Sizes
75
+ ### Render onto an existing canvas element
65
76
 
66
- The package includes several preset configurations for common use cases:
77
+ ```javascript
78
+ import { renderToCanvas } from 'git-hash-art/browser';
79
+
80
+ const canvas = document.getElementById('art-canvas');
81
+ canvas.width = 1024;
82
+ canvas.height = 1024;
83
+
84
+ renderToCanvas(canvas, '46192e59d42f741c761cbea79462a8b3815dd905');
85
+ ```
86
+
87
+ ### Generate a data URL (for `<img>` tags)
67
88
 
68
89
  ```javascript
69
- import { PRESETS } from 'git-hash-art-generator';
90
+ import { generateDataURL } from 'git-hash-art/browser';
70
91
 
71
- // Generate an Instagram-sized image
72
- generateImageFromHash(gitHash, PRESETS['instagram'].config);
92
+ const dataUrl = generateDataURL('46192e59d42f741c761cbea79462a8b3815dd905', {
93
+ width: 512,
94
+ height: 512,
95
+ });
73
96
 
74
- // Generate a mobile wallpaper
75
- generateImageFromHash(gitHash, PRESETS['phone-wallpaper'].config);
97
+ document.getElementById('preview').src = dataUrl;
76
98
  ```
77
99
 
78
- Available presets include:
79
- - Standard (1024x1024)
80
- - Banner (1920x480)
81
- - Ultrawide (3440x1440)
82
- - Instagram (1080x1080)
83
- - Instagram Story (1080x1920)
84
- - Twitter Header (1500x500)
85
- - LinkedIn Banner (1584x396)
86
- - Phone Wallpaper (1170x2532)
87
- - Tablet Wallpaper (2048x2732)
88
- - Print sizes (A4/A3 at 300 DPI)
100
+ ### Generate a Blob (for downloads or uploads)
89
101
 
90
- ## CLI Usage
102
+ ```javascript
103
+ import { generateImageBlob } from 'git-hash-art/browser';
104
+
105
+ const blob = await generateImageBlob('46192e59d42f741c761cbea79462a8b3815dd905', {
106
+ width: 1080,
107
+ height: 1080,
108
+ });
109
+
110
+ // Trigger a download
111
+ const url = URL.createObjectURL(blob);
112
+ const a = document.createElement('a');
113
+ a.href = url;
114
+ a.download = 'hash-art.png';
115
+ a.click();
116
+ ```
117
+
118
+ ## Core Renderer (Environment-Agnostic)
119
+
120
+ If you need full control, both entry points re-export `renderHashArt` which
121
+ accepts any standard `CanvasRenderingContext2D` — useful for custom canvas
122
+ setups, Web Workers with `OffscreenCanvas`, or server-side rendering
123
+ frameworks.
124
+
125
+ ```javascript
126
+ import { renderHashArt } from 'git-hash-art'; // or 'git-hash-art/browser'
127
+
128
+ const ctx = myCanvas.getContext('2d');
129
+ renderHashArt(ctx, '46192e59d42f741c761cbea79462a8b3815dd905', {
130
+ width: myCanvas.width,
131
+ height: myCanvas.height,
132
+ });
133
+ ```
134
+
135
+ ## Configuration Options
136
+
137
+ | Option | Type | Default | Description |
138
+ | ----------------- | ------ | ------- | ---------------------------------------------------- |
139
+ | `width` | number | 2048 | Canvas width in pixels |
140
+ | `height` | number | 2048 | Canvas height in pixels |
141
+ | `gridSize` | number | 5 | Controls base shape count per layer (gridSize² × 1.5)|
142
+ | `layers` | number | 4 | Number of layers to generate |
143
+ | `shapesPerLayer` | number | auto | Base shapes per layer (defaults to gridSize² × 1.5) |
144
+ | `minShapeSize` | number | 30 | Minimum shape size in pixels (scaled to canvas) |
145
+ | `maxShapeSize` | number | 400 | Maximum shape size in pixels (scaled to canvas) |
146
+ | `baseOpacity` | number | 0.7 | Starting opacity for the first layer |
147
+ | `opacityReduction`| number | 0.12 | Opacity reduction per layer |
148
+
149
+ ## Shape Categories
91
150
 
92
- The package includes a command-line interface:
151
+ Shapes are selected with layer-aware weighting — early layers favor simple shapes for background texture, later layers favor intricate ones for foreground detail.
152
+
153
+ **Basic** — circle, square, triangle, hexagon, star, diamond, cube, heart
154
+
155
+ **Complex** — platonic solids, fibonacci spiral, islamic pattern, celtic knot, merkaba, mandala, fractal
156
+
157
+ **Sacred Geometry** — flower of life, tree of life, Metatron's cube, Sri Yantra, seed of life, vesica piscis, torus, egg of life
158
+
159
+ ## Preset Sizes
160
+
161
+ ```javascript
162
+ import { PRESETS } from 'git-hash-art';
163
+
164
+ // Use a preset's hash and config
165
+ const preset = PRESETS['instagram-square'];
166
+ const imageBuffer = generateImageFromHash(preset.hash, preset);
167
+ ```
168
+
169
+ Available presets:
170
+
171
+ - Standard (1024×1024)
172
+ - Banner (1920×480)
173
+ - Ultrawide (3440×1440)
174
+ - Instagram Square (1080×1080)
175
+ - Instagram Story (1080×1920)
176
+ - Twitter Header (1500×500)
177
+ - LinkedIn Banner (1584×396)
178
+ - Phone Wallpaper (1170×2532)
179
+ - Tablet Wallpaper (2048×2732)
180
+ - Minimal, Complex (special configurations)
181
+
182
+ ## CLI Usage
93
183
 
94
184
  ```bash
95
- # Generate with default settings
185
+ # Generate from the current commit
96
186
  npx git-hash-art current
97
187
 
98
- # Generate from specific hash
188
+ # Generate from a specific hash
99
189
  npx git-hash-art generate <hash>
100
190
 
101
- # Generate with custom size
191
+ # Custom size
102
192
  npx git-hash-art generate <hash> --width 1920 --height 1080
103
193
  ```
104
194
 
@@ -115,7 +205,7 @@ jobs:
115
205
  steps:
116
206
  - uses: actions/checkout@v2
117
207
  - uses: actions/setup-node@v2
118
- - run: npm install git-hash-art-generator
208
+ - run: npm install git-hash-art @napi-rs/canvas
119
209
  - run: npx git-hash-art current --output artwork/
120
210
  ```
121
211
 
@@ -124,15 +214,33 @@ jobs:
124
214
  ```bash
125
215
  #!/bin/sh
126
216
  # .git/hooks/post-commit
127
-
128
217
  hash=$(git rev-parse HEAD)
129
218
  npx git-hash-art generate $hash --output .git/artwork/
130
219
  ```
131
220
 
221
+ ### React Component
222
+
223
+ ```jsx
224
+ import { useEffect, useRef } from 'react';
225
+ import { renderToCanvas } from 'git-hash-art/browser';
226
+
227
+ function CommitArt({ hash, width = 256, height = 256 }) {
228
+ const canvasRef = useRef(null);
229
+
230
+ useEffect(() => {
231
+ if (canvasRef.current) {
232
+ renderToCanvas(canvasRef.current, hash, { width, height });
233
+ }
234
+ }, [hash, width, height]);
235
+
236
+ return <canvas ref={canvasRef} width={width} height={height} />;
237
+ }
238
+ ```
239
+
132
240
  ## Contributing
133
241
 
134
242
  Contributions are welcome! Please see our [Contributing Guidelines](CONTRIBUTING.md) for more details.
135
243
 
136
244
  ## License
137
245
 
138
- MIT License - see [LICENSE](LICENSE) for details.
246
+ MIT License - see [LICENSE](LICENSE) for details.