@nexart/ui-renderer 0.2.1 → 0.4.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 CHANGED
@@ -1,36 +1,177 @@
1
1
  # @nexart/ui-renderer
2
2
 
3
- Version: 0.2.1
3
+ Version: 0.4.0
4
4
 
5
- **Declarative System Authoring SDK for NexArt Protocol**
5
+ **Declarative and Code Mode System Authoring SDK for NexArt Protocol**
6
6
 
7
7
  ---
8
8
 
9
- > ⚠️ **IMPORTANT DISCLAIMER**
9
+ > **This SDK is a PREVIEW MIRROR, not an authority.**
10
10
  >
11
- > **This SDK is for authoring and preview only.**
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
- > This SDK is:
13
+ > It is:
15
14
  > - **NOT canonical** — Does not produce archival-quality output
16
- > - **NOT archival** — Not suitable for NFT minting
17
- > - **NOT protocol-authoritative** — Best-effort rendering only
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 system → same preview output within this SDK, but **preview mint truth**.
18
+ > Same inputs → same restrictions same errors same semantics as @nexart/codemode-sdk.
20
19
 
21
20
  ---
22
21
 
23
- ## Philosophy
22
+ ## PROTOCOL LOCK — v1.0.0 (MIRROR)
24
23
 
25
- The NexArt Protocol defines how generative art systems work. This SDK provides:
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
- 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
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 exists to **reduce friction** for builders, artists, and AI platforms. It is the front door to the NexArt Protocol — not the authority.
35
+ This SDK mirrors:
36
+ - Execution model (Static and Loop modes)
37
+ - VAR[0..9] specification (exactly 10 read-only variables)
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
- **Canonical execution happens via `@nexart/codemode-sdk`.**
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 — LOCKED v1.0.0 (MIRROR)
87
+
88
+ VAR[0..9] is a read-only array of 10 protocol variables (0-100 recommended).
89
+
90
+ **VAR Specification (FROZEN — mirrors @nexart/codemode-sdk):**
91
+
92
+ | Property | Value | Enforcement |
93
+ |----------|-------|-------------|
94
+ | Count | Exactly 10 (VAR[0]..VAR[9]) | HARD — throws if not 10 |
95
+ | Type | number | HARD — throws if non-number |
96
+ | Range | 0-100 recommended | SOFT — warns, does NOT clamp |
97
+ | Mutability | Read-only | HARD — frozen, writes blocked |
98
+ | Injection | Before execution | Guaranteed |
99
+ | Lifecycle | Stable for entire render | Guaranteed |
100
+ | Default | All zeros | If not provided |
101
+
102
+ **This specification is INTENTIONAL and MUST NOT be extended in v1.x.**
103
+
104
+ **DO NOT** add support for dynamic-length VAR arrays.
105
+ **DO NOT** allow user-defined VAR counts.
106
+
107
+ ```typescript
108
+ // Correct usage
109
+ const size = map(VAR[0], 0, 100, 10, 200);
110
+ const count = floor(map(VAR[1], 0, 100, 5, 50));
111
+
112
+ // Error: VAR is read-only
113
+ VAR[0] = 50; // Blocked with warning
114
+ ```
115
+
116
+ **Error examples:**
117
+ ```typescript
118
+ // Protocol error: wrong length
119
+ vars: [50, 50, 50] // "[Code Mode Protocol Error] VAR array must have exactly 10 elements"
120
+
121
+ // Warning only: out of range (not clamped)
122
+ vars: [150, 50, 50, 50, 50, 50, 50, 50, 50, 50] // Warns but allows
123
+ ```
124
+
125
+ ---
126
+
127
+ ## Supported Element Types
128
+
129
+ The SDK supports three element types, rendered in order:
130
+
131
+ ### `background`
132
+
133
+ Opinionated presets with guardrails. Provides consistent, protocol-aligned backgrounds.
134
+
135
+ ```typescript
136
+ {
137
+ type: 'background',
138
+ style: 'gradient', // gradient, solid, noise, grain
139
+ palette: 'warm' // warm, cool, neutral, vibrant
140
+ }
141
+ ```
142
+
143
+ ### `primitive`
144
+
145
+ Declarative generative components. Structured parameters, no raw code.
146
+
147
+ ```typescript
148
+ {
149
+ type: 'primitive',
150
+ name: 'dots', // dots, lines, waves, grid, flowField, orbits
151
+ count: 100,
152
+ color: '#ffffff',
153
+ motion: { speed: 0.5 }
154
+ }
155
+ ```
156
+
157
+ ### `sketch`
158
+
159
+ Raw Code Mode execution in a sandboxed environment. Full p5-like API access.
160
+
161
+ ```typescript
162
+ {
163
+ type: 'sketch',
164
+ code: `
165
+ function setup() {
166
+ background(0);
167
+ }
168
+ function draw() {
169
+ ellipse(width/2, height/2, 100);
170
+ }
171
+ `,
172
+ normalize: true
173
+ }
174
+ ```
34
175
 
35
176
  ---
36
177
 
@@ -51,56 +192,66 @@ Or use directly in HTML:
51
192
 
52
193
  ## Quick Start
53
194
 
54
- ### 1. Create a System
195
+ ### Code Mode Systems with VAR
196
+
197
+ Create and preview Code Mode sketches using protocol variables:
55
198
 
56
199
  ```typescript
57
- import { createSystem } from '@nexart/ui-renderer';
200
+ import { createSystem, previewSystem } from '@nexart/ui-renderer';
58
201
 
59
202
  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]
203
+ type: 'code',
204
+ mode: 'loop',
205
+ width: 1950,
206
+ height: 2400,
207
+ totalFrames: 120,
208
+ seed: 12345,
209
+ vars: [50, 75, 25, 0, 100, 50, 50, 50, 50, 50], // VAR[0..9]
210
+ source: `
211
+ function setup() {
212
+ noFill();
213
+ stroke(0);
214
+ }
215
+ function draw() {
216
+ background(246, 245, 242);
217
+ var count = floor(map(VAR[0], 0, 100, 5, 30));
218
+ for (var i = 0; i < count; i++) {
219
+ var x = width / 2 + cos(t * TWO_PI + i * 0.5) * map(VAR[1], 0, 100, 50, 400);
220
+ var y = height / 2 + sin(t * TWO_PI + i * 0.3) * 200;
221
+ ellipse(x, y, 50);
222
+ }
77
223
  }
78
- ],
79
- motion: {
80
- source: 'time',
81
- speed: 0.2
82
- }
224
+ `
83
225
  });
84
- ```
85
-
86
- ### 2. Preview the System
87
-
88
- ```typescript
89
- import { previewSystem } from '@nexart/ui-renderer';
90
226
 
91
227
  const canvas = document.getElementById('canvas');
92
- const renderer = previewSystem(system, canvas, { mode: 'loop' });
93
-
228
+ const renderer = previewSystem(system, canvas);
94
229
  renderer.start();
95
230
  ```
96
231
 
97
- ### 3. Compile for Protocol
232
+ **Static Mode** (single-frame, setup only):
98
233
 
99
234
  ```typescript
100
- import { compileSystem } from '@nexart/ui-renderer';
235
+ const staticSystem = createSystem({
236
+ type: 'code',
237
+ mode: 'static',
238
+ width: 1950,
239
+ height: 2400,
240
+ seed: 12345,
241
+ vars: [50, 50, 50, 50, 50, 50, 50, 50, 50, 50],
242
+ source: `
243
+ function setup() {
244
+ background(246, 245, 242);
245
+ fill(0);
246
+ var count = floor(map(VAR[0], 0, 100, 10, 200));
247
+ for (var i = 0; i < count; i++) {
248
+ ellipse(random(width), random(height), random(10, 50));
249
+ }
250
+ }
251
+ `
252
+ });
101
253
 
102
- const compiled = compileSystem(system);
103
- console.log(JSON.stringify(compiled, null, 2));
254
+ previewSystem(staticSystem, canvas).render();
104
255
  ```
105
256
 
106
257
  ---
@@ -111,24 +262,17 @@ console.log(JSON.stringify(compiled, null, 2));
111
262
 
112
263
  Create a validated NexArt system.
113
264
 
265
+ **Code Mode Input:**
114
266
  ```typescript
115
267
  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
- }
268
+ type: 'code',
269
+ mode: 'static' | 'loop',
270
+ width: number,
271
+ height: number,
272
+ source: string, // Raw p5-like sketch code
273
+ seed?: number, // Optional: PRNG seed
274
+ totalFrames?: number, // Required for loop mode
275
+ vars?: number[] // Optional: VAR[0..9] (10 values, 0-100)
132
276
  });
133
277
  ```
134
278
 
@@ -148,25 +292,6 @@ renderer.stop(); // Stop loop
148
292
  renderer.destroy(); // Cleanup
149
293
  ```
150
294
 
151
- ### `compileSystem(system)`
152
-
153
- Compile to protocol-compatible JSON.
154
-
155
- ```typescript
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
- ```
169
-
170
295
  ### `validateSystem(input)`
171
296
 
172
297
  Validate system input without creating.
@@ -180,98 +305,59 @@ if (!result.valid) {
180
305
 
181
306
  ### `getCapabilities()`
182
307
 
183
- Discover SDK capabilities — critical for AI tools and builders.
308
+ Discover SDK capabilities.
184
309
 
185
310
  ```typescript
186
311
  import { getCapabilities } from '@nexart/ui-renderer';
187
312
 
188
313
  const caps = getCapabilities();
189
314
  // {
190
- // version: '0.2.0',
315
+ // version: '0.4.0',
191
316
  // isCanonical: false,
192
317
  // isArchival: false,
193
318
  // 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
319
+ // delegatesTo: '@nexart/codemode-sdk',
320
+ // protocolVersion: '1.0.0',
321
+ // ...
198
322
  // }
199
323
  ```
200
324
 
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
325
  ---
207
326
 
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 |
327
+ ## Delegation Logging
220
328
 
221
- ### Background
329
+ All Code Mode previews log their delegation:
222
330
 
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 |
331
+ ```
332
+ [UIRenderer] Preview delegation → @nexart/codemode-sdk
333
+ [UIRenderer] Protocol version: 1.0.0
334
+ [UIRenderer] Mode: loop
335
+ ```
236
336
 
237
337
  ---
238
338
 
239
- ## For AI Platforms
240
-
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']
339
+ ## Error Mirroring
250
340
 
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
- });
341
+ If the protocol rejects code:
342
+ - Rendering stops immediately
343
+ - Black canvas is displayed
344
+ - Error is logged verbatim
345
+ - No "best effort" recovery
259
346
 
260
- // 3. Preview
261
- previewSystem(system, canvas).render();
262
347
  ```
263
-
264
- **AI Prompt Example:**
265
- ```
266
- "Create a blue background with flowing waves using NexArt"
348
+ [UIRenderer Protocol Error] Forbidden pattern: Math.random() — use random() instead (seeded)
267
349
  ```
268
350
 
269
- The finite vocabulary prevents invalid systems and ensures protocol alignment.
351
+ ---
352
+
353
+ ## What This SDK Does NOT Guarantee
270
354
 
271
- **Key AI Integration Points:**
272
- - `getCapabilities()` — Discover what's possible
273
- - `validateSystem()` Check before creating
274
- - `compileSystem()` Export protocol JSON
355
+ | Not Guaranteed | Explanation |
356
+ |----------------|-------------|
357
+ | Canonical output | Production runtime is the only authority |
358
+ | Archival quality | Output is for preview, not permanent storage |
359
+ | Cross-version stability | Internal rendering may change between SDK versions |
360
+ | Frame-perfect matching | Minor differences from production are expected |
275
361
 
276
362
  ---
277
363
 
@@ -282,21 +368,6 @@ The finite vocabulary prevents invalid systems and ensures protocol alignment.
282
368
  - Safari 13+
283
369
  - Edge 80+
284
370
 
285
- No polyfills required.
286
-
287
- ---
288
-
289
- ## Comparison with @nexart/codemode-sdk
290
-
291
- | Feature | @nexart/ui-renderer | @nexart/codemode-sdk |
292
- |---------|---------------------|----------------------|
293
- | Environment | Browser only | Node.js / Server |
294
- | Purpose | Authoring / Preview | Production / Minting |
295
- | Canonical | ❌ No | ✅ Yes |
296
- | Archival | ❌ No | ✅ Yes |
297
- | Output | Canvas / JSON | PNG / MP4 buffers |
298
- | API | Declarative systems | Code execution |
299
-
300
371
  ---
301
372
 
302
373
  ## License
@@ -304,8 +375,3 @@ No polyfills required.
304
375
  MIT License
305
376
 
306
377
  Copyright (c) 2024 NexArt
307
-
308
- ---
309
-
310
- > **Reminder:** This SDK authors systems. It does NOT invent new rendering rules.
311
- > Canonical execution always happens via `@nexart/codemode-sdk`.
@@ -1,11 +1,12 @@
1
1
  /**
2
- * @nexart/ui-renderer v0.2.0 - System Compiler
2
+ * @nexart/ui-renderer v0.3.0 - System Compiler
3
3
  *
4
4
  * Compiles validated systems into canonical protocol-compatible JSON.
5
5
  */
6
6
  import type { NexArtSystem } from './types';
7
- export interface CompiledSystem {
7
+ export interface CompiledDeclarativeSystem {
8
8
  protocol: 'nexart';
9
+ systemType: 'declarative';
9
10
  systemVersion: string;
10
11
  seed: number;
11
12
  background: {
@@ -29,6 +30,21 @@ export interface CompiledSystem {
29
30
  compiledAt: string;
30
31
  compilerVersion: string;
31
32
  }
33
+ export interface CompiledCodeSystem {
34
+ protocol: 'nexart';
35
+ systemType: 'code';
36
+ systemVersion: string;
37
+ source: string;
38
+ mode: 'static' | 'loop';
39
+ width: number;
40
+ height: number;
41
+ seed: number;
42
+ totalFrames?: number;
43
+ deterministic: boolean;
44
+ compiledAt: string;
45
+ compilerVersion: string;
46
+ }
47
+ export type CompiledSystem = CompiledDeclarativeSystem | CompiledCodeSystem;
32
48
  export declare function compileSystem(system: NexArtSystem): CompiledSystem;
33
49
  export declare function serializeSystem(system: NexArtSystem): string;
34
50
  //# sourceMappingURL=compiler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAiB,MAAM,SAAS,CAAC;AAG3D,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,QAAQ,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE;QACV,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,CAAC,EAAE;YACT,IAAI,EAAE,MAAM,CAAC;YACb,MAAM,EAAE,MAAM,EAAE,CAAC;YACjB,KAAK,CAAC,EAAE,MAAM,CAAC;SAChB,CAAC;KACH,CAAC;IACF,QAAQ,EAAE,KAAK,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,CAAC,GAAG,EAAE,MAAM,GAAG,OA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nB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,QAAQ,GAAG,MAAM,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,OAAO,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,MAAM,cAAc,GAAG,yBAAyB,GAAG,kBAAkB,CAAC;AAI5E,wBAAgB,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,cAAc,CAMlE;AAyFD,wBAAgB,eAAe,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAG5D"}
package/dist/compiler.js CHANGED
@@ -1,22 +1,36 @@
1
1
  /**
2
- * @nexart/ui-renderer v0.2.0 - System Compiler
2
+ * @nexart/ui-renderer v0.3.0 - System Compiler
3
3
  *
4
4
  * Compiles validated systems into canonical protocol-compatible JSON.
5
5
  */
6
- import { validateSystem } from './system';
7
- const COMPILER_VERSION = '0.2.0';
6
+ import { isCodeModeSystem } from './system';
7
+ const COMPILER_VERSION = '0.3.0';
8
8
  export function compileSystem(system) {
9
- const validation = validateSystem({
10
- seed: system.seed,
11
- background: system.background,
12
- elements: system.elements,
13
- motion: system.motion,
14
- });
15
- if (!validation.valid) {
16
- throw new Error(`Cannot compile invalid system: ${validation.errors.join('; ')}`);
9
+ if (isCodeModeSystem(system)) {
10
+ return compileCodeSystem(system);
17
11
  }
12
+ return compileDeclarativeSystem(system);
13
+ }
14
+ function compileCodeSystem(system) {
15
+ return {
16
+ protocol: 'nexart',
17
+ systemType: 'code',
18
+ systemVersion: system.systemVersion,
19
+ source: system.source,
20
+ mode: system.mode,
21
+ width: system.width,
22
+ height: system.height,
23
+ seed: system.seed,
24
+ ...(system.totalFrames !== undefined && { totalFrames: system.totalFrames }),
25
+ deterministic: true,
26
+ compiledAt: new Date().toISOString(),
27
+ compilerVersion: COMPILER_VERSION,
28
+ };
29
+ }
30
+ function compileDeclarativeSystem(system) {
18
31
  const compiled = {
19
32
  protocol: 'nexart',
33
+ systemType: 'declarative',
20
34
  systemVersion: system.systemVersion,
21
35
  seed: system.seed,
22
36
  background: {
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @nexart/ui-renderer
3
- * Version: 0.2.0
3
+ * Version: 0.4.0
4
4
  *
5
- * Declarative System Authoring SDK for NexArt Protocol
5
+ * Opinionated Generative Design System SDK for NexArt Protocol
6
6
  *
7
7
  * ⚠️ IMPORTANT DISCLAIMER
8
8
  *
@@ -15,19 +15,30 @@
15
15
  * - NOT protocol-authoritative
16
16
  *
17
17
  * Use it for:
18
- * - Creating NexArt systems declaratively
18
+ * - Creating NexArt systems with background/primitive/sketch elements
19
19
  * - Previewing systems in the browser
20
- * - Compiling systems to protocol-compatible JSON
20
+ * - Building AI-friendly generative backgrounds
21
21
  * - Building platforms, tools, and integrations
22
+ *
23
+ * Design Philosophy:
24
+ * - Beauty by default > unlimited freedom
25
+ * - Aesthetic guardrails ensure pleasing output automatically
26
+ * - All elements compile to Code Mode for deterministic rendering
22
27
  */
23
- export { createSystem, validateSystem } from './system';
28
+ export { createSystem, validateSystem, isCodeModeSystem, isDeclarativeSystem, isUnifiedModeSystem } from './system';
24
29
  export { compileSystem, serializeSystem } from './compiler';
25
30
  export { previewSystem } from './preview/renderer';
31
+ export { renderCodeModeSystem } from './preview/code-renderer';
32
+ export { renderUnifiedSystem } from './preview/unified-renderer';
33
+ export { compileBackgroundPreset, getPaletteColors } from './presets/backgrounds';
34
+ export { compilePrimitive } from './presets/primitives';
35
+ export { wrapSketch, validateSketchSafety } from './presets/sketch-wrapper';
26
36
  export { getCapabilities, getPrimitiveTypes, getMotionSources, getBackgroundTextures, } from './capabilities';
27
- export type { NexArtSystemInput, NexArtSystem, SystemElement, DotsElement, LinesElement, WavesElement, GridElement, FlowFieldElement, OrbitsElement, BackgroundConfig, MotionConfig, PreviewOptions, ValidationResult, } from './types';
37
+ export type { NexArtSystemInput, NexArtSystem, DeclarativeSystemInput, DeclarativeSystem, CodeSystem, NexArtCodeSystem, UnifiedSystemInput, UnifiedSystem, UnifiedElement, BackgroundElement, PrimitiveElement, SketchElement, BackgroundPreset, PrimitiveName, ColorPalette, MotionSpeed, StrokeWeightAuto, LoopConfig, DeclarativeElement, SystemElement, DotsElement, LinesElement, WavesElement, GridElement, FlowFieldElement, OrbitsElement, BackgroundConfig, MotionConfig, PreviewOptions, ValidationResult, } from './types';
38
+ export { AESTHETIC_DEFAULTS, SDK_VERSION as TYPE_SDK_VERSION } from './types';
28
39
  export type { Capabilities, PrimitiveCapability, ParameterSpec, } from './capabilities';
29
- export declare const SDK_VERSION = "0.2.1";
30
- export declare const PROTOCOL_VERSION = "0.2";
40
+ export declare const SDK_VERSION = "0.4.0";
41
+ export declare const PROTOCOL_VERSION = "0.4";
31
42
  export declare const IS_CANONICAL = false;
32
43
  export declare const IS_ARCHIVAL = false;
33
44
  export declare const RENDERER = "@nexart/ui-renderer";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AAExB,YAAY,EACV,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,gBAAg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