@nexart/ui-renderer 0.3.1 → 0.6.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/README.md +343 -192
- package/dist/capabilities.d.ts +29 -8
- package/dist/capabilities.d.ts.map +1 -1
- package/dist/capabilities.js +120 -269
- package/dist/index.d.ts +10 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -4
- package/dist/presets/primitives.d.ts.map +1 -1
- package/dist/presets/primitives.js +651 -0
- package/dist/preview/code-renderer.d.ts +31 -10
- package/dist/preview/code-renderer.d.ts.map +1 -1
- package/dist/preview/code-renderer.js +167 -27
- package/dist/system.d.ts +2 -1
- package/dist/system.d.ts.map +1 -1
- package/dist/system.js +35 -3
- package/dist/types.d.ts +6 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +3 -2
- package/package.json +5 -2
- package/dist/preview/primitives/sketch.d.ts +0 -14
- package/dist/preview/primitives/sketch.d.ts.map +0 -1
- package/dist/preview/primitives/sketch.js +0 -407
package/README.md
CHANGED
|
@@ -1,36 +1,225 @@
|
|
|
1
1
|
# @nexart/ui-renderer
|
|
2
2
|
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.0
|
|
4
4
|
|
|
5
5
|
**Declarative and Code Mode System Authoring SDK for NexArt Protocol**
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
-
>
|
|
9
|
+
> **This SDK is a PREVIEW MIRROR, not an authority.**
|
|
10
10
|
>
|
|
11
|
-
>
|
|
12
|
-
> **Canonical, archival output is produced exclusively by @nexart/codemode-sdk.**
|
|
11
|
+
> It mirrors the behavior of @nexart/codemode-sdk faithfully for preview purposes.
|
|
13
12
|
>
|
|
14
|
-
>
|
|
13
|
+
> It is:
|
|
15
14
|
> - **NOT canonical** — Does not produce archival-quality output
|
|
16
|
-
> - **NOT archival** — Not
|
|
17
|
-
> - **NOT protocol-authoritative** —
|
|
15
|
+
> - **NOT archival** — Not the source of truth for production rendering
|
|
16
|
+
> - **NOT protocol-authoritative** — Delegates all Code Mode execution semantics
|
|
18
17
|
>
|
|
19
|
-
> Same
|
|
18
|
+
> Same inputs → same restrictions → same errors → same semantics as @nexart/codemode-sdk.
|
|
20
19
|
|
|
21
20
|
---
|
|
22
21
|
|
|
23
|
-
##
|
|
22
|
+
## PROTOCOL LOCK — v1.0.0 (MIRROR)
|
|
24
23
|
|
|
25
|
-
|
|
24
|
+
| Property | Value |
|
|
25
|
+
|----------|-------|
|
|
26
|
+
| Protocol Name | NexArt Code Mode |
|
|
27
|
+
| Version | v1.0.0 |
|
|
28
|
+
| Status | **HARD LOCKED** |
|
|
29
|
+
| This SDK | Mirror only — NOT authoritative |
|
|
30
|
+
| Canonical Authority | @nexart/codemode-sdk |
|
|
31
|
+
| Lock Date | December 2024 |
|
|
26
32
|
|
|
27
|
-
|
|
28
|
-
2. **Preview Rendering** — Visual approximation in the browser
|
|
29
|
-
3. **Compilation** — Export protocol-compatible JSON for canonical execution
|
|
33
|
+
**This SDK mirrors the frozen v1.0.0 protocol surface. Any future protocol change requires v2.0.0 in @nexart/codemode-sdk first.**
|
|
30
34
|
|
|
31
|
-
This SDK
|
|
35
|
+
This SDK mirrors:
|
|
36
|
+
- Execution model (Static and Loop modes)
|
|
37
|
+
- VAR[0..9] specification (0-10 input, always 10 at runtime)
|
|
38
|
+
- Determinism behavior (seed + VAR → consistent preview)
|
|
39
|
+
- Time semantics (t, frameCount, time, tGlobal)
|
|
40
|
+
- Forbidden patterns list (13 patterns)
|
|
41
|
+
- Error message format (`[Code Mode Protocol Error]`)
|
|
32
42
|
|
|
33
|
-
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Protocol Alignment (v1.0.0)
|
|
46
|
+
|
|
47
|
+
This SDK mirrors NexArt Protocol behavior. It is NOT canonical.
|
|
48
|
+
|
|
49
|
+
**Canonical execution is performed exclusively by @nexart/codemode-sdk.**
|
|
50
|
+
|
|
51
|
+
This SDK exists for:
|
|
52
|
+
- Preview and prototyping
|
|
53
|
+
- Tooling and AI builders
|
|
54
|
+
- Development and experimentation
|
|
55
|
+
|
|
56
|
+
### Authority Boundaries
|
|
57
|
+
|
|
58
|
+
| Aspect | This SDK | @nexart/codemode-sdk |
|
|
59
|
+
|--------|----------|---------------------|
|
|
60
|
+
| Authority | None — mirror only | Canonical gate |
|
|
61
|
+
| Determinism | Mirrors protocol RNG | Authoritative RNG |
|
|
62
|
+
| VAR Handling | Protocol-aligned (read-only, 0-100) | Authoritative enforcement |
|
|
63
|
+
| Error Behavior | Mirrors protocol errors | Defines protocol errors |
|
|
64
|
+
| Output | Preview-quality | Archival-quality |
|
|
65
|
+
|
|
66
|
+
### HARD Enforcement Modes
|
|
67
|
+
|
|
68
|
+
This SDK mirrors the following protocol-enforced modes:
|
|
69
|
+
- **Code Mode** — Seeded RNG, VAR[0..9], forbidden patterns
|
|
70
|
+
- **SoundArt** — Audio-to-visual transformation via Code Mode
|
|
71
|
+
- **Noise** — Perlin/Cellular noise via Code Mode
|
|
72
|
+
- **Shapes** — Geometric generation via Code Mode
|
|
73
|
+
|
|
74
|
+
### Forbidden Patterns
|
|
75
|
+
|
|
76
|
+
The following patterns are rejected (mirroring @nexart/codemode-sdk exactly):
|
|
77
|
+
|
|
78
|
+
- `setTimeout`, `setInterval`, `requestAnimationFrame` — async timing
|
|
79
|
+
- `Date.now()`, `new Date()` — time-based entropy
|
|
80
|
+
- `Math.random()` — use `random()` instead (seeded)
|
|
81
|
+
- `fetch()`, `XMLHttpRequest` — external IO
|
|
82
|
+
- `createCanvas()` — canvas is pre-initialized
|
|
83
|
+
- `document.*`, `window.*` — DOM access forbidden
|
|
84
|
+
- `import`, `require()` — external imports forbidden
|
|
85
|
+
|
|
86
|
+
### VAR Protocol — v1.0.0 (MIRROR of SDK v1.1.0)
|
|
87
|
+
|
|
88
|
+
VAR[0..9] is a read-only array of 10 protocol variables (0-100 strict range).
|
|
89
|
+
|
|
90
|
+
**VAR Specification (mirrors @nexart/codemode-sdk v1.1.0):**
|
|
91
|
+
|
|
92
|
+
| Property | Value | Enforcement |
|
|
93
|
+
|----------|-------|-------------|
|
|
94
|
+
| Input count | 0-10 (VAR[0]..VAR[9]) | HARD — throws if > 10 |
|
|
95
|
+
| Runtime count | Always 10 | Padded with zeros |
|
|
96
|
+
| Type | finite number | HARD — throws if non-number |
|
|
97
|
+
| Range | 0-100 | HARD — throws if out of range |
|
|
98
|
+
| Mutability | Read-only | HARD — frozen, writes throw |
|
|
99
|
+
| Injection | Before execution | Guaranteed |
|
|
100
|
+
| Lifecycle | Stable for entire render | Guaranteed |
|
|
101
|
+
| Default | All zeros | If not provided |
|
|
102
|
+
|
|
103
|
+
**This specification mirrors @nexart/codemode-sdk v1.1.0 exactly.**
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
// Correct usage
|
|
107
|
+
const size = map(VAR[0], 0, 100, 10, 200);
|
|
108
|
+
const count = floor(map(VAR[1], 0, 100, 5, 50));
|
|
109
|
+
|
|
110
|
+
// VAR[5] returns 0 if input had fewer than 6 elements
|
|
111
|
+
const value = VAR[5]; // Returns 0 if not provided
|
|
112
|
+
|
|
113
|
+
// Error: VAR is read-only
|
|
114
|
+
VAR[0] = 50; // Throws: "[Code Mode Protocol Error] VAR is read-only..."
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
**Error examples:**
|
|
118
|
+
```typescript
|
|
119
|
+
// Protocol error: too many elements
|
|
120
|
+
vars: [1,2,3,4,5,6,7,8,9,10,11] // Throws: "VAR array must have at most 10 elements, got 11"
|
|
121
|
+
|
|
122
|
+
// Protocol error: out of range
|
|
123
|
+
vars: [150, 50, 50] // Throws: "VAR[0] = 150 is out of range. Values must be 0-100."
|
|
124
|
+
|
|
125
|
+
// Valid: fewer than 10 elements (padded with zeros)
|
|
126
|
+
vars: [50, 75, 25] // Works! VAR[3..9] will be 0
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## Supported Element Types
|
|
132
|
+
|
|
133
|
+
The SDK supports three element types, rendered in order:
|
|
134
|
+
|
|
135
|
+
### `background`
|
|
136
|
+
|
|
137
|
+
Opinionated presets with guardrails. Provides consistent, protocol-aligned backgrounds.
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
{
|
|
141
|
+
type: 'background',
|
|
142
|
+
style: 'gradient', // gradient, solid, noise, grain
|
|
143
|
+
palette: 'warm' // warm, cool, neutral, vibrant
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### `primitive`
|
|
148
|
+
|
|
149
|
+
Declarative generative components. Structured parameters, no raw code. **30 primitives available:**
|
|
150
|
+
|
|
151
|
+
**Basic Shapes:**
|
|
152
|
+
- `dots` — Grid/random dot patterns
|
|
153
|
+
- `lines` — Vertical wavy lines
|
|
154
|
+
- `waves` — Horizontal wave patterns
|
|
155
|
+
- `stripes` — Simple horizontal stripes
|
|
156
|
+
- `circles` — Concentric pulsing circles
|
|
157
|
+
- `grid` — Rotating square grid
|
|
158
|
+
|
|
159
|
+
**Geometric:**
|
|
160
|
+
- `polygons` — Random rotating polygons (3-7 sides)
|
|
161
|
+
- `diamonds` — Diamond grid with noise rotation
|
|
162
|
+
- `hexgrid` — Honeycomb hexagonal grid
|
|
163
|
+
- `stars` — Scattered rotating star shapes
|
|
164
|
+
- `concentricSquares` — Nested rotating squares
|
|
165
|
+
|
|
166
|
+
**Radial:**
|
|
167
|
+
- `spirals` — Multiple expanding spirals
|
|
168
|
+
- `rays` — Lines emanating from center
|
|
169
|
+
- `orbits` — Wobbling orbital rings
|
|
170
|
+
- `rings` — Alternating concentric rings
|
|
171
|
+
- `arcs` — Random partial circles
|
|
172
|
+
- `radialLines` — Lines from inner to outer radius
|
|
173
|
+
- `petals` — Flower petal pattern
|
|
174
|
+
|
|
175
|
+
**Flow & Motion:**
|
|
176
|
+
- `flow` — Particle flow field
|
|
177
|
+
- `particles` — Scattered particles with tails
|
|
178
|
+
- `bubbles` — Rising floating bubbles
|
|
179
|
+
|
|
180
|
+
**Patterns:**
|
|
181
|
+
- `crosshatch` — Cross-hatched shading lines
|
|
182
|
+
- `chevrons` — V-shaped wave patterns
|
|
183
|
+
- `zigzag` — Zigzag horizontal lines
|
|
184
|
+
- `weave` — Interlocking woven pattern
|
|
185
|
+
- `moire` — Overlapping circle interference
|
|
186
|
+
|
|
187
|
+
**Organic:**
|
|
188
|
+
- `curves` — Random bezier curves
|
|
189
|
+
- `noise` — Perlin noise vector field
|
|
190
|
+
- `mesh` — Deformed triangular mesh
|
|
191
|
+
- `branches` — Fractal tree branches
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
{
|
|
195
|
+
type: 'primitive',
|
|
196
|
+
name: 'spirals', // Any of the 30 primitives above
|
|
197
|
+
count: 12,
|
|
198
|
+
color: '#ffffff',
|
|
199
|
+
motion: 'medium', // 'slow', 'medium', 'fast'
|
|
200
|
+
strokeWeight: 'thin', // 'thin', 'medium', 'thick', or number
|
|
201
|
+
opacity: 0.8
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### `sketch`
|
|
206
|
+
|
|
207
|
+
Raw Code Mode execution in a sandboxed environment. Full p5-like API access.
|
|
208
|
+
|
|
209
|
+
```typescript
|
|
210
|
+
{
|
|
211
|
+
type: 'sketch',
|
|
212
|
+
code: `
|
|
213
|
+
function setup() {
|
|
214
|
+
background(0);
|
|
215
|
+
}
|
|
216
|
+
function draw() {
|
|
217
|
+
ellipse(width/2, height/2, 100);
|
|
218
|
+
}
|
|
219
|
+
`,
|
|
220
|
+
normalize: true
|
|
221
|
+
}
|
|
222
|
+
```
|
|
34
223
|
|
|
35
224
|
---
|
|
36
225
|
|
|
@@ -51,9 +240,9 @@ Or use directly in HTML:
|
|
|
51
240
|
|
|
52
241
|
## Quick Start
|
|
53
242
|
|
|
54
|
-
### Code Mode Systems
|
|
243
|
+
### Code Mode Systems with VAR
|
|
55
244
|
|
|
56
|
-
Create and preview Code Mode sketches
|
|
245
|
+
Create and preview Code Mode sketches using protocol variables:
|
|
57
246
|
|
|
58
247
|
```typescript
|
|
59
248
|
import { createSystem, previewSystem } from '@nexart/ui-renderer';
|
|
@@ -65,6 +254,7 @@ const system = createSystem({
|
|
|
65
254
|
height: 2400,
|
|
66
255
|
totalFrames: 120,
|
|
67
256
|
seed: 12345,
|
|
257
|
+
vars: [50, 75, 25, 0, 100, 50, 50, 50, 50, 50], // VAR[0..9]
|
|
68
258
|
source: `
|
|
69
259
|
function setup() {
|
|
70
260
|
noFill();
|
|
@@ -72,8 +262,9 @@ const system = createSystem({
|
|
|
72
262
|
}
|
|
73
263
|
function draw() {
|
|
74
264
|
background(246, 245, 242);
|
|
75
|
-
|
|
76
|
-
|
|
265
|
+
var count = floor(map(VAR[0], 0, 100, 5, 30));
|
|
266
|
+
for (var i = 0; i < count; i++) {
|
|
267
|
+
var x = width / 2 + cos(t * TWO_PI + i * 0.5) * map(VAR[1], 0, 100, 50, 400);
|
|
77
268
|
var y = height / 2 + sin(t * TWO_PI + i * 0.3) * 200;
|
|
78
269
|
ellipse(x, y, 50);
|
|
79
270
|
}
|
|
@@ -95,11 +286,13 @@ const staticSystem = createSystem({
|
|
|
95
286
|
width: 1950,
|
|
96
287
|
height: 2400,
|
|
97
288
|
seed: 12345,
|
|
289
|
+
vars: [50, 50, 50, 50, 50, 50, 50, 50, 50, 50],
|
|
98
290
|
source: `
|
|
99
291
|
function setup() {
|
|
100
292
|
background(246, 245, 242);
|
|
101
293
|
fill(0);
|
|
102
|
-
|
|
294
|
+
var count = floor(map(VAR[0], 0, 100, 10, 200));
|
|
295
|
+
for (var i = 0; i < count; i++) {
|
|
103
296
|
ellipse(random(width), random(height), random(10, 50));
|
|
104
297
|
}
|
|
105
298
|
}
|
|
@@ -109,60 +302,6 @@ const staticSystem = createSystem({
|
|
|
109
302
|
previewSystem(staticSystem, canvas).render();
|
|
110
303
|
```
|
|
111
304
|
|
|
112
|
-
### Declarative Systems
|
|
113
|
-
|
|
114
|
-
### 1. Create a System
|
|
115
|
-
|
|
116
|
-
```typescript
|
|
117
|
-
import { createSystem } from '@nexart/ui-renderer';
|
|
118
|
-
|
|
119
|
-
const system = createSystem({
|
|
120
|
-
seed: 29445825,
|
|
121
|
-
background: {
|
|
122
|
-
color: 'blue',
|
|
123
|
-
texture: 'noise'
|
|
124
|
-
},
|
|
125
|
-
elements: [
|
|
126
|
-
{
|
|
127
|
-
type: 'waves',
|
|
128
|
-
axis: 'x',
|
|
129
|
-
amplitude: 0.4,
|
|
130
|
-
frequency: 0.7
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
type: 'dots',
|
|
134
|
-
distribution: 'radial',
|
|
135
|
-
count: 400,
|
|
136
|
-
size: [1, 4]
|
|
137
|
-
}
|
|
138
|
-
],
|
|
139
|
-
motion: {
|
|
140
|
-
source: 'time',
|
|
141
|
-
speed: 0.2
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
### 2. Preview the System
|
|
147
|
-
|
|
148
|
-
```typescript
|
|
149
|
-
import { previewSystem } from '@nexart/ui-renderer';
|
|
150
|
-
|
|
151
|
-
const canvas = document.getElementById('canvas');
|
|
152
|
-
const renderer = previewSystem(system, canvas, { mode: 'loop' });
|
|
153
|
-
|
|
154
|
-
renderer.start();
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
### 3. Compile for Protocol
|
|
158
|
-
|
|
159
|
-
```typescript
|
|
160
|
-
import { compileSystem } from '@nexart/ui-renderer';
|
|
161
|
-
|
|
162
|
-
const compiled = compileSystem(system);
|
|
163
|
-
console.log(JSON.stringify(compiled, null, 2));
|
|
164
|
-
```
|
|
165
|
-
|
|
166
305
|
---
|
|
167
306
|
|
|
168
307
|
## API Reference
|
|
@@ -180,29 +319,8 @@ const system = createSystem({
|
|
|
180
319
|
height: number,
|
|
181
320
|
source: string, // Raw p5-like sketch code
|
|
182
321
|
seed?: number, // Optional: PRNG seed
|
|
183
|
-
totalFrames?: number
|
|
184
|
-
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
**Declarative Input:**
|
|
188
|
-
```typescript
|
|
189
|
-
const system = createSystem({
|
|
190
|
-
version?: string, // Protocol version (default: '0.3')
|
|
191
|
-
seed: number, // Required: PRNG seed
|
|
192
|
-
background: {
|
|
193
|
-
color: string, // Required: background color
|
|
194
|
-
texture?: 'none' | 'noise' | 'grain',
|
|
195
|
-
gradient?: {
|
|
196
|
-
type: 'linear' | 'radial',
|
|
197
|
-
colors: string[],
|
|
198
|
-
angle?: number
|
|
199
|
-
}
|
|
200
|
-
},
|
|
201
|
-
elements: SystemElement[], // Required: array of primitives
|
|
202
|
-
motion?: {
|
|
203
|
-
source: 'none' | 'time' | 'seed',
|
|
204
|
-
speed?: number
|
|
205
|
-
}
|
|
322
|
+
totalFrames?: number, // Required for loop mode
|
|
323
|
+
vars?: number[] // Optional: VAR[0..9] (0-10 values, 0-100 range)
|
|
206
324
|
});
|
|
207
325
|
```
|
|
208
326
|
|
|
@@ -222,25 +340,6 @@ renderer.stop(); // Stop loop
|
|
|
222
340
|
renderer.destroy(); // Cleanup
|
|
223
341
|
```
|
|
224
342
|
|
|
225
|
-
### `compileSystem(system)`
|
|
226
|
-
|
|
227
|
-
Compile to protocol-compatible JSON.
|
|
228
|
-
|
|
229
|
-
```typescript
|
|
230
|
-
const compiled = compileSystem(system);
|
|
231
|
-
// {
|
|
232
|
-
// protocol: 'nexart',
|
|
233
|
-
// systemVersion: '0.2',
|
|
234
|
-
// seed: 29445825,
|
|
235
|
-
// background: {...},
|
|
236
|
-
// elements: [...],
|
|
237
|
-
// motion: {...},
|
|
238
|
-
// deterministic: true,
|
|
239
|
-
// compiledAt: '2024-12-26T...',
|
|
240
|
-
// compilerVersion: '0.2.0'
|
|
241
|
-
// }
|
|
242
|
-
```
|
|
243
|
-
|
|
244
343
|
### `validateSystem(input)`
|
|
245
344
|
|
|
246
345
|
Validate system input without creating.
|
|
@@ -254,98 +353,170 @@ if (!result.valid) {
|
|
|
254
353
|
|
|
255
354
|
### `getCapabilities()`
|
|
256
355
|
|
|
257
|
-
Discover SDK capabilities
|
|
356
|
+
Discover SDK capabilities for AI and tooling.
|
|
258
357
|
|
|
259
358
|
```typescript
|
|
260
359
|
import { getCapabilities } from '@nexart/ui-renderer';
|
|
261
360
|
|
|
262
361
|
const caps = getCapabilities();
|
|
263
362
|
// {
|
|
264
|
-
// version: '0.
|
|
363
|
+
// version: '0.6.0',
|
|
265
364
|
// isCanonical: false,
|
|
266
365
|
// isArchival: false,
|
|
267
366
|
// renderer: '@nexart/ui-renderer',
|
|
268
|
-
//
|
|
269
|
-
//
|
|
270
|
-
//
|
|
271
|
-
// limits: {...} // Max values for safety
|
|
367
|
+
// primitivesMeta: { notice: '...', count: 30, isCanonical: false },
|
|
368
|
+
// primitives: [ { name, category, description, parameters } ],
|
|
369
|
+
// ...
|
|
272
370
|
// }
|
|
273
371
|
```
|
|
274
372
|
|
|
275
|
-
|
|
276
|
-
- Prevent AI hallucination of non-existent primitives
|
|
277
|
-
- Validate parameter ranges before system creation
|
|
278
|
-
- Build dynamic UIs that adapt to SDK capabilities
|
|
373
|
+
### `getPrimitiveTypes()`
|
|
279
374
|
|
|
280
|
-
|
|
375
|
+
Get all 30 primitive names as array.
|
|
281
376
|
|
|
282
|
-
|
|
377
|
+
```typescript
|
|
378
|
+
import { getPrimitiveTypes } from '@nexart/ui-renderer';
|
|
283
379
|
|
|
284
|
-
|
|
380
|
+
const names = getPrimitiveTypes();
|
|
381
|
+
// ['dots', 'lines', 'waves', 'stripes', ... ]
|
|
382
|
+
```
|
|
285
383
|
|
|
286
|
-
|
|
287
|
-
|------|------------|
|
|
288
|
-
| `dots` | distribution, count, size, color, opacity |
|
|
289
|
-
| `lines` | direction, count, thickness, color, opacity |
|
|
290
|
-
| `waves` | axis, amplitude, frequency, count, color, opacity |
|
|
291
|
-
| `grid` | rows, cols, cellSize, shape, color, opacity |
|
|
292
|
-
| `flowField` | resolution, strength, particles, color, opacity |
|
|
293
|
-
| `orbits` | count, radius, dotCount, speed, color, opacity |
|
|
384
|
+
### `getPrimitivesByCategory()`
|
|
294
385
|
|
|
295
|
-
|
|
386
|
+
Get primitives organized by category.
|
|
387
|
+
|
|
388
|
+
```typescript
|
|
389
|
+
import { getPrimitivesByCategory } from '@nexart/ui-renderer';
|
|
390
|
+
|
|
391
|
+
const byCategory = getPrimitivesByCategory();
|
|
392
|
+
// {
|
|
393
|
+
// basic: ['dots', 'lines', 'waves', 'stripes', 'circles', 'grid'],
|
|
394
|
+
// geometric: ['polygons', 'diamonds', 'hexgrid', 'stars', 'concentricSquares'],
|
|
395
|
+
// radial: ['spirals', 'rays', 'orbits', 'rings', 'arcs', 'radialLines', 'petals'],
|
|
396
|
+
// flow: ['flow', 'particles', 'bubbles'],
|
|
397
|
+
// patterns: ['crosshatch', 'chevrons', 'zigzag', 'weave', 'moire'],
|
|
398
|
+
// organic: ['curves', 'noise', 'mesh', 'branches']
|
|
399
|
+
// }
|
|
400
|
+
```
|
|
296
401
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
402
|
+
### `getPrimitiveInfo(name)`
|
|
403
|
+
|
|
404
|
+
Get full capability info for a single primitive.
|
|
405
|
+
|
|
406
|
+
```typescript
|
|
407
|
+
import { getPrimitiveInfo } from '@nexart/ui-renderer';
|
|
408
|
+
|
|
409
|
+
const info = getPrimitiveInfo('spirals');
|
|
410
|
+
// {
|
|
411
|
+
// name: 'spirals',
|
|
412
|
+
// category: 'radial',
|
|
413
|
+
// description: 'Multiple expanding spirals from center',
|
|
414
|
+
// compilesTo: 'codemode',
|
|
415
|
+
// isCanonical: false,
|
|
416
|
+
// parameters: { count, color, opacity, strokeWeight, motion }
|
|
417
|
+
// }
|
|
418
|
+
```
|
|
302
419
|
|
|
303
|
-
###
|
|
420
|
+
### `isPrimitiveValid(name)`
|
|
304
421
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
422
|
+
Check if a primitive name is valid.
|
|
423
|
+
|
|
424
|
+
```typescript
|
|
425
|
+
import { isPrimitiveValid } from '@nexart/ui-renderer';
|
|
426
|
+
|
|
427
|
+
isPrimitiveValid('spirals'); // true
|
|
428
|
+
isPrimitiveValid('invalid'); // false
|
|
429
|
+
```
|
|
310
430
|
|
|
311
431
|
---
|
|
312
432
|
|
|
313
|
-
##
|
|
433
|
+
## AI Capabilities API
|
|
434
|
+
|
|
435
|
+
**Designed for AI agents to build valid systems without hallucination.**
|
|
314
436
|
|
|
315
|
-
|
|
437
|
+
⚠️ **Primitives are helper generators that compile to Code Mode sketches.**
|
|
438
|
+
They are NOT canonical. The canonical output is always the compiled Code Mode source.
|
|
439
|
+
|
|
440
|
+
### For AI Agents
|
|
316
441
|
|
|
317
442
|
```typescript
|
|
318
|
-
import { getCapabilities,
|
|
443
|
+
import { getCapabilities, isPrimitiveValid, getPrimitiveInfo } from '@nexart/ui-renderer';
|
|
319
444
|
|
|
320
|
-
// 1. Check what's available (prevents hallucination)
|
|
321
445
|
const caps = getCapabilities();
|
|
322
|
-
console.log(caps.primitives.map(p => p.type));
|
|
323
|
-
// ['dots', 'lines', 'waves', 'grid', 'flowField', 'orbits']
|
|
324
446
|
|
|
325
|
-
//
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
447
|
+
caps.primitivesMeta.notice; // "Primitives are helper generators..."
|
|
448
|
+
caps.primitivesMeta.count; // 30
|
|
449
|
+
caps.primitivesMeta.isCanonical; // false
|
|
450
|
+
|
|
451
|
+
for (const p of caps.primitives) {
|
|
452
|
+
console.log(p.name); // 'dots', 'spirals', etc.
|
|
453
|
+
console.log(p.category); // 'basic', 'radial', etc.
|
|
454
|
+
console.log(p.description); // Human-readable description
|
|
455
|
+
console.log(p.parameters.count.min); // 3
|
|
456
|
+
console.log(p.parameters.count.max); // 50
|
|
457
|
+
console.log(p.parameters.count.default); // 12
|
|
458
|
+
}
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
### Primitive Parameter Specification
|
|
462
|
+
|
|
463
|
+
All primitives share these parameters:
|
|
464
|
+
|
|
465
|
+
| Parameter | Type | Required | Range | Default |
|
|
466
|
+
|-----------|------|----------|-------|---------|
|
|
467
|
+
| `count` | number | No | 3-50 | 12 |
|
|
468
|
+
| `color` | string | No | CSS color | Palette foreground |
|
|
469
|
+
| `opacity` | number | No | 0.1-1 | 1 |
|
|
470
|
+
| `strokeWeight` | enum | No | 'auto', 'thin', 'medium', 'thick' | 'auto' |
|
|
471
|
+
| `motion` | enum | No | 'slow', 'medium', 'fast' | 'slow' |
|
|
472
|
+
|
|
473
|
+
### Valid Primitive Categories
|
|
474
|
+
|
|
475
|
+
| Category | Primitives |
|
|
476
|
+
|----------|-----------|
|
|
477
|
+
| `basic` | dots, lines, waves, stripes, circles, grid |
|
|
478
|
+
| `geometric` | polygons, diamonds, hexgrid, stars, concentricSquares |
|
|
479
|
+
| `radial` | spirals, rays, orbits, rings, arcs, radialLines, petals |
|
|
480
|
+
| `flow` | flow, particles, bubbles |
|
|
481
|
+
| `patterns` | crosshatch, chevrons, zigzag, weave, moire |
|
|
482
|
+
| `organic` | curves, noise, mesh, branches |
|
|
483
|
+
|
|
484
|
+
---
|
|
333
485
|
|
|
334
|
-
|
|
335
|
-
|
|
486
|
+
## Delegation Logging
|
|
487
|
+
|
|
488
|
+
All Code Mode previews log their delegation:
|
|
489
|
+
|
|
490
|
+
```
|
|
491
|
+
[UIRenderer] Preview delegation → @nexart/codemode-sdk
|
|
492
|
+
[UIRenderer] Protocol version: 1.0.0
|
|
493
|
+
[UIRenderer] Mode: loop
|
|
336
494
|
```
|
|
337
495
|
|
|
338
|
-
|
|
496
|
+
---
|
|
497
|
+
|
|
498
|
+
## Error Mirroring
|
|
499
|
+
|
|
500
|
+
If the protocol rejects code:
|
|
501
|
+
- Rendering stops immediately
|
|
502
|
+
- Black canvas is displayed
|
|
503
|
+
- Error is logged verbatim
|
|
504
|
+
- No "best effort" recovery
|
|
505
|
+
|
|
339
506
|
```
|
|
340
|
-
|
|
507
|
+
[UIRenderer Protocol Error] Forbidden pattern: Math.random() — use random() instead (seeded)
|
|
341
508
|
```
|
|
342
509
|
|
|
343
|
-
|
|
510
|
+
---
|
|
511
|
+
|
|
512
|
+
## What This SDK Does NOT Guarantee
|
|
344
513
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
514
|
+
| Not Guaranteed | Explanation |
|
|
515
|
+
|----------------|-------------|
|
|
516
|
+
| Canonical output | Production runtime is the only authority |
|
|
517
|
+
| Archival quality | Output is for preview, not permanent storage |
|
|
518
|
+
| Cross-version stability | Internal rendering may change between SDK versions |
|
|
519
|
+
| Frame-perfect matching | Minor differences from production are expected |
|
|
349
520
|
|
|
350
521
|
---
|
|
351
522
|
|
|
@@ -356,21 +527,6 @@ The finite vocabulary prevents invalid systems and ensures protocol alignment.
|
|
|
356
527
|
- Safari 13+
|
|
357
528
|
- Edge 80+
|
|
358
529
|
|
|
359
|
-
No polyfills required.
|
|
360
|
-
|
|
361
|
-
---
|
|
362
|
-
|
|
363
|
-
## Comparison with @nexart/codemode-sdk
|
|
364
|
-
|
|
365
|
-
| Feature | @nexart/ui-renderer | @nexart/codemode-sdk |
|
|
366
|
-
|---------|---------------------|----------------------|
|
|
367
|
-
| Environment | Browser only | Node.js / Server |
|
|
368
|
-
| Purpose | Authoring / Preview | Production / Minting |
|
|
369
|
-
| Canonical | ❌ No | ✅ Yes |
|
|
370
|
-
| Archival | ❌ No | ✅ Yes |
|
|
371
|
-
| Output | Canvas / JSON | PNG / MP4 buffers |
|
|
372
|
-
| API | Declarative systems | Code execution |
|
|
373
|
-
|
|
374
530
|
---
|
|
375
531
|
|
|
376
532
|
## License
|
|
@@ -378,8 +534,3 @@ No polyfills required.
|
|
|
378
534
|
MIT License
|
|
379
535
|
|
|
380
536
|
Copyright (c) 2024 NexArt
|
|
381
|
-
|
|
382
|
-
---
|
|
383
|
-
|
|
384
|
-
> **Reminder:** This SDK authors systems. It does NOT invent new rendering rules.
|
|
385
|
-
> Canonical execution always happens via `@nexart/codemode-sdk`.
|