@genart-dev/core 0.1.0 → 0.1.1
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/README.md +183 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# @genart-dev/core
|
|
2
|
+
|
|
3
|
+
Renderer adapters, skill registry, and runtime interfaces for [genart.dev](https://genart.dev) — a generative art platform with an MCP server, desktop app, and IDE extensions.
|
|
4
|
+
|
|
5
|
+
Re-exports everything from [`@genart-dev/format`](https://github.com/genart-dev/format) so consumers get the full format API without a separate import.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @genart-dev/core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import {
|
|
17
|
+
createDefaultRegistry,
|
|
18
|
+
createDefaultSkillRegistry,
|
|
19
|
+
parseGenart,
|
|
20
|
+
resolvePreset,
|
|
21
|
+
} from "@genart-dev/core";
|
|
22
|
+
|
|
23
|
+
// Set up renderer registry with all 5 adapters
|
|
24
|
+
const renderers = createDefaultRegistry();
|
|
25
|
+
|
|
26
|
+
// Parse a .genart file and resolve its renderer
|
|
27
|
+
const sketch = parseGenart(JSON.parse(fileContents));
|
|
28
|
+
const adapter = renderers.resolve(sketch.renderer.type); // → P5RendererAdapter
|
|
29
|
+
|
|
30
|
+
// Validate an algorithm for a specific renderer
|
|
31
|
+
const result = adapter.validate(sketch.algorithm);
|
|
32
|
+
if (!result.valid) {
|
|
33
|
+
console.error(result.errors);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Generate standalone HTML (embeds algorithm + CDN runtime)
|
|
37
|
+
const html = adapter.generateStandaloneHTML(sketch);
|
|
38
|
+
|
|
39
|
+
// Browse design knowledge skills
|
|
40
|
+
const skills = createDefaultSkillRegistry();
|
|
41
|
+
skills.list("composition"); // → 6 composition skills
|
|
42
|
+
skills.list("color"); // → 6 color skills
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Renderer Adapters
|
|
46
|
+
|
|
47
|
+
Five pluggable rendering engines, each implementing the `RendererAdapter` interface:
|
|
48
|
+
|
|
49
|
+
| Adapter | Type | Language | Runtime | Algorithm Signature |
|
|
50
|
+
|---------|------|----------|---------|-------------------|
|
|
51
|
+
| `P5RendererAdapter` | `p5` | JavaScript | p5.js 1.x | `function sketch(p, state)` |
|
|
52
|
+
| `Canvas2DRendererAdapter` | `canvas2d` | JavaScript | Native | `function sketch(ctx, state)` |
|
|
53
|
+
| `ThreeRendererAdapter` | `three` | JavaScript | Three.js | `function sketch(THREE, state, container)` |
|
|
54
|
+
| `GLSLRendererAdapter` | `glsl` | GLSL | WebGL2 | Fragment shader source |
|
|
55
|
+
| `SVGRendererAdapter` | `svg` | JavaScript | Native | `function sketch(state)` |
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { P5RendererAdapter } from "@genart-dev/core";
|
|
59
|
+
|
|
60
|
+
const p5 = new P5RendererAdapter();
|
|
61
|
+
|
|
62
|
+
// Validate algorithm source
|
|
63
|
+
p5.validate(algorithm);
|
|
64
|
+
|
|
65
|
+
// Compile for execution
|
|
66
|
+
const compiled = await p5.compile(algorithm);
|
|
67
|
+
|
|
68
|
+
// Create a live instance (browser context)
|
|
69
|
+
const instance = p5.createInstance(compiled, sketch.state, sketch.canvas);
|
|
70
|
+
instance.mount(document.getElementById("canvas"));
|
|
71
|
+
instance.updateState(newState);
|
|
72
|
+
instance.captureFrame({ format: "png" }); // → data URL
|
|
73
|
+
|
|
74
|
+
// Generate standalone HTML with embedded CDN runtime
|
|
75
|
+
const html = p5.generateStandaloneHTML(sketch);
|
|
76
|
+
|
|
77
|
+
// Get starter template for new sketches
|
|
78
|
+
const template = p5.getAlgorithmTemplate();
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### RendererRegistry
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
import { createDefaultRegistry, RendererRegistry } from "@genart-dev/core";
|
|
85
|
+
|
|
86
|
+
// Pre-loaded with all 5 adapters
|
|
87
|
+
const registry = createDefaultRegistry();
|
|
88
|
+
|
|
89
|
+
registry.resolve("p5"); // → P5RendererAdapter
|
|
90
|
+
registry.resolve("glsl"); // → GLSLRendererAdapter
|
|
91
|
+
registry.list(); // → ["p5", "canvas2d", "three", "glsl", "svg"]
|
|
92
|
+
registry.getDefault(); // → P5RendererAdapter
|
|
93
|
+
registry.has("three"); // → true
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Skill Registry
|
|
97
|
+
|
|
98
|
+
11 built-in design knowledge skills grounded in classical design theory — composition principles (Arnheim, Wong) and color theory (Albers, Itten). Each skill includes theory text, key principles, academic references, and optional renderer-specific algorithm examples.
|
|
99
|
+
|
|
100
|
+
### Composition Skills (6)
|
|
101
|
+
|
|
102
|
+
| ID | Complexity | Source |
|
|
103
|
+
|----|-----------|--------|
|
|
104
|
+
| `golden-ratio` | Intermediate | 1:1.618 proportions, spiral layouts |
|
|
105
|
+
| `rule-of-thirds` | Beginner | 3x3 grid, power points, dynamic balance |
|
|
106
|
+
| `visual-weight` | Intermediate | Size, value, saturation, position balance |
|
|
107
|
+
| `gestalt-grouping` | Intermediate | Proximity, similarity, closure, continuity |
|
|
108
|
+
| `figure-ground` | Beginner | Positive forms vs. negative space |
|
|
109
|
+
| `rhythm-movement` | Advanced | Repetition, variation, progression, flow |
|
|
110
|
+
|
|
111
|
+
### Color Skills (6)
|
|
112
|
+
|
|
113
|
+
| ID | Complexity | Source |
|
|
114
|
+
|----|-----------|--------|
|
|
115
|
+
| `color-harmony` | Beginner | Complementary, analogous, triadic, split-complementary |
|
|
116
|
+
| `simultaneous-contrast` | Advanced | Albers' adjacent color perception shifts |
|
|
117
|
+
| `color-temperature` | Beginner | Warm (advances) vs. cool (recedes) |
|
|
118
|
+
| `itten-contrasts` | Advanced | Itten's 7 contrast types |
|
|
119
|
+
| `value-structure` | Intermediate | Lights, mid-tones, darks; tonal keys |
|
|
120
|
+
| `palette-generation` | Intermediate | Algorithmic OKLCH color space generation |
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
import { createDefaultSkillRegistry } from "@genart-dev/core";
|
|
124
|
+
|
|
125
|
+
const skills = createDefaultSkillRegistry();
|
|
126
|
+
|
|
127
|
+
const skill = skills.resolve("golden-ratio");
|
|
128
|
+
skill.theory; // Markdown theory text
|
|
129
|
+
skill.principles; // Key design principles
|
|
130
|
+
skill.references; // Academic citations
|
|
131
|
+
skill.suggestedParameters; // Example ParamDefs for this technique
|
|
132
|
+
skill.examples?.p5; // p5.js algorithm example
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## API Reference
|
|
136
|
+
|
|
137
|
+
### Interfaces
|
|
138
|
+
|
|
139
|
+
| Interface | Description |
|
|
140
|
+
|-----------|-------------|
|
|
141
|
+
| `RendererAdapter` | Contract for rendering engines — validate, compile, mount, capture, export |
|
|
142
|
+
| `SketchInstance` | Live sketch — mount/unmount, updateState, pause/resume, captureFrame |
|
|
143
|
+
| `SkillDefinition` | Design knowledge skill — theory, principles, references, examples |
|
|
144
|
+
| `SkillReference` | Academic citation (title, author, year) |
|
|
145
|
+
| `ValidationResult` | Algorithm validation result (`valid` + `errors[]`) |
|
|
146
|
+
| `RuntimeDependency` | CDN dependency for standalone HTML export (name, version, cdnUrl) |
|
|
147
|
+
| `CaptureOptions` | Screenshot options (format, quality, scale) |
|
|
148
|
+
| `CompiledAlgorithm` | Opaque compiled algorithm handle |
|
|
149
|
+
|
|
150
|
+
### Classes
|
|
151
|
+
|
|
152
|
+
| Class | Description |
|
|
153
|
+
|-------|-------------|
|
|
154
|
+
| `RendererRegistry` | Register and resolve renderer adapters by type |
|
|
155
|
+
| `SkillRegistry` | Register and resolve design knowledge skills |
|
|
156
|
+
|
|
157
|
+
### Factory Functions
|
|
158
|
+
|
|
159
|
+
| Function | Description |
|
|
160
|
+
|----------|-------------|
|
|
161
|
+
| `createDefaultRegistry()` | Registry pre-loaded with all 5 renderer adapters |
|
|
162
|
+
| `createDefaultSkillRegistry()` | Registry pre-loaded with all 11 skills |
|
|
163
|
+
|
|
164
|
+
### Utilities
|
|
165
|
+
|
|
166
|
+
| Function | Description |
|
|
167
|
+
|----------|-------------|
|
|
168
|
+
| `hexToVec3(hex)` | Convert `"#rrggbb"` to `[r, g, b]` floats in [0, 1] — for GLSL uniforms |
|
|
169
|
+
|
|
170
|
+
### Re-exports from @genart-dev/format
|
|
171
|
+
|
|
172
|
+
All types and functions from `@genart-dev/format` are re-exported: `parseGenart`, `serializeGenart`, `parseWorkspace`, `serializeWorkspace`, `convertLegacySketch`, `CANVAS_PRESETS`, `resolvePreset`, `SketchDefinition`, `WorkspaceDefinition`, `ParamDef`, `ColorDef`, and more. See the [format README](https://github.com/genart-dev/format) for the full list.
|
|
173
|
+
|
|
174
|
+
## Related Packages
|
|
175
|
+
|
|
176
|
+
| Package | Purpose |
|
|
177
|
+
|---------|---------|
|
|
178
|
+
| [`@genart-dev/format`](https://github.com/genart-dev/format) | File format types, parsers, presets (dependency) |
|
|
179
|
+
| [`@genart-dev/mcp-server`](https://github.com/genart-dev/mcp-server) | 33-tool MCP server + CLI (depends on core) |
|
|
180
|
+
|
|
181
|
+
## License
|
|
182
|
+
|
|
183
|
+
MIT
|