@nexart/ui-renderer 0.1.0 → 0.2.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.
Files changed (41) hide show
  1. package/README.md +204 -95
  2. package/dist/capabilities.d.ts +54 -0
  3. package/dist/capabilities.d.ts.map +1 -0
  4. package/dist/capabilities.js +338 -0
  5. package/dist/compiler.d.ts +34 -0
  6. package/dist/compiler.d.ts.map +1 -0
  7. package/dist/compiler.js +80 -0
  8. package/dist/index.d.ts +21 -6
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +19 -5
  11. package/dist/preview/primitives/dots.d.ts +6 -0
  12. package/dist/preview/primitives/dots.d.ts.map +1 -0
  13. package/dist/preview/primitives/dots.js +53 -0
  14. package/dist/preview/primitives/flow.d.ts +6 -0
  15. package/dist/preview/primitives/flow.d.ts.map +1 -0
  16. package/dist/preview/primitives/flow.js +32 -0
  17. package/dist/preview/primitives/grid.d.ts +6 -0
  18. package/dist/preview/primitives/grid.d.ts.map +1 -0
  19. package/dist/preview/primitives/grid.js +38 -0
  20. package/dist/preview/primitives/lines.d.ts +6 -0
  21. package/dist/preview/primitives/lines.d.ts.map +1 -0
  22. package/dist/preview/primitives/lines.js +47 -0
  23. package/dist/preview/primitives/orbits.d.ts +6 -0
  24. package/dist/preview/primitives/orbits.d.ts.map +1 -0
  25. package/dist/preview/primitives/orbits.js +27 -0
  26. package/dist/preview/primitives/waves.d.ts +6 -0
  27. package/dist/preview/primitives/waves.d.ts.map +1 -0
  28. package/dist/preview/primitives/waves.js +44 -0
  29. package/dist/preview/renderer.d.ts +17 -0
  30. package/dist/preview/renderer.d.ts.map +1 -0
  31. package/dist/preview/renderer.js +167 -0
  32. package/dist/system.d.ts +9 -0
  33. package/dist/system.d.ts.map +1 -0
  34. package/dist/system.js +165 -0
  35. package/dist/types.d.ts +99 -0
  36. package/dist/types.d.ts.map +1 -0
  37. package/dist/types.js +7 -0
  38. package/package.json +16 -7
  39. package/dist/renderer.d.ts +0 -31
  40. package/dist/renderer.d.ts.map +0 -1
  41. package/dist/renderer.js +0 -210
package/README.md CHANGED
@@ -1,40 +1,36 @@
1
1
  # @nexart/ui-renderer
2
2
 
3
- Version: 0.1.0
3
+ Version: 0.2.1
4
4
 
5
- **Browser-first UI renderer for exploratory generative art.**
5
+ **Declarative System Authoring SDK for NexArt Protocol**
6
6
 
7
7
  ---
8
8
 
9
9
  > ⚠️ **IMPORTANT DISCLAIMER**
10
10
  >
11
- > **This SDK is for exploration and UI rendering only.**
11
+ > **This SDK is for authoring and preview only.**
12
12
  > **Canonical, archival output is produced exclusively by @nexart/codemode-sdk.**
13
13
  >
14
- > This renderer is:
15
- > - **NOT canonical**
16
- > - **NOT archival**
17
- > - **NOT protocol-authoritative**
14
+ > This SDK is:
15
+ > - **NOT canonical** — Does not produce archival-quality output
16
+ > - **NOT archival** — Not suitable for NFT minting
17
+ > - **NOT protocol-authoritative** — Best-effort rendering only
18
18
  >
19
- > Use it for demos, playgrounds, miniapps, and experimentation.
19
+ > Same system same preview output within this SDK, but **preview ≠ mint truth**.
20
20
 
21
21
  ---
22
22
 
23
- ## What This SDK Is
23
+ ## Philosophy
24
24
 
25
- A lightweight, browser-first renderer for NexArt-style generative art:
25
+ The NexArt Protocol defines how generative art systems work. This SDK provides:
26
26
 
27
- - Works in browsers, Vite, React, plain HTML
28
- - Uses deterministic PRNG for reproducible visuals
29
- - Renders abstract flow fields, vortices, and orbital motion
30
- - Zero dependencies
31
- - No Node.js required
27
+ 1. **System Authoring** Declarative API to define NexArt systems
28
+ 2. **Preview Rendering** Visual approximation in the browser
29
+ 3. **Compilation** Export protocol-compatible JSON for canonical execution
32
30
 
33
- ## What This SDK Is NOT
31
+ This SDK exists to **reduce friction** for builders, artists, and AI platforms. It is the front door to the NexArt Protocol — not the authority.
34
32
 
35
- - **Not canonical** Does not produce archival-quality output
36
- - **Not for NFT minting** — Use `@nexart/codemode-sdk` for production mints
37
- - **Not protocol-enforcing** — Best-effort determinism only
33
+ **Canonical execution happens via `@nexart/codemode-sdk`.**
38
34
 
39
35
  ---
40
36
 
@@ -47,7 +43,7 @@ npm install @nexart/ui-renderer
47
43
  Or use directly in HTML:
48
44
  ```html
49
45
  <script type="module">
50
- import { createUIRenderer } from 'https://unpkg.com/@nexart/ui-renderer/dist/index.js';
46
+ import { createSystem, previewSystem } from 'https://unpkg.com/@nexart/ui-renderer/dist/index.js';
51
47
  </script>
52
48
  ```
53
49
 
@@ -55,119 +51,232 @@ Or use directly in HTML:
55
51
 
56
52
  ## Quick Start
57
53
 
58
- ```typescript
59
- import { createUIRenderer } from '@nexart/ui-renderer';
60
-
61
- const canvas = document.getElementById('canvas') as HTMLCanvasElement;
54
+ ### 1. Create a System
62
55
 
63
- const renderer = createUIRenderer({
64
- canvas,
65
- seed: Date.now(),
66
- mode: 'static',
67
- width: 800,
68
- height: 800,
56
+ ```typescript
57
+ import { createSystem } from '@nexart/ui-renderer';
58
+
59
+ const system = createSystem({
60
+ seed: 29445825,
61
+ background: {
62
+ color: 'blue',
63
+ texture: 'noise'
64
+ },
65
+ elements: [
66
+ {
67
+ type: 'waves',
68
+ axis: 'x',
69
+ amplitude: 0.4,
70
+ frequency: 0.7
71
+ },
72
+ {
73
+ type: 'dots',
74
+ distribution: 'radial',
75
+ count: 400,
76
+ size: [1, 4]
77
+ }
78
+ ],
79
+ motion: {
80
+ source: 'time',
81
+ speed: 0.2
82
+ }
69
83
  });
70
-
71
- // Render once
72
- renderer.render();
73
-
74
- // Or start animation loop
75
- // renderer.start();
76
84
  ```
77
85
 
78
- ---
86
+ ### 2. Preview the System
87
+
88
+ ```typescript
89
+ import { previewSystem } from '@nexart/ui-renderer';
79
90
 
80
- ## API
91
+ const canvas = document.getElementById('canvas');
92
+ const renderer = previewSystem(system, canvas, { mode: 'loop' });
81
93
 
82
- ### `createUIRenderer(options)`
94
+ renderer.start();
95
+ ```
83
96
 
84
- Create a renderer instance.
97
+ ### 3. Compile for Protocol
85
98
 
86
99
  ```typescript
87
- const renderer = createUIRenderer({
88
- canvas: HTMLCanvasElement, // Required: target canvas
89
- seed: number, // Required: PRNG seed
90
- mode: 'static' | 'loop', // Required: render mode
91
- width?: number, // Optional: canvas width (default: canvas.width)
92
- height?: number, // Optional: canvas height (default: canvas.height)
93
- });
100
+ import { compileSystem } from '@nexart/ui-renderer';
101
+
102
+ const compiled = compileSystem(system);
103
+ console.log(JSON.stringify(compiled, null, 2));
94
104
  ```
95
105
 
96
- ### Renderer Methods
106
+ ---
97
107
 
98
- | Method | Description |
99
- |--------|-------------|
100
- | `render()` | Render a single static frame |
101
- | `start()` | Start animation loop (loop mode) |
102
- | `stop()` | Stop animation loop |
103
- | `setSeed(newSeed)` | Change seed and re-render |
104
- | `destroy()` | Clean up resources |
108
+ ## API Reference
105
109
 
106
- ### Renderer Properties
110
+ ### `createSystem(input)`
107
111
 
108
- | Property | Value | Description |
109
- |----------|-------|-------------|
110
- | `isCanonical` | `false` | Always false - this is not canonical |
111
- | `isArchival` | `false` | Always false - this is not archival |
112
+ Create a validated NexArt system.
112
113
 
113
- ---
114
+ ```typescript
115
+ const system = createSystem({
116
+ version?: string, // Protocol version (default: '0.2')
117
+ seed: number, // Required: PRNG seed
118
+ background: {
119
+ color: string, // Required: background color
120
+ texture?: 'none' | 'noise' | 'grain',
121
+ gradient?: {
122
+ type: 'linear' | 'radial',
123
+ colors: string[],
124
+ angle?: number
125
+ }
126
+ },
127
+ elements: SystemElement[], // Required: array of primitives
128
+ motion?: {
129
+ source: 'none' | 'time' | 'seed',
130
+ speed?: number
131
+ }
132
+ });
133
+ ```
114
134
 
115
- ## Examples
135
+ ### `previewSystem(system, canvas, options?)`
116
136
 
117
- ### Static Render
137
+ Render a visual preview.
118
138
 
119
139
  ```typescript
120
- const renderer = createUIRenderer({
121
- canvas: document.querySelector('canvas'),
122
- seed: 12345,
123
- mode: 'static',
140
+ const renderer = previewSystem(system, canvas, {
141
+ mode: 'static' | 'loop', // default: 'static'
142
+ showBadge: boolean // default: true
124
143
  });
125
144
 
126
- renderer.render();
145
+ renderer.render(); // Single frame
146
+ renderer.start(); // Animation loop
147
+ renderer.stop(); // Stop loop
148
+ renderer.destroy(); // Cleanup
127
149
  ```
128
150
 
129
- ### Animated Loop
151
+ ### `compileSystem(system)`
152
+
153
+ Compile to protocol-compatible JSON.
130
154
 
131
155
  ```typescript
132
- const renderer = createUIRenderer({
133
- canvas: document.querySelector('canvas'),
134
- seed: Date.now(),
135
- mode: 'loop',
136
- });
156
+ const compiled = compileSystem(system);
157
+ // {
158
+ // protocol: 'nexart',
159
+ // systemVersion: '0.2',
160
+ // seed: 29445825,
161
+ // background: {...},
162
+ // elements: [...],
163
+ // motion: {...},
164
+ // deterministic: true,
165
+ // compiledAt: '2024-12-26T...',
166
+ // compilerVersion: '0.2.0'
167
+ // }
168
+ ```
137
169
 
138
- renderer.start();
170
+ ### `validateSystem(input)`
171
+
172
+ Validate system input without creating.
139
173
 
140
- // Stop after 10 seconds
141
- setTimeout(() => renderer.stop(), 10000);
174
+ ```typescript
175
+ const result = validateSystem(input);
176
+ if (!result.valid) {
177
+ console.error(result.errors);
178
+ }
142
179
  ```
143
180
 
144
- ### Re-render with New Seed
181
+ ### `getCapabilities()`
182
+
183
+ Discover SDK capabilities — critical for AI tools and builders.
145
184
 
146
185
  ```typescript
147
- // Generate new art every 30 seconds
148
- setInterval(() => {
149
- renderer.setSeed(Date.now());
150
- }, 30000);
186
+ import { getCapabilities } from '@nexart/ui-renderer';
187
+
188
+ const caps = getCapabilities();
189
+ // {
190
+ // version: '0.2.0',
191
+ // isCanonical: false,
192
+ // isArchival: false,
193
+ // renderer: '@nexart/ui-renderer',
194
+ // primitives: [...], // Available element types with parameters
195
+ // background: {...}, // Background options
196
+ // motion: {...}, // Motion sources and speed
197
+ // limits: {...} // Max values for safety
198
+ // }
151
199
  ```
152
200
 
201
+ Use this to:
202
+ - Prevent AI hallucination of non-existent primitives
203
+ - Validate parameter ranges before system creation
204
+ - Build dynamic UIs that adapt to SDK capabilities
205
+
206
+ ---
207
+
208
+ ## Primitive Vocabulary (v0.2)
209
+
210
+ ### Elements
211
+
212
+ | Type | Properties |
213
+ |------|------------|
214
+ | `dots` | distribution, count, size, color, opacity |
215
+ | `lines` | direction, count, thickness, color, opacity |
216
+ | `waves` | axis, amplitude, frequency, count, color, opacity |
217
+ | `grid` | rows, cols, cellSize, shape, color, opacity |
218
+ | `flowField` | resolution, strength, particles, color, opacity |
219
+ | `orbits` | count, radius, dotCount, speed, color, opacity |
220
+
221
+ ### Background
222
+
223
+ | Property | Options |
224
+ |----------|---------|
225
+ | color | Any CSS color or name |
226
+ | texture | `none`, `noise`, `grain` |
227
+ | gradient | `{ type, colors, angle? }` |
228
+
229
+ ### Motion
230
+
231
+ | Source | Behavior |
232
+ |--------|----------|
233
+ | `none` | Static image |
234
+ | `time` | Animate based on elapsed time |
235
+ | `seed` | Static per seed |
236
+
153
237
  ---
154
238
 
155
- ## Visual Style
239
+ ## For AI Platforms
156
240
 
157
- The renderer produces abstract generative art featuring:
241
+ This SDK is designed for AI code generation. Use `getCapabilities()` first:
242
+
243
+ ```typescript
244
+ import { getCapabilities, createSystem, previewSystem } from '@nexart/ui-renderer';
245
+
246
+ // 1. Check what's available (prevents hallucination)
247
+ const caps = getCapabilities();
248
+ console.log(caps.primitives.map(p => p.type));
249
+ // ['dots', 'lines', 'waves', 'grid', 'flowField', 'orbits']
250
+
251
+ // 2. Create system using only valid primitives
252
+ const system = createSystem({
253
+ seed: Date.now(),
254
+ background: { color: 'blue' },
255
+ elements: [
256
+ { type: 'waves', axis: 'x', amplitude: 0.5, frequency: 1 }
257
+ ]
258
+ });
259
+
260
+ // 3. Preview
261
+ previewSystem(system, canvas).render();
262
+ ```
263
+
264
+ **AI Prompt Example:**
265
+ ```
266
+ "Create a blue background with flowing waves using NexArt"
267
+ ```
158
268
 
159
- - **Flow fields** Particle traces following noise-based vector fields
160
- - **Vortex patterns** — Spiral motion around canvas center
161
- - **Orbital elements** — Dots moving in elliptical paths
162
- - **Central glow** — Radial gradient for depth
269
+ The finite vocabulary prevents invalid systems and ensures protocol alignment.
163
270
 
164
- Colors are derived from the seed, creating unique palettes per render.
271
+ **Key AI Integration Points:**
272
+ - `getCapabilities()` — Discover what's possible
273
+ - `validateSystem()` — Check before creating
274
+ - `compileSystem()` — Export protocol JSON
165
275
 
166
276
  ---
167
277
 
168
278
  ## Browser Compatibility
169
279
 
170
- Works in all modern browsers:
171
280
  - Chrome 80+
172
281
  - Firefox 75+
173
282
  - Safari 13+
@@ -182,11 +291,11 @@ No polyfills required.
182
291
  | Feature | @nexart/ui-renderer | @nexart/codemode-sdk |
183
292
  |---------|---------------------|----------------------|
184
293
  | Environment | Browser only | Node.js / Server |
185
- | Purpose | Exploration / Demos | Production / NFT minting |
294
+ | Purpose | Authoring / Preview | Production / Minting |
186
295
  | Canonical | ❌ No | ✅ Yes |
187
296
  | Archival | ❌ No | ✅ Yes |
188
- | Output | Canvas rendering | PNG / MP4 buffers |
189
- | Determinism | Best-effort | Strict |
297
+ | Output | Canvas / JSON | PNG / MP4 buffers |
298
+ | API | Declarative systems | Code execution |
190
299
 
191
300
  ---
192
301
 
@@ -198,5 +307,5 @@ Copyright (c) 2024 NexArt
198
307
 
199
308
  ---
200
309
 
201
- > **Reminder:** This SDK is about access, not authority.
202
- > For canonical output, always use `@nexart/codemode-sdk`.
310
+ > **Reminder:** This SDK authors systems. It does NOT invent new rendering rules.
311
+ > Canonical execution always happens via `@nexart/codemode-sdk`.
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @nexart/ui-renderer v0.2.0 - Capabilities Discovery
3
+ *
4
+ * Exposes SDK capabilities for AI tools and builders.
5
+ * Critical for preventing hallucination and SDK bypass.
6
+ */
7
+ export interface PrimitiveCapability {
8
+ type: string;
9
+ description: string;
10
+ parameters: Record<string, ParameterSpec>;
11
+ }
12
+ export interface ParameterSpec {
13
+ type: 'number' | 'string' | 'enum' | 'tuple' | 'boolean';
14
+ required: boolean;
15
+ description: string;
16
+ min?: number;
17
+ max?: number;
18
+ options?: string[];
19
+ tupleLength?: number;
20
+ default?: unknown;
21
+ }
22
+ export interface Capabilities {
23
+ version: string;
24
+ isCanonical: false;
25
+ isArchival: false;
26
+ renderer: '@nexart/ui-renderer';
27
+ primitives: PrimitiveCapability[];
28
+ background: {
29
+ color: ParameterSpec;
30
+ texture: ParameterSpec;
31
+ gradient: {
32
+ type: ParameterSpec;
33
+ colors: ParameterSpec;
34
+ angle: ParameterSpec;
35
+ };
36
+ };
37
+ motion: {
38
+ sources: string[];
39
+ speed: ParameterSpec;
40
+ };
41
+ limits: {
42
+ maxElements: number;
43
+ maxParticles: number;
44
+ maxDots: number;
45
+ maxLines: number;
46
+ maxOrbits: number;
47
+ maxGridSize: number;
48
+ };
49
+ }
50
+ export declare function getCapabilities(): Capabilities;
51
+ export declare function getPrimitiveTypes(): string[];
52
+ export declare function getMotionSources(): string[];
53
+ export declare function getBackgroundTextures(): string[];
54
+ //# sourceMappingURL=capabilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../src/capabilities.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CAC3C;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;IACzD,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,KAAK,CAAC;IACnB,UAAU,EAAE,KAAK,CAAC;IAClB,QAAQ,EAAE,qBAAqB,CAAC;IAEhC,UAAU,EAAE,mBAAmB,EAAE,CAAC;IAElC,UAAU,EAAE;QACV,KAAK,EAAE,aAAa,CAAC;QACrB,OAAO,EAAE,aAAa,CAAC;QACvB,QAAQ,EAAE;YACR,IAAI,EAAE,aAAa,CAAC;YACpB,MAAM,EAAE,aAAa,CAAC;YACtB,KAAK,EAAE,aAAa,CAAC;SACtB,CAAC;KACH,CAAC;IAEF,MAAM,EAAE;QACN,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,KAAK,EAAE,aAAa,CAAC;KACtB,CAAC;IAEF,MAAM,EAAE;QACN,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,EAAE,MAAM,CAAC;QACrB,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;CACH;AAED,wBAAgB,eAAe,IAAI,YAAY,CAsU9C;AAED,wBAAgB,iBAAiB,IAAI,MAAM,EAAE,CAE5C;AAED,wBAAgB,gBAAgB,IAAI,MAAM,EAAE,CAE3C;AAED,wBAAgB,qBAAqB,IAAI,MAAM,EAAE,CAEhD"}